plugin settings menu fml checkbox

This commit is contained in:
Steffen Schröder 2014-06-15 03:15:06 +02:00
parent a16e00356b
commit 7488e83cb5

View File

@ -2,12 +2,14 @@
namespace ManiaControl\Plugins; namespace ManiaControl\Plugins;
use FML\Components\CheckBox;
use FML\Controls\Control; use FML\Controls\Control;
use FML\Controls\Entry; use FML\Controls\Entry;
use FML\Controls\Frame; use FML\Controls\Frame;
use FML\Controls\Label; use FML\Controls\Label;
use FML\Controls\Labels\Label_Button; use FML\Controls\Labels\Label_Button;
use FML\Controls\Labels\Label_Text; use FML\Controls\Labels\Label_Text;
use FML\Controls\Quad;
use FML\Controls\Quads\Quad_Icons128x128_1; use FML\Controls\Quads\Quad_Icons128x128_1;
use FML\Controls\Quads\Quad_Icons128x32_1; use FML\Controls\Quads\Quad_Icons128x32_1;
use FML\Controls\Quads\Quad_Icons64x64_1; use FML\Controls\Quads\Quad_Icons64x64_1;
@ -37,7 +39,6 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
const ACTION_PREFIX_DISABLEPLUGIN = 'PluginMenu.Disable.'; const ACTION_PREFIX_DISABLEPLUGIN = 'PluginMenu.Disable.';
const ACTION_PREFIX_SETTINGS = 'PluginMenu.Settings.'; const ACTION_PREFIX_SETTINGS = 'PluginMenu.Settings.';
const ACTION_PREFIX_SETTING = 'PluginMenuSetting.'; const ACTION_PREFIX_SETTING = 'PluginMenuSetting.';
const ACTION_SETTING_BOOL = 'PluginMenuActionBoolSetting.';
const ACTION_BACK_TO_PLUGINS = 'PluginMenu.BackToPlugins'; const ACTION_BACK_TO_PLUGINS = 'PluginMenu.BackToPlugins';
const ACTION_PREFIX_UPDATEPLUGIN = 'PluginMenu.Update.'; const ACTION_PREFIX_UPDATEPLUGIN = 'PluginMenu.Update.';
const ACTION_UPDATEPLUGINS = 'PluginMenu.Update.All'; const ACTION_UPDATEPLUGINS = 'PluginMenu.Update.All';
@ -50,7 +51,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
private $maniaControl = null; private $maniaControl = null;
/** /**
* Create a new plugin menu instance * Create a new Plugin Menu Instance
* *
* @param ManiaControl $maniaControl * @param ManiaControl $maniaControl
*/ */
@ -246,47 +247,38 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
* @return Frame * @return Frame
*/ */
private function getPluginSettingsMenu(Frame $frame, $width, $height, Paging $paging, Player $player, $settingClass) { private function getPluginSettingsMenu(Frame $frame, $width, $height, Paging $paging, Player $player, $settingClass) {
// TODO: use maniacontrol settings menu // TODO: centralize menu code to use by mc settings and plugin settings
$settings = $this->maniaControl->settingManager->getSettingsByClass($settingClass); $settings = $this->maniaControl->settingManager->getSettingsByClass($settingClass);
$pageSettingsMaxCount = 12; $pageSettingsMaxCount = 11;
$posY = 0; $posY = 0;
$index = 0; $index = 0;
$settingHeight = 5.; $settingHeight = 5.;
$pageFrame = null; $pageFrame = null;
//Headline Label
$headLabel = new Label_Text();
$frame->add($headLabel);
$headLabel->setHAlign($headLabel::LEFT);
$headLabel->setPosition($width * -0.46, $height * 0.41);
$headLabel->setSize($width * 0.6, $settingHeight);
$headLabel->setStyle($headLabel::STYLE_TextCardSmall);
$headLabel->setTextSize(3);
$headLabel->setText($settingClass);
$headLabel->setTextColor('ff0');
foreach ($settings as $setting) { foreach ($settings as $setting) {
if ($index % $pageSettingsMaxCount === 0) { if ($index % $pageSettingsMaxCount === 0) {
$pageFrame = new Frame(); $pageFrame = new Frame();
$frame->add($pageFrame); $frame->add($pageFrame);
$paging->addPage($pageFrame); $paging->addPage($pageFrame);
$posY = $height * 0.41; $posY = $height * 0.41 - $settingHeight * 1.5;
} }
$settingFrame = new Frame(); $settingFrame = new Frame();
$pageFrame->add($settingFrame); $pageFrame->add($settingFrame);
$settingFrame->setY($posY); $settingFrame->setY($posY);
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");
$posY -= $settingHeight;
}
$settingFrame = new Frame();
$pageFrame->add($settingFrame);
$settingFrame->setY($posY);
// Headline Label finished
$nameLabel = new Label_Text(); $nameLabel = new Label_Text();
$settingFrame->add($nameLabel); $settingFrame->add($nameLabel);
$nameLabel->setHAlign(Control::LEFT); $nameLabel->setHAlign(Control::LEFT);
@ -297,6 +289,15 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
$nameLabel->setText($setting->setting); $nameLabel->setText($setting->setting);
$nameLabel->setTextColor("FFF"); $nameLabel->setTextColor("FFF");
if ($setting->type === Setting::TYPE_BOOL) {
// Boolean checkbox
$quad = new Quad();
$quad->setPosition($width * 0.33, 0, -0.01);
$quad->setSize(4, 4);
$checkBox = new CheckBox(self::ACTION_PREFIX_SETTING . $setting->index, $setting->value, $quad);
$settingFrame->add($checkBox);
} else {
// Value entry
$entry = new Entry(); $entry = new Entry();
$settingFrame->add($entry); $settingFrame->add($entry);
$entry->setStyle(Label_Text::STYLE_TextValueSmall); $entry->setStyle(Label_Text::STYLE_TextValueSmall);
@ -305,22 +306,6 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
$entry->setSize($width * 0.3, $settingHeight * 0.9); $entry->setSize($width * 0.3, $settingHeight * 0.9);
$entry->setName(self::ACTION_PREFIX_SETTING . $setting->index); $entry->setName(self::ACTION_PREFIX_SETTING . $setting->index);
$entry->setDefault($setting->value); $entry->setDefault($setting->value);
if ($setting->type === Setting::TYPE_BOOL) {
if ($setting->value) {
$substyle = Quad_Icons64x64_1::SUBSTYLE_LvlGreen;
} else {
$substyle = Quad_Icons64x64_1::SUBSTYLE_LvlRed;
}
$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->setAction(self::ACTION_SETTING_BOOL . $setting->index);
$entry->setVisible(false);
} }
$posY -= $settingHeight; $posY -= $settingHeight;
@ -356,8 +341,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
$enable = (strpos($actionId, self::ACTION_PREFIX_ENABLEPLUGIN) === 0); $enable = (strpos($actionId, self::ACTION_PREFIX_ENABLEPLUGIN) === 0);
$disable = (strpos($actionId, self::ACTION_PREFIX_DISABLEPLUGIN) === 0); $disable = (strpos($actionId, self::ACTION_PREFIX_DISABLEPLUGIN) === 0);
$settings = (strpos($actionId, self::ACTION_PREFIX_SETTINGS) === 0); $settings = (strpos($actionId, self::ACTION_PREFIX_SETTINGS) === 0);
$boolSetting = (strpos($actionId, self::ACTION_SETTING_BOOL) === 0); if (!$enable && !$disable && !$settings) {
if (!$enable && !$disable && !$settings && !$boolSetting) {
return; return;
} }
@ -385,15 +369,6 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
// Open Settings Menu // Open Settings Menu
$pluginClass = substr($actionId, strlen(self::ACTION_PREFIX_SETTINGS)); $pluginClass = substr($actionId, strlen(self::ACTION_PREFIX_SETTINGS));
$player->setCache($this, self::CACHE_SETTING_CLASS, $pluginClass); $player->setCache($this, self::CACHE_SETTING_CLASS, $pluginClass);
} else if ($boolSetting) {
$actionArray = explode(".", $actionId);
$setting = $actionArray[1];
// Toggle the Boolean Setting
$this->toggleBooleanSetting($setting, $player);
// Save all Changes
$this->saveConfigData($callback[1], $player);
} }
// Reopen the Menu // Reopen the Menu
@ -401,28 +376,6 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
$this->maniaControl->configurator->reopenMenu($player, $menuId); $this->maniaControl->configurator->reopenMenu($player, $menuId);
} }
/**
* Toggle a Boolean Value
*
* @param int $settingIndex
* @param Player $player
*/
public function toggleBooleanSetting($settingIndex, Player $player) {
if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_CHANGE_PLUGIN_SETTINGS)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player);
return;
}
$oldSetting = $this->maniaControl->settingManager->getSettingObjectByIndex($settingIndex);
if (!$oldSetting) {
var_dump('no setting with index: ' . $settingIndex);
return;
}
// Toggle value
$this->maniaControl->settingManager->setSetting($oldSetting->class, $oldSetting->setting, !$oldSetting->value);
}
/** /**
* @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData() * @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData()
*/ */
@ -445,7 +398,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
continue; continue;
} }
if ($setting['Value'] == $settingObject->value || $settingObject->type === $settingObject::TYPE_BOOL) { if ($setting['Value'] == $settingObject->value) {
continue; continue;
} }