fixed doubled reopening of plugin menu
This commit is contained in:
parent
e50ee01d01
commit
ce1863318c
@ -10,7 +10,6 @@ use FML\Controls\Quads\Quad_BgRaceScore2;
|
||||
use FML\Controls\Quads\Quad_Icons64x64_1;
|
||||
use FML\Controls\Quads\Quad_UIConstruction_Buttons;
|
||||
use FML\ManiaLink;
|
||||
use FML\Script\Features\Menu;
|
||||
use ManiaControl\Admin\AuthenticationManager;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\CallbackManager;
|
||||
@ -152,7 +151,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
||||
* @param Player $player
|
||||
* @return \FML\ManiaLink
|
||||
*/
|
||||
private function buildManialink($menuIdShown = 0, Player $player) {
|
||||
private function buildManialink($menuIdShown = 0, Player $player = null) {
|
||||
$menuPosX = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSX);
|
||||
$menuPosY = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSY);
|
||||
$menuWidth = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_WIDTH);
|
||||
@ -191,9 +190,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
||||
$menusFrame->setX($menuWidth * -0.5 + $menuListWidth + $subMenuWidth * 0.5);
|
||||
|
||||
// Create script and features
|
||||
$script = $manialink->getScript();
|
||||
$menuScript = new Menu();
|
||||
$script->addFeature($menuScript);
|
||||
$script = $manialink->getScript();
|
||||
|
||||
$menuItemY = $menuHeight * 0.42;
|
||||
$menuId = 0;
|
||||
@ -213,7 +210,6 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
||||
if ($menuId == $menuIdShown) {
|
||||
$menuControl = $menu->getMenu($subMenuWidth, $subMenuHeight, $script, $player);
|
||||
$menusFrame->add($menuControl);
|
||||
$menuScript->addElement($menuItemLabel, $menuControl);
|
||||
}
|
||||
|
||||
$menuItemY -= $menuItemHeight * 1.1;
|
||||
|
@ -19,7 +19,7 @@ use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
||||
use ManiaControl\Players\Player;
|
||||
|
||||
/**
|
||||
* Configurator for enabling and disabling Plugins
|
||||
* Configurator for installing Plugins
|
||||
*
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
@ -29,11 +29,16 @@ class PluginInstallMenu implements CallbackListener, ConfiguratorMenu, Manialink
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
const SETTING_PERMISSION_INSTALL_PLUGINS = 'Install plugins';
|
||||
const SETTING_PERMISSION_INSTALL_PLUGINS = 'Install Plugins';
|
||||
const ACTION_PREFIX_INSTALLPLUGIN = 'PluginInstallMenu.Install.';
|
||||
|
||||
/*
|
||||
* Private Properties
|
||||
*/
|
||||
private $maniaControl = null;
|
||||
|
||||
/**
|
||||
* Create a new plugin menu instance
|
||||
* Create a new Plugin Install Menu
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
*/
|
||||
@ -44,22 +49,14 @@ class PluginInstallMenu implements CallbackListener, ConfiguratorMenu, Manialink
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Menu Title
|
||||
*
|
||||
* @return string
|
||||
* @see \ManiaControl\Configurators\ConfiguratorMenu::getTitle()
|
||||
*/
|
||||
public function getTitle() {
|
||||
return 'Install Plugins';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Configurator Menu Frame
|
||||
*
|
||||
* @param float $width
|
||||
* @param float $height
|
||||
* @param Script $script
|
||||
* @param Player $player
|
||||
* @return \FML\Controls\Frame
|
||||
* @see \ManiaControl\Configurators\ConfiguratorMenu::getMenu()
|
||||
*/
|
||||
public function getMenu($width, $height, Script $script, Player $player) {
|
||||
$paging = new Paging();
|
||||
@ -175,10 +172,7 @@ class PluginInstallMenu implements CallbackListener, ConfiguratorMenu, Manialink
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the Config Data
|
||||
*
|
||||
* @param array $configData
|
||||
* @param Player $player
|
||||
* @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData()
|
||||
*/
|
||||
public function saveConfigData(array $configData, Player $player) {
|
||||
// TODO: Implement saveConfigData() method.
|
||||
|
@ -364,47 +364,46 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
|
||||
* @param array $callback
|
||||
*/
|
||||
public function handleManialinkPageAnswer(array $callback) {
|
||||
$actionId = $callback[1][2];
|
||||
$enable = (strpos($actionId, self::ACTION_PREFIX_ENABLEPLUGIN) === 0);
|
||||
$disable = (strpos($actionId, self::ACTION_PREFIX_DISABLEPLUGIN) === 0);
|
||||
$settings = (strpos($actionId, self::ACTION_PREFIX_SETTINGS) === 0);
|
||||
$boolSetting = (strpos($actionId, self::ACTION_SETTING_BOOL) === 0);
|
||||
|
||||
if (!$enable && !$disable && !$settings && !$boolSetting) {
|
||||
return;
|
||||
}
|
||||
$login = $callback[1][1];
|
||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||
if (!$player) {
|
||||
return;
|
||||
}
|
||||
|
||||
$actionId = $callback[1][2];
|
||||
$enable = (strpos($actionId, self::ACTION_PREFIX_ENABLEPLUGIN) === 0);
|
||||
$disable = (strpos($actionId, self::ACTION_PREFIX_DISABLEPLUGIN) === 0);
|
||||
$settings = (strpos($actionId, self::ACTION_PREFIX_SETTINGS) === 0);
|
||||
$boolSetting = (strpos($actionId, self::ACTION_SETTING_BOOL) === 0);
|
||||
if (!$enable && !$disable && !$settings && !$boolSetting) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($enable) {
|
||||
$pluginClass = substr($actionId, strlen(self::ACTION_PREFIX_ENABLEPLUGIN));
|
||||
/** @var Plugin $pluginClass */
|
||||
$activated = $this->maniaControl->pluginManager->activatePlugin($pluginClass, $player->login);
|
||||
if ($activated) {
|
||||
$this->maniaControl->chat->sendSuccess($pluginClass::getName() . ' activated!', $player->login);
|
||||
$this->maniaControl->configurator->showMenu($player);
|
||||
$this->maniaControl->log(Formatter::stripCodes("{$player->login} activated '{$pluginClass}'!"));
|
||||
$this->maniaControl->chat->sendSuccess($pluginClass::getName() . ' activated!', $player);
|
||||
$this->maniaControl->log("{$player->login} activated '{$pluginClass}'!", true);
|
||||
} else {
|
||||
$this->maniaControl->chat->sendError('Error activating ' . $pluginClass::getName() . '!', $player->login);
|
||||
$this->maniaControl->chat->sendError('Error activating ' . $pluginClass::getName() . '!', $player);
|
||||
}
|
||||
} else if ($disable) {
|
||||
$pluginClass = substr($actionId, strlen(self::ACTION_PREFIX_DISABLEPLUGIN));
|
||||
/** @var Plugin $pluginClass */
|
||||
$deactivated = $this->maniaControl->pluginManager->deactivatePlugin($pluginClass);
|
||||
if ($deactivated) {
|
||||
$this->maniaControl->chat->sendSuccess($pluginClass::getName() . ' deactivated!', $player->login);
|
||||
$this->maniaControl->configurator->showMenu($player);
|
||||
$this->maniaControl->log(Formatter::stripCodes("{$player->login} deactivated '{$pluginClass}'!"));
|
||||
$this->maniaControl->chat->sendSuccess($pluginClass::getName() . ' deactivated!', $player);
|
||||
$this->maniaControl->log("{$player->login} deactivated '{$pluginClass}'!", true);
|
||||
} else {
|
||||
$this->maniaControl->chat->sendError('Error deactivating ' . $pluginClass::getName() . '!', $player->login);
|
||||
$this->maniaControl->chat->sendError('Error deactivating ' . $pluginClass::getName() . '!', $player);
|
||||
}
|
||||
} else if ($settings) { //Open Settings Menu
|
||||
} else if ($settings) {
|
||||
// Open Settings Menu
|
||||
$pluginClass = substr($actionId, strlen(self::ACTION_PREFIX_SETTINGS));
|
||||
$this->settingsClass = $pluginClass;
|
||||
} else if ($boolSetting) {
|
||||
|
||||
$actionArray = explode(".", $actionId);
|
||||
$setting = $actionArray[1];
|
||||
|
||||
@ -415,38 +414,32 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
|
||||
$this->saveConfigData($callback[1], $player);
|
||||
}
|
||||
|
||||
//Reopen the Menu
|
||||
|
||||
// Reopen the Menu
|
||||
$menuId = $this->maniaControl->configurator->getMenuId($this->getTitle());
|
||||
|
||||
$this->maniaControl->configurator->reopenMenu($player, $menuId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle a Boolean Value
|
||||
*
|
||||
* @param $setting
|
||||
* @param int $settingIndex
|
||||
* @param Player $player
|
||||
*/
|
||||
public function toggleBooleanSetting($setting, Player $player) {
|
||||
public function toggleBooleanSetting($settingIndex, Player $player) {
|
||||
if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_CHANGE_PLUGIN_SETTINGS)) {
|
||||
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
||||
return;
|
||||
}
|
||||
|
||||
$oldSetting = $this->maniaControl->settingManager->getSettingByIndex($setting);
|
||||
$oldSetting = $this->maniaControl->settingManager->getSettingByIndex($settingIndex);
|
||||
|
||||
if (!isset($oldSetting)) {
|
||||
var_dump('no setting ' . $setting);
|
||||
var_dump('no setting with index: ' . $settingIndex);
|
||||
return;
|
||||
}
|
||||
|
||||
//Toggle value
|
||||
if ($oldSetting->value == "1") {
|
||||
$this->maniaControl->settingManager->setSetting($oldSetting->class, $oldSetting->setting, "0");
|
||||
} else {
|
||||
$this->maniaControl->settingManager->setSetting($oldSetting->class, $oldSetting->setting, "1");
|
||||
}
|
||||
// Toggle value
|
||||
$this->maniaControl->settingManager->setSetting($oldSetting->class, $oldSetting->setting, !$oldSetting->value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user