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