improved plugin menu

use player cache for selected setting class
This commit is contained in:
Steffen Schröder 2014-05-09 20:11:48 +02:00
parent 6fd7775bcb
commit ba0f417f59
3 changed files with 155 additions and 139 deletions

View File

@ -61,6 +61,7 @@ class ManiaControl implements CommandListener, TimerListener {
public $authenticationManager = null; public $authenticationManager = null;
public $callbackManager = null; public $callbackManager = null;
public $chat = null; public $chat = null;
/** @var \SimpleXMLElement $config */
public $config = null; public $config = null;
public $configurator = null; public $configurator = null;
/** /**

View File

@ -244,10 +244,40 @@ class Player {
$this->currentTargetId = intval($spectatorStatus / 10000); $this->currentTargetId = intval($spectatorStatus / 10000);
} }
/**
* Get the Cache with the given Name
*
* @param string $cacheName
* @return mixed
*/
public function getCache($cacheName) {
if (isset($this->cache[$cacheName])) {
return $this->cache[$cacheName];
}
return null;
}
/**
* Set the Cache Data for the given Name
*
* @param string $cacheName
* @param mixed $data
*/
public function setCache($cacheName, $data) {
$this->cache[$cacheName] = data;
}
/** /**
* Clear the Player's Temporary Data * Clear the Player's Temporary Data
*/ */
public function clearCache() { public function clearCache() {
$this->cache = array(); $this->cache = array();
} }
/**
* Var_Dump the Player
*/
public function dump() {
var_dump(json_decode(json_encode($this)));
}
} }

View File

@ -17,10 +17,10 @@ use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Configurators\ConfiguratorMenu; use ManiaControl\Configurators\ConfiguratorMenu;
use ManiaControl\Formatter;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkPageAnswerListener; use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use ManiaControl\Settings\SettingManager;
/** /**
* Configurator for enabling and disabling Plugins * Configurator for enabling and disabling Plugins
@ -42,12 +42,12 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
const ACTION_PREFIX_UPDATEPLUGIN = 'PluginMenu.Update.'; const ACTION_PREFIX_UPDATEPLUGIN = 'PluginMenu.Update.';
const ACTION_UPDATEPLUGINS = 'PluginMenu.Update.All'; const ACTION_UPDATEPLUGINS = 'PluginMenu.Update.All';
const SETTING_PERMISSION_CHANGE_PLUGIN_SETTINGS = 'Change Plugin Settings'; const SETTING_PERMISSION_CHANGE_PLUGIN_SETTINGS = 'Change Plugin Settings';
const CACHE_SETTING_CLASS = 'PluginMenuCache.SettingClass';
/* /*
* Private Properties * Private Properties
*/ */
private $maniaControl = null; private $maniaControl = null;
private $settingsClass = ''; //TODO needs to be improved
/** /**
* Create a new plugin menu instance * Create a new plugin menu instance
@ -66,7 +66,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
* Returns Back to the Plugins * Returns Back to the Plugins
*/ */
public function backToPlugins($callback, Player $player) { public function backToPlugins($callback, Player $player) {
$this->settingsClass = ''; //TODO specify player unset($player->cache[self::CACHE_SETTING_CLASS]);
$menuId = $this->maniaControl->configurator->getMenuId($this->getTitle()); $menuId = $this->maniaControl->configurator->getMenuId($this->getTitle());
$this->maniaControl->configurator->reopenMenu($player, $menuId); $this->maniaControl->configurator->reopenMenu($player, $menuId);
} }
@ -91,7 +91,6 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
// Config // Config
$pagerSize = 9.; $pagerSize = 9.;
$entryHeight = 5.; $entryHeight = 5.;
$labelTextSize = 2;
$pageMaxCount = 10; $pageMaxCount = 10;
// Pagers // Pagers
@ -119,128 +118,14 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
$paging->setLabel($pageCountLabel); $paging->setLabel($pageCountLabel);
//Show Settings Menu $settingClass = $player->getCache(self::CACHE_SETTING_CLASS);
if ($this->settingsClass != '') { //TODO improve if ($settingClass) {
/** @var ManiaControl/SettingManager $this->maniaControl->settingManager */ // Show Settings Menu
$settings = $this->maniaControl->settingManager->getSettingsByClass($this->settingsClass); return $this->getPluginSettingsMenu($frame, $width, $height, $paging, $player, $settingClass);
$pageFrames = array();
$pageSettingsMaxCount = 12;
$y = 0;
$index = 1;
$settingHeight = 5.;
foreach ($settings as $setting) {
if (!isset($pageFrame)) {
$pageFrame = new Frame();
$frame->add($pageFrame);
if (!empty($pageFrames)) {
$pageFrame->setVisible(false);
}
array_push($pageFrames, $pageFrame);
$y = $height * 0.41;
$paging->addPage($pageFrame);
} }
$settingFrame = new Frame(); // Display normal Plugin List
$pageFrame->add($settingFrame);
$settingFrame->setY($y);
if ($index == 1) {
//Headline Label
$headLabel = new Label_Text();
$settingFrame->add($headLabel);
$headLabel->setHAlign(Control::LEFT);
$headLabel->setX($width * -0.46);
$headLabel->setSize($width * 0.6, $settingHeight);
$headLabel->setStyle($headLabel::STYLE_TextCardSmall);
$headLabel->setTextSize($labelTextSize);
$headLabel->setText($setting->class);
$headLabel->setTextColor("F00");
$y -= $settingHeight;
if ($index % $pageMaxCount == $pageMaxCount - 1) {
$pageFrame = new Frame();
$frame->add($pageFrame);
if (!empty($pageFrames)) {
$pageFrame->setVisible(false);
}
array_push($pageFrames, $pageFrame);
$y = $height * 0.41;
$paging->addPage($pageFrame);
}
}
$settingFrame = new Frame();
$pageFrame->add($settingFrame);
$settingFrame->setY($y);
//Headline Label finished
$nameLabel = new Label_Text();
$settingFrame->add($nameLabel);
$nameLabel->setHAlign(Control::LEFT);
$nameLabel->setX($width * -0.46);
$nameLabel->setSize($width * 0.6, $settingHeight);
$nameLabel->setStyle($nameLabel::STYLE_TextCardSmall);
$nameLabel->setTextSize($labelTextSize);
$nameLabel->setText($setting->setting);
$nameLabel->setTextColor("FFF");
$substyle = '';
$entry = new Entry();
$settingFrame->add($entry);
$entry->setStyle(Label_Text::STYLE_TextValueSmall);
$entry->setHAlign(Control::CENTER);
$entry->setX($width / 2 * 0.65);
$entry->setTextSize(1);
$entry->setSize($width * 0.3, $settingHeight * 0.9);
$entry->setName(self::ACTION_PREFIX_SETTING . '.' . $setting->index);
$entry->setDefault($setting->value);
if ($setting->type == "bool") {
if ($setting->value == "0") {
$substyle = Quad_Icons64x64_1::SUBSTYLE_LvlRed;
} else if ($setting->value == "1") {
$substyle = Quad_Icons64x64_1::SUBSTYLE_LvlGreen;
}
$quad = new Quad_Icons64x64_1();
$settingFrame->add($quad);
$quad->setX($width / 2 * 0.6);
$quad->setZ(-0.01);
$quad->setSubStyle($substyle);
$quad->setSize(4, 4);
$quad->setHAlign(Control::CENTER2);
$quad->setAction(self::ACTION_SETTING_BOOL . $setting->index);
$entry->setVisible(false);
}
$y -= $settingHeight;
if ($index % $pageSettingsMaxCount == $pageSettingsMaxCount - 1) {
unset($pageFrame);
}
$index++;
}
$quad = new Label_Button();
$frame->add($quad);
$quad->setStyle($quad::STYLE_CardMain_Quit);
$quad->setHAlign(Control::LEFT);
$quad->setScale(0.75);
$quad->setText("Back");
$quad->setPosition(-$width / 2 + 7, -$height / 2 + 7);
$quad->setAction(self::ACTION_BACK_TO_PLUGINS);
return $frame;
}
//Display normal Plugin List
// Plugin pages // Plugin pages
$pageFrames = array();
$y = 0.; $y = 0.;
$pluginUpdates = $this->maniaControl->updateManager->pluginUpdateManager->getPluginsUpdates(); $pluginUpdates = $this->maniaControl->updateManager->pluginUpdateManager->getPluginsUpdates();
@ -252,14 +137,9 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
foreach ($pluginClasses as $index => $pluginClass) { foreach ($pluginClasses as $index => $pluginClass) {
/** @var Plugin $pluginClass */ /** @var Plugin $pluginClass */
if (!isset($pageFrame)) { if ($index % $pageMaxCount === 0) {
$pageFrame = new Frame(); $pageFrame = new Frame();
$frame->add($pageFrame); $frame->add($pageFrame);
if (!empty($pageFrames)) {
$pageFrame->setVisible(false);
}
array_push($pageFrames, $pageFrame);
$paging->addPage($pageFrame); $paging->addPage($pageFrame);
$y = $height * 0.41; $y = $height * 0.41;
} }
@ -286,7 +166,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
$nameLabel->setX($width * -0.4); $nameLabel->setX($width * -0.4);
$nameLabel->setSize($width * 0.5, $entryHeight); $nameLabel->setSize($width * 0.5, $entryHeight);
$nameLabel->setStyle($nameLabel::STYLE_TextCardSmall); $nameLabel->setStyle($nameLabel::STYLE_TextCardSmall);
$nameLabel->setTextSize($labelTextSize); $nameLabel->setTextSize(2);
$nameLabel->setText($pluginClass::getName()); $nameLabel->setText($pluginClass::getName());
$descriptionLabel = new Label(); $descriptionLabel = new Label();
@ -337,9 +217,6 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
} }
$y -= $entryHeight; $y -= $entryHeight;
if ($index % $pageMaxCount == $pageMaxCount - 1) {
unset($pageFrame);
}
} }
if ($pluginUpdates != false) { if ($pluginUpdates != false) {
@ -358,6 +235,114 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
return $frame; return $frame;
} }
/**
* Get the Frame with the Plugin Settings
*
* @param Frame $frame
* @param float $width
* @param float $height
* @param Paging $paging
* @param Player $player
* @param string $settingClass
* @return Frame
*/
private function getPluginSettingsMenu(Frame $frame, $width, $height, Paging $paging, Player $player, $settingClass) {
$settings = $this->maniaControl->settingManager->getSettingsByClass($settingClass);
$pageSettingsMaxCount = 12;
$y = 0;
$index = 0;
$settingHeight = 5.;
foreach ($settings as $setting) {
if ($index % $pageSettingsMaxCount === 0) {
$pageFrame = new Frame();
$frame->add($pageFrame);
$paging->addPage($pageFrame);
$y = $height * 0.41;
}
$settingFrame = new Frame();
$pageFrame->add($settingFrame);
$settingFrame->setY($y);
if ($index === 0) {
//Headline Label
$headLabel = new Label_Text();
$settingFrame->add($headLabel);
$headLabel->setHAlign(Control::LEFT);
$headLabel->setX($width * -0.46);
$headLabel->setSize($width * 0.6, $settingHeight);
$headLabel->setStyle($headLabel::STYLE_TextCardSmall);
$headLabel->setTextSize(2);
$headLabel->setText($setting->class);
$headLabel->setTextColor("F00");
$y -= $settingHeight;
}
$settingFrame = new Frame();
$pageFrame->add($settingFrame);
$settingFrame->setY($y);
// Headline Label finished
$nameLabel = new Label_Text();
$settingFrame->add($nameLabel);
$nameLabel->setHAlign(Control::LEFT);
$nameLabel->setX($width * -0.46);
$nameLabel->setSize($width * 0.6, $settingHeight);
$nameLabel->setStyle($nameLabel::STYLE_TextCardSmall);
$nameLabel->setTextSize(2);
$nameLabel->setText($setting->setting);
$nameLabel->setTextColor("FFF");
$substyle = '';
$entry = new Entry();
$settingFrame->add($entry);
$entry->setStyle(Label_Text::STYLE_TextValueSmall);
$entry->setHAlign(Control::CENTER);
$entry->setX($width / 2 * 0.65);
$entry->setTextSize(1);
$entry->setSize($width * 0.3, $settingHeight * 0.9);
$entry->setName(self::ACTION_PREFIX_SETTING . '.' . $setting->index);
$entry->setDefault($setting->value);
if ($setting->type === SettingManager::TYPE_BOOL) {
if ($setting->value == "0") {
$substyle = Quad_Icons64x64_1::SUBSTYLE_LvlRed;
} else if ($setting->value == "1") {
$substyle = Quad_Icons64x64_1::SUBSTYLE_LvlGreen;
}
$quad = new Quad_Icons64x64_1();
$settingFrame->add($quad);
$quad->setX($width / 2 * 0.6);
$quad->setZ(-0.01);
$quad->setSubStyle($substyle);
$quad->setSize(4, 4);
$quad->setHAlign(Control::CENTER2);
$quad->setAction(self::ACTION_SETTING_BOOL . $setting->index);
$entry->setVisible(false);
}
$y -= $settingHeight;
$index++;
}
$quad = new Label_Button();
$frame->add($quad);
$quad->setStyle($quad::STYLE_CardMain_Quit);
$quad->setHAlign(Control::LEFT);
$quad->setScale(0.75);
$quad->setText("Back");
$quad->setPosition(-$width / 2 + 7, -$height / 2 + 7);
$quad->setAction(self::ACTION_BACK_TO_PLUGINS);
return $frame;
}
/** /**
* Handle PlayerManialinkPageAnswer callback * Handle PlayerManialinkPageAnswer callback
* *
@ -402,7 +387,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
} else if ($settings) { } else if ($settings) {
// Open Settings Menu // Open Settings Menu
$pluginClass = substr($actionId, strlen(self::ACTION_PREFIX_SETTINGS)); $pluginClass = substr($actionId, strlen(self::ACTION_PREFIX_SETTINGS));
$this->settingsClass = $pluginClass; $player->cache[self::CACHE_SETTING_CLASS] = $pluginClass;
} else if ($boolSetting) { } else if ($boolSetting) {
$actionArray = explode(".", $actionId); $actionArray = explode(".", $actionId);
$setting = $actionArray[1]; $setting = $actionArray[1];