TrackManiaControl/core/Configurator/ManiaControlSettings.php

539 lines
18 KiB
PHP
Raw Permalink Normal View History

2014-01-05 19:00:11 +01:00
<?php
namespace ManiaControl\Configurator;
2014-01-05 19:00:11 +01:00
2014-06-15 02:13:00 +02:00
use FML\Components\CheckBox;
use FML\Components\ValuePicker;
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;
2014-06-15 02:13:00 +02:00
use FML\Controls\Quad;
2014-01-05 19:20:54 +01:00
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;
use ManiaControl\Settings\Setting;
use ManiaControl\Settings\SettingManager;
2014-01-05 19:00:11 +01:00
/**
* Class offering a Configurator for ManiaControl Settings
2014-05-02 17:50:30 +02:00
*
* @author ManiaControl Team <mail@maniacontrol.com>
2020-01-22 10:39:35 +01:00
* @copyright 2014-2020 ManiaControl Team
2014-05-02 17:50:30 +02:00
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
2014-01-05 22:51:21 +01:00
class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
/*
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_SETTING_LINK = 'MCSettingLink.';
2014-05-02 17:50:30 +02:00
const ACTION_PREFIX_SETTINGCLASS = 'MCSettingClass.';
const ACTION_PREFIX_SETTINGLINKS = 'MCSettingLinks.';
2014-05-02 17:50:30 +02:00
const ACTION_SETTINGCLASS_BACK = 'MCSettingClassBack';
2014-01-31 16:55:01 +01:00
const SETTING_PERMISSION_CHANGE_MC_SETTINGS = 'Change ManiaControl Settings';
const CACHE_CLASS_OPENED = 'ClassOpened';
2014-05-02 17:50:30 +02:00
/*
* Private properties
2014-01-05 19:00:11 +01:00
*/
/** @var ManiaControl $maniaControl */
2014-01-05 19:00:11 +01:00
private $maniaControl = null;
/**
* Construct a new ManiaControl 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
// Callbacks
2014-08-13 11:05:52 +02:00
$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
2014-05-02 17:50:30 +02:00
// Permissions
2014-08-13 11:05:52 +02:00
$this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_CHANGE_MC_SETTINGS, AuthenticationManager::AUTH_LEVEL_ADMIN);
}
/**
2017-03-25 18:40:15 +01:00
* @see \ManiaControl\Configurator\ConfiguratorMenu::getTitle()
*/
public static function getTitle() {
return self::TITLE;
}
2014-01-05 19:00:11 +01:00
/**
2017-03-25 18:40:15 +01:00
* @see \ManiaControl\Configurator\ConfiguratorMenu::getMenu()
*/
public function getMenu($width, $height, Script $script, Player $player) {
$SubMenu = $player->getCache($this, self::CACHE_CLASS_OPENED);
if ($SubMenu) {
// Show Settings Menu
if (strpos($SubMenu, self::ACTION_PREFIX_SETTINGCLASS) === 0) {
$settingClass = substr($SubMenu, strlen(self::ACTION_PREFIX_SETTINGCLASS));
return $this->getMenuSettingsForClass($settingClass, $width, $height, $script);
} else if (strpos($SubMenu, self::ACTION_PREFIX_SETTINGLINKS) === 0) {
$settingClass = substr($SubMenu, strlen(self::ACTION_PREFIX_SETTINGLINKS));
return $this->getManageSettingsLink($settingClass, $width, $height, $script);
}
}
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
*
* @param string $settingClass
2014-05-02 17:50:30 +02:00
* @param float $width
* @param float $height
* @param Script $script
* @param Player $player
* @return \FML\Controls\Frame
*/
private function getMenuSettingsForClass($settingClass, $width, $height, Script $script) {
2014-08-13 11:05:52 +02:00
$settings = $this->maniaControl->getSettingManager()->getSettingsByClass($settingClass);
$isunlinkable = $this->maniaControl->getSettingManager()->getSettingValue($this->maniaControl->getSettingManager(), SettingManager::SETTING_ALLOW_UNLINK_SERVER);
2014-05-02 17:50:30 +02:00
$paging = new Paging();
$script->addFeature($paging);
$frame = new Frame();
2014-05-02 17:50:30 +02:00
// Config
2014-05-02 17:50:30 +02:00
$pagerSize = 9.;
$settingHeight = 5.;
$labelTextSize = 2;
$pageMaxCount = floor(($height * 0.78) / $settingHeight);
2014-05-02 17:50:30 +02:00
// Pagers
$pagerPrev = new Quad_Icons64x64_1();
2017-03-25 19:15:50 +01:00
$frame->addChild($pagerPrev);
$pagerPrev->setPosition($width * 0.5 - 12, $height * -0.5 + 5, 2);
$pagerPrev->setSize($pagerSize, $pagerSize);
$pagerPrev->setSubStyle($pagerPrev::SUBSTYLE_ArrowPrev);
2014-05-02 17:50:30 +02:00
$pagerNext = new Quad_Icons64x64_1();
2017-03-25 19:15:50 +01:00
$frame->addChild($pagerNext);
$pagerNext->setPosition($width * 0.5 - 5, $height * -0.5 + 5, 2);
$pagerNext->setSize($pagerSize, $pagerSize);
$pagerNext->setSubStyle($pagerNext::SUBSTYLE_ArrowNext);
2014-05-02 17:50:30 +02:00
2017-03-25 18:40:15 +01:00
$paging->addButtonControl($pagerNext);
$paging->addButtonControl($pagerPrev);
2014-05-02 17:50:30 +02:00
$pageCountLabel = new Label_Text();
2017-03-25 19:15:50 +01:00
$frame->addChild($pageCountLabel);
$pageCountLabel->setHorizontalAlign($pageCountLabel::RIGHT);
$pageCountLabel->setPosition($width * 0.5 - 16, $height * -0.5 + 5, 1);
$pageCountLabel->setStyle($pageCountLabel::STYLE_TextTitle1);
$pageCountLabel->setTextSize(2);
2014-05-02 17:50:30 +02:00
$paging->setLabel($pageCountLabel);
2014-05-02 17:50:30 +02:00
$backLabel = new Label_Button();
2017-03-25 19:15:50 +01:00
$frame->addChild($backLabel);
$backLabel->setStyle($backLabel::STYLE_CardMain_Quit);
2020-05-19 22:07:18 +02:00
$backLabel->setPosition(-$width / 2 + 5, -$height / 2 + 5);
2017-03-25 19:15:50 +01:00
$backLabel->setHorizontalAlign($backLabel::LEFT);
2020-05-19 22:07:18 +02:00
$backLabel->setScale(0.5);
$backLabel->setTextSize(2);
$backLabel->setText('Back');
$backLabel->setAction(self::ACTION_SETTINGCLASS_BACK);
2014-05-02 17:50:30 +02:00
2014-06-15 01:58:25 +02:00
$headLabel = new Label_Text();
2017-03-25 19:15:50 +01:00
$frame->addChild($headLabel);
$headLabel->setHorizontalAlign($headLabel::LEFT);
2014-06-15 01:58:25 +02:00
$headLabel->setPosition($width * -0.46, $height * 0.41);
$headLabel->setSize($width * 0.6, $settingHeight);
$headLabel->setStyle($headLabel::STYLE_TextCardSmall);
$headLabel->setTextSize(3);
$headLabel->setText($settingClass);
$headLabel->setTextColor('ff0');
$pageFrame = null;
2014-05-02 17:50:30 +02:00
$index = 0;
2014-06-15 01:58:25 +02:00
$posY = 0;
foreach ($settings as $setting) {
if ($index % $pageMaxCount === 0) {
2014-01-05 19:20:54 +01:00
$pageFrame = new Frame();
2017-03-25 19:15:50 +01:00
$frame->addChild($pageFrame);
2017-03-25 18:40:15 +01:00
$paging->addPageControl($pageFrame);
2014-06-15 01:58:25 +02:00
$posY = $height * 0.41 - $settingHeight * 1.5;
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();
2017-03-25 19:15:50 +01:00
$pageFrame->addChild($settingFrame);
2014-06-15 01:58:25 +02:00
$settingFrame->setY($posY);
2014-05-02 17:50:30 +02:00
2014-01-05 19:20:54 +01:00
$nameLabel = new Label_Text();
2017-03-25 19:15:50 +01:00
$settingFrame->addChild($nameLabel);
$nameLabel->setHorizontalAlign($nameLabel::LEFT);
2014-01-05 19:20:54 +01:00
$nameLabel->setX($width * -0.46);
$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-06-22 19:02:18 +02:00
$nameLabel->setTextColor('fff');
2014-05-02 17:50:30 +02:00
2020-05-19 22:07:18 +02:00
$descriptionLabel = new Label_Text();
$pageFrame->addChild($descriptionLabel);
$descriptionLabel->setHorizontalAlign($descriptionLabel::LEFT);
$descriptionLabel->setPosition(-0.45 * $width, -0.35 * $height);
$descriptionLabel->setSize(0.9 * $width, $settingHeight);
$descriptionLabel->setTextSize($labelTextSize);
$descriptionLabel->setTranslate(true);
$nameLabel->addTooltipLabelFeature($descriptionLabel, $setting->description);
$settingName = self::ACTION_PREFIX_SETTING . $setting->index;
if ($isunlinkable && $setting->setting != SettingManager::SETTING_ALLOW_UNLINK_SERVER) {
$quadlink = new Quad();
$settingFrame->addChild($quadlink);
$quadlink->setPosition(-0.48 * $width, 0.2, -0.01);
$quadlink->setSize(4, 4);
$quadlink->setColorize("ccccccaa");
$quadlink->setStyle("UICommon64_1");
$quadlink->setSubStyle("Padlock_light");
$quadlink->setStyleSelected($setting->linked);
}
if ($setting->type === Setting::TYPE_BOOL) {
2014-06-15 02:13:00 +02:00
// Boolean checkbox
$quad = new Quad();
$quad->setPosition($width * 0.33, 0, -0.01);
$quad->setSize(4, 4);
2014-06-15 02:13:00 +02:00
$checkBox = new CheckBox($settingName, $setting->value, $quad);
2017-03-25 19:15:50 +01:00
$settingFrame->addChild($checkBox);
} else if ($setting->type === Setting::TYPE_SET) {
// SET value picker
$label = new Label_Text();
$label->setX($width * 0.33);
$label->setSize($width * 0.3, $settingHeight * 0.9);
$label->setStyle($label::STYLE_TextValueSmall);
$label->setTextSize(1);
$valuePicker = new ValuePicker($settingName, $setting->set, $setting->value, $label);
2017-03-25 19:15:50 +01:00
$settingFrame->addChild($valuePicker);
} else {
// Standard entry
$entry = new Entry();
2017-03-25 19:15:50 +01:00
$settingFrame->addChild($entry);
$entry->setX($width * 0.33);
$entry->setSize($width * 0.3, $settingHeight * 0.9);
$entry->setStyle(Label_Text::STYLE_TextValueSmall);
$entry->setTextSize(1);
$entry->setMaxLength(1000);
$entry->setName($settingName);
$entry->setDefault($setting->value);
}
2014-05-02 17:50:30 +02:00
2014-06-15 01:58:25 +02:00
$posY -= $settingHeight;
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
if ($isunlinkable) {
$mapNameButton = $this->maniaControl->getManialinkManager()->getElementBuilder()->buildRoundTextButton(
'Manage settings link',
30,
5,
self::ACTION_PREFIX_SETTINGLINKS . $settingClass
);
$frame->addChild($mapNameButton);
2023-09-08 16:00:30 +02:00
$mapNameButton->setPosition(-$width / 2 + 60, $height * -0.45);
}
return $frame;
}
/**
* getManageSettingsLink
*
* @param mixed $settingClass
* @param float $width
* @param float $height
* @param Script $script
* @param Player $player
* @return void
*/
public function getManageSettingsLink($settingClass, $width, $height, Script $script) {
$settings = $this->maniaControl->getSettingManager()->getSettingsByClass($settingClass);
$paging = new Paging();
$script->addFeature($paging);
$frame = new Frame();
// Config
$pagerSize = 9.;
$settingHeight = 5.;
$labelTextSize = 2;
$pageMaxCount = floor(($height * 0.78) / $settingHeight);
// Pagers
$pagerPrev = new Quad_Icons64x64_1();
$frame->addChild($pagerPrev);
$pagerPrev->setPosition($width * 0.5 - 12, $height * -0.5 + 5, 2);
$pagerPrev->setSize($pagerSize, $pagerSize);
$pagerPrev->setSubStyle($pagerPrev::SUBSTYLE_ArrowPrev);
$pagerNext = new Quad_Icons64x64_1();
$frame->addChild($pagerNext);
$pagerNext->setPosition($width * 0.5 - 5, $height * -0.5 + 5, 2);
$pagerNext->setSize($pagerSize, $pagerSize);
$pagerNext->setSubStyle($pagerNext::SUBSTYLE_ArrowNext);
$paging->addButtonControl($pagerNext);
$paging->addButtonControl($pagerPrev);
$pageCountLabel = new Label_Text();
$frame->addChild($pageCountLabel);
$pageCountLabel->setHorizontalAlign($pageCountLabel::RIGHT);
$pageCountLabel->setPosition($width * 0.5 - 16, $height * -0.5 + 5, 1);
$pageCountLabel->setStyle($pageCountLabel::STYLE_TextTitle1);
$pageCountLabel->setTextSize(2);
$paging->setLabel($pageCountLabel);
$backLabel = new Label_Button();
$frame->addChild($backLabel);
$backLabel->setStyle($backLabel::STYLE_CardMain_Quit);
$backLabel->setPosition(-$width / 2 + 5, -$height / 2 + 5);
$backLabel->setHorizontalAlign($backLabel::LEFT);
$backLabel->setScale(0.5);
$backLabel->setTextSize(2);
$backLabel->setText('Back');
$backLabel->setAction(self::ACTION_PREFIX_SETTINGCLASS . $settingClass);
$headLabel = new Label_Text();
$frame->addChild($headLabel);
$headLabel->setHorizontalAlign($headLabel::LEFT);
$headLabel->setPosition($width * -0.46, $height * 0.41);
$headLabel->setSize($width * 0.6, $settingHeight);
$headLabel->setStyle($headLabel::STYLE_TextCardSmall);
$headLabel->setTextSize(3);
$headLabel->setText($settingClass);
$headLabel->setTextColor('ff0');
$pageFrame = null;
$index = 0;
$posY = 0;
foreach ($settings as $setting) {
if ($index % $pageMaxCount === 0) {
$pageFrame = new Frame();
$frame->addChild($pageFrame);
$paging->addPageControl($pageFrame);
$posY = $height * 0.41 - $settingHeight * 1.5;
}
$settingFrame = new Frame();
$pageFrame->addChild($settingFrame);
$settingFrame->setY($posY);
$nameLabel = new Label_Text();
$settingFrame->addChild($nameLabel);
$nameLabel->setHorizontalAlign($nameLabel::LEFT);
$nameLabel->setX($width * -0.46);
$nameLabel->setSize($width * 0.6, $settingHeight);
$nameLabel->setStyle($nameLabel::STYLE_TextCardSmall);
$nameLabel->setTextSize($labelTextSize);
$nameLabel->setText($setting->setting);
$nameLabel->setTextColor('fff');
$descriptionLabel = new Label_Text();
$pageFrame->addChild($descriptionLabel);
$descriptionLabel->setHorizontalAlign($descriptionLabel::LEFT);
$descriptionLabel->setPosition(-0.45 * $width, -0.35 * $height);
$descriptionLabel->setSize(0.9 * $width, $settingHeight);
$descriptionLabel->setTextSize($labelTextSize);
$descriptionLabel->setTranslate(true);
$nameLabel->addTooltipLabelFeature($descriptionLabel, $setting->description);
if ($setting->setting != SettingManager::SETTING_ALLOW_UNLINK_SERVER) {
$quad = new Quad();
$quad->setPosition($width * 0.33, 0.2, -0.01);
$quad->setSize(4, 4);
$checkBox = new CheckBox(self::ACTION_PREFIX_SETTING_LINK . $setting->index, $setting->linked, $quad);
$checkBox->setEnabledDesign("UICommon64_1", "Padlock_light");
$checkBox->setDisabledDesign("UICommon64_1", "Padlock_light");
$settingFrame->addChild($checkBox);
}
$posY -= $settingHeight;
$index++;
}
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
*/
private function getMenuSettingClasses($width, $height, Script $script) {
2014-08-13 11:05:52 +02:00
$settingClasses = $this->maniaControl->getSettingManager()->getSettingClasses(true);
2014-05-02 17:50:30 +02:00
$paging = new Paging();
$script->addFeature($paging);
$frame = new Frame();
// Config
$pagerSize = 9.;
$settingHeight = 5.;
$pageMaxCount = floor(($height - 10) / $settingHeight);
2014-05-02 17:50:30 +02:00
// Pagers
$pagerPrev = new Quad_Icons64x64_1();
2017-03-25 19:15:50 +01:00
$frame->addChild($pagerPrev);
$pagerPrev->setPosition($width * 0.5 - 12, $height * -0.5 + 5, 2);
2014-05-02 17:50:30 +02:00
$pagerPrev->setSize($pagerSize, $pagerSize);
$pagerPrev->setSubStyle($pagerPrev::SUBSTYLE_ArrowPrev);
$pagerNext = new Quad_Icons64x64_1();
2017-03-25 19:15:50 +01:00
$frame->addChild($pagerNext);
$pagerNext->setPosition($width * 0.5 - 5, $height * -0.5 + 5, 2);
2014-05-02 17:50:30 +02:00
$pagerNext->setSize($pagerSize, $pagerSize);
$pagerNext->setSubStyle($pagerNext::SUBSTYLE_ArrowNext);
2017-03-25 18:40:15 +01:00
$paging->addButtonControl($pagerNext);
$paging->addButtonControl($pagerPrev);
2014-05-02 17:50:30 +02:00
$pageCountLabel = new Label_Text();
2017-03-25 19:15:50 +01:00
$frame->addChild($pageCountLabel);
$pageCountLabel->setHorizontalAlign($pageCountLabel::RIGHT);
$pageCountLabel->setPosition($width * 0.5 - 16, $height * -0.5 + 5, 1);
2014-05-02 17:50:30 +02:00
$pageCountLabel->setStyle($pageCountLabel::STYLE_TextTitle1);
$pageCountLabel->setTextSize(2);
$paging->setLabel($pageCountLabel);
$repositionnedFrame = new Frame();
$frame->addChild($repositionnedFrame);
$repositionnedFrame->setPosition($width * -0.5, $height * 0.5);
2014-05-02 17:50:30 +02:00
$pageFrame = null;
$index = 0;
foreach ($settingClasses as $settingClass) {
if ($index % $pageMaxCount === 0) {
2014-05-02 17:50:30 +02:00
$pageFrame = new Frame();
$repositionnedFrame->addChild($pageFrame);
2017-03-25 18:40:15 +01:00
$paging->addPageControl($pageFrame);
$index = 1;
}
2014-05-02 17:50:30 +02:00
$classLabel = new Label_Text();
$settingClassArray = explode('\\', $settingClass);
$className = '';
2014-05-02 17:50:30 +02:00
for ($i = 1; $i < count($settingClassArray); $i++) {
$className .= $settingClassArray[$i] . ' - ';
2014-05-02 17:50:30 +02:00
}
$className = substr($className, 0, -3);
2017-03-25 19:15:50 +01:00
$pageFrame->addChild($classLabel);
$classLabel->setHorizontalAlign($classLabel::LEFT);
$classLabel->setPosition(2, $settingHeight * $index * -1);
$classLabel->setSize($width - 6, $settingHeight * 0.9);
2014-05-02 17:50:30 +02:00
$classLabel->setStyle($classLabel::STYLE_TextCardSmall);
$classLabel->setTextSize(2);
$classLabel->setText($className);
$classLabel->setTextColor('fff');
$classLabel->setAction(self::ACTION_PREFIX_SETTINGCLASS . $settingClass);
$index++;
}
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) {
$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-08-13 11:05:52 +02:00
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
$player->destroyCache($this, self::CACHE_CLASS_OPENED);
2014-08-13 11:05:52 +02:00
$menuId = $this->maniaControl->getConfigurator()->getMenuId($this);
$this->maniaControl->getConfigurator()->showMenu($player, $menuId);
} else if (strpos($actionId, self::ACTION_PREFIX_SETTINGCLASS) === 0 || strpos($actionId, self::ACTION_PREFIX_SETTINGLINKS) === 0) {
2014-05-02 17:50:30 +02:00
$login = $callback[1][1];
2014-08-13 11:05:52 +02:00
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
if (!$player) {
return;
}
$player->setCache($this, self::CACHE_CLASS_OPENED, $actionId);
2014-05-02 17:50:30 +02:00
2014-08-13 11:05:52 +02:00
$menuId = $this->maniaControl->getConfigurator()->getMenuId($this);
$this->maniaControl->getConfigurator()->showMenu($player, $menuId);
2014-01-05 22:51:21 +01:00
}
}
2014-05-02 17:50:30 +02:00
/**
2014-06-15 03:23:44 +02:00
* @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData()
2014-05-02 17:50:30 +02:00
*/
public function saveConfigData(array $configData, Player $player) {
2014-08-13 11:05:52 +02:00
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_CHANGE_MC_SETTINGS)
2014-08-05 02:17:41 +02:00
) {
2014-08-13 11:05:52 +02:00
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
2014-05-02 17:50:30 +02:00
return;
}
if (!$configData[3] || (strpos($configData[3][0]['Name'], self::ACTION_PREFIX_SETTING) !== 0 && strpos($configData[3][0]['Name'], self::ACTION_PREFIX_SETTING_LINK) !== 0)) {
2014-05-02 17:50:30 +02:00
return;
}
foreach ($configData[3] as $settingData) {
if (!$settingData || !isset($settingData['Value'])) {
2014-06-15 03:23:44 +02:00
continue;
}
2014-05-02 17:50:30 +02:00
$data = explode(".", $settingData["Name"]);
$type = $data[0];
$index = $data[1];
$settingObjectByIndex = $this->maniaControl->getSettingManager()->getSettingObjectByIndex($index);
if (!$settingObjectByIndex) {
2014-05-02 17:50:30 +02:00
continue;
}
if ($type . "." == self::ACTION_PREFIX_SETTING_LINK) {
if ($settingData['Value'] && !$settingObjectByIndex->linked) {
$this->maniaControl->getSettingManager()->deleteSettingUnlinked($settingObjectByIndex);
$setting = $this->maniaControl->getSettingManager()->getSettingObject($settingObjectByIndex->class, $settingObjectByIndex->setting);
$setting->linked = True;
} else if (!$settingData['Value'] && $settingObjectByIndex->linked) {
$setting = $settingObjectByIndex;
$setting->linked = false;
$this->maniaControl->getSettingManager()->setSettingUnlinked($setting);
} else {
continue;
}
} else {
$setting = $settingObjectByIndex;
if ($settingData['Value'] == $setting->value) {
continue;
}
$setting->value = $settingData['Value'];
}
$this->maniaControl->getSettingManager()->saveSetting($setting);
2014-05-02 17:50:30 +02:00
}
2014-08-13 11:05:52 +02:00
$this->maniaControl->getChat()->sendSuccess('Settings saved!', $player);
2014-05-16 20:42:37 +02:00
2014-05-02 17:50:30 +02:00
// Reopen the Menu
2014-08-13 11:05:52 +02:00
$this->maniaControl->getConfigurator()->showMenu($player, $this);
2014-05-02 17:50:30 +02:00
}
}