implemented checkbox for mc settings

This commit is contained in:
Steffen Schröder 2014-06-15 02:13:00 +02:00
parent 65919efb43
commit 4ed545d7a5
2 changed files with 9 additions and 55 deletions

View File

@ -2,12 +2,14 @@
namespace ManiaControl\Configurators; namespace ManiaControl\Configurators;
use FML\Components\CheckBox;
use FML\Components\ValuePicker; use FML\Components\ValuePicker;
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\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_Icons64x64_1; use FML\Controls\Quads\Quad_Icons64x64_1;
use FML\Script\Features\Paging; use FML\Script\Features\Paging;
use FML\Script\Script; use FML\Script\Script;
@ -33,7 +35,6 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
const ACTION_PREFIX_SETTING = 'MCSetting.'; const ACTION_PREFIX_SETTING = 'MCSetting.';
const ACTION_PREFIX_SETTINGCLASS = 'MCSettingClass.'; const ACTION_PREFIX_SETTINGCLASS = 'MCSettingClass.';
const ACTION_SETTINGCLASS_BACK = 'MCSettingClassBack'; const ACTION_SETTINGCLASS_BACK = 'MCSettingClassBack';
const ACTION_SETTING_BOOL = 'MCSettings.ActionBoolSetting.';
const SETTING_PERMISSION_CHANGE_MC_SETTINGS = 'Change ManiaControl Settings'; const SETTING_PERMISSION_CHANGE_MC_SETTINGS = 'Change ManiaControl Settings';
const CACHE_CLASS_OPENED = 'ClassOpened'; const CACHE_CLASS_OPENED = 'ClassOpened';
@ -161,13 +162,12 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
$settingName = self::ACTION_PREFIX_SETTING . $setting->index; $settingName = self::ACTION_PREFIX_SETTING . $setting->index;
if ($setting->type === Setting::TYPE_BOOL) { if ($setting->type === Setting::TYPE_BOOL) {
// TODO: implement fml checkbox // Boolean checkbox
$quad = new Quad_Icons64x64_1(); $quad = new Quad();
$settingFrame->add($quad);
$quad->setPosition($width * 0.33, 0, -0.01); $quad->setPosition($width * 0.33, 0, -0.01);
$quad->setSize(4, 4); $quad->setSize(4, 4);
$quad->setSubStyle(($setting->value ? $quad::SUBSTYLE_LvlGreen : $quad::SUBSTYLE_LvlRed)); $checkBox = new CheckBox($settingName, $setting->value, $quad);
$quad->setAction($settingName); $settingFrame->add($checkBox);
} else if ($setting->type === Setting::TYPE_SET) { } else if ($setting->type === Setting::TYPE_SET) {
// SET value picker // SET value picker
$label = new Label_Text(); $label = new Label_Text();
@ -293,24 +293,6 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
$player->destroyCache($this, self::CACHE_CLASS_OPENED); $player->destroyCache($this, self::CACHE_CLASS_OPENED);
$menuId = $this->maniaControl->configurator->getMenuId($this); $menuId = $this->maniaControl->configurator->getMenuId($this);
$this->maniaControl->configurator->showMenu($player, $menuId); $this->maniaControl->configurator->showMenu($player, $menuId);
} else if (strpos($actionId, self::ACTION_SETTING_BOOL) === 0) {
// Bool setting change
$settingIndex = (int)substr($actionId, strlen(self::ACTION_SETTING_BOOL));
$login = $callback[1][1];
$player = $this->maniaControl->playerManager->getPlayer($login);
// Toggle the Boolean Setting
$this->toggleBooleanSetting($settingIndex, $player);
if ($callback[1][3]) {
// Save all Changes
$this->saveConfigData($callback[1], $player);
} else {
// Reopen menu directly
$menuId = $this->maniaControl->configurator->getMenuId($this);
$this->maniaControl->configurator->reopenMenu($player, $menuId);
}
} else if (strpos($actionId, self::ACTION_PREFIX_SETTINGCLASS) === 0) { } else if (strpos($actionId, self::ACTION_PREFIX_SETTINGCLASS) === 0) {
// Setting class selected // Setting class selected
$settingClass = substr($actionId, strlen(self::ACTION_PREFIX_SETTINGCLASS)); $settingClass = substr($actionId, strlen(self::ACTION_PREFIX_SETTINGCLASS));
@ -324,28 +306,6 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
} }
} }
/**
* Toggles 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_MC_SETTINGS)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player);
return;
}
$oldSetting = $this->maniaControl->settingManager->getSettingObjectByIndex($settingIndex);
if (!$oldSetting) {
var_dump('no setting ' . $settingIndex);
return;
}
// Toggle value
$this->maniaControl->settingManager->setSetting($oldSetting->class, $oldSetting->setting, !$oldSetting->value);
}
/** /**
* Save the Config Data * Save the Config Data
* *
@ -358,16 +318,15 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
return; return;
} }
if (!$configData[3] || strpos($configData[3][0]['Name'], self::ACTION_PREFIX_SETTING) !== 0) { if (!$configData[3] || strpos($configData[3][0]['Name'], self::ACTION_PREFIX_SETTING) !== 0) {
// TODO: improve needed, this won't save configData passed by boolean setting change
return; return;
} }
$prefixLength = strlen(self::ACTION_PREFIX_SETTING); $prefixLength = strlen(self::ACTION_PREFIX_SETTING);
foreach ($configData[3] as $settingData) { foreach ($configData[3] as $settingData) {
$settingIndex = substr($settingData['Name'], $prefixLength); $settingIndex = substr($settingData['Name'], $prefixLength);
$setting = $this->maniaControl->settingManager->getSettingObjectByIndex($settingIndex); $setting = $this->maniaControl->settingManager->getSettingObjectByIndex($settingIndex);
if (!$setting || $settingData['Value'] == $setting->value || $setting->type === Setting::TYPE_BOOL) {
if (!$setting || $settingData['Value'] == $setting->value) {
continue; continue;
} }

View File

@ -307,12 +307,7 @@ class SettingManager implements CallbackListener {
`default`, `default`,
`set` `set`
) VALUES ( ) VALUES (
?, ?, ?, ?, ?, ?, ?
?,
?,
?,
?,
?
) ON DUPLICATE KEY UPDATE ) ON DUPLICATE KEY UPDATE
`index` = LAST_INSERT_ID(`index`), `index` = LAST_INSERT_ID(`index`),
`type` = VALUES(`type`), `type` = VALUES(`type`),