refactor codestyle (chaining)
This commit is contained in:
@ -70,36 +70,24 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
||||
$this->addActionsMenuItem();
|
||||
|
||||
// Settings
|
||||
$this->maniaControl->getSettingManager()
|
||||
->initSetting($this, self::SETTING_MENU_POSX, 0.);
|
||||
$this->maniaControl->getSettingManager()
|
||||
->initSetting($this, self::SETTING_MENU_POSY, 3.);
|
||||
$this->maniaControl->getSettingManager()
|
||||
->initSetting($this, self::SETTING_MENU_WIDTH, 170.);
|
||||
$this->maniaControl->getSettingManager()
|
||||
->initSetting($this, self::SETTING_MENU_HEIGHT, 81.);
|
||||
$this->maniaControl->getSettingManager()
|
||||
->initSetting($this, self::SETTING_MENU_STYLE, Quad_BgRaceScore2::STYLE);
|
||||
$this->maniaControl->getSettingManager()
|
||||
->initSetting($this, self::SETTING_MENU_SUBSTYLE, Quad_BgRaceScore2::SUBSTYLE_HandleSelectable);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MENU_POSX, 0.);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MENU_POSY, 3.);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MENU_WIDTH, 170.);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MENU_HEIGHT, 81.);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MENU_STYLE, Quad_BgRaceScore2::STYLE);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MENU_SUBSTYLE, Quad_BgRaceScore2::SUBSTYLE_HandleSelectable);
|
||||
|
||||
// Permissions
|
||||
$this->maniaControl->getAuthenticationManager()
|
||||
->definePermissionLevel(self::SETTING_PERMISSION_OPEN_CONFIGURATOR, AuthenticationManager::AUTH_LEVEL_ADMIN);
|
||||
$this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_OPEN_CONFIGURATOR, AuthenticationManager::AUTH_LEVEL_ADMIN);
|
||||
|
||||
// Page answers
|
||||
$this->maniaControl->getManialinkManager()
|
||||
->registerManialinkPageAnswerListener(self::ACTION_TOGGLEMENU, $this, 'handleToggleMenuAction');
|
||||
$this->maniaControl->getManialinkManager()
|
||||
->registerManialinkPageAnswerListener(self::ACTION_SAVECONFIG, $this, 'handleSaveConfigAction');
|
||||
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_TOGGLEMENU, $this, 'handleToggleMenuAction');
|
||||
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_SAVECONFIG, $this, 'handleSaveConfigAction');
|
||||
|
||||
// Callbacks
|
||||
$this->maniaControl->getCallbackManager()
|
||||
->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
||||
$this->maniaControl->getCallbackManager()
|
||||
->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_OPENED, $this, 'handleWidgetOpened');
|
||||
$this->maniaControl->getCallbackManager()
|
||||
->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_CLOSED, $this, 'closeWidget');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_OPENED, $this, 'handleWidgetOpened');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_CLOSED, $this, 'closeWidget');
|
||||
|
||||
// Create server options menu
|
||||
$this->serverOptionsMenu = new ServerOptionsMenu($maniaControl);
|
||||
@ -118,8 +106,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
||||
$this->addMenu($this->maniaControlSettings);
|
||||
|
||||
// Chat commands
|
||||
$this->maniaControl->getCommandManager()
|
||||
->registerCommandListener('config', $this, 'handleConfigCommand', true, 'Loads Config panel.');
|
||||
$this->maniaControl->getCommandManager()->registerCommandListener('config', $this, 'handleConfigCommand', true, 'Loads Config panel.');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -127,10 +114,8 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
||||
*/
|
||||
private function addActionsMenuItem() {
|
||||
$itemQuad = new Quad_UIConstruction_Buttons();
|
||||
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Tools)
|
||||
->setAction(self::ACTION_TOGGLEMENU);
|
||||
$this->maniaControl->getActionsMenu()
|
||||
->addAdminMenuItem($itemQuad, 100, 'Settings');
|
||||
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Tools)->setAction(self::ACTION_TOGGLEMENU);
|
||||
$this->maniaControl->getActionsMenu()->addAdminMenuItem($itemQuad, 100, 'Settings');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -149,11 +134,9 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
||||
* @param Player $player
|
||||
*/
|
||||
public function handleConfigCommand(array $callback, Player $player) {
|
||||
if (!$this->maniaControl->getAuthenticationManager()
|
||||
->checkPermission($player, self::SETTING_PERMISSION_OPEN_CONFIGURATOR)
|
||||
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_OPEN_CONFIGURATOR)
|
||||
) {
|
||||
$this->maniaControl->getAuthenticationManager()
|
||||
->sendNotAllowed($player);
|
||||
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -171,8 +154,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
||||
$menuId = $this->getMenuId($menuId->getTitle());
|
||||
}
|
||||
$manialink = $this->buildManialink($menuId, $player);
|
||||
$this->maniaControl->getManialinkManager()
|
||||
->displayWidget($manialink, $player, self::MENU_NAME);
|
||||
$this->maniaControl->getManialinkManager()->displayWidget($manialink, $player, self::MENU_NAME);
|
||||
$player->setCache($this, self::CACHE_MENU_SHOWN, true);
|
||||
}
|
||||
|
||||
@ -201,18 +183,12 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
||||
* @return \FML\ManiaLink
|
||||
*/
|
||||
private function buildManialink($menuIdShown = 0, Player $player = null) {
|
||||
$menuPosX = $this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_MENU_POSX);
|
||||
$menuPosY = $this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_MENU_POSY);
|
||||
$menuWidth = $this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_MENU_WIDTH);
|
||||
$menuHeight = $this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_MENU_HEIGHT);
|
||||
$quadStyle = $this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_MENU_STYLE);
|
||||
$quadSubstyle = $this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_MENU_SUBSTYLE);
|
||||
$menuPosX = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_POSX);
|
||||
$menuPosY = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_POSY);
|
||||
$menuWidth = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_WIDTH);
|
||||
$menuHeight = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_HEIGHT);
|
||||
$quadStyle = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_STYLE);
|
||||
$quadSubstyle = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_SUBSTYLE);
|
||||
|
||||
$menuListWidth = $menuWidth * 0.3;
|
||||
$menuItemHeight = 10.;
|
||||
@ -227,9 +203,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
||||
|
||||
$backgroundQuad = new Quad();
|
||||
$frame->add($backgroundQuad);
|
||||
$backgroundQuad->setZ(-10)
|
||||
->setSize($menuWidth, $menuHeight)
|
||||
->setStyles($quadStyle, $quadSubstyle);
|
||||
$backgroundQuad->setZ(-10)->setSize($menuWidth, $menuHeight)->setStyles($quadStyle, $quadSubstyle);
|
||||
|
||||
$menuItemsFrame = new Frame();
|
||||
$frame->add($menuItemsFrame);
|
||||
@ -238,8 +212,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
||||
$itemsBackgroundQuad = new Quad();
|
||||
$menuItemsFrame->add($itemsBackgroundQuad);
|
||||
$backgroundQuad->setZ(-9);
|
||||
$itemsBackgroundQuad->setSize($menuListWidth, $menuHeight)
|
||||
->setStyles($quadStyle, $quadSubstyle);
|
||||
$itemsBackgroundQuad->setSize($menuListWidth, $menuHeight)->setStyles($quadStyle, $quadSubstyle);
|
||||
|
||||
$menusFrame = new Frame();
|
||||
$frame->add($menusFrame);
|
||||
@ -254,11 +227,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
||||
// 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);
|
||||
$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) {
|
||||
@ -266,8 +235,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
||||
if ($menuControl) {
|
||||
$menusFrame->add($menuControl);
|
||||
} else {
|
||||
$this->maniaControl->getChat()
|
||||
->sendError('Error loading Menu!', $player);
|
||||
$this->maniaControl->getChat()->sendError('Error loading Menu!', $player);
|
||||
}
|
||||
}
|
||||
|
||||
@ -278,32 +246,17 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
||||
// 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);
|
||||
$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);
|
||||
$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);
|
||||
$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;
|
||||
}
|
||||
@ -338,8 +291,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
||||
*/
|
||||
public function hideMenu(Player $player) {
|
||||
$this->closeWidget($player);
|
||||
$this->maniaControl->getManialinkManager()
|
||||
->closeWidget($player);
|
||||
$this->maniaControl->getManialinkManager()->closeWidget($player);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -388,8 +340,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
||||
}
|
||||
|
||||
$login = $callback[1][1];
|
||||
$player = $this->maniaControl->getPlayerManager()
|
||||
->getPlayer($login);
|
||||
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
|
||||
|
||||
if ($player) {
|
||||
$actionArray = explode('.', $callback[1][2]);
|
||||
|
@ -52,12 +52,10 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
// Callbacks
|
||||
$this->maniaControl->getCallbackManager()
|
||||
->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
||||
|
||||
// Permissions
|
||||
$this->maniaControl->getAuthenticationManager()
|
||||
->definePermissionLevel(self::SETTING_PERMISSION_CHANGE_MC_SETTINGS, AuthenticationManager::AUTH_LEVEL_ADMIN);
|
||||
$this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_CHANGE_MC_SETTINGS, AuthenticationManager::AUTH_LEVEL_ADMIN);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -89,8 +87,7 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
|
||||
* @return \FML\Controls\Frame
|
||||
*/
|
||||
private function getMenuSettingsForClass($settingClass, $width, $height, Script $script, Player $player) {
|
||||
$settings = $this->maniaControl->getSettingManager()
|
||||
->getSettingsByClass($settingClass);
|
||||
$settings = $this->maniaControl->getSettingManager()->getSettingsByClass($settingClass);
|
||||
|
||||
$paging = new Paging();
|
||||
$script->addFeature($paging);
|
||||
@ -217,8 +214,7 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
|
||||
* @return \FML\Controls\Frame
|
||||
*/
|
||||
private function getMenuSettingClasses($width, $height, Script $script, Player $player) {
|
||||
$settingClasses = $this->maniaControl->getSettingManager()
|
||||
->getSettingClasses(true);
|
||||
$settingClasses = $this->maniaControl->getSettingManager()->getSettingClasses(true);
|
||||
|
||||
$paging = new Paging();
|
||||
$script->addFeature($paging);
|
||||
@ -301,26 +297,20 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
|
||||
if ($actionId === self::ACTION_SETTINGCLASS_BACK) {
|
||||
// Back to classes list
|
||||
$login = $callback[1][1];
|
||||
$player = $this->maniaControl->getPlayerManager()
|
||||
->getPlayer($login);
|
||||
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
|
||||
$player->destroyCache($this, self::CACHE_CLASS_OPENED);
|
||||
$menuId = $this->maniaControl->getConfigurator()
|
||||
->getMenuId($this);
|
||||
$this->maniaControl->getConfigurator()
|
||||
->showMenu($player, $menuId);
|
||||
$menuId = $this->maniaControl->getConfigurator()->getMenuId($this);
|
||||
$this->maniaControl->getConfigurator()->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->getPlayerManager()
|
||||
->getPlayer($login);
|
||||
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
|
||||
$player->setCache($this, self::CACHE_CLASS_OPENED, $settingClass);
|
||||
|
||||
$menuId = $this->maniaControl->getConfigurator()
|
||||
->getMenuId($this);
|
||||
$this->maniaControl->getConfigurator()
|
||||
->showMenu($player, $menuId);
|
||||
$menuId = $this->maniaControl->getConfigurator()->getMenuId($this);
|
||||
$this->maniaControl->getConfigurator()->showMenu($player, $menuId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -328,11 +318,9 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
|
||||
* @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData()
|
||||
*/
|
||||
public function saveConfigData(array $configData, Player $player) {
|
||||
if (!$this->maniaControl->getAuthenticationManager()
|
||||
->checkPermission($player, self::SETTING_PERMISSION_CHANGE_MC_SETTINGS)
|
||||
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_CHANGE_MC_SETTINGS)
|
||||
) {
|
||||
$this->maniaControl->getAuthenticationManager()
|
||||
->sendNotAllowed($player);
|
||||
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
|
||||
return;
|
||||
}
|
||||
if (!$configData[3] || strpos($configData[3][0]['Name'], self::ACTION_PREFIX_SETTING) !== 0) {
|
||||
@ -343,8 +331,7 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
|
||||
|
||||
foreach ($configData[3] as $settingData) {
|
||||
$settingIndex = (int)substr($settingData['Name'], $prefixLength);
|
||||
$settingObject = $this->maniaControl->getSettingManager()
|
||||
->getSettingObjectByIndex($settingIndex);
|
||||
$settingObject = $this->maniaControl->getSettingManager()->getSettingObjectByIndex($settingIndex);
|
||||
if (!$settingObject) {
|
||||
continue;
|
||||
}
|
||||
@ -354,15 +341,12 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
|
||||
}
|
||||
|
||||
$settingObject->value = $settingData['Value'];
|
||||
$this->maniaControl->getSettingManager()
|
||||
->saveSetting($settingObject);
|
||||
$this->maniaControl->getSettingManager()->saveSetting($settingObject);
|
||||
}
|
||||
|
||||
$this->maniaControl->getChat()
|
||||
->sendSuccess('Settings saved!', $player);
|
||||
$this->maniaControl->getChat()->sendSuccess('Settings saved!', $player);
|
||||
|
||||
// Reopen the Menu
|
||||
$this->maniaControl->getConfigurator()
|
||||
->showMenu($player, $this);
|
||||
$this->maniaControl->getConfigurator()->showMenu($player, $this);
|
||||
}
|
||||
}
|
||||
|
@ -53,18 +53,14 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
||||
$this->initTables();
|
||||
|
||||
// Callbacks
|
||||
$this->maniaControl->getCallbackManager()
|
||||
->registerCallbackListener(Callbacks::ONINIT, $this, 'onInit');
|
||||
$this->maniaControl->getCallbackManager()
|
||||
->registerCallbackListener(Callbacks::BEGINMAP, $this, 'onBeginMap');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ONINIT, $this, 'onInit');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::BEGINMAP, $this, 'onBeginMap');
|
||||
|
||||
// Settings
|
||||
$this->maniaControl->getSettingManager()
|
||||
->initSetting($this, self::SETTING_LOAD_DEFAULT_SETTINGS_MAP_BEGIN, false);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_LOAD_DEFAULT_SETTINGS_MAP_BEGIN, false);
|
||||
|
||||
// Permissions
|
||||
$this->maniaControl->getAuthenticationManager()
|
||||
->definePermissionLevel(self::SETTING_PERMISSION_CHANGE_SCRIPT_SETTINGS, AuthenticationManager::AUTH_LEVEL_ADMIN);
|
||||
$this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_CHANGE_SCRIPT_SETTINGS, AuthenticationManager::AUTH_LEVEL_ADMIN);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -73,8 +69,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
||||
* @return boolean
|
||||
*/
|
||||
private function initTables() {
|
||||
$mysqli = $this->maniaControl->getDatabase()
|
||||
->getMysqli();
|
||||
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
|
||||
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_SCRIPT_SETTINGS . "` (
|
||||
`index` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`serverIndex` int(11) NOT NULL,
|
||||
@ -119,14 +114,12 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
||||
*/
|
||||
public function loadSettingsFromDatabase() {
|
||||
try {
|
||||
$scriptSettings = $this->maniaControl->getClient()
|
||||
->getModeScriptSettings();
|
||||
$scriptSettings = $this->maniaControl->getClient()->getModeScriptSettings();
|
||||
} catch (GameModeException $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$mysqli = $this->maniaControl->getDatabase()
|
||||
->getMysqli();
|
||||
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
|
||||
$serverIndex = $this->maniaControl->getServer()->index;
|
||||
$query = "SELECT * FROM `" . self::TABLE_SCRIPT_SETTINGS . "`
|
||||
WHERE serverIndex = {$serverIndex};";
|
||||
@ -149,16 +142,14 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->maniaControl->getClient()
|
||||
->setModeScriptSettings($loadedSettings);
|
||||
return $this->maniaControl->getClient()->setModeScriptSettings($loadedSettings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Begin Map Callback
|
||||
*/
|
||||
public function onBeginMap() {
|
||||
if ($this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_LOAD_DEFAULT_SETTINGS_MAP_BEGIN)
|
||||
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_LOAD_DEFAULT_SETTINGS_MAP_BEGIN)
|
||||
) {
|
||||
$this->loadSettingsFromDatabase();
|
||||
}
|
||||
@ -173,8 +164,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
||||
$frame = new Frame();
|
||||
|
||||
try {
|
||||
$scriptInfo = $this->maniaControl->getClient()
|
||||
->getModeScriptInfo();
|
||||
$scriptInfo = $this->maniaControl->getClient()->getModeScriptInfo();
|
||||
} catch (GameModeException $e) {
|
||||
$label = new Label();
|
||||
$frame->add($label);
|
||||
@ -185,8 +175,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
||||
$scriptParams = $scriptInfo->paramDescs;
|
||||
|
||||
try {
|
||||
$scriptSettings = $this->maniaControl->getClient()
|
||||
->getModeScriptSettings();
|
||||
$scriptSettings = $this->maniaControl->getClient()->getModeScriptSettings();
|
||||
} catch (GameModeException $e) {
|
||||
}
|
||||
|
||||
@ -293,11 +282,9 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
||||
* @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData()
|
||||
*/
|
||||
public function saveConfigData(array $configData, Player $player) {
|
||||
if (!$this->maniaControl->getAuthenticationManager()
|
||||
->checkPermission($player, self::SETTING_PERMISSION_CHANGE_SCRIPT_SETTINGS)
|
||||
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_CHANGE_SCRIPT_SETTINGS)
|
||||
) {
|
||||
$this->maniaControl->getAuthenticationManager()
|
||||
->sendNotAllowed($player);
|
||||
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
|
||||
return;
|
||||
}
|
||||
if (!$configData[3] || strpos($configData[3][0]['Name'], self::ACTION_PREFIX_SETTING) !== 0) {
|
||||
@ -305,8 +292,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
||||
}
|
||||
|
||||
try {
|
||||
$scriptSettings = $this->maniaControl->getClient()
|
||||
->getModeScriptSettings();
|
||||
$scriptSettings = $this->maniaControl->getClient()->getModeScriptSettings();
|
||||
} catch (GameModeException $e) {
|
||||
return;
|
||||
}
|
||||
@ -332,16 +318,13 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
||||
|
||||
$success = $this->applyNewScriptSettings($newSettings, $player);
|
||||
if ($success) {
|
||||
$this->maniaControl->getChat()
|
||||
->sendSuccess('Script Settings saved!', $player);
|
||||
$this->maniaControl->getChat()->sendSuccess('Script Settings saved!', $player);
|
||||
} else {
|
||||
$this->maniaControl->getChat()
|
||||
->sendError('Script Settings Saving failed!', $player);
|
||||
$this->maniaControl->getChat()->sendError('Script Settings Saving failed!', $player);
|
||||
}
|
||||
|
||||
// Reopen the Menu
|
||||
$this->maniaControl->getConfigurator()
|
||||
->showMenu($player, $this);
|
||||
$this->maniaControl->getConfigurator()->showMenu($player, $this);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -356,12 +339,10 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->maniaControl->getClient()
|
||||
->setModeScriptSettings($newSettings);
|
||||
$this->maniaControl->getClient()->setModeScriptSettings($newSettings);
|
||||
|
||||
// Save Settings into Database
|
||||
$mysqli = $this->maniaControl->getDatabase()
|
||||
->getMysqli();
|
||||
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
|
||||
$query = "INSERT INTO `" . self::TABLE_SCRIPT_SETTINGS . "` (
|
||||
`serverIndex`,
|
||||
`settingName`,
|
||||
@ -382,8 +363,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
||||
// Notifications
|
||||
$settingsCount = count($newSettings);
|
||||
$settingIndex = 0;
|
||||
$title = $this->maniaControl->getAuthenticationManager()
|
||||
->getAuthLevelName($player);
|
||||
$title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($player);
|
||||
$chatMessage = '$ff0' . $title . ' ' . $player->getEscapedNickname() . ' set ScriptSetting' . ($settingsCount > 1 ? 's' : '') . ' ';
|
||||
foreach ($newSettings as $setting => $value) {
|
||||
$chatMessage .= '$<' . '$fff' . preg_replace('/^S_/', '', $setting) . '$z$s$ff0 ';
|
||||
@ -402,19 +382,16 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
||||
}
|
||||
|
||||
// Trigger own callback
|
||||
$this->maniaControl->getCallbackManager()
|
||||
->triggerCallback(self::CB_SCRIPTSETTING_CHANGED, $setting, $value);
|
||||
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_SCRIPTSETTING_CHANGED, $setting, $value);
|
||||
|
||||
$settingIndex++;
|
||||
}
|
||||
$statement->close();
|
||||
|
||||
$this->maniaControl->getCallbackManager()
|
||||
->triggerCallback(self::CB_SCRIPTSETTINGS_CHANGED);
|
||||
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_SCRIPTSETTINGS_CHANGED);
|
||||
|
||||
$chatMessage .= '!';
|
||||
$this->maniaControl->getChat()
|
||||
->sendInformation($chatMessage);
|
||||
$this->maniaControl->getChat()->sendInformation($chatMessage);
|
||||
Logger::logInfo($chatMessage, true);
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user