reopen menus on change
This commit is contained in:
parent
24fa0863b7
commit
a743356be3
@ -76,8 +76,8 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
|||||||
|
|
||||||
// Register for callbacks
|
// Register for callbacks
|
||||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect');
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect');
|
||||||
$this->maniaControl->callbackManager->registerCallbackListener(ScriptSettings::CB_SCRIPTSETTINGS_CHANGED, $this, 'reopenMenu');
|
//$this->maniaControl->callbackManager->registerCallbackListener(ScriptSettings::CB_SCRIPTSETTINGS_CHANGED, $this, 'reopenMenu');
|
||||||
$this->maniaControl->callbackManager->registerCallbackListener(ServerSettings::CB_SERVERSETTINGS_CHANGED, $this, 'reopenMenu');
|
//$this->maniaControl->callbackManager->registerCallbackListener(ServerSettings::CB_SERVERSETTINGS_CHANGED, $this, 'reopenMenu');
|
||||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
||||||
|
|
||||||
// Create server settings
|
// Create server settings
|
||||||
@ -119,11 +119,11 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
|||||||
*
|
*
|
||||||
* @param array $callback
|
* @param array $callback
|
||||||
*/
|
*/
|
||||||
public function reopenMenu(array $callback) {
|
public function reopenMenu($menuId = 0) {
|
||||||
foreach($this->playersMenuShown as $login => $shown) {
|
foreach($this->playersMenuShown as $login => $shown) {
|
||||||
if($shown == true) {
|
if($shown == true) {
|
||||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||||
$this->showMenu($player);
|
$this->showMenu($player, $menuId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -200,6 +200,24 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the Menu Id
|
||||||
|
*
|
||||||
|
* @param $name
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getMenuId($name) {
|
||||||
|
$i = 0;
|
||||||
|
foreach($this->menus as $menu) {
|
||||||
|
/** @var ConfiguratorMenu $menu */
|
||||||
|
if($menu->getTitle() == $name) {
|
||||||
|
return $i;
|
||||||
|
}
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build menu manialink if necessary
|
* Build menu manialink if necessary
|
||||||
*
|
*
|
||||||
@ -248,9 +266,8 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
|||||||
$script = new Script();
|
$script = new Script();
|
||||||
$manialink->setScript($script);
|
$manialink->setScript($script);
|
||||||
|
|
||||||
$menuRelationships = array();
|
$menuItemY = $menuHeight * 0.42;
|
||||||
$menuItemY = $menuHeight * 0.42;
|
$menuId = 0;
|
||||||
$menuId = 0;
|
|
||||||
foreach($this->menus as $index => $menu) {
|
foreach($this->menus as $index => $menu) {
|
||||||
/** @var ConfiguratorMenu $menu */
|
/** @var ConfiguratorMenu $menu */
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@ use FML\Controls\Quads\Quad_Icons64x64_1;
|
|||||||
use FML\Script\Script;
|
use FML\Script\Script;
|
||||||
use ManiaControl\Callbacks\CallbackListener;
|
use ManiaControl\Callbacks\CallbackListener;
|
||||||
use ManiaControl\Callbacks\CallbackManager;
|
use ManiaControl\Callbacks\CallbackManager;
|
||||||
use ManiaControl\Formatter;
|
|
||||||
use ManiaControl\ManiaControl;
|
use ManiaControl\ManiaControl;
|
||||||
use ManiaControl\Players\Player;
|
use ManiaControl\Players\Player;
|
||||||
|
|
||||||
@ -24,12 +23,12 @@ 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';
|
||||||
const CB_SCRIPTSETTINGS_CHANGED = 'ScriptSettings.SettingsChanged';
|
const CB_SCRIPTSETTINGS_CHANGED = 'ScriptSettings.SettingsChanged';
|
||||||
const TABLE_SCRIPT_SETTINGS = 'mc_scriptsettings';
|
const TABLE_SCRIPT_SETTINGS = 'mc_scriptsettings';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private Properties
|
* Private Properties
|
||||||
*/
|
*/
|
||||||
@ -42,10 +41,9 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
*/
|
*/
|
||||||
public function __construct(ManiaControl $maniaControl) {
|
public function __construct(ManiaControl $maniaControl) {
|
||||||
$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');
|
|
||||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'onInit');
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'onInit');
|
||||||
$this->initTables();
|
$this->initTables();
|
||||||
}
|
}
|
||||||
@ -57,20 +55,20 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
*/
|
*/
|
||||||
private function initTables() {
|
private function initTables() {
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_SCRIPT_SETTINGS . "` (
|
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_SCRIPT_SETTINGS . "` (
|
||||||
`serverIndex` int(11) NOT NULL AUTO_INCREMENT,
|
`serverIndex` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
`settingName` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
|
`settingName` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
|
||||||
`settingValue` varchar(500) COLLATE utf8_unicode_ci NOT NULL,
|
`settingValue` varchar(500) COLLATE utf8_unicode_ci NOT NULL,
|
||||||
UNIQUE KEY `setting` (`serverIndex`, `settingName`)
|
UNIQUE KEY `setting` (`serverIndex`, `settingName`)
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Script Settings' AUTO_INCREMENT=1;";
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Script Settings' AUTO_INCREMENT=1;";
|
||||||
|
|
||||||
$statement = $mysqli->prepare($query);
|
$statement = $mysqli->prepare($query);
|
||||||
if ($mysqli->error) {
|
if($mysqli->error) {
|
||||||
trigger_error($mysqli->error, E_USER_ERROR);
|
trigger_error($mysqli->error, E_USER_ERROR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
if ($statement->error) {
|
if($statement->error) {
|
||||||
trigger_error($statement->error, E_USER_ERROR);
|
trigger_error($statement->error, E_USER_ERROR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -95,31 +93,35 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
public function loadSettingsFromDatabase() {
|
public function loadSettingsFromDatabase() {
|
||||||
$this->maniaControl->client->query('GetModeScriptSettings');
|
$this->maniaControl->client->query('GetModeScriptSettings');
|
||||||
$scriptSettings = $this->maniaControl->client->getResponse();
|
$scriptSettings = $this->maniaControl->client->getResponse();
|
||||||
if (isset($scriptSettings['faultString'])) {
|
if(isset($scriptSettings['faultString'])) {
|
||||||
if ($scriptSettings['faultString'] == 'Not in script mode.') return false;
|
if($scriptSettings['faultString'] == 'Not in script mode.') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
trigger_error('Error occured: ' . $scriptSettings['faultString']);
|
trigger_error('Error occured: ' . $scriptSettings['faultString']);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$query = "SELECT * FROM `" . self::TABLE_SCRIPT_SETTINGS . "`;";
|
$query = "SELECT * FROM `" . self::TABLE_SCRIPT_SETTINGS . "`;";
|
||||||
$result = $mysqli->query($query);
|
$result = $mysqli->query($query);
|
||||||
if ($mysqli->error) {
|
if($mysqli->error) {
|
||||||
trigger_error($mysqli->error);
|
trigger_error($mysqli->error);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$loadedSettings = array();
|
$loadedSettings = array();
|
||||||
while ($row = $result->fetch_object()) {
|
while($row = $result->fetch_object()) {
|
||||||
if (!isset($scriptSettings[$row->settingName])) continue;
|
if(!isset($scriptSettings[$row->settingName]))
|
||||||
|
continue;
|
||||||
$loadedSettings[$row->settingName] = $row->settingValue;
|
$loadedSettings[$row->settingName] = $row->settingValue;
|
||||||
settype($loadedSettings[$row->settingName], gettype($scriptSettings[$row->settingName]));
|
settype($loadedSettings[$row->settingName], gettype($scriptSettings[$row->settingName]));
|
||||||
}
|
}
|
||||||
$result->close();
|
$result->close();
|
||||||
if (!$loadedSettings) return true;
|
if(!$loadedSettings)
|
||||||
|
return true;
|
||||||
|
|
||||||
$success = $this->maniaControl->client->query('SetModeScriptSettings', $loadedSettings);
|
$success = $this->maniaControl->client->query('SetModeScriptSettings', $loadedSettings);
|
||||||
if (!$success) {
|
if(!$success) {
|
||||||
trigger_error('Error occured: ' . $this->maniaControl->getClientErrorText());
|
trigger_error('Error occured: ' . $this->maniaControl->getClientErrorText());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -140,11 +142,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);
|
||||||
@ -152,66 +154,66 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
return $frame;
|
return $frame;
|
||||||
}
|
}
|
||||||
$scriptParams = $scriptInfo['ParamDescs'];
|
$scriptParams = $scriptInfo['ParamDescs'];
|
||||||
|
|
||||||
$this->maniaControl->client->query('GetModeScriptSettings');
|
$this->maniaControl->client->query('GetModeScriptSettings');
|
||||||
$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();
|
||||||
$frame->add($pagerPrev);
|
$frame->add($pagerPrev);
|
||||||
$pagerPrev->setPosition($width * 0.39, $height * -0.44, 2);
|
$pagerPrev->setPosition($width * 0.39, $height * -0.44, 2);
|
||||||
$pagerPrev->setSize($pagerSize, $pagerSize);
|
$pagerPrev->setSize($pagerSize, $pagerSize);
|
||||||
$pagerPrev->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowPrev);
|
$pagerPrev->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowPrev);
|
||||||
|
|
||||||
$pagerNext = new Quad_Icons64x64_1();
|
$pagerNext = new Quad_Icons64x64_1();
|
||||||
$frame->add($pagerNext);
|
$frame->add($pagerNext);
|
||||||
$pagerNext->setPosition($width * 0.45, $height * -0.44, 2);
|
$pagerNext->setPosition($width * 0.45, $height * -0.44, 2);
|
||||||
$pagerNext->setSize($pagerSize, $pagerSize);
|
$pagerNext->setSize($pagerSize, $pagerSize);
|
||||||
$pagerNext->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowNext);
|
$pagerNext->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowNext);
|
||||||
|
|
||||||
$script->addPager($pagerPrev, -1, $pagesId);
|
$script->addPager($pagerPrev, -1, $pagesId);
|
||||||
$script->addPager($pagerNext, 1, $pagesId);
|
$script->addPager($pagerNext, 1, $pagesId);
|
||||||
|
|
||||||
$pageCountLabel = new Label();
|
$pageCountLabel = new Label();
|
||||||
$frame->add($pageCountLabel);
|
$frame->add($pageCountLabel);
|
||||||
$pageCountLabel->setHAlign(Control::RIGHT);
|
$pageCountLabel->setHAlign(Control::RIGHT);
|
||||||
$pageCountLabel->setPosition($width * 0.35, $height * -0.44, 1);
|
$pageCountLabel->setPosition($width * 0.35, $height * -0.44, 1);
|
||||||
$pageCountLabel->setStyle('TextTitle1');
|
$pageCountLabel->setStyle('TextTitle1');
|
||||||
$pageCountLabel->setTextSize(2);
|
$pageCountLabel->setTextSize(2);
|
||||||
|
|
||||||
$script->addPageLabel($pageCountLabel, $pagesId);
|
$script->addPageLabel($pageCountLabel, $pagesId);
|
||||||
|
|
||||||
// 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])) {
|
if(!isset($scriptSettings[$settingName])) {
|
||||||
continue;
|
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);
|
||||||
$y = $height * 0.41;
|
$y = $height * 0.41;
|
||||||
$script->addPage($pageFrame, count($pageFrames), $pagesId);
|
$script->addPage($pageFrame, count($pageFrames), $pagesId);
|
||||||
}
|
}
|
||||||
|
|
||||||
$settingFrame = new Frame();
|
$settingFrame = new Frame();
|
||||||
$pageFrame->add($settingFrame);
|
$pageFrame->add($settingFrame);
|
||||||
$settingFrame->setY($y);
|
$settingFrame->setY($y);
|
||||||
|
|
||||||
$nameLabel = new Label_Text();
|
$nameLabel = new Label_Text();
|
||||||
$settingFrame->add($nameLabel);
|
$settingFrame->add($nameLabel);
|
||||||
$nameLabel->setHAlign(Control::LEFT);
|
$nameLabel->setHAlign(Control::LEFT);
|
||||||
@ -220,18 +222,17 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
$nameLabel->setStyle($nameLabel::STYLE_TextCardSmall);
|
$nameLabel->setStyle($nameLabel::STYLE_TextCardSmall);
|
||||||
$nameLabel->setTextSize($labelTextSize);
|
$nameLabel->setTextSize($labelTextSize);
|
||||||
$nameLabel->setText($settingName);
|
$nameLabel->setText($settingName);
|
||||||
|
|
||||||
$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);
|
||||||
@ -240,8 +241,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);
|
||||||
@ -249,10 +249,10 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
$entry->setX($width / 2 * 0.55);
|
$entry->setX($width / 2 * 0.55);
|
||||||
$entry->setTextSize(1);
|
$entry->setTextSize(1);
|
||||||
$entry->setSize($width * 0.3, $settingHeight * 0.9);
|
$entry->setSize($width * 0.3, $settingHeight * 0.9);
|
||||||
$entry->setName(self::ACTION_PREFIX_SETTING . $settingName);
|
$entry->setName(self::ACTION_PREFIX_SETTING . '.' . $settingName);
|
||||||
$entry->setDefault($settingValue);
|
$entry->setDefault($settingValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
$descriptionLabel = new Label();
|
$descriptionLabel = new Label();
|
||||||
$pageFrame->add($descriptionLabel);
|
$pageFrame->add($descriptionLabel);
|
||||||
$descriptionLabel->setHAlign(Control::LEFT);
|
$descriptionLabel->setHAlign(Control::LEFT);
|
||||||
@ -263,13 +263,13 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
// $descriptionLabel->setTextPrefix('Desc: ');
|
// $descriptionLabel->setTextPrefix('Desc: ');
|
||||||
$descriptionLabel->setText($scriptParam['Desc']);
|
$descriptionLabel->setText($scriptParam['Desc']);
|
||||||
$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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $frame;
|
return $frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,33 +278,41 @@ 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) {
|
||||||
|
|
||||||
|
$prefix = explode(".", $configData[3][0]['Name']);
|
||||||
|
if($prefix[0] != self::ACTION_PREFIX_SETTING) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$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;
|
|
||||||
}
|
$settingName = substr($setting['Name'], $prefixLength + 1);
|
||||||
|
if(!isset($scriptSettings[$settingName])) {
|
||||||
$settingName = substr($setting['Name'], $prefixLength);
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
$newSettings[$settingName] = $setting['Value'];
|
$newSettings[$settingName] = $setting['Value'];
|
||||||
settype($newSettings[$settingName], gettype($scriptSettings[$settingName]));
|
settype($newSettings[$settingName], gettype($scriptSettings[$settingName]));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->applyNewScriptSettings($newSettings, $player);
|
$this->applyNewScriptSettings($newSettings, $player);
|
||||||
|
|
||||||
|
//Reopen the Menu
|
||||||
|
$menuId = $this->maniaControl->configurator->getMenuId($this->getTitle());
|
||||||
|
$this->maniaControl->configurator->reopenMenu($menuId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -313,18 +321,18 @@ 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) {
|
if(!$boolSetting) {
|
||||||
return;
|
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
|
// Save all Changes
|
||||||
$this->saveConfigData($callback[1], $player);
|
$this->saveConfigData($callback[1], $player);
|
||||||
// Toggle the Boolean Setting
|
// Toggle the Boolean Setting
|
||||||
@ -335,41 +343,42 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
* @param bool
|
* @param bool
|
||||||
*/
|
*/
|
||||||
private function applyNewScriptSettings(array $newSettings, Player $player) {
|
private function applyNewScriptSettings(array $newSettings, Player $player) {
|
||||||
if (!$newSettings) return true;
|
if(!$newSettings)
|
||||||
|
return true;
|
||||||
$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 false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save Settings into Database
|
// Save Settings into Database
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$query = "INSERT INTO `" . self::TABLE_SCRIPT_SETTINGS . "` (
|
$query = "INSERT INTO `" . self::TABLE_SCRIPT_SETTINGS . "` (
|
||||||
`serverIndex`,
|
`serverIndex`,
|
||||||
`settingName`,
|
`settingName`,
|
||||||
`settingValue`
|
`settingValue`
|
||||||
@ -378,45 +387,44 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
) ON DUPLICATE KEY UPDATE
|
) ON DUPLICATE KEY UPDATE
|
||||||
`settingValue` = VALUES(`settingValue`);";
|
`settingValue` = VALUES(`settingValue`);";
|
||||||
$statement = $mysqli->prepare($query);
|
$statement = $mysqli->prepare($query);
|
||||||
if ($mysqli->error) {
|
if($mysqli->error) {
|
||||||
trigger_error($mysqli->error);
|
trigger_error($mysqli->error);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$serverIndex = $this->maniaControl->server->getIndex();
|
$serverIndex = $this->maniaControl->server->getIndex();
|
||||||
|
|
||||||
// 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 .= ', ';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add To Database
|
// Add To Database
|
||||||
$statement->bind_param('iss', $serverIndex, $setting, $value);
|
$statement->bind_param('iss', $serverIndex, $setting, $value);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
if ($statement->error) {
|
if($statement->error) {
|
||||||
trigger_error($statement->error);
|
trigger_error($statement->error);
|
||||||
$statement->close();
|
$statement->close();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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++;
|
||||||
}
|
}
|
||||||
$statement->close();
|
$statement->close();
|
||||||
|
|
||||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_SCRIPTSETTINGS_CHANGED, array(self::CB_SCRIPTSETTINGS_CHANGED));
|
$this->maniaControl->callbackManager->triggerCallback(self::CB_SCRIPTSETTINGS_CHANGED, array(self::CB_SCRIPTSETTINGS_CHANGED));
|
||||||
|
|
||||||
$chatMessage .= '!';
|
$chatMessage .= '!';
|
||||||
$this->maniaControl->chat->sendInformation($chatMessage);
|
$this->maniaControl->chat->sendInformation($chatMessage);
|
||||||
$this->maniaControl->log($chatMessage, true);
|
$this->maniaControl->log($chatMessage, true);
|
||||||
@ -430,9 +438,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,12 +23,12 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
/**
|
/**
|
||||||
* Constants
|
* Constants
|
||||||
*/
|
*/
|
||||||
const ACTION_PREFIX_SETTING = 'ServerSettings.';
|
const ACTION_PREFIX_SETTING = 'ServerSettings';
|
||||||
const ACTION_SETTING_BOOL = 'ServerSettings.ActionBoolSetting.';
|
const ACTION_SETTING_BOOL = 'ServerSettings.ActionBoolSetting.';
|
||||||
const CB_SERVERSETTING_CHANGED = 'ServerSettings.SettingChanged';
|
const CB_SERVERSETTING_CHANGED = 'ServerSettings.SettingChanged';
|
||||||
const CB_SERVERSETTINGS_CHANGED = 'ServerSettings.SettingsChanged';
|
const CB_SERVERSETTINGS_CHANGED = 'ServerSettings.SettingsChanged';
|
||||||
const TABLE_SERVER_SETTINGS = 'mc_serversettings';
|
const TABLE_SERVER_SETTINGS = 'mc_serversettings';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private Properties
|
* Private Properties
|
||||||
*/
|
*/
|
||||||
@ -42,10 +42,9 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
public function __construct(ManiaControl $maniaControl) {
|
public function __construct(ManiaControl $maniaControl) {
|
||||||
$this->maniaControl = $maniaControl;
|
$this->maniaControl = $maniaControl;
|
||||||
$this->initTables();
|
$this->initTables();
|
||||||
|
|
||||||
// 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');
|
|
||||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'onInit');
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'onInit');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,20 +54,20 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function initTables() {
|
private function initTables() {
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_SERVER_SETTINGS . "` (
|
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_SERVER_SETTINGS . "` (
|
||||||
`serverIndex` int(11) NOT NULL AUTO_INCREMENT,
|
`serverIndex` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
`settingName` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
|
`settingName` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
|
||||||
`settingValue` varchar(500) COLLATE utf8_unicode_ci NOT NULL,
|
`settingValue` varchar(500) COLLATE utf8_unicode_ci NOT NULL,
|
||||||
UNIQUE KEY `setting` (`serverIndex`, `settingName`)
|
UNIQUE KEY `setting` (`serverIndex`, `settingName`)
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Server Settings' AUTO_INCREMENT=1;";
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Server Settings' AUTO_INCREMENT=1;";
|
||||||
$statement = $mysqli->prepare($query);
|
$statement = $mysqli->prepare($query);
|
||||||
if ($mysqli->error) {
|
if($mysqli->error) {
|
||||||
trigger_error($mysqli->error, E_USER_ERROR);
|
trigger_error($mysqli->error, E_USER_ERROR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
if ($statement->error) {
|
if($statement->error) {
|
||||||
trigger_error($statement->error, E_USER_ERROR);
|
trigger_error($statement->error, E_USER_ERROR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -92,26 +91,29 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
*/
|
*/
|
||||||
public function loadSettingsFromDatabase() {
|
public function loadSettingsFromDatabase() {
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$query = "SELECT * FROM `" . self::TABLE_SERVER_SETTINGS . "`;";
|
$query = "SELECT * FROM `" . self::TABLE_SERVER_SETTINGS . "`;";
|
||||||
$result = $mysqli->query($query);
|
$result = $mysqli->query($query);
|
||||||
if ($mysqli->error) {
|
if($mysqli->error) {
|
||||||
trigger_error($mysqli->error);
|
trigger_error($mysqli->error);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->maniaControl->client->query('GetServerOptions');
|
$this->maniaControl->client->query('GetServerOptions');
|
||||||
$serverSettings = $this->maniaControl->client->getResponse();
|
$serverSettings = $this->maniaControl->client->getResponse();
|
||||||
$loadedSettings = array();
|
$loadedSettings = array();
|
||||||
while ($row = $result->fetch_object()) {
|
while($row = $result->fetch_object()) {
|
||||||
if (!isset($serverSettings[$row->settingName])) continue;
|
if(!isset($serverSettings[$row->settingName])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$loadedSettings[$row->settingName] = $row->settingValue;
|
$loadedSettings[$row->settingName] = $row->settingValue;
|
||||||
settype($loadedSettings[$row->settingName], gettype($serverSettings[$row->settingName]));
|
settype($loadedSettings[$row->settingName], gettype($serverSettings[$row->settingName]));
|
||||||
}
|
}
|
||||||
$result->close();
|
$result->close();
|
||||||
if (!$loadedSettings) return true;
|
if(!$loadedSettings)
|
||||||
|
return true;
|
||||||
|
|
||||||
$success = $this->maniaControl->client->query('SetServerOptions', $loadedSettings);
|
$success = $this->maniaControl->client->query('SetServerOptions', $loadedSettings);
|
||||||
if (!$success) {
|
if(!$success) {
|
||||||
trigger_error('Error occurred: ' . $this->maniaControl->getClientErrorText());
|
trigger_error('Error occurred: ' . $this->maniaControl->getClientErrorText());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -132,69 +134,69 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
*/
|
*/
|
||||||
public function getMenu($width, $height, Script $script) {
|
public function getMenu($width, $height, Script $script) {
|
||||||
$pagesId = 'ServerSettingsPages';
|
$pagesId = 'ServerSettingsPages';
|
||||||
$frame = new Frame();
|
$frame = new Frame();
|
||||||
|
|
||||||
$this->maniaControl->client->query('GetServerOptions');
|
$this->maniaControl->client->query('GetServerOptions');
|
||||||
$serverSettings = $this->maniaControl->client->getResponse();
|
$serverSettings = $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();
|
||||||
$frame->add($pagerPrev);
|
$frame->add($pagerPrev);
|
||||||
$pagerPrev->setPosition($width * 0.39, $height * -0.44, 2);
|
$pagerPrev->setPosition($width * 0.39, $height * -0.44, 2);
|
||||||
$pagerPrev->setSize($pagerSize, $pagerSize);
|
$pagerPrev->setSize($pagerSize, $pagerSize);
|
||||||
$pagerPrev->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowPrev);
|
$pagerPrev->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowPrev);
|
||||||
|
|
||||||
$pagerNext = new Quad_Icons64x64_1();
|
$pagerNext = new Quad_Icons64x64_1();
|
||||||
$frame->add($pagerNext);
|
$frame->add($pagerNext);
|
||||||
$pagerNext->setPosition($width * 0.45, $height * -0.44, 2);
|
$pagerNext->setPosition($width * 0.45, $height * -0.44, 2);
|
||||||
$pagerNext->setSize($pagerSize, $pagerSize);
|
$pagerNext->setSize($pagerSize, $pagerSize);
|
||||||
$pagerNext->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowNext);
|
$pagerNext->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowNext);
|
||||||
|
|
||||||
$script->addPager($pagerPrev, -1, $pagesId);
|
$script->addPager($pagerPrev, -1, $pagesId);
|
||||||
$script->addPager($pagerNext, 1, $pagesId);
|
$script->addPager($pagerNext, 1, $pagesId);
|
||||||
|
|
||||||
$pageCountLabel = new Label();
|
$pageCountLabel = new Label();
|
||||||
$frame->add($pageCountLabel);
|
$frame->add($pageCountLabel);
|
||||||
$pageCountLabel->setHAlign(Control::RIGHT);
|
$pageCountLabel->setHAlign(Control::RIGHT);
|
||||||
$pageCountLabel->setPosition($width * 0.35, $height * -0.44, 1);
|
$pageCountLabel->setPosition($width * 0.35, $height * -0.44, 1);
|
||||||
$pageCountLabel->setStyle('TextTitle1');
|
$pageCountLabel->setStyle('TextTitle1');
|
||||||
$pageCountLabel->setTextSize(2);
|
$pageCountLabel->setTextSize(2);
|
||||||
|
|
||||||
$script->addPageLabel($pageCountLabel, $pagesId);
|
$script->addPageLabel($pageCountLabel, $pagesId);
|
||||||
|
|
||||||
// Setting pages
|
// Setting pages
|
||||||
$pageFrames = array();
|
$pageFrames = array();
|
||||||
$y = 0.;
|
$y = 0.;
|
||||||
$id = 0;
|
$id = 0;
|
||||||
foreach ($serverSettings as $name => $value) {
|
foreach($serverSettings as $name => $value) {
|
||||||
// TODO Comment 4 lines maybe
|
// TODO Comment 4 lines maybe
|
||||||
// Continue on CurrentMaxPlayers...
|
// Continue on CurrentMaxPlayers...
|
||||||
$pos = strpos($name, "Current"); // TODO maybe current irgentwo anzeigen
|
$pos = strpos($name, "Current"); // TODO maybe current irgentwo anzeigen
|
||||||
if ($pos !== false) {
|
if($pos !== false) {
|
||||||
continue;
|
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);
|
||||||
$y = $height * 0.41;
|
$y = $height * 0.41;
|
||||||
$script->addPage($pageFrame, count($pageFrames), $pagesId);
|
$script->addPage($pageFrame, count($pageFrames), $pagesId);
|
||||||
}
|
}
|
||||||
|
|
||||||
$settingFrame = new Frame();
|
$settingFrame = new Frame();
|
||||||
$pageFrame->add($settingFrame);
|
$pageFrame->add($settingFrame);
|
||||||
$settingFrame->setY($y);
|
$settingFrame->setY($y);
|
||||||
|
|
||||||
$nameLabel = new Label_Text();
|
$nameLabel = new Label_Text();
|
||||||
$settingFrame->add($nameLabel);
|
$settingFrame->add($nameLabel);
|
||||||
$nameLabel->setHAlign(Control::LEFT);
|
$nameLabel->setHAlign(Control::LEFT);
|
||||||
@ -204,17 +206,16 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
$nameLabel->setTextSize($labelTextSize);
|
$nameLabel->setTextSize($labelTextSize);
|
||||||
$nameLabel->setText($name);
|
$nameLabel->setText($name);
|
||||||
$nameLabel->setTextColor("FFF");
|
$nameLabel->setTextColor("FFF");
|
||||||
|
|
||||||
// $settingValue = $scriptSettings[$name];
|
// $settingValue = $scriptSettings[$name];
|
||||||
|
|
||||||
$substyle = '';
|
$substyle = '';
|
||||||
if ($value === false) {
|
if($value === false) {
|
||||||
$substyle = Quad_Icons64x64_1::SUBSTYLE_LvlRed;
|
$substyle = Quad_Icons64x64_1::SUBSTYLE_LvlRed;
|
||||||
}
|
} else if($value === true) {
|
||||||
else if ($value === true) {
|
|
||||||
$substyle = Quad_Icons64x64_1::SUBSTYLE_LvlGreen;
|
$substyle = Quad_Icons64x64_1::SUBSTYLE_LvlGreen;
|
||||||
}
|
}
|
||||||
|
|
||||||
$entry = new Entry();
|
$entry = new Entry();
|
||||||
$settingFrame->add($entry);
|
$settingFrame->add($entry);
|
||||||
$entry->setStyle(Label_Text::STYLE_TextValueSmall);
|
$entry->setStyle(Label_Text::STYLE_TextValueSmall);
|
||||||
@ -222,10 +223,10 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
$entry->setX($width / 2 * 0.46);
|
$entry->setX($width / 2 * 0.46);
|
||||||
$entry->setTextSize(1);
|
$entry->setTextSize(1);
|
||||||
$entry->setSize($width * 0.48, $settingHeight * 0.9);
|
$entry->setSize($width * 0.48, $settingHeight * 0.9);
|
||||||
$entry->setName(self::ACTION_PREFIX_SETTING . $name);
|
$entry->setName(self::ACTION_PREFIX_SETTING . '.' . $name);
|
||||||
$entry->setDefault($value);
|
$entry->setDefault($value);
|
||||||
|
|
||||||
if ($name == "Comment") { //
|
if($name == "Comment") { //
|
||||||
$entry->setAutoNewLine(true);
|
$entry->setAutoNewLine(true);
|
||||||
$entry->setSize($width * 0.48, $settingHeight * 3 + $settingHeight * 0.9);
|
$entry->setSize($width * 0.48, $settingHeight * 3 + $settingHeight * 0.9);
|
||||||
$settingFrame->setY($y - $settingHeight * 1.5);
|
$settingFrame->setY($y - $settingHeight * 1.5);
|
||||||
@ -233,8 +234,8 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
$y -= $settingHeight * 3;
|
$y -= $settingHeight * 3;
|
||||||
$id += 3;
|
$id += 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
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.46);
|
$quad->setX($width / 2 * 0.46);
|
||||||
@ -243,18 +244,18 @@ class ServerSettings 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 . $name);
|
$quad->setAction(self::ACTION_SETTING_BOOL . $name);
|
||||||
|
|
||||||
$entry->setVisible(false);
|
$entry->setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
$y -= $settingHeight;
|
$y -= $settingHeight;
|
||||||
if ($id % $pageMaxCount == $pageMaxCount - 1) {
|
if($id % $pageMaxCount == $pageMaxCount - 1) {
|
||||||
unset($pageFrame);
|
unset($pageFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
$id++;
|
$id++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $frame;
|
return $frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,37 +264,43 @@ class ServerSettings 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) {
|
||||||
|
|
||||||
|
$prefix = explode(".", $configData[3][0]['Name']);
|
||||||
|
if($prefix[0] != self::ACTION_PREFIX_SETTING) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Note on ServerOptions the whole Options have to be saved, otherwise a error will appear
|
// Note on ServerOptions the whole Options have to be saved, otherwise a error will appear
|
||||||
$this->maniaControl->client->query('GetServerOptions');
|
$this->maniaControl->client->query('GetServerOptions');
|
||||||
$serverSettings = $this->maniaControl->client->getResponse();
|
$serverSettings = $this->maniaControl->client->getResponse();
|
||||||
|
|
||||||
$prefixLength = strlen(self::ACTION_PREFIX_SETTING);
|
$prefixLength = strlen(self::ACTION_PREFIX_SETTING);
|
||||||
|
|
||||||
$actionArray = explode(".", $configData[2]);
|
$actionArray = explode(".", $configData[2]);
|
||||||
|
|
||||||
$boolSettingName = '';
|
$boolSettingName = '';
|
||||||
if (isset($actionArray[2])) {
|
if(isset($actionArray[2])) {
|
||||||
$boolSettingName = self::ACTION_PREFIX_SETTING . $actionArray[2];
|
$boolSettingName = self::ACTION_PREFIX_SETTING . '.' . $actionArray[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
$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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if it was a boolean button
|
// Check if it was a boolean button
|
||||||
if ($setting['Name'] == $boolSettingName) {
|
if($setting['Name'] == $boolSettingName) {
|
||||||
$setting['Value'] = ($setting['Value'] ? false : true);
|
$setting['Value'] = ($setting['Value'] ? false : true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$settingName = substr($setting['Name'], $prefixLength);
|
$settingName = substr($setting['Name'], $prefixLength + 1);
|
||||||
|
|
||||||
$newSettings[$settingName] = $setting['Value'];
|
$newSettings[$settingName] = $setting['Value'];
|
||||||
settype($newSettings[$settingName], gettype($serverSettings[$settingName]));
|
settype($newSettings[$settingName], gettype($serverSettings[$settingName]));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->applyNewScriptSettings($newSettings, $player);
|
$this->applyNewScriptSettings($newSettings, $player);
|
||||||
|
|
||||||
|
//Reopen the Menu
|
||||||
|
$menuId = $this->maniaControl->configurator->getMenuId($this->getTitle());
|
||||||
|
$this->maniaControl->configurator->reopenMenu($menuId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -302,13 +309,14 @@ class ServerSettings 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;
|
||||||
$login = $callback[1][1];
|
|
||||||
|
$login = $callback[1][1];
|
||||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||||
|
|
||||||
// Save all Changes
|
// Save all Changes
|
||||||
$this->saveConfigData($callback[1], $player);
|
$this->saveConfigData($callback[1], $player);
|
||||||
}
|
}
|
||||||
@ -316,22 +324,23 @@ class ServerSettings 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
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function applyNewScriptSettings(array $newSettings, Player $player) {
|
private function applyNewScriptSettings(array $newSettings, Player $player) {
|
||||||
if (!$newSettings) return true;
|
if(!$newSettings)
|
||||||
|
return true;
|
||||||
$success = $this->maniaControl->client->query('SetServerOptions', $newSettings);
|
$success = $this->maniaControl->client->query('SetServerOptions', $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 false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save Settings into Database
|
// Save Settings into Database
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
|
|
||||||
$query = "INSERT INTO `" . self::TABLE_SERVER_SETTINGS . "` (
|
$query = "INSERT INTO `" . self::TABLE_SERVER_SETTINGS . "` (
|
||||||
`serverIndex`,
|
`serverIndex`,
|
||||||
`settingName`,
|
`settingName`,
|
||||||
`settingValue`
|
`settingValue`
|
||||||
@ -340,50 +349,49 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
) ON DUPLICATE KEY UPDATE
|
) ON DUPLICATE KEY UPDATE
|
||||||
`settingValue` = VALUES(`settingValue`);";
|
`settingValue` = VALUES(`settingValue`);";
|
||||||
$statement = $mysqli->prepare($query);
|
$statement = $mysqli->prepare($query);
|
||||||
if ($mysqli->error) {
|
if($mysqli->error) {
|
||||||
trigger_error($mysqli->error);
|
trigger_error($mysqli->error);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$serverIndex = $this->maniaControl->server->getIndex();
|
$serverIndex = $this->maniaControl->server->getIndex();
|
||||||
|
|
||||||
// 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) {
|
||||||
$statement->bind_param('iss', $serverIndex, $setting, $value);
|
$statement->bind_param('iss', $serverIndex, $setting, $value);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
if ($statement->error) {
|
if($statement->error) {
|
||||||
trigger_error($statement->error);
|
trigger_error($statement->error);
|
||||||
$statement->close();
|
$statement->close();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// $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) { $chatMessage .= ', '; }
|
* if ($settingIndex <= $settingsCount - 2) { $chatMessage .= ', '; }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Trigger own callback
|
// Trigger own callback
|
||||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_SERVERSETTING_CHANGED,
|
$this->maniaControl->callbackManager->triggerCallback(self::CB_SERVERSETTING_CHANGED, array(self::CB_SERVERSETTING_CHANGED, $setting, $value));
|
||||||
array(self::CB_SERVERSETTING_CHANGED, $setting, $value));
|
|
||||||
|
|
||||||
$settingIndex++;
|
$settingIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
$statement->close();
|
$statement->close();
|
||||||
|
|
||||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_SERVERSETTINGS_CHANGED, array(self::CB_SERVERSETTINGS_CHANGED));
|
$this->maniaControl->callbackManager->triggerCallback(self::CB_SERVERSETTINGS_CHANGED, array(self::CB_SERVERSETTINGS_CHANGED));
|
||||||
|
|
||||||
// $chatMessage .= '!';
|
// $chatMessage .= '!';
|
||||||
// $this->maniaControl->chat->sendInformation($chatMessage);
|
// $this->maniaControl->chat->sendInformation($chatMessage);
|
||||||
// $this->maniaControl->log(Formatter::stripCodes($chatMessage));
|
// $this->maniaControl->log(Formatter::stripCodes($chatMessage));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -394,9 +402,9 @@ class ServerSettings 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user