use of player cache in settings config menu

This commit is contained in:
Steffen Schröder 2014-05-18 21:50:15 +02:00
parent 53ff6b35cd
commit 722c0f483e

View File

@ -15,7 +15,6 @@ use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager;
use ManiaControl\Settings\Setting; use ManiaControl\Settings\Setting;
/** /**
@ -35,12 +34,12 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
const ACTION_SETTINGCLASS_BACK = 'MCSettingClassBack'; const ACTION_SETTINGCLASS_BACK = 'MCSettingClassBack';
const ACTION_SETTING_BOOL = 'MCSettings.ActionBoolSetting.'; const ACTION_SETTING_BOOL = 'MCSettings.ActionBoolSetting.';
const SETTING_PERMISSION_CHANGE_MC_SETTINGS = 'Change ManiaControl Settings'; const SETTING_PERMISSION_CHANGE_MC_SETTINGS = 'Change ManiaControl Settings';
const CACHE_CLASS_OPENED = 'ClassOpened';
/* /*
* Private Properties * Private Properties
*/ */
private $maniaControl = null; private $maniaControl = null;
private $playersSettingCategoryOpened = array();
/** /**
* Create a new Script Settings Instance * Create a new Script Settings Instance
@ -52,29 +51,19 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
// Register for callbacks // 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(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect');
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_CHANGE_MC_SETTINGS, AuthenticationManager::AUTH_LEVEL_ADMIN); $this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_CHANGE_MC_SETTINGS, AuthenticationManager::AUTH_LEVEL_ADMIN);
} }
/**
* Handle Player Disconnect Callback
*
* @param Player $player
*/
public function handlePlayerDisconnect(Player $player) {
unset($this->playersSettingCategoryOpened[$player->login]);
}
/** /**
* @see \ManiaControl\Configurators\ConfiguratorMenu::getMenu() * @see \ManiaControl\Configurators\ConfiguratorMenu::getMenu()
*/ */
public function getMenu($width, $height, Script $script, Player $player) { public function getMenu($width, $height, Script $script, Player $player) {
if (isset($this->playersSettingCategoryOpened[$player->login]) && strlen($this->playersSettingCategoryOpened[$player->login]) > 0) { $openedClass = $player->getCache($this, self::CACHE_CLASS_OPENED);
return $this->getMenuSettingsForClass($this->playersSettingCategoryOpened[$player->login], $width, $height, $script, $player); if ($openedClass) {
} else { return $this->getMenuSettingsForClass($openedClass, $width, $height, $script, $player);
return $this->getMenuSettingClasses($width, $height, $script, $player);
} }
return $this->getMenuSettingClasses($width, $height, $script, $player);
} }
/** /**
@ -302,7 +291,7 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
// Back to classes list // Back to classes list
$login = $callback[1][1]; $login = $callback[1][1];
$player = $this->maniaControl->playerManager->getPlayer($login); $player = $this->maniaControl->playerManager->getPlayer($login);
unset($this->playersSettingCategoryOpened[$player->login]); $player->destroyCache($this, self::CACHE_CLASS_OPENED);
$menuId = $this->maniaControl->configurator->getMenuId($this); $menuId = $this->maniaControl->configurator->getMenuId($this);
$this->maniaControl->configurator->showMenu($player, $menuId); $this->maniaControl->configurator->showMenu($player, $menuId);
} else if (strpos($actionId, self::ACTION_SETTING_BOOL) === 0) { } else if (strpos($actionId, self::ACTION_SETTING_BOOL) === 0) {
@ -329,8 +318,7 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
$login = $callback[1][1]; $login = $callback[1][1];
$player = $this->maniaControl->playerManager->getPlayer($login); $player = $this->maniaControl->playerManager->getPlayer($login);
$player->setCache($this, self::CACHE_CLASS_OPENED, $settingClass);
$this->playersSettingCategoryOpened[$player->login] = $settingClass;
$menuId = $this->maniaControl->configurator->getMenuId($this); $menuId = $this->maniaControl->configurator->getMenuId($this);
$this->maniaControl->configurator->showMenu($player, $menuId); $this->maniaControl->configurator->showMenu($player, $menuId);