serversettings panel
This commit is contained in:
parent
0df42c9e2d
commit
9e599c829c
@ -24,6 +24,7 @@ use ManiaControl\Commands\CommandListener;
|
|||||||
|
|
||||||
require_once __DIR__ . '/ConfiguratorMenu.php';
|
require_once __DIR__ . '/ConfiguratorMenu.php';
|
||||||
require_once __DIR__ . '/ScriptSettings.php';
|
require_once __DIR__ . '/ScriptSettings.php';
|
||||||
|
require_once __DIR__ . '/ServerSettings.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class managing ingame ManiaControl configuration
|
* Class managing ingame ManiaControl configuration
|
||||||
@ -48,6 +49,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
|||||||
*/
|
*/
|
||||||
private $maniaControl = null;
|
private $maniaControl = null;
|
||||||
private $scriptSettings = null;
|
private $scriptSettings = null;
|
||||||
|
private $serverSettings = null;
|
||||||
private $menus = array();
|
private $menus = array();
|
||||||
private $playersMenuShown = array();
|
private $playersMenuShown = array();
|
||||||
private $manialink = null;
|
private $manialink = null;
|
||||||
@ -80,11 +82,17 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
|||||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERDISCONNECT, $this,
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERDISCONNECT, $this,
|
||||||
'handlePlayerDisconnect');
|
'handlePlayerDisconnect');
|
||||||
$this->maniaControl->callbackManager->registerCallbackListener(ScriptSettings::CB_SCRIPTSETTING_CHANGED, $this, 'reopenMenu');
|
$this->maniaControl->callbackManager->registerCallbackListener(ScriptSettings::CB_SCRIPTSETTING_CHANGED, $this, 'reopenMenu');
|
||||||
|
$this->maniaControl->callbackManager->registerCallbackListener(ServerSettings::CB_SERVERSETTING_CHANGED, $this, 'reopenMenu');
|
||||||
|
|
||||||
// Create script settings
|
// Create script settings
|
||||||
$this->scriptSettings = new ScriptSettings($maniaControl);
|
$this->scriptSettings = new ScriptSettings($maniaControl);
|
||||||
$this->addMenu($this->scriptSettings);
|
$this->addMenu($this->scriptSettings);
|
||||||
|
|
||||||
|
// Create server settings
|
||||||
|
$this->serverSettings = new ServerSettings($maniaControl);
|
||||||
|
$this->addMenu($this->serverSettings);
|
||||||
|
|
||||||
|
|
||||||
// Register for commands
|
// Register for commands
|
||||||
$this->maniaControl->commandManager->registerCommandListener('config', $this, 'handleConfigCommand', true);
|
$this->maniaControl->commandManager->registerCommandListener('config', $this, 'handleConfigCommand', true);
|
||||||
}
|
}
|
||||||
|
@ -2,19 +2,19 @@
|
|||||||
|
|
||||||
namespace ManiaControl\Configurators;
|
namespace ManiaControl\Configurators;
|
||||||
|
|
||||||
|
use FML\Controls\Control;
|
||||||
|
use FML\Controls\Entry;
|
||||||
|
use FML\Controls\Frame;
|
||||||
|
use FML\Controls\Label;
|
||||||
|
use FML\Controls\Labels\Label_Text;
|
||||||
|
use FML\Controls\Quads\Quad_Icons64x64_1;
|
||||||
|
use FML\Script\Pages;
|
||||||
use FML\Script\Script;
|
use FML\Script\Script;
|
||||||
|
use FML\Script\Tooltips;
|
||||||
use ManiaControl\Callbacks\CallbackListener;
|
use ManiaControl\Callbacks\CallbackListener;
|
||||||
use ManiaControl\Callbacks\CallbackManager;
|
use ManiaControl\Callbacks\CallbackManager;
|
||||||
use ManiaControl\Formatter;
|
use ManiaControl\Formatter;
|
||||||
use ManiaControl\ManiaControl;
|
use ManiaControl\ManiaControl;
|
||||||
use FML\Controls\Frame;
|
|
||||||
use FML\Controls\Label;
|
|
||||||
use FML\Script\Pages;
|
|
||||||
use FML\Script\Tooltips;
|
|
||||||
use FML\Controls\Control;
|
|
||||||
use FML\Controls\Quads\Quad_Icons64x64_1;
|
|
||||||
use FML\Controls\Labels\Label_Text;
|
|
||||||
use FML\Controls\Entry;
|
|
||||||
use ManiaControl\Players\Player;
|
use ManiaControl\Players\Player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -26,8 +26,8 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
/**
|
/**
|
||||||
* Constants
|
* Constants
|
||||||
*/
|
*/
|
||||||
const ACTION_PREFIX_SETTING = 'ScriptSetting.';
|
const ACTION_PREFIX_SETTING = 'ScriptSetting.';
|
||||||
const ACTION_SETTING_BOOL = 'ScriptSetting.ActionBoolSetting.';
|
const ACTION_SETTING_BOOL = 'ScriptSetting.ActionBoolSetting.';
|
||||||
const CB_SCRIPTSETTING_CHANGED = 'ScriptSettings.SettingChanged';
|
const CB_SCRIPTSETTING_CHANGED = 'ScriptSettings.SettingChanged';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -44,8 +44,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
$this->maniaControl = $maniaControl;
|
$this->maniaControl = $maniaControl;
|
||||||
|
|
||||||
// Register for callbacks
|
// Register for callbacks
|
||||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this,
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
||||||
'handleManialinkPageAnswer');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -62,11 +61,11 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
*/
|
*/
|
||||||
public function getMenu($width, $height, Script $script) {
|
public function getMenu($width, $height, Script $script) {
|
||||||
$pagesId = 'ScriptSettingsPages';
|
$pagesId = 'ScriptSettingsPages';
|
||||||
$frame = new Frame();
|
$frame = new Frame();
|
||||||
|
|
||||||
$this->maniaControl->client->query('GetModeScriptInfo');
|
$this->maniaControl->client->query('GetModeScriptInfo');
|
||||||
$scriptInfo = $this->maniaControl->client->getResponse();
|
$scriptInfo = $this->maniaControl->client->getResponse();
|
||||||
if (isset($scriptInfo['faultCode'])) {
|
if(isset($scriptInfo['faultCode'])) {
|
||||||
// Not in script mode
|
// Not in script mode
|
||||||
$label = new Label();
|
$label = new Label();
|
||||||
$frame->add($label);
|
$frame->add($label);
|
||||||
@ -79,10 +78,10 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
$scriptSettings = $this->maniaControl->client->getResponse();
|
$scriptSettings = $this->maniaControl->client->getResponse();
|
||||||
|
|
||||||
// Config
|
// Config
|
||||||
$pagerSize = 9.;
|
$pagerSize = 9.;
|
||||||
$settingHeight = 5.;
|
$settingHeight = 5.;
|
||||||
$labelTextSize = 2;
|
$labelTextSize = 2;
|
||||||
$pageMaxCount = 13;
|
$pageMaxCount = 13;
|
||||||
|
|
||||||
// Pagers
|
// Pagers
|
||||||
$pagerPrev = new Quad_Icons64x64_1();
|
$pagerPrev = new Quad_Icons64x64_1();
|
||||||
@ -111,16 +110,18 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
|
|
||||||
// Setting pages
|
// Setting pages
|
||||||
$pageFrames = array();
|
$pageFrames = array();
|
||||||
$y = 0.;
|
$y = 0.;
|
||||||
foreach ($scriptParams as $index => $scriptParam) {
|
foreach($scriptParams as $index => $scriptParam) {
|
||||||
$settingName = $scriptParam['Name'];
|
$settingName = $scriptParam['Name'];
|
||||||
|
|
||||||
if (!isset($scriptSettings[$settingName])) continue;
|
if(!isset($scriptSettings[$settingName])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!isset($pageFrame)) {
|
if(!isset($pageFrame)) {
|
||||||
$pageFrame = new Frame();
|
$pageFrame = new Frame();
|
||||||
$frame->add($pageFrame);
|
$frame->add($pageFrame);
|
||||||
if (!empty($pageFrames)) {
|
if(!empty($pageFrames)) {
|
||||||
$pageFrame->setVisible(false);
|
$pageFrame->setVisible(false);
|
||||||
}
|
}
|
||||||
array_push($pageFrames, $pageFrame);
|
array_push($pageFrames, $pageFrame);
|
||||||
@ -144,14 +145,13 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
$settingValue = $scriptSettings[$settingName];
|
$settingValue = $scriptSettings[$settingName];
|
||||||
|
|
||||||
$substyle = '';
|
$substyle = '';
|
||||||
if ($settingValue === false) {
|
if($settingValue === false) {
|
||||||
$substyle = Quad_Icons64x64_1::SUBSTYLE_LvlRed;
|
$substyle = Quad_Icons64x64_1::SUBSTYLE_LvlRed;
|
||||||
}
|
} else if($settingValue === true) {
|
||||||
else if ($settingValue === true) {
|
|
||||||
$substyle = Quad_Icons64x64_1::SUBSTYLE_LvlGreen;
|
$substyle = Quad_Icons64x64_1::SUBSTYLE_LvlGreen;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($substyle != '') {
|
if($substyle != '') {
|
||||||
$quad = new Quad_Icons64x64_1();
|
$quad = new Quad_Icons64x64_1();
|
||||||
$settingFrame->add($quad);
|
$settingFrame->add($quad);
|
||||||
$quad->setX($width / 2 * 0.545);
|
$quad->setX($width / 2 * 0.545);
|
||||||
@ -160,8 +160,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
$quad->setSize(4, 4);
|
$quad->setSize(4, 4);
|
||||||
$quad->setHAlign(Control::CENTER);
|
$quad->setHAlign(Control::CENTER);
|
||||||
$quad->setAction(self::ACTION_SETTING_BOOL . $settingName);
|
$quad->setAction(self::ACTION_SETTING_BOOL . $settingName);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$entry = new Entry();
|
$entry = new Entry();
|
||||||
$settingFrame->add($entry);
|
$settingFrame->add($entry);
|
||||||
$entry->setStyle(Label_Text::STYLE_TextValueSmall);
|
$entry->setStyle(Label_Text::STYLE_TextValueSmall);
|
||||||
@ -185,7 +184,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
$script->addTooltip($nameLabel, $descriptionLabel);
|
$script->addTooltip($nameLabel, $descriptionLabel);
|
||||||
|
|
||||||
$y -= $settingHeight;
|
$y -= $settingHeight;
|
||||||
if ($index % $pageMaxCount == $pageMaxCount - 1) {
|
if($index % $pageMaxCount == $pageMaxCount - 1) {
|
||||||
unset($pageFrame);
|
unset($pageFrame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -198,22 +197,24 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
* @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData()
|
* @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData()
|
||||||
*/
|
*/
|
||||||
public function saveConfigData(array $configData, Player $player) {
|
public function saveConfigData(array $configData, Player $player) {
|
||||||
|
|
||||||
$this->maniaControl->client->query('GetModeScriptSettings');
|
$this->maniaControl->client->query('GetModeScriptSettings');
|
||||||
$scriptSettings = $this->maniaControl->client->getResponse();
|
$scriptSettings = $this->maniaControl->client->getResponse();
|
||||||
|
|
||||||
$prefixLength = strlen(self::ACTION_PREFIX_SETTING);
|
$prefixLength = strlen(self::ACTION_PREFIX_SETTING);
|
||||||
|
|
||||||
$newSettings = array();
|
$newSettings = array();
|
||||||
foreach ($configData[3] as $setting) {
|
foreach($configData[3] as $setting) {
|
||||||
if (substr($setting['Name'], 0, $prefixLength) != self::ACTION_PREFIX_SETTING) continue;
|
if(substr($setting['Name'], 0, $prefixLength) != self::ACTION_PREFIX_SETTING)
|
||||||
|
continue;
|
||||||
|
|
||||||
$settingName = substr($setting['Name'], $prefixLength);
|
$settingName = substr($setting['Name'], $prefixLength);
|
||||||
if (!isset($scriptSettings[$settingName])) {
|
if(!isset($scriptSettings[$settingName])) {
|
||||||
var_dump('no setting ' . $settingName);
|
var_dump('no setting ' . $settingName);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($setting['Value'] == $scriptSettings[$settingName]) {
|
if($setting['Value'] == $scriptSettings[$settingName]) {
|
||||||
// Not changed
|
// Not changed
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -231,16 +232,20 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
* @param array $callback
|
* @param array $callback
|
||||||
*/
|
*/
|
||||||
public function handleManialinkPageAnswer(array $callback) {
|
public function handleManialinkPageAnswer(array $callback) {
|
||||||
$actionId = $callback[1][2];
|
$actionId = $callback[1][2];
|
||||||
$boolSetting = (strpos($actionId, self::ACTION_SETTING_BOOL) === 0);
|
$boolSetting = (strpos($actionId, self::ACTION_SETTING_BOOL) === 0);
|
||||||
if (!$boolSetting) return;
|
if(!$boolSetting)
|
||||||
|
return;
|
||||||
|
|
||||||
$actionArray = explode(".", $actionId);
|
$actionArray = explode(".", $actionId);
|
||||||
$setting = $actionArray[2];
|
$setting = $actionArray[2];
|
||||||
|
|
||||||
$login = $callback[1][1];
|
$login = $callback[1][1];
|
||||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||||
|
|
||||||
|
//Save all Changes
|
||||||
|
$this->saveConfigData($callback[1], $player);
|
||||||
|
//Toggle the Boolean Setting
|
||||||
$this->toggleBooleanSetting($setting, $player);
|
$this->toggleBooleanSetting($setting, $player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,18 +253,18 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
* Toogle a Boolean Setting
|
* Toogle a Boolean Setting
|
||||||
*
|
*
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
* @param $setting
|
* @param $setting
|
||||||
*/
|
*/
|
||||||
public function toggleBooleanSetting($setting, Player $player) {
|
public function toggleBooleanSetting($setting, Player $player) {
|
||||||
$this->maniaControl->client->query('GetModeScriptSettings');
|
$this->maniaControl->client->query('GetModeScriptSettings');
|
||||||
$scriptSettings = $this->maniaControl->client->getResponse();
|
$scriptSettings = $this->maniaControl->client->getResponse();
|
||||||
|
|
||||||
if (!isset($scriptSettings[$setting])) {
|
if(!isset($scriptSettings[$setting])) {
|
||||||
var_dump('no setting ' . $setting);
|
var_dump('no setting ' . $setting);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$newSettings = array();
|
$newSettings = array();
|
||||||
$newSettings[$setting] = ($scriptSettings[$setting] ? false : true);
|
$newSettings[$setting] = ($scriptSettings[$setting] ? false : true);
|
||||||
|
|
||||||
$this->applyNewScriptSettings($newSettings, $player);
|
$this->applyNewScriptSettings($newSettings, $player);
|
||||||
@ -268,33 +273,33 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
/**
|
/**
|
||||||
* Apply the Array of new Script Settings
|
* Apply the Array of new Script Settings
|
||||||
*
|
*
|
||||||
* @param array $newSettings
|
* @param array $newSettings
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
*/
|
*/
|
||||||
private function applyNewScriptSettings(array $newSettings, Player $player) {
|
private function applyNewScriptSettings(array $newSettings, Player $player) {
|
||||||
if (!$newSettings) return;
|
if(!$newSettings)
|
||||||
|
return;
|
||||||
$success = $this->maniaControl->client->query('SetModeScriptSettings', $newSettings);
|
$success = $this->maniaControl->client->query('SetModeScriptSettings', $newSettings);
|
||||||
if (!$success) {
|
if(!$success) {
|
||||||
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
|
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notifications
|
// Notifications
|
||||||
$settingsCount = count($newSettings);
|
$settingsCount = count($newSettings);
|
||||||
$settingIndex = 0;
|
$settingIndex = 0;
|
||||||
$title = $this->maniaControl->authenticationManager->getAuthLevelName($player->authLevel);
|
$title = $this->maniaControl->authenticationManager->getAuthLevelName($player->authLevel);
|
||||||
$chatMessage = '$ff0' . $title . ' $<' . $player->nickname . '$> set ScriptSetting' . ($settingsCount > 1 ? 's' : '') . ' ';
|
$chatMessage = '$ff0' . $title . ' $<' . $player->nickname . '$> set ScriptSetting' . ($settingsCount > 1 ? 's' : '') . ' ';
|
||||||
foreach ($newSettings as $setting => $value) {
|
foreach($newSettings as $setting => $value) {
|
||||||
$chatMessage .= '$<' . '$fff' . preg_replace('/^S_/', '', $setting) . '$z$s$ff0 ';
|
$chatMessage .= '$<' . '$fff' . preg_replace('/^S_/', '', $setting) . '$z$s$ff0 ';
|
||||||
$chatMessage .= 'to $fff' . $this->parseSettingValue($value) . '$>';
|
$chatMessage .= 'to $fff' . $this->parseSettingValue($value) . '$>';
|
||||||
|
|
||||||
if ($settingIndex <= $settingsCount - 2) {
|
if($settingIndex <= $settingsCount - 2) {
|
||||||
$chatMessage .= ', ';
|
$chatMessage .= ', ';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trigger own callback
|
// Trigger own callback
|
||||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_SCRIPTSETTING_CHANGED,
|
$this->maniaControl->callbackManager->triggerCallback(self::CB_SCRIPTSETTING_CHANGED, array(self::CB_SCRIPTSETTING_CHANGED, $setting, $value));
|
||||||
array(self::CB_SCRIPTSETTING_CHANGED, $setting, $value));
|
|
||||||
|
|
||||||
$settingIndex++;
|
$settingIndex++;
|
||||||
}
|
}
|
||||||
@ -311,9 +316,9 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function parseSettingValue($value) {
|
private function parseSettingValue($value) {
|
||||||
if (is_bool($value)) {
|
if(is_bool($value)) {
|
||||||
return ($value ? 'True' : 'False');
|
return ($value ? 'True' : 'False');
|
||||||
}
|
}
|
||||||
return (string) $value;
|
return (string)$value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
329
application/core/Configurators/ServerSettings.php
Normal file
329
application/core/Configurators/ServerSettings.php
Normal file
@ -0,0 +1,329 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace ManiaControl\Configurators;
|
||||||
|
|
||||||
|
use FML\Controls\Control;
|
||||||
|
use FML\Controls\Entry;
|
||||||
|
use FML\Controls\Frame;
|
||||||
|
use FML\Controls\Label;
|
||||||
|
use FML\Controls\Labels\Label_Text;
|
||||||
|
use FML\Controls\Quads\Quad_Icons64x64_1;
|
||||||
|
use FML\Script\Script;
|
||||||
|
use ManiaControl\Callbacks\CallbackListener;
|
||||||
|
use ManiaControl\Callbacks\CallbackManager;
|
||||||
|
use ManiaControl\ManiaControl;
|
||||||
|
use ManiaControl\Players\Player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class offering a Configurator for Server Settings
|
||||||
|
*
|
||||||
|
* @author steeffeen & kremsy
|
||||||
|
*/
|
||||||
|
class ServerSettings implements ConfiguratorMenu, CallbackListener {
|
||||||
|
/**
|
||||||
|
* Constants
|
||||||
|
*/
|
||||||
|
const TITLE = 'Server Settings';
|
||||||
|
const ACTION_PREFIX_SETTING = 'ServerSettings.';
|
||||||
|
const ACTION_SETTING_BOOL = 'ServerSettings.ActionBoolSetting.';
|
||||||
|
const CB_SERVERSETTING_CHANGED = 'ServerSettings.SettingChanged';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Private Properties
|
||||||
|
*/
|
||||||
|
private $maniaControl = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Server 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');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @see \ManiaControl\Configurators\ConfiguratorMenu::getTitle()
|
||||||
|
*/
|
||||||
|
public function getTitle() {
|
||||||
|
return self::TITLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @see \ManiaControl\Configurators\ConfiguratorMenu::getMenu()
|
||||||
|
*/
|
||||||
|
public function getMenu($width, $height, Script $script) {
|
||||||
|
$pagesId = 'ServerSettingsPages';
|
||||||
|
$frame = new Frame();
|
||||||
|
|
||||||
|
$this->maniaControl->client->query('GetServerOptions');
|
||||||
|
$serverSettings = $this->maniaControl->client->getResponse();
|
||||||
|
|
||||||
|
// Config
|
||||||
|
$pagerSize = 9.;
|
||||||
|
$settingHeight = 5.;
|
||||||
|
$labelTextSize = 2;
|
||||||
|
$pageMaxCount = 13;
|
||||||
|
|
||||||
|
// Pagers
|
||||||
|
$pagerPrev = new Quad_Icons64x64_1();
|
||||||
|
$frame->add($pagerPrev);
|
||||||
|
$pagerPrev->setPosition($width * 0.39, $height * -0.44, 2);
|
||||||
|
$pagerPrev->setSize($pagerSize, $pagerSize);
|
||||||
|
$pagerPrev->setSubStyle(Quad_Icons64x64_1::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(Quad_Icons64x64_1::SUBSTYLE_ArrowNext);
|
||||||
|
|
||||||
|
$script->addPager($pagerPrev, -1, $pagesId);
|
||||||
|
$script->addPager($pagerNext, 1, $pagesId);
|
||||||
|
|
||||||
|
$pageCountLabel = new Label();
|
||||||
|
$frame->add($pageCountLabel);
|
||||||
|
$pageCountLabel->setHAlign(Control::RIGHT);
|
||||||
|
$pageCountLabel->setPosition($width * 0.35, $height * -0.44, 1);
|
||||||
|
$pageCountLabel->setStyle('TextTitle1');
|
||||||
|
$pageCountLabel->setTextSize(2);
|
||||||
|
|
||||||
|
$script->addPageLabel($pageCountLabel, $pagesId);
|
||||||
|
|
||||||
|
|
||||||
|
// Setting pages
|
||||||
|
$pageFrames = array();
|
||||||
|
$y = 0.;
|
||||||
|
$id = 0;
|
||||||
|
foreach($serverSettings as $name => $value) {
|
||||||
|
//TODO Comment 4 lines maybe
|
||||||
|
//Continue on CurrentMaxPlayers...
|
||||||
|
$pos = strpos($name, "Current"); //TODO maybe current irgentwo anzeigen
|
||||||
|
if($pos !== false) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!isset($pageFrame)) {
|
||||||
|
$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);
|
||||||
|
}
|
||||||
|
|
||||||
|
$settingFrame = new Frame();
|
||||||
|
$pageFrame->add($settingFrame);
|
||||||
|
$settingFrame->setY($y);
|
||||||
|
|
||||||
|
$nameLabel = new Label_Text();
|
||||||
|
$settingFrame->add($nameLabel);
|
||||||
|
$nameLabel->setHAlign(Control::LEFT);
|
||||||
|
$nameLabel->setX($width * -0.46);
|
||||||
|
$nameLabel->setSize($width * 0.4, $settingHeight);
|
||||||
|
$nameLabel->setStyle($nameLabel::STYLE_TextCardSmall);
|
||||||
|
$nameLabel->setTextSize($labelTextSize);
|
||||||
|
$nameLabel->setText($name);
|
||||||
|
$nameLabel->setTextColor("FFF");
|
||||||
|
|
||||||
|
//$settingValue = $scriptSettings[$name];
|
||||||
|
|
||||||
|
$substyle = '';
|
||||||
|
if($value === false) {
|
||||||
|
$substyle = Quad_Icons64x64_1::SUBSTYLE_LvlRed;
|
||||||
|
} else if($value === true) {
|
||||||
|
$substyle = Quad_Icons64x64_1::SUBSTYLE_LvlGreen;
|
||||||
|
}
|
||||||
|
|
||||||
|
$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);
|
||||||
|
|
||||||
|
|
||||||
|
if($substyle != '') {
|
||||||
|
$quad = new Quad_Icons64x64_1();
|
||||||
|
$settingFrame->add($quad);
|
||||||
|
$quad->setX($width / 2 * 0.46);
|
||||||
|
$quad->setZ(-0.01);
|
||||||
|
$quad->setSubStyle($substyle);
|
||||||
|
$quad->setSize(4, 4);
|
||||||
|
$quad->setHAlign(Control::CENTER);
|
||||||
|
$quad->setAction(self::ACTION_SETTING_BOOL . $name);
|
||||||
|
|
||||||
|
$entry->setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$y -= $settingHeight;
|
||||||
|
if($id % $pageMaxCount == $pageMaxCount - 1) {
|
||||||
|
unset($pageFrame);
|
||||||
|
}
|
||||||
|
|
||||||
|
$id++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $frame;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData()
|
||||||
|
*/
|
||||||
|
public function saveConfigData(array $configData, Player $player) {
|
||||||
|
//Note on ServerOptions the whole Options have to be saved, otherwise a error will appear
|
||||||
|
|
||||||
|
$this->maniaControl->client->query('GetServerOptions');
|
||||||
|
$serverSettings = $this->maniaControl->client->getResponse();
|
||||||
|
|
||||||
|
$prefixLength = strlen(self::ACTION_PREFIX_SETTING);
|
||||||
|
|
||||||
|
|
||||||
|
$actionArray = explode(".", $configData[2]);
|
||||||
|
|
||||||
|
$boolSettingName = '';
|
||||||
|
if(isset($actionArray[2])) {
|
||||||
|
$boolSettingName = self::ACTION_PREFIX_SETTING . $actionArray[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
//var_dump($configData[3]);
|
||||||
|
$newSettings = array();
|
||||||
|
foreach($configData[3] as $setting) {
|
||||||
|
if(substr($setting['Name'], 0, $prefixLength) != self::ACTION_PREFIX_SETTING) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Check if it was a boolbox
|
||||||
|
// var_dump($setting['Name'], $boolSettingName, "");
|
||||||
|
if($setting['Name'] == $boolSettingName) {
|
||||||
|
$setting['Value'] = ($setting['Value'] ? false : true);
|
||||||
|
var_dump($setting['Value']);
|
||||||
|
var_dump("test13");
|
||||||
|
}
|
||||||
|
|
||||||
|
$settingName = substr($setting['Name'], $prefixLength);
|
||||||
|
|
||||||
|
$newSettings[$settingName] = $setting['Value'];
|
||||||
|
settype($newSettings[$settingName], gettype($serverSettings[$settingName]));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->applyNewScriptSettings($newSettings, $player);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
$actionArray = explode(".", $actionId);
|
||||||
|
$setting = $actionArray[2];
|
||||||
|
|
||||||
|
$login = $callback[1][1];
|
||||||
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||||
|
|
||||||
|
|
||||||
|
//Save all Changes
|
||||||
|
$this->saveConfigData($callback[1], $player);
|
||||||
|
//$this->toggleBooleanSetting($setting, $player);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Toogle a Boolean Setting
|
||||||
|
*
|
||||||
|
* @param Player $player
|
||||||
|
* @param $setting
|
||||||
|
*/
|
||||||
|
public function toggleBooleanSetting($setting, Player $player) {
|
||||||
|
$this->maniaControl->client->query('GetServerOptions');
|
||||||
|
$serverSettings = $this->maniaControl->client->getResponse();
|
||||||
|
|
||||||
|
if(!isset($serverSettings[$setting])) {
|
||||||
|
var_dump('no setting ' . $setting);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$newSettings = array();
|
||||||
|
$newSettings[$setting] = ($serverSettings[$setting] ? false : true);
|
||||||
|
|
||||||
|
var_dump($newSettings);
|
||||||
|
$this->applyNewScriptSettings($newSettings, $player);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply the Array of new Script Settings
|
||||||
|
*
|
||||||
|
* @param array $newSettings
|
||||||
|
* @param Player $player
|
||||||
|
*/
|
||||||
|
private function applyNewScriptSettings(array $newSettings, Player $player) {
|
||||||
|
if(!$newSettings) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$success = $this->maniaControl->client->query('SetServerOptions', $newSettings);
|
||||||
|
if(!$success) {
|
||||||
|
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//var_dump($newSettings);
|
||||||
|
// Notifications
|
||||||
|
$settingsCount = count($newSettings);
|
||||||
|
$settingIndex = 0;
|
||||||
|
$title = $this->maniaControl->authenticationManager->getAuthLevelName($player->authLevel);
|
||||||
|
//$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 .= ', ';
|
||||||
|
}*/
|
||||||
|
|
||||||
|
// Trigger own callback
|
||||||
|
$this->maniaControl->callbackManager->triggerCallback(self::CB_SERVERSETTING_CHANGED, array(self::CB_SERVERSETTING_CHANGED, $setting, $value));
|
||||||
|
|
||||||
|
$settingIndex++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// $chatMessage .= '!';
|
||||||
|
// $this->maniaControl->chat->sendInformation($chatMessage);
|
||||||
|
//$this->maniaControl->log(Formatter::stripCodes($chatMessage));
|
||||||
|
|
||||||
|
//TODO reopen menu
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user