plugin reopened

This commit is contained in:
kremsy 2014-01-05 20:42:16 +01:00
parent 8294ff5922
commit a9ed2ad878
2 changed files with 59 additions and 63 deletions

View File

@ -76,8 +76,6 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
// Register for callbacks // Register for callbacks
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect');
//$this->maniaControl->callbackManager->registerCallbackListener(ScriptSettings::CB_SCRIPTSETTINGS_CHANGED, $this, 'reopenMenu');
//$this->maniaControl->callbackManager->registerCallbackListener(ServerSettings::CB_SERVERSETTINGS_CHANGED, $this, 'reopenMenu');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
// Create server settings // Create server settings

View File

@ -2,21 +2,21 @@
namespace ManiaControl\Plugins; namespace ManiaControl\Plugins;
use FML\Script\Script; use FML\Controls\Control;
use ManiaControl\ManiaControl;
use ManiaControl\Players\Player;
use ManiaControl\Configurators\ConfiguratorMenu;
use FML\Script\Pages;
use FML\Script\Tooltips;
use FML\Controls\Frame; use FML\Controls\Frame;
use FML\Controls\Label; use FML\Controls\Label;
use FML\Controls\Labels\Label_Text;
use FML\Controls\Control;
use FML\Controls\Quads\Quad_Icons64x64_1;
use FML\Controls\Labels\Label_Button; use FML\Controls\Labels\Label_Button;
use ManiaControl\Callbacks\CallbackManager; use FML\Controls\Labels\Label_Text;
use FML\Controls\Quads\Quad_Icons64x64_1;
use FML\Script\Pages;
use FML\Script\Script;
use FML\Script\Tooltips;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Configurators\ConfiguratorMenu;
use ManiaControl\Formatter; use ManiaControl\Formatter;
use ManiaControl\ManiaControl;
use ManiaControl\Players\Player;
/** /**
* Configurator for enabling and disabling plugins * Configurator for enabling and disabling plugins
@ -27,9 +27,9 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu {
/** /**
* Constants * Constants
*/ */
const ACTION_PREFIX_ENABLEPLUGIN = 'PluginMenu.Enable.'; const ACTION_PREFIX_ENABLEPLUGIN = 'PluginMenu.Enable.';
const ACTION_PREFIX_DISABLEPLUGIN = 'PluginMenu.Disable.'; const ACTION_PREFIX_DISABLEPLUGIN = 'PluginMenu.Disable.';
/** /**
* Private properties * Private properties
*/ */
@ -42,9 +42,8 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu {
*/ */
public function __construct(ManiaControl $maniaControl) { public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
'handleManialinkPageAnswer');
} }
/** /**
@ -61,73 +60,72 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu {
*/ */
public function getMenu($width, $height, Script $script) { public function getMenu($width, $height, Script $script) {
$pagesId = 'PluginPages'; $pagesId = 'PluginPages';
$frame = new Frame(); $frame = new Frame();
$pluginClasses = $this->maniaControl->pluginManager->getPluginClasses(); $pluginClasses = $this->maniaControl->pluginManager->getPluginClasses();
// Config // Config
$pagerSize = 9.; $pagerSize = 9.;
$entryHeight = 5.; $entryHeight = 5.;
$labelTextSize = 2; $labelTextSize = 2;
$pageMaxCount = 10; $pageMaxCount = 10;
// Pagers // Pagers
$pagerPrev = new Quad_Icons64x64_1(); $pagerPrev = new Quad_Icons64x64_1();
$frame->add($pagerPrev); $frame->add($pagerPrev);
$pagerPrev->setPosition($width * 0.39, $height * -0.44, 2); $pagerPrev->setPosition($width * 0.39, $height * -0.44, 2);
$pagerPrev->setSize($pagerSize, $pagerSize); $pagerPrev->setSize($pagerSize, $pagerSize);
$pagerPrev->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowPrev); $pagerPrev->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowPrev);
$pagerNext = new Quad_Icons64x64_1(); $pagerNext = new Quad_Icons64x64_1();
$frame->add($pagerNext); $frame->add($pagerNext);
$pagerNext->setPosition($width * 0.45, $height * -0.44, 2); $pagerNext->setPosition($width * 0.45, $height * -0.44, 2);
$pagerNext->setSize($pagerSize, $pagerSize); $pagerNext->setSize($pagerSize, $pagerSize);
$pagerNext->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowNext); $pagerNext->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowNext);
$script->addPager($pagerPrev, -1, $pagesId); $script->addPager($pagerPrev, -1, $pagesId);
$script->addPager($pagerNext, 1, $pagesId); $script->addPager($pagerNext, 1, $pagesId);
$pageCountLabel = new Label_Text(); $pageCountLabel = new Label_Text();
$frame->add($pageCountLabel); $frame->add($pageCountLabel);
$pageCountLabel->setHAlign(Control::RIGHT); $pageCountLabel->setHAlign(Control::RIGHT);
$pageCountLabel->setPosition($width * 0.35, $height * -0.44, 1); $pageCountLabel->setPosition($width * 0.35, $height * -0.44, 1);
$pageCountLabel->setStyle($pageCountLabel::STYLE_TextTitle1); $pageCountLabel->setStyle($pageCountLabel::STYLE_TextTitle1);
$pageCountLabel->setTextSize(2); $pageCountLabel->setTextSize(2);
$script->addPageLabel($pageCountLabel, $pagesId); $script->addPageLabel($pageCountLabel, $pagesId);
// Plugin pages // Plugin pages
$pageFrames = array(); $pageFrames = array();
$y = 0.; $y = 0.;
foreach ($pluginClasses as $index => $pluginClass) { foreach($pluginClasses as $index => $pluginClass) {
if (!isset($pageFrame)) { if(!isset($pageFrame)) {
$pageFrame = new Frame(); $pageFrame = new Frame();
$frame->add($pageFrame); $frame->add($pageFrame);
if (!empty($pageFrames)) { if(!empty($pageFrames)) {
$pageFrame->setVisible(false); $pageFrame->setVisible(false);
} }
array_push($pageFrames, $pageFrame); array_push($pageFrames, $pageFrame);
$script->addPage($pageFrame, count($pageFrames), $pagesId); $script->addPage($pageFrame, count($pageFrames), $pagesId);
$y = $height * 0.41; $y = $height * 0.41;
} }
$active = $this->maniaControl->pluginManager->isPluginActive($pluginClass); $active = $this->maniaControl->pluginManager->isPluginActive($pluginClass);
$pluginFrame = new Frame(); $pluginFrame = new Frame();
$pageFrame->add($pluginFrame); $pageFrame->add($pluginFrame);
$pluginFrame->setY($y); $pluginFrame->setY($y);
$activeQuad = new Quad_Icons64x64_1(); $activeQuad = new Quad_Icons64x64_1();
$pluginFrame->add($activeQuad); $pluginFrame->add($activeQuad);
$activeQuad->setPosition($width * -0.45, -0.1, 1); $activeQuad->setPosition($width * -0.45, -0.1, 1);
$activeQuad->setSize($entryHeight * 0.9, $entryHeight * 0.9); $activeQuad->setSize($entryHeight * 0.9, $entryHeight * 0.9);
if ($active) { if($active) {
$activeQuad->setSubStyle($activeQuad::SUBSTYLE_LvlGreen); $activeQuad->setSubStyle($activeQuad::SUBSTYLE_LvlGreen);
} } else {
else {
$activeQuad->setSubStyle($activeQuad::SUBSTYLE_LvlRed); $activeQuad->setSubStyle($activeQuad::SUBSTYLE_LvlRed);
} }
$nameLabel = new Label_Text(); $nameLabel = new Label_Text();
$pluginFrame->add($nameLabel); $pluginFrame->add($nameLabel);
$nameLabel->setHAlign(Control::LEFT); $nameLabel->setHAlign(Control::LEFT);
@ -136,7 +134,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu {
$nameLabel->setStyle($nameLabel::STYLE_TextCardSmall); $nameLabel->setStyle($nameLabel::STYLE_TextCardSmall);
$nameLabel->setTextSize($labelTextSize); $nameLabel->setTextSize($labelTextSize);
$nameLabel->setText($pluginClass::getName()); $nameLabel->setText($pluginClass::getName());
$descriptionLabel = new Label(); $descriptionLabel = new Label();
$pageFrame->add($descriptionLabel); $pageFrame->add($descriptionLabel);
$descriptionLabel->setAlign(Control::LEFT, Control::TOP); $descriptionLabel->setAlign(Control::LEFT, Control::TOP);
@ -150,29 +148,28 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu {
$description = "Author: {$pluginClass::getAuthor()}\nVersion: {$pluginClass::getVersion()}\nDesc: {$pluginClass::getDescription()}"; $description = "Author: {$pluginClass::getAuthor()}\nVersion: {$pluginClass::getVersion()}\nDesc: {$pluginClass::getDescription()}";
$descriptionLabel->setText($description); $descriptionLabel->setText($description);
$script->addTooltip($nameLabel, $descriptionLabel); $script->addTooltip($nameLabel, $descriptionLabel);
$statusChangeButton = new Label_Button(); $statusChangeButton = new Label_Button();
$pluginFrame->add($statusChangeButton); $pluginFrame->add($statusChangeButton);
$statusChangeButton->setHAlign(Control::RIGHT); $statusChangeButton->setHAlign(Control::RIGHT);
$statusChangeButton->setX($width * 0.45); $statusChangeButton->setX($width * 0.45);
$statusChangeButton->setStyle($statusChangeButton::STYLE_CardButtonSmall); $statusChangeButton->setStyle($statusChangeButton::STYLE_CardButtonSmall);
if ($active) { if($active) {
$statusChangeButton->setTextPrefix('$f00'); $statusChangeButton->setTextPrefix('$f00');
$statusChangeButton->setText('Deactivate'); $statusChangeButton->setText('Deactivate');
$statusChangeButton->setAction(self::ACTION_PREFIX_DISABLEPLUGIN . $pluginClass); $statusChangeButton->setAction(self::ACTION_PREFIX_DISABLEPLUGIN . $pluginClass);
} } else {
else {
$statusChangeButton->setTextPrefix('a'); $statusChangeButton->setTextPrefix('a');
$statusChangeButton->setText('Activate'); $statusChangeButton->setText('Activate');
$statusChangeButton->setAction(self::ACTION_PREFIX_ENABLEPLUGIN . $pluginClass); $statusChangeButton->setAction(self::ACTION_PREFIX_ENABLEPLUGIN . $pluginClass);
} }
$y -= $entryHeight; $y -= $entryHeight;
if ($index % $pageMaxCount == $pageMaxCount - 1) { if($index % $pageMaxCount == $pageMaxCount - 1) {
unset($pageFrame); unset($pageFrame);
} }
} }
return $frame; return $frame;
} }
@ -190,39 +187,40 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu {
*/ */
public function handleManialinkPageAnswer(array $callback) { public function handleManialinkPageAnswer(array $callback) {
$actionId = $callback[1][2]; $actionId = $callback[1][2];
$enable = (strpos($actionId, self::ACTION_PREFIX_ENABLEPLUGIN) === 0); $enable = (strpos($actionId, self::ACTION_PREFIX_ENABLEPLUGIN) === 0);
$disable = (strpos($actionId, self::ACTION_PREFIX_DISABLEPLUGIN) === 0); $disable = (strpos($actionId, self::ACTION_PREFIX_DISABLEPLUGIN) === 0);
if (!$enable && !$disable) { if(!$enable && !$disable) {
return; 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;
} }
if ($enable) { if($enable) {
$pluginClass = substr($actionId, strlen(self::ACTION_PREFIX_ENABLEPLUGIN)); $pluginClass = substr($actionId, strlen(self::ACTION_PREFIX_ENABLEPLUGIN));
$activated = $this->maniaControl->pluginManager->activatePlugin($pluginClass); $activated = $this->maniaControl->pluginManager->activatePlugin($pluginClass);
if ($activated) { if($activated) {
$this->maniaControl->chat->sendSuccess($pluginClass::getName() . ' activated!', $player->login); $this->maniaControl->chat->sendSuccess($pluginClass::getName() . ' activated!', $player->login);
$this->maniaControl->configurator->showMenu($player); $this->maniaControl->configurator->showMenu($player);
$this->maniaControl->log(Formatter::stripCodes("{$player->login} activated '{$pluginClass}'!")); $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->login);
} }
} } else {
else {
$pluginClass = substr($actionId, strlen(self::ACTION_PREFIX_DISABLEPLUGIN)); $pluginClass = substr($actionId, strlen(self::ACTION_PREFIX_DISABLEPLUGIN));
$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->login);
$this->maniaControl->configurator->showMenu($player); $this->maniaControl->configurator->showMenu($player);
$this->maniaControl->log(Formatter::stripCodes("{$player->login} deactivated '{$pluginClass}'!")); $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->login);
} }
} }
//Reopen the Menu
$menuId = $this->maniaControl->configurator->getMenuId($this->getTitle());
$this->maniaControl->configurator->reopenMenu($menuId);
} }
} }