script settings and plugin configurators improvements

This commit is contained in:
Steffen Schröder 2013-12-12 19:41:37 +01:00
parent 196b6eeee4
commit 30717ce343
4 changed files with 185 additions and 89 deletions

View File

@ -215,7 +215,7 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener {
$menuRelationships = array();
$menuItemY = $menuHeight * 0.42;
foreach ($this->menus as $menu) {
foreach ($this->menus as $index => $menu) {
// Add title
$menuItemLabel = new Label();
$menuItemsFrame->add($menuItemLabel);
@ -226,6 +226,9 @@ class Configurator implements CallbackListener, ManialinkPageAnswerListener {
// Add menu
$menuControl = $menu->getMenu($subMenuWidth, $subMenuHeight, $pages, $tooltips);
if ($index > 0) {
$menuControl->setVisible(false);
}
$menusFrame->add($menuControl);
// Add menu relationship

View File

@ -18,14 +18,12 @@ use ManiaControl\Players\Player;
*
* @author steeffeen & kremsy
*/
// TODO: boolean script settings not as entries
class ScriptSettings implements ConfiguratorMenu {
/**
* Constants
*/
const NAME_PREFIX = 'Script.';
const SETTING_TITLE = 'Menu Title';
const SETTING_STYLE_SETTING = 'Setting Label Style';
const SETTING_STYLE_DESCRIPTION = 'Description Label Style';
const ACTION_PREFIX_SETTING = 'ScriptSetting.';
/**
* Private properties
@ -39,11 +37,6 @@ class ScriptSettings implements ConfiguratorMenu {
*/
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
// Init settings
$this->maniaControl->settingManager->initSetting($this, self::SETTING_TITLE, 'Script Settings');
$this->maniaControl->settingManager->initSetting($this, self::SETTING_STYLE_SETTING, Label_Text::STYLE_TextStaticSmall);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_STYLE_DESCRIPTION, Label_Text::STYLE_TextTips);
}
/**
@ -51,9 +44,9 @@ class ScriptSettings implements ConfiguratorMenu {
* @see \ManiaControl\Configurators\ConfiguratorMenu::getTitle()
*/
public function getTitle() {
return $this->maniaControl->settingManager->getSetting($this, self::SETTING_TITLE);
return 'Script Settings';
}
//TODO: boolean values not as entry
/**
*
* @see \ManiaControl\Configurators\ConfiguratorMenu::getMenu()
@ -69,8 +62,6 @@ class ScriptSettings implements ConfiguratorMenu {
$scriptSettings = $this->maniaControl->client->getResponse();
// Config
$labelStyleSetting = $this->maniaControl->settingManager->getSetting($this, self::SETTING_STYLE_SETTING);
$labelStyleDescription = $this->maniaControl->settingManager->getSetting($this, self::SETTING_STYLE_DESCRIPTION);
$pagerSize = 9.;
$settingHeight = 5.;
$labelTextSize = 2;
@ -114,12 +105,12 @@ class ScriptSettings implements ConfiguratorMenu {
$pageFrame->add($settingFrame);
$settingFrame->setY($y);
$nameLabel = new Label();
$nameLabel = new Label_Text();
$settingFrame->add($nameLabel);
$nameLabel->setHAlign(Control::LEFT);
$nameLabel->setX($width * -0.46);
$nameLabel->setSize($width * 0.4, $settingHeight);
$nameLabel->setStyle($labelStyleSetting);
$nameLabel->setStyle($nameLabel::STYLE_TextCardSmall);
$nameLabel->setTextSize($labelTextSize);
$nameLabel->setText($settingName);
@ -127,8 +118,8 @@ class ScriptSettings implements ConfiguratorMenu {
$settingFrame->add($entry);
$entry->setHAlign(Control::RIGHT);
$entry->setX($width * 0.44);
$entry->setSize($width * 0.43, $settingHeight);
$entry->setName(self::NAME_PREFIX . $settingName);
$entry->setSize($width * 0.4, $settingHeight);
$entry->setName(self::ACTION_PREFIX_SETTING . $settingName);
$settingValue = $scriptSettings[$settingName];
if ($settingValue === false) {
$settingValue = 0;
@ -140,7 +131,6 @@ class ScriptSettings implements ConfiguratorMenu {
$descriptionLabel->setHAlign(Control::LEFT);
$descriptionLabel->setPosition($width * -0.45, $height * -0.44);
$descriptionLabel->setSize($width * 0.7, $settingHeight);
$descriptionLabel->setStyle($labelStyleDescription);
$descriptionLabel->setTranslate(true);
$descriptionLabel->setTextPrefix('Desc: ');
$descriptionLabel->setText($scriptParam['Desc']);
@ -166,11 +156,13 @@ class ScriptSettings implements ConfiguratorMenu {
$scriptSettings = $this->maniaControl->client->getResponse();
// var_dump($configData);
// var_dump($scriptSettings);
$prefixLength = strlen(self::NAME_PREFIX);
$prefixLength = strlen(self::ACTION_PREFIX_SETTING);
foreach ($configData[3] as $dataName => $dataValue) {
if (substr($dataName, 0, $prefixLength) != self::NAME_PREFIX) continue;
if (substr($dataName, 0, $prefixLength) != self::ACTION_PREFIX_SETTING) continue;
$settingName = substr($dataName, $prefixLength);
// TODO: apply new script settings
}
}
}

View File

@ -26,7 +26,6 @@ class PluginManager {
private $activePlugins = array();
private $pluginClasses = array();
/**
* Construct plugin manager
*
@ -138,6 +137,40 @@ class PluginManager {
return $active;
}
/**
* Activate and start the plugin with the given name
*
* @param string $pluginClass
* @return bool
*/
public function activatePlugin($pluginClass) {
if (!in_array($pluginClass, $this->pluginClasses)) {
return false;
}
if (isset($this->activePlugins[$pluginClass])) {
return false;
}
$this->savePluginStatus($pluginClass, true);
return true;
}
/**
* Deactivate the plugin with the given name
*
* @param string $pluginClass
* @return bool
*/
public function deactivatePlugin($pluginClass) {
if (!in_array($pluginClass, $this->pluginClasses)) {
return false;
}
if (!isset($this->activePlugins[$pluginClass])) {
return false;
}
$this->savePluginStatus($pluginClass, false);
return true;
}
/**
* Load complete plugins directory and start all configured plugins
*/
@ -165,24 +198,26 @@ class PluginManager {
continue;
}
$plugin = new $className($this->maniaControl);
array_push($this->activePlugins, $plugin);
$this->activePlugins[$className] = $plugin;
}
}
}
/**
* Get all declared plugin class names
*
* @return array
*/
public function getPluginClasses()
{
public function getPluginClasses() {
return $this->pluginClasses;
}
/**
* Get all active plugins
*
* @return array
*/
public function getActivePlugins()
{
public function getActivePlugins() {
return $this->activePlugins;
}
}

View File

@ -12,13 +12,23 @@ use FML\Controls\Frame;
use FML\Controls\Label;
use FML\Controls\Labels\Label_Text;
use FML\Controls\Control;
use FML\Controls\Quads\Quad_Icons64x64_1;
use FML\Controls\Labels\Label_Button;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\CallbackListener;
/**
* Configurator for enabling and disabling plugins
*
* @author steeffeen
*/
class PluginMenu implements ConfiguratorMenu {
class PluginMenu implements CallbackListener, ConfiguratorMenu {
/**
* Constants
*/
const ACTION_PREFIX_ENABLEPLUGIN = 'PluginMenu.Enable.';
const ACTION_PREFIX_DISABLEPLUGIN = 'PluginMenu.Disable.';
/**
* Private properties
*/
@ -31,6 +41,9 @@ class PluginMenu implements ConfiguratorMenu {
*/
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this,
'handleManialinkPageAnswer');
}
/**
@ -38,7 +51,7 @@ class PluginMenu implements ConfiguratorMenu {
* @see \ManiaControl\Configurators\ConfiguratorMenu::getTitle()
*/
public function getTitle() {
return "Plugins";
return 'Plugins';
}
/**
@ -49,15 +62,37 @@ class PluginMenu implements ConfiguratorMenu {
$frame = new Frame();
$pluginClasses = $this->maniaControl->pluginManager->getPluginClasses();
//$labelStyleSetting = $this->maniaControl->settingManager->getSetting($this, self::SETTING_STYLE_SETTING);
$labelStyleSetting = Label_Text::STYLE_TextStaticSmall;
// $pagerSize = 9.;
// Config
$pagerSize = 9.;
$entryHeight = 5.;
$labelTextSize = 2;
// $pageMaxCount = 13;
$pageMaxCount = 10;
// Pagers
$pagerPrev = new Quad_Icons64x64_1();
$frame->add($pagerPrev);
$pagerPrev->setPosition($width * 0.39, $height * -0.44, 2);
$pagerPrev->setSize($pagerSize, $pagerSize);
$pagerPrev->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowPrev);
$pagerNext = new Quad_Icons64x64_1();
$frame->add($pagerNext);
$pagerNext->setPosition($width * 0.45, $height * -0.44, 2);
$pagerNext->setSize($pagerSize, $pagerSize);
$pagerNext->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowNext);
$pageCountLabel = new Label_Text();
$frame->add($pageCountLabel);
$pageCountLabel->setHAlign(Control::RIGHT);
$pageCountLabel->setPosition($width * 0.35, $height * -0.44, 1);
$pageCountLabel->setStyle($pageCountLabel::STYLE_TextTitle1);
$pageCountLabel->setTextSize(2);
// Plugin pages
$pageFrames = array();
$y = 0.;
foreach ($pluginClasses as $pluginClass) {
foreach ($pluginClasses as $index => $pluginClass) {
if (!isset($pageFrame)) {
$pageFrame = new Frame();
$frame->add($pageFrame);
@ -65,64 +100,69 @@ class PluginMenu implements ConfiguratorMenu {
$y = $height * 0.41;
}
//check if plugin is aktiv
$active = $this->maniaControl->pluginManager->getPluginStatus($pluginClass);
$pluginFrame = new Frame();
$pageFrame->add($pluginFrame);
$pluginFrame->setY($y);
$settingFrame = new Frame();
$pageFrame->add($settingFrame);
$settingFrame->setY($y);
$activeQuad = new Quad_Icons64x64_1();
$pluginFrame->add($activeQuad);
$activeQuad->setPosition($width * -0.45, -0.1, 1);
$activeQuad->setSize($entryHeight * 0.9, $entryHeight * 0.9);
if ($active) {
$activeQuad->setSubStyle($activeQuad::SUBSTYLE_LvlGreen);
}
else {
$activeQuad->setSubStyle($activeQuad::SUBSTYLE_LvlRed);
}
//TODO: Red or Green quad to see if the plugin is aktiv (not working yet)
$activeQuad = new Quad();
$settingFrame->add($activeQuad);
if($active)
$activeQuad->setStyles("Icons64x64_1", "LvlGreen");
else
$activeQuad->setStyles("Icons64x64_1", "LvlRed");
$activeQuad->setHeight(5);
$activeQuad->setWidth(5);
$activeQuad->setX($width * -0.455);
//TODO handle z position automatically in fml pls
$nameLabel = new Label();
$settingFrame->add($nameLabel);
$nameLabel = new Label_Text();
$pluginFrame->add($nameLabel);
$nameLabel->setHAlign(Control::LEFT);
$nameLabel->setX($width * -0.4);
$nameLabel->setSize($width * 0.4, $entryHeight);
$nameLabel->setStyle($labelStyleSetting);
$nameLabel->setSize($width * 0.5, $entryHeight);
$nameLabel->setStyle($nameLabel::STYLE_TextCardSmall);
$nameLabel->setTextSize($labelTextSize);
$nameLabel->setText($pluginClass);
$nameLabel->setText($pluginClass::getName());
//TODO description
$descriptionLabel = new Label();
$pageFrame->add($descriptionLabel);
$descriptionLabel->setHAlign(Control::LEFT);
$descriptionLabel->setPosition($width * -0.45, $height * -0.44);
//$descriptionLabel->setSize($width * 0.7, $settingHeight);
//$descriptionLabel->setStyle($labelStyleDescription);
$descriptionLabel->setAlign(Control::LEFT, Control::TOP);
$descriptionLabel->setPosition($width * -0.45, $height * -0.22);
$descriptionLabel->setSize($width * 0.7, $entryHeight);
$descriptionLabel->setTextSize(2);
$descriptionLabel->setTranslate(true);
$descriptionLabel->setTextPrefix('Desc: ');
//$descriptionLabel->setText($scriptParam['Desc']);
$descriptionLabel->setVisible(false);
$descriptionLabel->setAutoNewLine(true);
$descriptionLabel->setMaxLines(5);
$description = "Author: {$pluginClass::getAuthor()}\nVersion: {$pluginClass::getVersion()}\nDesc: {$pluginClass::getDescription()}";
$descriptionLabel->setText($description);
$tooltips->add($nameLabel, $descriptionLabel);
//TODO set aktive button
/*$aktivButton = new Quad();
$aktivButton->setBgColor("F00");
$aktivButton->setHeight(10);
$aktivButton->setWidth(10);
$aktivButton->setX($width * 0.2);
$settingFrame->add($aktivButton);*/
//$aktivButton = new Labels\Label_Button();
$statusChangeButton = new Label_Button();
$pluginFrame->add($statusChangeButton);
$statusChangeButton->setHAlign(Control::RIGHT);
$statusChangeButton->setX($width * 0.45);
$statusChangeButton->setStyle($statusChangeButton::STYLE_CardButtonSmall);
if ($active) {
$statusChangeButton->setTextPrefix('$f00');
$statusChangeButton->setText('Deactivate');
$statusChangeButton->setAction(self::ACTION_PREFIX_DISABLEPLUGIN . $pluginClass);
}
else {
$statusChangeButton->setTextPrefix('a');
$statusChangeButton->setText('Activate');
$statusChangeButton->setAction(self::ACTION_PREFIX_ENABLEPLUGIN . $pluginClass);
}
$y -= $entryHeight;
// if ($index % $pageMaxCount == $pageMaxCount - 1) {
// unset($pageFrame);
//}
if ($index % $pageMaxCount == $pageMaxCount - 1) {
unset($pageFrame);
}
//TODO multiple pages
//$pages->add(array(-1 => $pagerPrev, 1 => $pagerNext), $pageFrames, $pageCountLabel);
}
$pages->add(array(-1 => $pagerPrev, 1 => $pagerNext), $pageFrames, $pageCountLabel);
return $frame;
}
@ -133,6 +173,32 @@ class PluginMenu implements ConfiguratorMenu {
*/
public function saveConfigData(array $configData, Player $player) {
}
/**
* Handle PlayerManialinkPageAnswer callback
*
* @param array $callback
*/
public function handleManialinkPageAnswer(array $callback) {
$actionId = $callback[1][2];
$enable = (strpos($actionId, self::ACTION_PREFIX_ENABLEPLUGIN) === 0);
$disable = (strpos($actionId, self::ACTION_PREFIX_DISABLEPLUGIN) === 0);
if (!$enable && !$disable) {
return;
}
$login = $callback[1][1];
$player = $this->maniaControl->playerManager->getPlayer($login);
if (!$player) {
return;
}
if ($enable) {
$pluginClass = substr($actionId, strlen(self::ACTION_PREFIX_ENABLEPLUGIN));
}
else {
$pluginClass = substr($actionId, strlen(self::ACTION_PREFIX_DISABLEPLUGIN));
}
var_dump($pluginClass);
}
}
?>