server setting with checkboxes for boolean values
This commit is contained in:
parent
f7070a51e1
commit
db3d59d47f
@ -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,43 +200,36 @@ 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
$entry = new Entry();
|
$quad = new Quad();
|
||||||
$settingFrame->add($entry);
|
$checkBox->setQuad($quad);
|
||||||
$entry->setStyle(Label_Text::STYLE_TextValueSmall);
|
|
||||||
$entry->setHAlign(Control::CENTER);
|
|
||||||
$entry->setX($width / 2 * 0.46);
|
|
||||||
$entry->setTextSize(1);
|
|
||||||
$entry->setSize($width * 0.48, $settingHeight * 0.9);
|
|
||||||
$entry->setName(self::ACTION_PREFIX_SETTING . '.' . $name);
|
|
||||||
$entry->setDefault($value);
|
|
||||||
|
|
||||||
if ($name == "Comment") { //
|
|
||||||
$entry->setAutoNewLine(true);
|
|
||||||
$entry->setSize($width * 0.48, $settingHeight * 3 + $settingHeight * 0.9);
|
|
||||||
$settingFrame->setY($y - $settingHeight * 1.5);
|
|
||||||
// dummy:
|
|
||||||
$y -= $settingHeight * 3;
|
|
||||||
$id += 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($substyle != '') {
|
|
||||||
$quad = new Quad_Icons64x64_1();
|
|
||||||
$settingFrame->add($quad);
|
|
||||||
$quad->setX($width / 2 * 0.46);
|
$quad->setX($width / 2 * 0.46);
|
||||||
$quad->setZ(-0.01);
|
$quad->setZ(-0.01);
|
||||||
$quad->setSubStyle($substyle);
|
|
||||||
$quad->setSize(4, 4);
|
$quad->setSize(4, 4);
|
||||||
$quad->setHAlign(Control::CENTER);
|
} else {
|
||||||
$quad->setAction(self::ACTION_SETTING_BOOL . $name);
|
// Other
|
||||||
|
$entry = new Entry();
|
||||||
|
$settingFrame->add($entry);
|
||||||
|
$entry->setStyle(Label_Text::STYLE_TextValueSmall);
|
||||||
|
$entry->setHAlign(Control::CENTER);
|
||||||
|
$entry->setX($width / 2 * 0.46);
|
||||||
|
$entry->setTextSize(1);
|
||||||
|
$entry->setSize($width * 0.48, $settingHeight * 0.9);
|
||||||
|
$entry->setName(self::ACTION_PREFIX_SETTING . $name);
|
||||||
|
$entry->setDefault($value);
|
||||||
|
|
||||||
$entry->setVisible(false);
|
if ($name == "Comment") { //
|
||||||
|
$entry->setAutoNewLine(true);
|
||||||
|
$entry->setSize($width * 0.48, $settingHeight * 3 + $settingHeight * 0.9);
|
||||||
|
$settingFrame->setY($y - $settingHeight * 1.5);
|
||||||
|
// dummy:
|
||||||
|
$y -= $settingHeight * 3;
|
||||||
|
$id += 3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$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]));
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
Loading…
Reference in New Issue
Block a user