mc setting manager, boolean not made yet
This commit is contained in:
parent
f4f66b5b94
commit
2154276a71
@ -8,6 +8,7 @@ namespace ManiaControl\Configurators;
|
|||||||
|
|
||||||
|
|
||||||
use FML\Controls\Control;
|
use FML\Controls\Control;
|
||||||
|
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;
|
||||||
@ -21,6 +22,8 @@ class ManiaControlSettings implements ConfiguratorMenu{
|
|||||||
* Constants
|
* Constants
|
||||||
*/
|
*/
|
||||||
const TITLE = 'ManiaControl Settings';
|
const TITLE = 'ManiaControl Settings';
|
||||||
|
const ACTION_PREFIX_SETTING = 'ManiaControlSettings';
|
||||||
|
const ACTION_SETTING_BOOL = 'ManiaControlSettings.ActionBoolSetting.';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private Properties
|
* Private Properties
|
||||||
@ -96,7 +99,8 @@ class ManiaControlSettings implements ConfiguratorMenu{
|
|||||||
$pageFrames = array();
|
$pageFrames = array();
|
||||||
$y = 0;
|
$y = 0;
|
||||||
$index = 1;
|
$index = 1;
|
||||||
foreach($settings as $setting){
|
$prevClass = '';
|
||||||
|
foreach($settings as $id => $setting) {
|
||||||
|
|
||||||
if(!isset($pageFrame)) {
|
if(!isset($pageFrame)) {
|
||||||
$pageFrame = new Frame();
|
$pageFrame = new Frame();
|
||||||
@ -113,17 +117,83 @@ class ManiaControlSettings implements ConfiguratorMenu{
|
|||||||
$pageFrame->add($settingFrame);
|
$pageFrame->add($settingFrame);
|
||||||
$settingFrame->setY($y);
|
$settingFrame->setY($y);
|
||||||
|
|
||||||
|
//Headline Label
|
||||||
|
if($prevClass != $setting->class) {
|
||||||
|
$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($labelTextSize);
|
||||||
|
$headLabel->setText($setting->class);
|
||||||
|
$headLabel->setTextColor("F00");
|
||||||
|
|
||||||
|
$y -= $settingHeight;
|
||||||
|
|
||||||
|
|
||||||
|
if($index % $pageMaxCount == $pageMaxCount - 1) {
|
||||||
|
$pageFrame = new Frame();
|
||||||
|
$frame->add($pageFrame);
|
||||||
|
if(!empty($pageFrames)) {
|
||||||
|
$pageFrame->setVisible(false);
|
||||||
|
}
|
||||||
|
array_push($pageFrames, $pageFrame);
|
||||||
|
$y = $height * 0.41;
|
||||||
|
$script->addPage($pageFrame, count($pageFrames), $pagesId);
|
||||||
|
}
|
||||||
|
|
||||||
|
$index++;
|
||||||
|
|
||||||
|
$settingFrame = new Frame();
|
||||||
|
$pageFrame->add($settingFrame);
|
||||||
|
$settingFrame->setY($y);
|
||||||
|
} //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);
|
||||||
$nameLabel->setX($width * -0.46);
|
$nameLabel->setX($width * -0.46);
|
||||||
$nameLabel->setSize($width * 0.4, $settingHeight);
|
$nameLabel->setSize($width * 0.6, $settingHeight);
|
||||||
$nameLabel->setStyle($nameLabel::STYLE_TextCardSmall);
|
$nameLabel->setStyle($nameLabel::STYLE_TextCardSmall);
|
||||||
$nameLabel->setTextSize($labelTextSize);
|
$nameLabel->setTextSize($labelTextSize);
|
||||||
$nameLabel->setText($setting->setting);
|
$nameLabel->setText($setting->setting);
|
||||||
|
$nameLabel->setTextColor("FFF");
|
||||||
|
|
||||||
|
$substyle = '';
|
||||||
|
|
||||||
|
|
||||||
// var_dump($setting);
|
$entry = new Entry();
|
||||||
|
$settingFrame->add($entry);
|
||||||
|
$entry->setStyle(Label_Text::STYLE_TextValueSmall);
|
||||||
|
$entry->setHAlign(Control::CENTER);
|
||||||
|
$entry->setX($width / 2 * 0.65);
|
||||||
|
$entry->setTextSize(1);
|
||||||
|
$entry->setSize($width * 0.3, $settingHeight * 0.9);
|
||||||
|
$entry->setName(self::ACTION_PREFIX_SETTING . '.' . $setting->index);
|
||||||
|
$entry->setDefault($setting->value);
|
||||||
|
|
||||||
|
|
||||||
|
if($setting->type == "bool") {
|
||||||
|
if($setting->value == "0") {
|
||||||
|
$substyle = Quad_Icons64x64_1::SUBSTYLE_LvlRed;
|
||||||
|
} else if($setting->value == "1") {
|
||||||
|
$substyle = Quad_Icons64x64_1::SUBSTYLE_LvlGreen;
|
||||||
|
}
|
||||||
|
|
||||||
|
$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->setHAlign(Control::CENTER2);
|
||||||
|
$quad->setAction(self::ACTION_SETTING_BOOL . $setting->index);
|
||||||
|
$entry->setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$prevClass = $setting->class;
|
||||||
|
|
||||||
$y -= $settingHeight;
|
$y -= $settingHeight;
|
||||||
if($index % $pageMaxCount == $pageMaxCount - 1) {
|
if($index % $pageMaxCount == $pageMaxCount - 1) {
|
||||||
@ -143,6 +213,27 @@ class ManiaControlSettings implements ConfiguratorMenu{
|
|||||||
* @param Player $player
|
* @param Player $player
|
||||||
*/
|
*/
|
||||||
public function saveConfigData(array $configData, Player $player) {
|
public function saveConfigData(array $configData, Player $player) {
|
||||||
// TODO: Implement saveConfigData() method.
|
$prefix = explode(".", $configData[3][0]['Name']);
|
||||||
|
if($prefix[0] != self::ACTION_PREFIX_SETTING) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$maniaControlSettings = $this->maniaControl->settingManager->getSettings();
|
||||||
|
|
||||||
|
$prefixLength = strlen(self::ACTION_PREFIX_SETTING);
|
||||||
|
|
||||||
|
foreach($configData[3] as $setting) {
|
||||||
|
$settingName = substr($setting['Name'], $prefixLength + 1);
|
||||||
|
$oldSetting = $maniaControlSettings[$settingName];
|
||||||
|
if($setting['Value'] == $oldSetting->value) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->maniaControl->settingManager->updateSetting($oldSetting->class, $oldSetting->setting, $setting['Value']);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Reopen the Menu
|
||||||
|
$menuId = $this->maniaControl->configurator->getMenuId($this->getTitle());
|
||||||
|
$this->maniaControl->configurator->reopenMenu($menuId);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -206,8 +206,6 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
$nameLabel->setText($name);
|
$nameLabel->setText($name);
|
||||||
$nameLabel->setTextColor("FFF");
|
$nameLabel->setTextColor("FFF");
|
||||||
|
|
||||||
// $settingValue = $scriptSettings[$name];
|
|
||||||
|
|
||||||
$substyle = '';
|
$substyle = '';
|
||||||
if($value === false) {
|
if($value === false) {
|
||||||
$substyle = Quad_Icons64x64_1::SUBSTYLE_LvlRed;
|
$substyle = Quad_Icons64x64_1::SUBSTYLE_LvlRed;
|
||||||
|
@ -247,15 +247,13 @@ class SettingManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a setting for the given object
|
* Updates a Setting
|
||||||
*
|
* @param $className
|
||||||
* @param object $object
|
* @param $settingName
|
||||||
* @param string $settingName
|
* @param $value
|
||||||
* @param mixed $value
|
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function setSetting($object, $settingName, $value) {
|
public function updateSetting($className, $settingName, $value){
|
||||||
$className = $this->getClassName($object);
|
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$settingQuery = "UPDATE `" . self::TABLE_SETTINGS . "`
|
$settingQuery = "UPDATE `" . self::TABLE_SETTINGS . "`
|
||||||
SET `value` = ?
|
SET `value` = ?
|
||||||
@ -278,6 +276,19 @@ class SettingManager {
|
|||||||
return $success;
|
return $success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a setting for the given object
|
||||||
|
*
|
||||||
|
* @param object $object
|
||||||
|
* @param string $settingName
|
||||||
|
* @param mixed $value
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function setSetting($object, $settingName, $value) {
|
||||||
|
$className = $this->getClassName($object);
|
||||||
|
$this->updateSetting($className, $settingName, $value);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset a setting to its default value
|
* Reset a setting to its default value
|
||||||
*
|
*
|
||||||
@ -353,7 +364,8 @@ class SettingManager {
|
|||||||
}
|
}
|
||||||
$settings = array();
|
$settings = array();
|
||||||
while ($setting = $result->fetch_object()) {
|
while ($setting = $result->fetch_object()) {
|
||||||
array_push($settings, $setting);
|
$settings[$setting->index] = $setting;
|
||||||
|
//array_push($settings, $setting);
|
||||||
}
|
}
|
||||||
$result->free();
|
$result->free();
|
||||||
return $settings;
|
return $settings;
|
||||||
|
Loading…
Reference in New Issue
Block a user