From f6ac379dc03527f907e42d0e7d29f0bf7555b295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Schro=CC=88der?= Date: Sun, 15 Jun 2014 03:23:44 +0200 Subject: [PATCH] plugin settings menu fml value picker --- .../Configurators/ManiaControlSettings.php | 25 +++++++++-------- application/core/Plugins/PluginMenu.php | 27 ++++++++++++------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/application/core/Configurators/ManiaControlSettings.php b/application/core/Configurators/ManiaControlSettings.php index d1a9a27e..27f8dff7 100644 --- a/application/core/Configurators/ManiaControlSettings.php +++ b/application/core/Configurators/ManiaControlSettings.php @@ -307,10 +307,7 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener { } /** - * Save the Config Data - * - * @param array $configData - * @param Player $player + * @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData() */ public function saveConfigData(array $configData, Player $player) { if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_CHANGE_MC_SETTINGS)) { @@ -322,16 +319,20 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener { } $prefixLength = strlen(self::ACTION_PREFIX_SETTING); - foreach ($configData[3] as $settingData) { - $settingIndex = substr($settingData['Name'], $prefixLength); - $setting = $this->maniaControl->settingManager->getSettingObjectByIndex($settingIndex); - if (!$setting || $settingData['Value'] == $setting->value) { + foreach ($configData[3] as $settingData) { + $settingIndex = (int)substr($settingData['Name'], $prefixLength); + $settingObject = $this->maniaControl->settingManager->getSettingObjectByIndex($settingIndex); + if (!$settingObject) { continue; } - $setting->value = $settingData['Value']; - $this->maniaControl->settingManager->saveSetting($setting); + if (!$settingData || $settingData['Value'] == $settingObject->value) { + continue; + } + + $settingObject->value = $settingData['Value']; + $this->maniaControl->settingManager->saveSetting($settingObject); } $this->maniaControl->chat->sendSuccess('Settings saved!', $player); @@ -342,9 +343,7 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener { } /** - * Get the Menu Title - * - * @return string + * @see \ManiaControl\Configurators\ConfiguratorMenu::getTitle() */ public function getTitle() { return self::TITLE; diff --git a/application/core/Plugins/PluginMenu.php b/application/core/Plugins/PluginMenu.php index 6339467d..a2df1749 100644 --- a/application/core/Plugins/PluginMenu.php +++ b/application/core/Plugins/PluginMenu.php @@ -3,6 +3,7 @@ namespace ManiaControl\Plugins; use FML\Components\CheckBox; +use FML\Components\ValuePicker; use FML\Controls\Control; use FML\Controls\Entry; use FML\Controls\Frame; @@ -296,14 +297,23 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns $quad->setSize(4, 4); $checkBox = new CheckBox(self::ACTION_PREFIX_SETTING . $setting->index, $setting->value, $quad); $settingFrame->add($checkBox); + } else if ($setting->type === Setting::TYPE_SET) { + // SET value picker + $label = new Label_Text(); + $label->setX($width * 0.33); + $label->setSize($width * 0.3, $settingHeight * 0.9); + $label->setStyle($label::STYLE_TextValueSmall); + $label->setTextSize(1); + $valuePicker = new ValuePicker(self::ACTION_PREFIX_SETTING . $setting->index, $setting->set, $setting->value, $label); + $settingFrame->add($valuePicker); } else { // Value entry $entry = new Entry(); $settingFrame->add($entry); - $entry->setStyle(Label_Text::STYLE_TextValueSmall); - $entry->setX($width / 2 * 0.65); - $entry->setTextSize(1); + $entry->setX($width * 0.33); $entry->setSize($width * 0.3, $settingHeight * 0.9); + $entry->setTextSize(1); + $entry->setStyle(Label_Text::STYLE_TextValueSmall); $entry->setName(self::ACTION_PREFIX_SETTING . $setting->index); $entry->setDefault($setting->value); } @@ -390,25 +400,24 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns $prefixLength = strlen(self::ACTION_PREFIX_SETTING); - foreach ($configData[3] as $setting) { - $settingIndex = (int)substr($setting['Name'], $prefixLength); - + foreach ($configData[3] as $settingData) { + $settingIndex = (int)substr($settingData['Name'], $prefixLength); $settingObject = $this->maniaControl->settingManager->getSettingObjectByIndex($settingIndex); if (!$settingObject) { continue; } - if ($setting['Value'] == $settingObject->value) { + if (!$settingData || $settingData['Value'] == $settingObject->value) { continue; } - $settingObject->value = $setting['Value']; + $settingObject->value = $settingData['Value']; $this->maniaControl->settingManager->saveSetting($settingObject); } $this->maniaControl->chat->sendSuccess('Plugin Settings saved!', $player); - //Reopen the Menu + // Reopen the Menu $menuId = $this->maniaControl->configurator->getMenuId($this->getTitle()); $this->maniaControl->configurator->reopenMenu($player, $menuId); }