server setting with checkboxes for boolean values

This commit is contained in:
Steffen Schröder 2014-05-15 23:05:57 +02:00
parent f7070a51e1
commit db3d59d47f
2 changed files with 30 additions and 70 deletions

View File

@ -2,11 +2,13 @@
namespace ManiaControl\Configurators; namespace ManiaControl\Configurators;
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_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;
@ -28,8 +30,7 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
/* /*
* Constants * Constants
*/ */
const ACTION_PREFIX_SETTING = 'ServerSettings'; const ACTION_PREFIX_SETTING = 'ServerSettings.';
const ACTION_SETTING_BOOL = 'ServerSettings.ActionBoolSetting.';
const CB_SERVERSETTING_CHANGED = 'ServerSettings.SettingChanged'; const CB_SERVERSETTING_CHANGED = 'ServerSettings.SettingChanged';
const CB_SERVERSETTINGS_CHANGED = 'ServerSettings.SettingsChanged'; const CB_SERVERSETTINGS_CHANGED = 'ServerSettings.SettingsChanged';
const TABLE_SERVER_SETTINGS = 'mc_serversettings'; const TABLE_SERVER_SETTINGS = 'mc_serversettings';
@ -50,7 +51,6 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
$this->initTables(); $this->initTables();
// Register for callbacks // Register for callbacks
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_ONINIT, $this, 'onInit'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_ONINIT, $this, 'onInit');
//Permission for Change Script-Settings //Permission for Change Script-Settings
@ -141,7 +141,6 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
$pagerSize = 9.; $pagerSize = 9.;
$settingHeight = 5.; $settingHeight = 5.;
$labelTextSize = 2; $labelTextSize = 2;
$pageMaxCount = 13;
// Pagers // Pagers
$pagerPrev = new Quad_Icons64x64_1(); $pagerPrev = new Quad_Icons64x64_1();
@ -201,13 +200,18 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
$nameLabel->setText($name); $nameLabel->setText($name);
$nameLabel->setTextColor("FFF"); $nameLabel->setTextColor("FFF");
$substyle = ''; if (is_bool($value)) {
if ($value === false) { // Boolean checkbox
$substyle = Quad_Icons64x64_1::SUBSTYLE_LvlRed; $checkBox = new CheckBox(self::ACTION_PREFIX_SETTING . $name, $value);
} else if ($value === true) { $settingFrame->add($checkBox);
$substyle = Quad_Icons64x64_1::SUBSTYLE_LvlGreen;
}
$quad = new Quad();
$checkBox->setQuad($quad);
$quad->setX($width / 2 * 0.46);
$quad->setZ(-0.01);
$quad->setSize(4, 4);
} else {
// Other
$entry = new Entry(); $entry = new Entry();
$settingFrame->add($entry); $settingFrame->add($entry);
$entry->setStyle(Label_Text::STYLE_TextValueSmall); $entry->setStyle(Label_Text::STYLE_TextValueSmall);
@ -215,7 +219,7 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
$entry->setX($width / 2 * 0.46); $entry->setX($width / 2 * 0.46);
$entry->setTextSize(1); $entry->setTextSize(1);
$entry->setSize($width * 0.48, $settingHeight * 0.9); $entry->setSize($width * 0.48, $settingHeight * 0.9);
$entry->setName(self::ACTION_PREFIX_SETTING . '.' . $name); $entry->setName(self::ACTION_PREFIX_SETTING . $name);
$entry->setDefault($value); $entry->setDefault($value);
if ($name == "Comment") { // if ($name == "Comment") { //
@ -226,18 +230,6 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
$y -= $settingHeight * 3; $y -= $settingHeight * 3;
$id += 3; $id += 3;
} }
if ($substyle != '') {
$quad = new Quad_Icons64x64_1();
$settingFrame->add($quad);
$quad->setX($width / 2 * 0.46);
$quad->setZ(-0.01);
$quad->setSubStyle($substyle);
$quad->setSize(4, 4);
$quad->setHAlign(Control::CENTER);
$quad->setAction(self::ACTION_SETTING_BOOL . $name);
$entry->setVisible(false);
} }
$y -= $settingHeight; $y -= $settingHeight;
@ -247,25 +239,6 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
return $frame; return $frame;
} }
/**
* Handle ManialinkPageAnswer Callback
*
* @param array $callback
*/
public function handleManialinkPageAnswer(array $callback) {
$actionId = $callback[1][2];
$boolSetting = (strpos($actionId, self::ACTION_SETTING_BOOL) === 0);
if (!$boolSetting) {
return;
}
$login = $callback[1][1];
$player = $this->maniaControl->playerManager->getPlayer($login);
// Save all Changes
$this->saveConfigData($callback[1], $player);
}
/** /**
* @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData() * @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData()
*/ */
@ -282,22 +255,9 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
$prefixLength = strlen(self::ACTION_PREFIX_SETTING); $prefixLength = strlen(self::ACTION_PREFIX_SETTING);
$actionArray = explode(".", $configData[2]);
$boolSettingName = '';
if (isset($actionArray[2])) {
$boolSettingName = self::ACTION_PREFIX_SETTING . '.' . $actionArray[2];
}
$newSettings = array(); $newSettings = array();
foreach ($configData[3] as $setting) { foreach ($configData[3] as $setting) {
// Check if it was a boolean button $settingName = substr($setting['Name'], $prefixLength);
if ($setting['Name'] == $boolSettingName) {
$setting['Value'] = ($setting['Value'] ? false : true);
}
$settingName = substr($setting['Name'], $prefixLength + 1);
$newSettings[$settingName] = $setting['Value']; $newSettings[$settingName] = $setting['Value'];
settype($newSettings[$settingName], gettype($serverSettings[$settingName])); settype($newSettings[$settingName], gettype($serverSettings[$settingName]));
} }

View File

@ -178,7 +178,7 @@ declare Text[Boolean] " . self::VAR_CHECKBOX_DESIGNS . " as Designs for Quad_Che
Designs[True] = \"{$enabledDesignString}\"; Designs[True] = \"{$enabledDesignString}\";
Designs[False] = \"{$disabledDesignString}\"; Designs[False] = \"{$disabledDesignString}\";
declare Boolean " . self::VAR_CHECKBOX_ENABLED . " as Enabled for Quad_CheckBox; declare Boolean " . self::VAR_CHECKBOX_ENABLED . " as Enabled for Quad_CheckBox;
Enabled = {$default}; Enabled = !{$default};
declare Text " . self::VAR_CHECKBOX_ENTRY_ID . " as EntryId for Quad_CheckBox; declare Text " . self::VAR_CHECKBOX_ENTRY_ID . " as EntryId for Quad_CheckBox;
EntryId = \"{$entryId}\"; EntryId = \"{$entryId}\";
" . self::FUNCTION_UPDATE_QUAD_DESIGN . "(Quad_CheckBox); " . self::FUNCTION_UPDATE_QUAD_DESIGN . "(Quad_CheckBox);