script settings improvements
This commit is contained in:
parent
1091afb771
commit
d28269ade6
@ -24,7 +24,6 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
||||
/**
|
||||
* Constants
|
||||
*/
|
||||
const TITLE = 'Script Settings';
|
||||
const ACTION_PREFIX_SETTING = 'ScriptSetting.';
|
||||
const ACTION_SETTING_BOOL = 'ScriptSetting.ActionBoolSetting.';
|
||||
const CB_SCRIPTSETTING_CHANGED = 'ScriptSettings.SettingChanged';
|
||||
@ -44,11 +43,17 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
// Register for callbacks
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this,
|
||||
'handleManialinkPageAnswer');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'onInit');
|
||||
$this->initTables();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 . "` (
|
||||
@ -61,17 +66,14 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
||||
$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;
|
||||
}
|
||||
|
||||
@ -90,33 +92,31 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
||||
* @return bool
|
||||
*/
|
||||
public function loadSettingsFromDatabase() {
|
||||
$this->maniaControl->client->query('GetModeScriptSettings');
|
||||
$scriptSettings = $this->maniaControl->client->getResponse();
|
||||
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
|
||||
$loadedSettings = array();
|
||||
|
||||
$query = "SELECT * FROM `" . self::TABLE_SCRIPT_SETTINGS . "`;";
|
||||
$result = $mysqli->query($query);
|
||||
if(!$result) {
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error);
|
||||
return false;
|
||||
}
|
||||
|
||||
while($row = $result->fetch_object()) {
|
||||
$loadedSettings[$row->settingName] = $row->settingValue;
|
||||
settype($loadedSettings[$row->settingName], gettype($scriptSettings[$row->settingName]));
|
||||
}
|
||||
|
||||
if ($result->num_rows) {
|
||||
$result->close();
|
||||
|
||||
if(count($loadedSettings) == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->maniaControl->client->query('GetModeScriptSettings');
|
||||
$scriptSettings = $this->maniaControl->client->getResponse();
|
||||
$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->close();
|
||||
|
||||
$success = $this->maniaControl->client->query('SetModeScriptSettings', $loadedSettings);
|
||||
if (!$success) {
|
||||
$this->maniaControl->log('Error occurred: ' . $this->maniaControl->getClientErrorText());
|
||||
trigger_error('Error occured: ' . $this->maniaControl->getClientErrorText());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -127,7 +127,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
||||
* @see \ManiaControl\Configurators\ConfiguratorMenu::getTitle()
|
||||
*/
|
||||
public function getTitle() {
|
||||
return self::TITLE;
|
||||
return 'Script Settings';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -222,7 +222,8 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
||||
$substyle = '';
|
||||
if ($settingValue === false) {
|
||||
$substyle = Quad_Icons64x64_1::SUBSTYLE_LvlRed;
|
||||
} else if($settingValue === true) {
|
||||
}
|
||||
else if ($settingValue === true) {
|
||||
$substyle = Quad_Icons64x64_1::SUBSTYLE_LvlGreen;
|
||||
}
|
||||
|
||||
@ -235,7 +236,8 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
||||
$quad->setSize(4, 4);
|
||||
$quad->setHAlign(Control::CENTER);
|
||||
$quad->setAction(self::ACTION_SETTING_BOOL . $settingName);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
$entry = new Entry();
|
||||
$settingFrame->add($entry);
|
||||
$entry->setStyle(Label_Text::STYLE_TextValueSmall);
|
||||
@ -272,7 +274,6 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
||||
* @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData()
|
||||
*/
|
||||
public function saveConfigData(array $configData, Player $player) {
|
||||
|
||||
$this->maniaControl->client->query('GetModeScriptSettings');
|
||||
$scriptSettings = $this->maniaControl->client->getResponse();
|
||||
|
||||
@ -354,9 +355,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
||||
* @param Player $player
|
||||
*/
|
||||
private function applyNewScriptSettings(array $newSettings, Player $player) {
|
||||
if(!$newSettings) {
|
||||
return true;
|
||||
}
|
||||
if (!$newSettings) return true;
|
||||
$success = $this->maniaControl->client->query('SetModeScriptSettings', $newSettings);
|
||||
if (!$success) {
|
||||
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
|
||||
@ -365,7 +364,6 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
||||
|
||||
// Save Settings into Database
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
|
||||
$query = "INSERT INTO `" . self::TABLE_SCRIPT_SETTINGS . "` (
|
||||
`serverId`,
|
||||
`settingName`,
|
||||
@ -382,7 +380,6 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
||||
|
||||
$serverId = $this->maniaControl->server->getServerId();
|
||||
|
||||
|
||||
// Notifications
|
||||
$settingsCount = count($newSettings);
|
||||
$settingIndex = 0;
|
||||
@ -406,7 +403,8 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
||||
}
|
||||
|
||||
// Trigger own callback
|
||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_SCRIPTSETTING_CHANGED, array(self::CB_SCRIPTSETTING_CHANGED, $setting, $value));
|
||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_SCRIPTSETTING_CHANGED,
|
||||
array(self::CB_SCRIPTSETTING_CHANGED, $setting, $value));
|
||||
|
||||
$settingIndex++;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user