2014-01-05 19:00:11 +01:00
|
|
|
<?php
|
|
|
|
|
2014-04-12 12:14:37 +02:00
|
|
|
namespace ManiaControl\Configurators;
|
2014-01-05 19:00:11 +01:00
|
|
|
|
2014-01-05 19:20:54 +01:00
|
|
|
use FML\Controls\Control;
|
2014-01-05 21:48:49 +01:00
|
|
|
use FML\Controls\Entry;
|
2014-01-05 19:10:11 +01:00
|
|
|
use FML\Controls\Frame;
|
2014-05-02 17:50:30 +02:00
|
|
|
use FML\Controls\Labels\Label_Button;
|
2014-01-05 19:20:54 +01:00
|
|
|
use FML\Controls\Labels\Label_Text;
|
|
|
|
use FML\Controls\Quads\Quad_Icons64x64_1;
|
2014-04-27 16:22:12 +02:00
|
|
|
use FML\Script\Features\Paging;
|
2014-01-05 19:00:11 +01:00
|
|
|
use FML\Script\Script;
|
2014-01-31 16:55:01 +01:00
|
|
|
use ManiaControl\Admin\AuthenticationManager;
|
2014-01-05 22:51:21 +01:00
|
|
|
use ManiaControl\Callbacks\CallbackListener;
|
|
|
|
use ManiaControl\Callbacks\CallbackManager;
|
2014-01-05 19:00:11 +01:00
|
|
|
use ManiaControl\ManiaControl;
|
|
|
|
use ManiaControl\Players\Player;
|
2014-04-30 05:27:23 +02:00
|
|
|
use ManiaControl\Players\PlayerManager;
|
|
|
|
use ManiaControl\Settings\SettingManager;
|
2014-01-05 19:00:11 +01:00
|
|
|
|
2014-04-12 12:14:37 +02:00
|
|
|
/**
|
|
|
|
* Class offering a Configurator for ManiaControl Settings
|
2014-05-02 17:50:30 +02:00
|
|
|
*
|
|
|
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
|
|
|
* @copyright 2014 ManiaControl Team
|
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
2014-04-12 12:14:37 +02:00
|
|
|
*/
|
2014-01-05 22:51:21 +01:00
|
|
|
class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
|
2014-04-12 12:14:37 +02:00
|
|
|
/*
|
2014-01-05 19:00:11 +01:00
|
|
|
* Constants
|
|
|
|
*/
|
2014-05-02 17:50:30 +02:00
|
|
|
const TITLE = 'ManiaControl Settings';
|
|
|
|
const ACTION_PREFIX_SETTING = 'MCSetting.';
|
|
|
|
const ACTION_PREFIX_SETTINGCLASS = 'MCSettingClass.';
|
|
|
|
const ACTION_SETTINGCLASS_BACK = 'MCSettingClassBack';
|
|
|
|
const ACTION_SETTING_BOOL = 'MCSettings.ActionBoolSetting.';
|
2014-01-31 16:55:01 +01:00
|
|
|
const SETTING_PERMISSION_CHANGE_MC_SETTINGS = 'Change ManiaControl Settings';
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-04-12 12:14:37 +02:00
|
|
|
/*
|
2014-01-05 19:00:11 +01:00
|
|
|
* Private Properties
|
|
|
|
*/
|
|
|
|
private $maniaControl = null;
|
2014-04-30 05:27:23 +02:00
|
|
|
private $playersSettingCategoryOpened = array();
|
2014-01-05 19:00:11 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new Script Settings Instance
|
2014-05-02 17:50:30 +02:00
|
|
|
*
|
2014-01-05 19:00:11 +01:00
|
|
|
* @param ManiaControl $maniaControl
|
|
|
|
*/
|
|
|
|
public function __construct(ManiaControl $maniaControl) {
|
|
|
|
$this->maniaControl = $maniaControl;
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-01-05 22:51:21 +01:00
|
|
|
// Register for callbacks
|
|
|
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
2014-04-30 05:27:23 +02:00
|
|
|
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect');
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-04-30 05:27:23 +02:00
|
|
|
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_CHANGE_MC_SETTINGS, AuthenticationManager::AUTH_LEVEL_ADMIN);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle Player Disconnect Callback
|
2014-05-02 17:50:30 +02:00
|
|
|
*
|
2014-04-30 05:27:23 +02:00
|
|
|
* @param Player $player
|
|
|
|
*/
|
|
|
|
public function handlePlayerDisconnect(Player $player) {
|
|
|
|
unset($this->playersSettingCategoryOpened[$player->login]);
|
2014-01-05 19:00:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-04-30 05:27:23 +02:00
|
|
|
* @see \ManiaControl\Configurators\ConfiguratorMenu::getMenu()
|
|
|
|
*/
|
|
|
|
public function getMenu($width, $height, Script $script, Player $player) {
|
|
|
|
if (isset($this->playersSettingCategoryOpened[$player->login]) && strlen($this->playersSettingCategoryOpened[$player->login]) > 0) {
|
|
|
|
return $this->getMenuSettingsForClass($this->playersSettingCategoryOpened[$player->login], $width, $height, $script, $player);
|
2014-05-02 17:50:30 +02:00
|
|
|
} else {
|
2014-04-30 05:27:23 +02:00
|
|
|
return $this->getMenuSettingClasses($width, $height, $script, $player);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the Menu showing the Settings for the given Class
|
2014-05-02 17:50:30 +02:00
|
|
|
*
|
2014-04-30 05:27:23 +02:00
|
|
|
* @param string $settingClass
|
2014-05-02 17:50:30 +02:00
|
|
|
* @param float $width
|
|
|
|
* @param float $height
|
2014-04-30 05:27:23 +02:00
|
|
|
* @param Script $script
|
|
|
|
* @param Player $player
|
|
|
|
* @return \FML\Controls\Frame
|
|
|
|
*/
|
|
|
|
private function getMenuSettingsForClass($settingClass, $width, $height, Script $script, Player $player) {
|
|
|
|
$settings = $this->maniaControl->settingManager->getSettingsByClass($settingClass);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-04-30 05:27:23 +02:00
|
|
|
$paging = new Paging();
|
|
|
|
$script->addFeature($paging);
|
|
|
|
$frame = new Frame();
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-04-30 05:27:23 +02:00
|
|
|
// Config
|
2014-05-02 17:50:30 +02:00
|
|
|
$pagerSize = 9.;
|
2014-04-30 05:27:23 +02:00
|
|
|
$settingHeight = 5.;
|
|
|
|
$labelTextSize = 2;
|
2014-05-02 17:50:30 +02:00
|
|
|
$pageMaxCount = 13;
|
|
|
|
|
2014-04-30 05:27:23 +02:00
|
|
|
// Pagers
|
|
|
|
$pagerPrev = new Quad_Icons64x64_1();
|
|
|
|
$frame->add($pagerPrev);
|
|
|
|
$pagerPrev->setPosition($width * 0.39, $height * -0.44, 2);
|
|
|
|
$pagerPrev->setSize($pagerSize, $pagerSize);
|
|
|
|
$pagerPrev->setSubStyle($pagerPrev::SUBSTYLE_ArrowPrev);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-04-30 05:27:23 +02:00
|
|
|
$pagerNext = new Quad_Icons64x64_1();
|
|
|
|
$frame->add($pagerNext);
|
|
|
|
$pagerNext->setPosition($width * 0.45, $height * -0.44, 2);
|
|
|
|
$pagerNext->setSize($pagerSize, $pagerSize);
|
|
|
|
$pagerNext->setSubStyle($pagerNext::SUBSTYLE_ArrowNext);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-04-30 05:27:23 +02:00
|
|
|
$paging->addButton($pagerNext);
|
|
|
|
$paging->addButton($pagerPrev);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-04-30 05:27:23 +02:00
|
|
|
$pageCountLabel = new Label_Text();
|
|
|
|
$frame->add($pageCountLabel);
|
|
|
|
$pageCountLabel->setHAlign($pageCountLabel::RIGHT);
|
|
|
|
$pageCountLabel->setPosition($width * 0.35, $height * -0.44);
|
|
|
|
$pageCountLabel->setStyle($pageCountLabel::STYLE_TextTitle1);
|
|
|
|
$pageCountLabel->setTextSize(2);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-04-30 05:27:23 +02:00
|
|
|
$paging->setLabel($pageCountLabel);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-04-30 05:27:23 +02:00
|
|
|
$backLabel = new Label_Button();
|
|
|
|
$frame->add($backLabel);
|
|
|
|
$backLabel->setPosition($width * -0.49, $height * -0.44);
|
|
|
|
$backLabel->setHAlign($backLabel::LEFT);
|
|
|
|
$backLabel->setTextSize(2);
|
|
|
|
$backLabel->setText('Back');
|
|
|
|
$backLabel->setAction(self::ACTION_SETTINGCLASS_BACK);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-04-30 05:27:23 +02:00
|
|
|
$pageFrame = null;
|
2014-05-02 17:50:30 +02:00
|
|
|
$index = 0;
|
|
|
|
$y = 0;
|
2014-04-30 05:27:23 +02:00
|
|
|
foreach ($settings as $setting) {
|
|
|
|
if (!$pageFrame) {
|
2014-01-05 19:20:54 +01:00
|
|
|
$pageFrame = new Frame();
|
|
|
|
$frame->add($pageFrame);
|
|
|
|
$y = $height * 0.41;
|
2014-04-30 05:27:23 +02:00
|
|
|
$paging->addPage($pageFrame);
|
2014-01-05 19:20:54 +01:00
|
|
|
}
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-01-05 19:20:54 +01:00
|
|
|
$settingFrame = new Frame();
|
|
|
|
$pageFrame->add($settingFrame);
|
|
|
|
$settingFrame->setY($y);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-04-30 05:27:23 +02:00
|
|
|
// TODO: display currently select setting class
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-04-30 05:27:23 +02:00
|
|
|
// Headline Label
|
|
|
|
if (false) {
|
2014-01-05 21:48:49 +01:00
|
|
|
$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");
|
2014-04-30 05:27:23 +02:00
|
|
|
} // Headline
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-01-05 19:20:54 +01:00
|
|
|
$nameLabel = new Label_Text();
|
|
|
|
$settingFrame->add($nameLabel);
|
|
|
|
$nameLabel->setHAlign(Control::LEFT);
|
|
|
|
$nameLabel->setX($width * -0.46);
|
2014-01-05 21:48:49 +01:00
|
|
|
$nameLabel->setSize($width * 0.6, $settingHeight);
|
2014-01-05 19:20:54 +01:00
|
|
|
$nameLabel->setStyle($nameLabel::STYLE_TextCardSmall);
|
|
|
|
$nameLabel->setTextSize($labelTextSize);
|
|
|
|
$nameLabel->setText($setting->setting);
|
2014-01-05 21:48:49 +01:00
|
|
|
$nameLabel->setTextColor("FFF");
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-04-30 05:27:23 +02:00
|
|
|
if ($setting->type === SettingManager::TYPE_BOOL) {
|
2014-01-05 21:48:49 +01:00
|
|
|
$quad = new Quad_Icons64x64_1();
|
|
|
|
$settingFrame->add($quad);
|
|
|
|
$quad->setX($width / 2 * 0.6);
|
|
|
|
$quad->setZ(-0.01);
|
2014-04-30 05:27:23 +02:00
|
|
|
$quad->setSubStyle(($setting->value ? $quad::SUBSTYLE_LvlGreen : $quad::SUBSTYLE_LvlRed));
|
2014-01-05 21:48:49 +01:00
|
|
|
$quad->setSize(4, 4);
|
|
|
|
$quad->setAction(self::ACTION_SETTING_BOOL . $setting->index);
|
2014-05-02 17:50:30 +02:00
|
|
|
} else {
|
2014-04-30 05:27:23 +02:00
|
|
|
$entry = new Entry();
|
|
|
|
$settingFrame->add($entry);
|
|
|
|
$entry->setStyle(Label_Text::STYLE_TextValueSmall);
|
|
|
|
$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);
|
|
|
|
}
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-01-05 19:20:54 +01:00
|
|
|
$y -= $settingHeight;
|
2014-01-31 16:55:01 +01:00
|
|
|
if ($index % $pageMaxCount == $pageMaxCount - 1) {
|
2014-04-30 05:27:23 +02:00
|
|
|
$pageFrame = null;
|
2014-01-05 19:20:54 +01:00
|
|
|
}
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-01-05 19:20:54 +01:00
|
|
|
$index++;
|
2014-01-05 19:10:11 +01:00
|
|
|
}
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-01-05 19:10:11 +01:00
|
|
|
return $frame;
|
2014-01-05 19:00:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-02 17:50:30 +02:00
|
|
|
* Get the Menu showing all possible Classes
|
|
|
|
*
|
|
|
|
* @param float $width
|
|
|
|
* @param float $height
|
|
|
|
* @param Script $script
|
2014-01-05 19:00:11 +01:00
|
|
|
* @param Player $player
|
2014-05-02 17:50:30 +02:00
|
|
|
* @return \FML\Controls\Frame
|
2014-01-05 19:00:11 +01:00
|
|
|
*/
|
2014-05-02 17:50:30 +02:00
|
|
|
private function getMenuSettingClasses($width, $height, Script $script, Player $player) {
|
|
|
|
$settingClasses = $this->maniaControl->settingManager->getSettingClasses(true);
|
|
|
|
|
|
|
|
$paging = new Paging();
|
|
|
|
$script->addFeature($paging);
|
|
|
|
$frame = new Frame();
|
|
|
|
|
|
|
|
// Config
|
|
|
|
$pagerSize = 9.;
|
|
|
|
$settingHeight = 5.;
|
|
|
|
$pageMaxCount = 13;
|
|
|
|
$y = 0;
|
|
|
|
|
|
|
|
// Pagers
|
|
|
|
$pagerPrev = new Quad_Icons64x64_1();
|
|
|
|
$frame->add($pagerPrev);
|
|
|
|
$pagerPrev->setPosition($width * 0.39, $height * -0.44, 2);
|
|
|
|
$pagerPrev->setSize($pagerSize, $pagerSize);
|
|
|
|
$pagerPrev->setSubStyle($pagerPrev::SUBSTYLE_ArrowPrev);
|
|
|
|
|
|
|
|
$pagerNext = new Quad_Icons64x64_1();
|
|
|
|
$frame->add($pagerNext);
|
|
|
|
$pagerNext->setPosition($width * 0.45, $height * -0.44, 2);
|
|
|
|
$pagerNext->setSize($pagerSize, $pagerSize);
|
|
|
|
$pagerNext->setSubStyle($pagerNext::SUBSTYLE_ArrowNext);
|
|
|
|
|
|
|
|
$paging->addButton($pagerNext);
|
|
|
|
$paging->addButton($pagerPrev);
|
|
|
|
|
|
|
|
$pageCountLabel = new Label_Text();
|
|
|
|
$frame->add($pageCountLabel);
|
|
|
|
$pageCountLabel->setHAlign($pageCountLabel::RIGHT);
|
|
|
|
$pageCountLabel->setPosition($width * 0.35, $height * -0.44, 1);
|
|
|
|
$pageCountLabel->setStyle($pageCountLabel::STYLE_TextTitle1);
|
|
|
|
$pageCountLabel->setTextSize(2);
|
|
|
|
|
|
|
|
$paging->setLabel($pageCountLabel);
|
|
|
|
|
|
|
|
$pageFrame = null;
|
|
|
|
$index = 0;
|
|
|
|
foreach ($settingClasses as $settingClass) {
|
|
|
|
if (!$pageFrame) {
|
|
|
|
$pageFrame = new Frame();
|
|
|
|
$frame->add($pageFrame);
|
|
|
|
$y = $height * 0.41;
|
|
|
|
$paging->addPage($pageFrame);
|
2014-01-05 21:48:49 +01:00
|
|
|
}
|
2014-05-02 17:50:30 +02:00
|
|
|
|
|
|
|
$classLabel = new Label_Text();
|
|
|
|
|
|
|
|
$settingClassArray = explode('\\', $settingClass);
|
|
|
|
$className = "";
|
|
|
|
for ($i = 1; $i < count($settingClassArray); $i++) {
|
|
|
|
$className .= $settingClassArray[$i] . " - ";
|
|
|
|
}
|
|
|
|
$className = substr($className, 0, -3);
|
|
|
|
|
|
|
|
$pageFrame->add($classLabel);
|
|
|
|
$classLabel->setHAlign($classLabel::LEFT);
|
|
|
|
$classLabel->setPosition($width * -0.45, $y);
|
|
|
|
$classLabel->setSize($width * 0.9, $settingHeight * 0.9);
|
|
|
|
$classLabel->setStyle($classLabel::STYLE_TextCardSmall);
|
|
|
|
$classLabel->setTextSize(2);
|
|
|
|
$classLabel->setText($className);
|
|
|
|
$classLabel->setTextColor('fff');
|
|
|
|
$classLabel->setAction(self::ACTION_PREFIX_SETTINGCLASS . $settingClass);
|
|
|
|
|
|
|
|
$y -= $settingHeight;
|
|
|
|
|
|
|
|
if ($index % $pageMaxCount == $pageMaxCount - 1) {
|
|
|
|
$pageFrame = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$index++;
|
2014-01-05 21:48:49 +01:00
|
|
|
}
|
2014-05-02 17:50:30 +02:00
|
|
|
|
|
|
|
return $frame;
|
2014-01-05 19:00:11 +01:00
|
|
|
}
|
2014-01-05 22:51:21 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle ManialinkPageAnswer Callback
|
2014-05-02 17:50:30 +02:00
|
|
|
*
|
2014-01-05 22:51:21 +01:00
|
|
|
* @param array $callback
|
|
|
|
*/
|
|
|
|
public function handleManialinkPageAnswer(array $callback) {
|
2014-04-30 05:27:23 +02:00
|
|
|
$actionId = $callback[1][2];
|
|
|
|
if ($actionId === self::ACTION_SETTINGCLASS_BACK) {
|
|
|
|
// Back to classes list
|
2014-05-02 17:50:30 +02:00
|
|
|
$login = $callback[1][1];
|
2014-04-30 05:27:23 +02:00
|
|
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
|
|
|
unset($this->playersSettingCategoryOpened[$player->login]);
|
|
|
|
$menuId = $this->maniaControl->configurator->getMenuId($this);
|
|
|
|
$this->maniaControl->configurator->showMenu($player, $menuId);
|
2014-05-02 17:50:30 +02:00
|
|
|
} else if (strpos($actionId, self::ACTION_SETTING_BOOL) === 0) {
|
2014-04-30 05:27:23 +02:00
|
|
|
// Bool setting change
|
2014-05-02 17:50:30 +02:00
|
|
|
$settingIndex = (int)substr($actionId, strlen(self::ACTION_SETTING_BOOL));
|
|
|
|
|
|
|
|
$login = $callback[1][1];
|
2014-04-30 05:27:23 +02:00
|
|
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-04-30 05:27:23 +02:00
|
|
|
// Toggle the Boolean Setting
|
|
|
|
$this->toggleBooleanSetting($settingIndex, $player);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-04-30 05:27:23 +02:00
|
|
|
if ($callback[1][3]) {
|
|
|
|
// Save all Changes
|
|
|
|
$this->saveConfigData($callback[1], $player);
|
2014-05-02 17:50:30 +02:00
|
|
|
} else {
|
2014-04-30 05:27:23 +02:00
|
|
|
// Reopen menu directly
|
|
|
|
$menuId = $this->maniaControl->configurator->getMenuId($this);
|
|
|
|
$this->maniaControl->configurator->reopenMenu($player, $menuId);
|
|
|
|
}
|
2014-05-02 17:50:30 +02:00
|
|
|
} else if (strpos($actionId, self::ACTION_PREFIX_SETTINGCLASS) === 0) {
|
2014-04-30 05:27:23 +02:00
|
|
|
// Setting class selected
|
|
|
|
$settingClass = substr($actionId, strlen(self::ACTION_PREFIX_SETTINGCLASS));
|
2014-05-02 17:50:30 +02:00
|
|
|
|
|
|
|
$login = $callback[1][1];
|
2014-04-30 05:27:23 +02:00
|
|
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-04-30 05:27:23 +02:00
|
|
|
$this->playersSettingCategoryOpened[$player->login] = $settingClass;
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-04-30 05:27:23 +02:00
|
|
|
$menuId = $this->maniaControl->configurator->getMenuId($this);
|
|
|
|
$this->maniaControl->configurator->showMenu($player, $menuId);
|
2014-01-05 22:51:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggles a Boolean Value
|
2014-05-02 17:50:30 +02:00
|
|
|
*
|
|
|
|
* @param int $settingIndex
|
2014-01-05 22:51:21 +01:00
|
|
|
* @param Player $player
|
|
|
|
*/
|
2014-04-30 05:27:23 +02:00
|
|
|
public function toggleBooleanSetting($settingIndex, Player $player) {
|
2014-01-31 16:55:01 +01:00
|
|
|
if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_CHANGE_MC_SETTINGS)) {
|
|
|
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
|
|
|
return;
|
|
|
|
}
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-04-30 05:27:23 +02:00
|
|
|
$oldSetting = $this->maniaControl->settingManager->getSettingByIndex($settingIndex);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-01-31 16:55:01 +01:00
|
|
|
if (!isset($oldSetting)) {
|
2014-04-30 05:27:23 +02:00
|
|
|
var_dump('no setting ' . $settingIndex);
|
2014-01-05 22:51:21 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-04-30 05:27:23 +02:00
|
|
|
// Toggle value
|
|
|
|
$this->maniaControl->settingManager->setSetting($oldSetting->class, $oldSetting->setting, !$oldSetting->value);
|
2014-01-05 22:51:21 +01:00
|
|
|
}
|
2014-05-02 17:50:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Save the Config Data
|
|
|
|
*
|
|
|
|
* @param array $configData
|
|
|
|
* @param Player $player
|
|
|
|
*/
|
|
|
|
public function saveConfigData(array $configData, Player $player) {
|
|
|
|
if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_CHANGE_MC_SETTINGS)) {
|
|
|
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
$maniaControlSettings = $this->maniaControl->settingManager->getSettings();
|
|
|
|
|
|
|
|
$prefixLength = strlen(self::ACTION_PREFIX_SETTING);
|
|
|
|
|
|
|
|
foreach ($configData[3] as $setting) {
|
|
|
|
$settingName = substr($setting['Name'], $prefixLength);
|
|
|
|
|
|
|
|
$oldSetting = $maniaControlSettings[$settingName];
|
|
|
|
if ($setting['Value'] == $oldSetting->value || $oldSetting->type == 'bool') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->maniaControl->settingManager->setSetting($oldSetting->class, $oldSetting->setting, $setting['Value']);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reopen the Menu
|
|
|
|
$menuId = $this->maniaControl->configurator->getMenuId($this->getTitle());
|
|
|
|
$this->maniaControl->configurator->reopenMenu($player, $menuId);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the Menu Title
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getTitle() {
|
|
|
|
return self::TITLE;
|
|
|
|
}
|
2014-04-30 05:27:23 +02:00
|
|
|
}
|