renamed 'Configurators' namespace to 'Configurator'
This commit is contained in:
357
application/core/Configurator/Configurator.php
Normal file
357
application/core/Configurator/Configurator.php
Normal file
@ -0,0 +1,357 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Configurator;
|
||||
|
||||
use FML\Controls\Frame;
|
||||
use FML\Controls\Labels\Label_Text;
|
||||
use FML\Controls\Quad;
|
||||
use FML\Controls\Quads\Quad_BgRaceScore2;
|
||||
use FML\Controls\Quads\Quad_Icons64x64_1;
|
||||
use FML\Controls\Quads\Quad_UIConstruction_Buttons;
|
||||
use FML\ManiaLink;
|
||||
use ManiaControl\Admin\AuthenticationManager;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\CallbackManager;
|
||||
use ManiaControl\Commands\CommandListener;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Manialinks\ManialinkManager;
|
||||
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
||||
use ManiaControl\Players\Player;
|
||||
use ManiaControl\Server\ServerOptionsMenu;
|
||||
|
||||
/**
|
||||
* Class managing ingame ManiaControl Configuration
|
||||
*
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class Configurator implements CallbackListener, CommandListener, ManialinkPageAnswerListener {
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
const ACTION_TOGGLEMENU = 'Configurator.ToggleMenuAction';
|
||||
const ACTION_SAVECONFIG = 'Configurator.SaveConfigAction';
|
||||
const ACTION_SELECTMENU = 'Configurator.SelectMenu.';
|
||||
const SETTING_MENU_POSX = 'Menu Widget Position: X';
|
||||
const SETTING_MENU_POSY = 'Menu Widget Position: Y';
|
||||
const SETTING_MENU_WIDTH = 'Menu Widget Width';
|
||||
const SETTING_MENU_HEIGHT = 'Menu Widget Height';
|
||||
const SETTING_MENU_STYLE = 'Menu Widget BackgroundQuad Style';
|
||||
const SETTING_MENU_SUBSTYLE = 'Menu Widget BackgroundQuad Substyle';
|
||||
const SETTING_PERMISSION_OPEN_CONFIGURATOR = 'Open Configurator';
|
||||
const CACHE_MENU_SHOWN = 'MenuShown';
|
||||
const MENU_NAME = 'Configurator';
|
||||
|
||||
/*
|
||||
* Private Properties
|
||||
*/
|
||||
private $maniaControl = null;
|
||||
private $scriptSettings = null;
|
||||
private $serverOptionsMenu = null;
|
||||
private $maniaControlSettings = null;
|
||||
/** @var ConfiguratorMenu[] $menus */
|
||||
private $menus = array();
|
||||
|
||||
/**
|
||||
* Create a new Configurator
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
$this->addActionsMenuItem();
|
||||
|
||||
// Init settings
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_POSX, 0.);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_POSY, 3.);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_WIDTH, 170.);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_HEIGHT, 81.);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_STYLE, Quad_BgRaceScore2::STYLE);
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_SUBSTYLE, Quad_BgRaceScore2::SUBSTYLE_HandleSelectable);
|
||||
|
||||
//Permission for opening
|
||||
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_OPEN_CONFIGURATOR, AuthenticationManager::AUTH_LEVEL_ADMIN);
|
||||
|
||||
// Register for page answers
|
||||
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_TOGGLEMENU, $this, 'handleToggleMenuAction');
|
||||
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_SAVECONFIG, $this, 'handleSaveConfigAction');
|
||||
|
||||
// Register for callbacks
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_OPENED, $this, 'handleWidgetOpened');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_CLOSED, $this, 'closeWidget');
|
||||
|
||||
// Create server settings
|
||||
$this->serverOptionsMenu = new ServerOptionsMenu($maniaControl);
|
||||
$this->addMenu($this->serverOptionsMenu);
|
||||
|
||||
// Create script settings
|
||||
$this->scriptSettings = new ScriptSettings($maniaControl);
|
||||
$this->addMenu($this->scriptSettings);
|
||||
|
||||
// Create Mania Control Settings
|
||||
$this->maniaControlSettings = new ManiaControlSettings($maniaControl);
|
||||
$this->addMenu($this->maniaControlSettings);
|
||||
|
||||
// Register for commands
|
||||
$this->maniaControl->commandManager->registerCommandListener('config', $this, 'handleConfigCommand', true, 'Loads Config panel.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Menu Item to the Actions Menu
|
||||
*/
|
||||
private function addActionsMenuItem() {
|
||||
$itemQuad = new Quad_UIConstruction_Buttons();
|
||||
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Tools)
|
||||
->setAction(self::ACTION_TOGGLEMENU);
|
||||
$this->maniaControl->actionsMenu->addAdminMenuItem($itemQuad, 100, 'Settings');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a configurator menu
|
||||
*
|
||||
* @param ConfiguratorMenu $menu
|
||||
*/
|
||||
public function addMenu(ConfiguratorMenu $menu) {
|
||||
array_push($this->menus, $menu);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Config Admin Command
|
||||
*
|
||||
* @param array $callback
|
||||
* @param Player $player
|
||||
*/
|
||||
public function handleConfigCommand(array $callback, Player $player) {
|
||||
if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_OPEN_CONFIGURATOR)) {
|
||||
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->showMenu($player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the Menu to the Player
|
||||
*
|
||||
* @param Player $player
|
||||
* @param mixed $menuId
|
||||
*/
|
||||
public function showMenu(Player $player, $menuId = 0) {
|
||||
if ($menuId instanceof ConfiguratorMenu) {
|
||||
$menuId = $this->getMenuId($menuId->getTitle());
|
||||
}
|
||||
$manialink = $this->buildManialink($menuId, $player);
|
||||
$this->maniaControl->manialinkManager->displayWidget($manialink, $player, self::MENU_NAME);
|
||||
$player->setCache($this, self::CACHE_MENU_SHOWN, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Menu Id
|
||||
*
|
||||
* @param string $title
|
||||
* @return int
|
||||
*/
|
||||
public function getMenuId($title) {
|
||||
$index = 0;
|
||||
foreach ($this->menus as $menu) {
|
||||
if ($menu === $title || $menu->getTitle() === $title) {
|
||||
return $index;
|
||||
}
|
||||
$index++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build Menu ManiaLink if necessary
|
||||
*
|
||||
* @param int $menuIdShown
|
||||
* @param Player $player
|
||||
* @return \FML\ManiaLink
|
||||
*/
|
||||
private function buildManialink($menuIdShown = 0, Player $player = null) {
|
||||
$menuPosX = $this->maniaControl->settingManager->getSettingValue($this, self::SETTING_MENU_POSX);
|
||||
$menuPosY = $this->maniaControl->settingManager->getSettingValue($this, self::SETTING_MENU_POSY);
|
||||
$menuWidth = $this->maniaControl->settingManager->getSettingValue($this, self::SETTING_MENU_WIDTH);
|
||||
$menuHeight = $this->maniaControl->settingManager->getSettingValue($this, self::SETTING_MENU_HEIGHT);
|
||||
$quadStyle = $this->maniaControl->settingManager->getSettingValue($this, self::SETTING_MENU_STYLE);
|
||||
$quadSubstyle = $this->maniaControl->settingManager->getSettingValue($this, self::SETTING_MENU_SUBSTYLE);
|
||||
|
||||
$menuListWidth = $menuWidth * 0.3;
|
||||
$menuItemHeight = 10.;
|
||||
$subMenuWidth = $menuWidth - $menuListWidth;
|
||||
$subMenuHeight = $menuHeight;
|
||||
|
||||
$manialink = new ManiaLink(ManialinkManager::MAIN_MLID);
|
||||
|
||||
$frame = new Frame();
|
||||
$manialink->add($frame);
|
||||
$frame->setPosition($menuPosX, $menuPosY, 10);
|
||||
|
||||
$backgroundQuad = new Quad();
|
||||
$frame->add($backgroundQuad);
|
||||
$backgroundQuad->setZ(-10)
|
||||
->setSize($menuWidth, $menuHeight)
|
||||
->setStyles($quadStyle, $quadSubstyle);
|
||||
|
||||
$menuItemsFrame = new Frame();
|
||||
$frame->add($menuItemsFrame);
|
||||
$menuItemsFrame->setX($menuWidth * -0.5 + $menuListWidth * 0.5);
|
||||
|
||||
$itemsBackgroundQuad = new Quad();
|
||||
$menuItemsFrame->add($itemsBackgroundQuad);
|
||||
$backgroundQuad->setZ(-9);
|
||||
$itemsBackgroundQuad->setSize($menuListWidth, $menuHeight)
|
||||
->setStyles($quadStyle, $quadSubstyle);
|
||||
|
||||
$menusFrame = new Frame();
|
||||
$frame->add($menusFrame);
|
||||
$menusFrame->setX($menuWidth * -0.5 + $menuListWidth + $subMenuWidth * 0.5);
|
||||
|
||||
// Create script and features
|
||||
$script = $manialink->getScript();
|
||||
|
||||
$menuItemY = $menuHeight * 0.42;
|
||||
$menuId = 0;
|
||||
foreach ($this->menus as $menu) {
|
||||
// Add title
|
||||
$menuItemLabel = new Label_Text();
|
||||
$menuItemsFrame->add($menuItemLabel);
|
||||
$menuItemLabel->setY($menuItemY)
|
||||
->setSize($menuListWidth * 0.9, $menuItemHeight * 0.9)
|
||||
->setStyle($menuItemLabel::STYLE_TextCardRaceRank)
|
||||
->setText($menu->getTitle())
|
||||
->setAction(self::ACTION_SELECTMENU . $menuId);
|
||||
|
||||
// Show the menu
|
||||
if ($menuId === $menuIdShown) {
|
||||
$menuControl = $menu->getMenu($subMenuWidth, $subMenuHeight, $script, $player);
|
||||
$menusFrame->add($menuControl);
|
||||
}
|
||||
|
||||
$menuItemY -= $menuItemHeight * 1.1;
|
||||
$menuId++;
|
||||
}
|
||||
|
||||
// Add Close Quad (X)
|
||||
$closeQuad = new Quad_Icons64x64_1();
|
||||
$frame->add($closeQuad);
|
||||
$closeQuad->setPosition($menuWidth * 0.483, $menuHeight * 0.467, 3)
|
||||
->setSize(6, 6)
|
||||
->setSubStyle($closeQuad::SUBSTYLE_QuitRace)
|
||||
->setAction(ManialinkManager::ACTION_CLOSEWIDGET);
|
||||
|
||||
// Add close button
|
||||
$closeButton = new Label_Text();
|
||||
$frame->add($closeButton);
|
||||
$closeButton->setPosition($menuWidth * -0.5 + $menuListWidth * 0.29, $menuHeight * -0.43)
|
||||
->setSize($menuListWidth * 0.3, $menuListWidth * 0.1)
|
||||
->setStyle($closeButton::STYLE_TextButtonNavBack)
|
||||
->setTextPrefix('$999')
|
||||
->setTranslate(true)
|
||||
->setText('Close')
|
||||
->setAction(self::ACTION_TOGGLEMENU);
|
||||
|
||||
// Add save button
|
||||
$saveButton = new Label_Text();
|
||||
$frame->add($saveButton);
|
||||
$saveButton->setPosition($menuWidth * -0.5 + $menuListWidth * 0.71, $menuHeight * -0.43)
|
||||
->setSize($menuListWidth * 0.3, $menuListWidth * 0.1)
|
||||
->setStyle($saveButton::STYLE_TextButtonNavBack)
|
||||
->setTextPrefix('$0f5')
|
||||
->setTranslate(true)
|
||||
->setText('Save')
|
||||
->setAction(self::ACTION_SAVECONFIG);
|
||||
|
||||
return $manialink;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle toggle menu action
|
||||
*
|
||||
* @param array $callback
|
||||
* @param Player $player
|
||||
*/
|
||||
public function handleToggleMenuAction(array $callback, Player $player) {
|
||||
$this->toggleMenu($player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle the Menu for the Player
|
||||
*
|
||||
* @param Player $player
|
||||
*/
|
||||
public function toggleMenu(Player $player) {
|
||||
if ($player->getCache($this, self::CACHE_MENU_SHOWN)) {
|
||||
$this->hideMenu($player);
|
||||
} else {
|
||||
$this->showMenu($player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide the Menu for the Player
|
||||
*
|
||||
* @param Player $player
|
||||
*/
|
||||
public function hideMenu(Player $player) {
|
||||
$this->closeWidget($player);
|
||||
$this->maniaControl->manialinkManager->closeWidget($player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle widget being closed
|
||||
*
|
||||
* @param Player $player
|
||||
*/
|
||||
public function closeWidget(Player $player) {
|
||||
$player->destroyCache($this, self::CACHE_MENU_SHOWN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the config data received from the manialink
|
||||
*
|
||||
* @param array $callback
|
||||
* @param Player $player
|
||||
*/
|
||||
public function handleSaveConfigAction(array $callback, Player $player) {
|
||||
foreach ($this->menus as $menu) {
|
||||
$menu->saveConfigData($callback[1], $player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset the player if he opened another Main Widget
|
||||
*
|
||||
* @param Player $player
|
||||
* @param string $openedWidget
|
||||
*/
|
||||
public function handleWidgetOpened(Player $player, $openedWidget) {
|
||||
if ($openedWidget !== self::MENU_NAME) {
|
||||
$player->destroyCache($this, self::CACHE_MENU_SHOWN);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle ManialinkPageAnswer Callback
|
||||
*
|
||||
* @param array $callback
|
||||
*/
|
||||
public function handleManialinkPageAnswer(array $callback) {
|
||||
$actionId = $callback[1][2];
|
||||
$boolSelectMenu = (strpos($actionId, self::ACTION_SELECTMENU) === 0);
|
||||
if (!$boolSelectMenu) {
|
||||
return;
|
||||
}
|
||||
|
||||
$login = $callback[1][1];
|
||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||
|
||||
if ($player) {
|
||||
$actionArray = explode('.', $callback[1][2]);
|
||||
$this->showMenu($player, intval($actionArray[2]));
|
||||
}
|
||||
}
|
||||
}
|
42
application/core/Configurator/ConfiguratorMenu.php
Normal file
42
application/core/Configurator/ConfiguratorMenu.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Configurator;
|
||||
|
||||
use FML\Script\Script;
|
||||
use ManiaControl\Players\Player;
|
||||
|
||||
/**
|
||||
* Interface for Configurator Menus
|
||||
*
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
interface ConfiguratorMenu {
|
||||
|
||||
/**
|
||||
* Get the Menu Title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getTitle();
|
||||
|
||||
/**
|
||||
* Get the Configurator Menu Frame
|
||||
*
|
||||
* @param float $width
|
||||
* @param float $height
|
||||
* @param Script $script
|
||||
* @param Player $player
|
||||
* @return \FML\Controls\Frame
|
||||
*/
|
||||
public function getMenu($width, $height, Script $script, Player $player);
|
||||
|
||||
/**
|
||||
* Save the Config Data
|
||||
*
|
||||
* @param array $configData
|
||||
* @param Player $player
|
||||
*/
|
||||
public function saveConfigData(array $configData, Player $player);
|
||||
}
|
349
application/core/Configurator/ManiaControlSettings.php
Normal file
349
application/core/Configurator/ManiaControlSettings.php
Normal file
@ -0,0 +1,349 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Configurator;
|
||||
|
||||
use FML\Components\CheckBox;
|
||||
use FML\Components\ValuePicker;
|
||||
use FML\Controls\Entry;
|
||||
use FML\Controls\Frame;
|
||||
use FML\Controls\Labels\Label_Button;
|
||||
use FML\Controls\Labels\Label_Text;
|
||||
use FML\Controls\Quad;
|
||||
use FML\Controls\Quads\Quad_Icons64x64_1;
|
||||
use FML\Script\Features\Paging;
|
||||
use FML\Script\Script;
|
||||
use ManiaControl\Admin\AuthenticationManager;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\CallbackManager;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Players\Player;
|
||||
use ManiaControl\Settings\Setting;
|
||||
|
||||
/**
|
||||
* Class offering a Configurator for ManiaControl Settings
|
||||
*
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
const TITLE = 'ManiaControl Settings';
|
||||
const ACTION_PREFIX_SETTING = 'MCSetting.';
|
||||
const ACTION_PREFIX_SETTINGCLASS = 'MCSettingClass.';
|
||||
const ACTION_SETTINGCLASS_BACK = 'MCSettingClassBack';
|
||||
const SETTING_PERMISSION_CHANGE_MC_SETTINGS = 'Change ManiaControl Settings';
|
||||
const CACHE_CLASS_OPENED = 'ClassOpened';
|
||||
|
||||
/*
|
||||
* Private Properties
|
||||
*/
|
||||
private $maniaControl = null;
|
||||
|
||||
/**
|
||||
* Create a new Script Settings Instance
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
// Register for callbacks
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
||||
|
||||
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_CHANGE_MC_SETTINGS, AuthenticationManager::AUTH_LEVEL_ADMIN);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \ManiaControl\Configurators\ConfiguratorMenu::getTitle()
|
||||
*/
|
||||
public static function getTitle() {
|
||||
return self::TITLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \ManiaControl\Configurators\ConfiguratorMenu::getMenu()
|
||||
*/
|
||||
public function getMenu($width, $height, Script $script, Player $player) {
|
||||
$openedClass = $player->getCache($this, self::CACHE_CLASS_OPENED);
|
||||
if ($openedClass) {
|
||||
return $this->getMenuSettingsForClass($openedClass, $width, $height, $script, $player);
|
||||
}
|
||||
return $this->getMenuSettingClasses($width, $height, $script, $player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Menu showing the Settings for the given Class
|
||||
*
|
||||
* @param string $settingClass
|
||||
* @param float $width
|
||||
* @param float $height
|
||||
* @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);
|
||||
|
||||
$paging = new Paging();
|
||||
$script->addFeature($paging);
|
||||
$frame = new Frame();
|
||||
|
||||
// Config
|
||||
$pagerSize = 9.;
|
||||
$settingHeight = 5.;
|
||||
$labelTextSize = 2;
|
||||
$pageMaxCount = 11;
|
||||
|
||||
// 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);
|
||||
$pageCountLabel->setStyle($pageCountLabel::STYLE_TextTitle1);
|
||||
$pageCountLabel->setTextSize(2);
|
||||
|
||||
$paging->setLabel($pageCountLabel);
|
||||
|
||||
$backLabel = new Label_Button();
|
||||
$frame->add($backLabel);
|
||||
$backLabel->setStyle($backLabel::STYLE_CardMain_Quit);
|
||||
$backLabel->setPosition(-$width / 2 + 7, -$height / 2 + 7);
|
||||
$backLabel->setHAlign($backLabel::LEFT);
|
||||
$backLabel->setTextSize(2);
|
||||
$backLabel->setText('Back');
|
||||
$backLabel->setAction(self::ACTION_SETTINGCLASS_BACK);
|
||||
|
||||
$headLabel = new Label_Text();
|
||||
$frame->add($headLabel);
|
||||
$headLabel->setHAlign($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->add($pageFrame);
|
||||
$paging->addPage($pageFrame);
|
||||
$posY = $height * 0.41 - $settingHeight * 1.5;
|
||||
}
|
||||
|
||||
$settingFrame = new Frame();
|
||||
$pageFrame->add($settingFrame);
|
||||
$settingFrame->setY($posY);
|
||||
|
||||
$nameLabel = new Label_Text();
|
||||
$settingFrame->add($nameLabel);
|
||||
$nameLabel->setHAlign($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');
|
||||
|
||||
$settingName = self::ACTION_PREFIX_SETTING . $setting->index;
|
||||
if ($setting->type === Setting::TYPE_BOOL) {
|
||||
// Boolean checkbox
|
||||
$quad = new Quad();
|
||||
$quad->setPosition($width * 0.33, 0, -0.01);
|
||||
$quad->setSize(4, 4);
|
||||
$checkBox = new CheckBox($settingName, $setting->value, $quad);
|
||||
$settingFrame->add($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);
|
||||
$settingFrame->add($valuePicker);
|
||||
} else {
|
||||
// Standard entry
|
||||
$entry = new Entry();
|
||||
$settingFrame->add($entry);
|
||||
$entry->setX($width * 0.33);
|
||||
$entry->setSize($width * 0.3, $settingHeight * 0.9);
|
||||
$entry->setStyle(Label_Text::STYLE_TextValueSmall);
|
||||
$entry->setTextSize(1);
|
||||
$entry->setName($settingName);
|
||||
$entry->setDefault($setting->value);
|
||||
}
|
||||
|
||||
$posY -= $settingHeight;
|
||||
$index++;
|
||||
}
|
||||
|
||||
return $frame;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Menu showing all possible Classes
|
||||
*
|
||||
* @param float $width
|
||||
* @param float $height
|
||||
* @param Script $script
|
||||
* @param Player $player
|
||||
* @return \FML\Controls\Frame
|
||||
*/
|
||||
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;
|
||||
$posY = 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 ($index % $pageMaxCount === 0) {
|
||||
$pageFrame = new Frame();
|
||||
$frame->add($pageFrame);
|
||||
$posY = $height * 0.41;
|
||||
$paging->addPage($pageFrame);
|
||||
}
|
||||
|
||||
$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, $posY);
|
||||
$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);
|
||||
|
||||
$posY -= $settingHeight;
|
||||
$index++;
|
||||
}
|
||||
|
||||
return $frame;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle ManialinkPageAnswer Callback
|
||||
*
|
||||
* @param array $callback
|
||||
*/
|
||||
public function handleManialinkPageAnswer(array $callback) {
|
||||
$actionId = $callback[1][2];
|
||||
if ($actionId === self::ACTION_SETTINGCLASS_BACK) {
|
||||
// Back to classes list
|
||||
$login = $callback[1][1];
|
||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||
$player->destroyCache($this, self::CACHE_CLASS_OPENED);
|
||||
$menuId = $this->maniaControl->configurator->getMenuId($this);
|
||||
$this->maniaControl->configurator->showMenu($player, $menuId);
|
||||
} else if (strpos($actionId, self::ACTION_PREFIX_SETTINGCLASS) === 0) {
|
||||
// Setting class selected
|
||||
$settingClass = substr($actionId, strlen(self::ACTION_PREFIX_SETTINGCLASS));
|
||||
|
||||
$login = $callback[1][1];
|
||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||
$player->setCache($this, self::CACHE_CLASS_OPENED, $settingClass);
|
||||
|
||||
$menuId = $this->maniaControl->configurator->getMenuId($this);
|
||||
$this->maniaControl->configurator->showMenu($player, $menuId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData()
|
||||
*/
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
|
||||
$prefixLength = strlen(self::ACTION_PREFIX_SETTING);
|
||||
|
||||
foreach ($configData[3] as $settingData) {
|
||||
$settingIndex = (int)substr($settingData['Name'], $prefixLength);
|
||||
$settingObject = $this->maniaControl->settingManager->getSettingObjectByIndex($settingIndex);
|
||||
if (!$settingObject) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$settingData || $settingData['Value'] == $settingObject->value) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$settingObject->value = $settingData['Value'];
|
||||
$this->maniaControl->settingManager->saveSetting($settingObject);
|
||||
}
|
||||
|
||||
$this->maniaControl->chat->sendSuccess('Settings saved!', $player);
|
||||
|
||||
// Reopen the Menu
|
||||
$this->maniaControl->configurator->showMenu($player, $this);
|
||||
}
|
||||
}
|
405
application/core/Configurator/ScriptSettings.php
Normal file
405
application/core/Configurator/ScriptSettings.php
Normal file
@ -0,0 +1,405 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Configurator;
|
||||
|
||||
use FML\Components\CheckBox;
|
||||
use FML\Controls\Entry;
|
||||
use FML\Controls\Frame;
|
||||
use FML\Controls\Label;
|
||||
use FML\Controls\Labels\Label_Text;
|
||||
use FML\Controls\Quad;
|
||||
use FML\Controls\Quads\Quad_Icons64x64_1;
|
||||
use FML\Script\Features\Paging;
|
||||
use FML\Script\Script;
|
||||
use ManiaControl\Admin\AuthenticationManager;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\Callbacks;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Players\Player;
|
||||
use Maniaplanet\DedicatedServer\Xmlrpc\GameModeException;
|
||||
|
||||
/**
|
||||
* Class offering a Configurator for Script Settings
|
||||
*
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
const ACTION_PREFIX_SETTING = 'ScriptSetting.';
|
||||
const CB_SCRIPTSETTING_CHANGED = 'ScriptSettings.SettingChanged';
|
||||
const CB_SCRIPTSETTINGS_CHANGED = 'ScriptSettings.SettingsChanged';
|
||||
const TABLE_SCRIPT_SETTINGS = 'mc_scriptsettings';
|
||||
const SETTING_LOAD_DEFAULT_SETTINGS_MAP_BEGIN = 'Load Stored Script-Settings on Map-Begin';
|
||||
const SETTING_PERMISSION_CHANGE_SCRIPT_SETTINGS = 'Change Script-Settings';
|
||||
|
||||
/*
|
||||
* Private Properties
|
||||
*/
|
||||
private $maniaControl = null;
|
||||
|
||||
/**
|
||||
* Create a new Script Settings Instance
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
$this->initTables();
|
||||
|
||||
// Register for callbacks
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(Callbacks::ONINIT, $this, 'onInit');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(Callbacks::BEGINMAP, $this, 'onBeginMap');
|
||||
$this->maniaControl->settingManager->initSetting($this, self::SETTING_LOAD_DEFAULT_SETTINGS_MAP_BEGIN, true);
|
||||
|
||||
//Permission for Change Script-Settings
|
||||
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_CHANGE_SCRIPT_SETTINGS, AuthenticationManager::AUTH_LEVEL_ADMIN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create all necessary Database Tables
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private function initTables() {
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_SCRIPT_SETTINGS . "` (
|
||||
`index` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`serverIndex` int(11) NOT NULL,
|
||||
`settingName` varchar(100) NOT NULL,
|
||||
`settingValue` varchar(500) NOT NULL,
|
||||
PRIMARY KEY (`index`),
|
||||
UNIQUE KEY `setting` (`serverIndex`, `settingName`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Script Settings' AUTO_INCREMENT=1;";
|
||||
|
||||
$statement = $mysqli->prepare($query);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error, E_USER_ERROR);
|
||||
return false;
|
||||
}
|
||||
$statement->execute();
|
||||
if ($statement->error) {
|
||||
trigger_error($statement->error, E_USER_ERROR);
|
||||
return false;
|
||||
}
|
||||
$statement->close();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \ManiaControl\Configurators\ConfiguratorMenu::getTitle()
|
||||
*/
|
||||
public static function getTitle() {
|
||||
return 'Script Settings';
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle OnInit callback
|
||||
*/
|
||||
public function onInit() {
|
||||
$this->loadSettingsFromDatabase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Settings from Database
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function loadSettingsFromDatabase() {
|
||||
try {
|
||||
$scriptSettings = $this->maniaControl->client->getModeScriptSettings();
|
||||
} catch (GameModeException $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
$serverIndex = $this->maniaControl->server->index;
|
||||
$query = "SELECT * FROM `" . self::TABLE_SCRIPT_SETTINGS . "`
|
||||
WHERE serverIndex = {$serverIndex};";
|
||||
$result = $mysqli->query($query);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error);
|
||||
return false;
|
||||
}
|
||||
|
||||
$loadedSettings = array();
|
||||
while ($row = $result->fetch_object()) {
|
||||
if (!isset($scriptSettings[$row->settingName])) {
|
||||
continue;
|
||||
}
|
||||
$loadedSettings[$row->settingName] = $row->settingValue;
|
||||
settype($loadedSettings[$row->settingName], gettype($scriptSettings[$row->settingName]));
|
||||
}
|
||||
$result->free();
|
||||
if (empty($loadedSettings)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->maniaControl->client->setModeScriptSettings($loadedSettings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Begin Map Callback
|
||||
*/
|
||||
public function onBeginMap() {
|
||||
if ($this->maniaControl->settingManager->getSettingValue($this, self::SETTING_LOAD_DEFAULT_SETTINGS_MAP_BEGIN)) {
|
||||
$this->loadSettingsFromDatabase();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \ManiaControl\Configurators\ConfiguratorMenu::getMenu()
|
||||
*/
|
||||
public function getMenu($width, $height, Script $script, Player $player) {
|
||||
$paging = new Paging();
|
||||
$script->addFeature($paging);
|
||||
$frame = new Frame();
|
||||
|
||||
try {
|
||||
$scriptInfo = $this->maniaControl->client->getModeScriptInfo();
|
||||
} catch (GameModeException $e) {
|
||||
$label = new Label();
|
||||
$frame->add($label);
|
||||
$label->setText($e->getMessage());
|
||||
return $frame;
|
||||
}
|
||||
|
||||
$scriptParams = $scriptInfo->paramDescs;
|
||||
|
||||
try {
|
||||
$scriptSettings = $this->maniaControl->client->getModeScriptSettings();
|
||||
} catch (GameModeException $e) {
|
||||
}
|
||||
|
||||
// Config
|
||||
$pagerSize = 9.;
|
||||
$settingHeight = 5.;
|
||||
$labelTextSize = 2;
|
||||
|
||||
// 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);
|
||||
|
||||
// Setting pages
|
||||
$pageFrame = null;
|
||||
$posY = 0.;
|
||||
|
||||
foreach ($scriptParams as $index => $scriptParam) {
|
||||
/** @var \Maniaplanet\DedicatedServer\Structures\ScriptSettings $scriptParam */
|
||||
$settingName = $scriptParam->name;
|
||||
|
||||
if (!isset($scriptSettings[$settingName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($index % 13 === 0) {
|
||||
$pageFrame = new Frame();
|
||||
$frame->add($pageFrame);
|
||||
$posY = $height * 0.41;
|
||||
$paging->addPage($pageFrame);
|
||||
}
|
||||
|
||||
$settingFrame = new Frame();
|
||||
$pageFrame->add($settingFrame);
|
||||
$settingFrame->setY($posY);
|
||||
|
||||
$nameLabel = new Label_Text();
|
||||
$settingFrame->add($nameLabel);
|
||||
$nameLabel->setHAlign($nameLabel::LEFT);
|
||||
$nameLabel->setX($width * -0.46);
|
||||
$nameLabel->setSize($width * 0.4, $settingHeight);
|
||||
$nameLabel->setStyle($nameLabel::STYLE_TextCardSmall);
|
||||
$nameLabel->setTextSize($labelTextSize);
|
||||
$nameLabel->setText($settingName);
|
||||
|
||||
$settingValue = $scriptSettings[$settingName];
|
||||
|
||||
if (is_bool($settingValue)) {
|
||||
// Boolean checkbox
|
||||
$quad = new Quad();
|
||||
$quad->setX($width / 2 * 0.545);
|
||||
$quad->setSize(4, 4);
|
||||
$checkBox = new CheckBox(self::ACTION_PREFIX_SETTING . $settingName, $settingValue, $quad);
|
||||
$settingFrame->add($checkBox);
|
||||
} else {
|
||||
// Value entry
|
||||
$entry = new Entry();
|
||||
$settingFrame->add($entry);
|
||||
$entry->setStyle(Label_Text::STYLE_TextValueSmall);
|
||||
$entry->setX($width / 2 * 0.55);
|
||||
$entry->setTextSize(1);
|
||||
$entry->setSize($width * 0.3, $settingHeight * 0.9);
|
||||
$entry->setName(self::ACTION_PREFIX_SETTING . $settingName);
|
||||
$entry->setDefault($settingValue);
|
||||
}
|
||||
|
||||
$descriptionLabel = new Label();
|
||||
$pageFrame->add($descriptionLabel);
|
||||
$descriptionLabel->setHAlign($descriptionLabel::LEFT);
|
||||
$descriptionLabel->setPosition($width * -0.45, $height * -0.44);
|
||||
$descriptionLabel->setSize($width * 0.7, $settingHeight);
|
||||
$descriptionLabel->setTextSize($labelTextSize);
|
||||
$descriptionLabel->setTranslate(true);
|
||||
$descriptionLabel->setText($scriptParam->desc);
|
||||
$nameLabel->addTooltipFeature($descriptionLabel);
|
||||
|
||||
$posY -= $settingHeight;
|
||||
}
|
||||
|
||||
return $frame;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData()
|
||||
*/
|
||||
public function saveConfigData(array $configData, Player $player) {
|
||||
if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_CHANGE_SCRIPT_SETTINGS)) {
|
||||
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
||||
return;
|
||||
}
|
||||
if (!$configData[3] || strpos($configData[3][0]['Name'], self::ACTION_PREFIX_SETTING) !== 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$scriptSettings = $this->maniaControl->client->getModeScriptSettings();
|
||||
} catch (GameModeException $e) {
|
||||
return;
|
||||
}
|
||||
|
||||
$prefixLength = strlen(self::ACTION_PREFIX_SETTING);
|
||||
|
||||
$newSettings = array();
|
||||
foreach ($configData[3] as $setting) {
|
||||
$settingName = substr($setting['Name'], $prefixLength);
|
||||
if (!isset($scriptSettings[$settingName])) {
|
||||
var_dump('no setting ' . $settingName);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($setting['Value'] == $scriptSettings[$settingName]) {
|
||||
// Not changed
|
||||
continue;
|
||||
}
|
||||
|
||||
$newSettings[$settingName] = $setting['Value'];
|
||||
settype($newSettings[$settingName], gettype($scriptSettings[$settingName]));
|
||||
}
|
||||
|
||||
$success = $this->applyNewScriptSettings($newSettings, $player);
|
||||
if ($success) {
|
||||
$this->maniaControl->chat->sendSuccess('Script Settings saved!', $player);
|
||||
} else {
|
||||
$this->maniaControl->chat->sendError('Script Settings Saving failed!', $player);
|
||||
}
|
||||
|
||||
// Reopen the Menu
|
||||
$this->maniaControl->configurator->showMenu($player, $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the Array of new Script Settings
|
||||
*
|
||||
* @param array $newSettings
|
||||
* @param Player $player
|
||||
* @return bool
|
||||
*/
|
||||
private function applyNewScriptSettings(array $newSettings, Player $player) {
|
||||
if (empty($newSettings)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->maniaControl->client->setModeScriptSettings($newSettings);
|
||||
|
||||
// Save Settings into Database
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
$query = "INSERT INTO `" . self::TABLE_SCRIPT_SETTINGS . "` (
|
||||
`serverIndex`,
|
||||
`settingName`,
|
||||
`settingValue`
|
||||
) VALUES (
|
||||
?, ?, ?
|
||||
) ON DUPLICATE KEY UPDATE
|
||||
`settingValue` = VALUES(`settingValue`);";
|
||||
$statement = $mysqli->prepare($query);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error);
|
||||
return false;
|
||||
}
|
||||
$settingName = null;
|
||||
$settingValue = null;
|
||||
$statement->bind_param('iss', $this->maniaControl->server->index, $settingName, $settingValue);
|
||||
|
||||
// Notifications
|
||||
$settingsCount = count($newSettings);
|
||||
$settingIndex = 0;
|
||||
$title = $this->maniaControl->authenticationManager->getAuthLevelName($player);
|
||||
$chatMessage = '$ff0' . $title . ' $<' . $player->nickname . '$> set ScriptSetting' . ($settingsCount > 1 ? 's' : '') . ' ';
|
||||
foreach ($newSettings as $setting => $value) {
|
||||
$chatMessage .= '$<' . '$fff' . preg_replace('/^S_/', '', $setting) . '$z$s$ff0 ';
|
||||
$chatMessage .= 'to $fff' . $this->parseSettingValue($value) . '$>';
|
||||
|
||||
if ($settingIndex <= $settingsCount - 2) {
|
||||
$chatMessage .= ', ';
|
||||
}
|
||||
|
||||
// Add To Database
|
||||
$settingName = $setting;
|
||||
$settingValue = $value;
|
||||
$statement->execute();
|
||||
if ($statement->error) {
|
||||
trigger_error($statement->error);
|
||||
}
|
||||
|
||||
// Trigger own callback
|
||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_SCRIPTSETTING_CHANGED, $setting, $value);
|
||||
|
||||
$settingIndex++;
|
||||
}
|
||||
$statement->close();
|
||||
|
||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_SCRIPTSETTINGS_CHANGED);
|
||||
|
||||
$chatMessage .= '!';
|
||||
$this->maniaControl->chat->sendInformation($chatMessage);
|
||||
$this->maniaControl->log($chatMessage, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the Setting Value to a String Representation
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return string
|
||||
*/
|
||||
private function parseSettingValue($value) {
|
||||
if (is_bool($value)) {
|
||||
return ($value ? 'True' : 'False');
|
||||
}
|
||||
return (string)$value;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user