Added Interface for SidebarMenuManager, improved its functionality

This commit is contained in:
Jocy 2017-05-11 22:35:16 +02:00
parent f1ce8d8004
commit 9f701cddea
6 changed files with 100 additions and 23 deletions

View File

@ -15,6 +15,7 @@ use ManiaControl\General\UsageInformationTrait;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkManager; use ManiaControl\Manialinks\ManialinkManager;
use ManiaControl\Manialinks\ManialinkPageAnswerListener; use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Manialinks\SidebarMenuEntryRenderable;
use ManiaControl\Manialinks\SidebarMenuManager; use ManiaControl\Manialinks\SidebarMenuManager;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager; use ManiaControl\Players\PlayerManager;
@ -29,7 +30,7 @@ use ManiaControl\Settings\SettingManager;
* @copyright 2014-2017 ManiaControl Team * @copyright 2014-2017 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/ */
class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener, UsageInformationAble { class ActionsMenu implements SidebarMenuEntryRenderable, CallbackListener, ManialinkPageAnswerListener, UsageInformationAble {
use UsageInformationTrait; use UsageInformationTrait;
/* /*
@ -74,8 +75,8 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener, Usag
$this->maniaControl->getCallbackManager()->registerCallbackListener(AuthenticationManager::CB_AUTH_LEVEL_CHANGED, $this, 'handlePlayerJoined'); $this->maniaControl->getCallbackManager()->registerCallbackListener(AuthenticationManager::CB_AUTH_LEVEL_CHANGED, $this, 'handlePlayerJoined');
$this->maniaControl->getCallbackManager()->registerCallbackListener(SettingManager::CB_SETTING_CHANGED, $this, 'handleSettingChanged'); $this->maniaControl->getCallbackManager()->registerCallbackListener(SettingManager::CB_SETTING_CHANGED, $this, 'handleSettingChanged');
$this->maniaControl->getManialinkManager()->getSidebarMenuManager()->addMenuEntry(SidebarMenuManager::ORDER_ADMIN_MENU, self::ADMIN_MENU_ID); $this->maniaControl->getManialinkManager()->getSidebarMenuManager()->addMenuEntry($this,SidebarMenuManager::ORDER_ADMIN_MENU, self::ADMIN_MENU_ID);
$this->maniaControl->getManialinkManager()->getSidebarMenuManager()->addMenuEntry(SidebarMenuManager::ORDER_PLAYER_MENU, self::PLAYER_MENU_ID); $this->maniaControl->getManialinkManager()->getSidebarMenuManager()->addMenuEntry($this,SidebarMenuManager::ORDER_PLAYER_MENU, self::PLAYER_MENU_ID);
} }
/** /**
@ -356,4 +357,11 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener, Usag
$this->rebuildAndShowMenu(); $this->rebuildAndShowMenu();
} }
/**
* Call here the function which updates the MenuIcon Manialink
*/
public function renderMenuIcon() {
$this->rebuildAndShowMenu();
}
} }

View File

@ -3,7 +3,19 @@
namespace ManiaControl\Manialinks; namespace ManiaControl\Manialinks;
/**
* Interface for the Sidebar managing
*
* @api
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014-2017 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
interface SidebarMenuEntryable { interface SidebarMenuEntryRenderable {
public function reloadMenuIcon();
/**
* Call here the function which updates the MenuIcon Manialink
*/
public function renderMenuIcon();
} }

View File

@ -7,7 +7,14 @@ use ManiaControl\General\UsageInformationAble;
use ManiaControl\General\UsageInformationTrait; use ManiaControl\General\UsageInformationTrait;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
/**
* Class managing the Sidebar icons
*
* @api
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014-2017 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class SidebarMenuManager implements UsageInformationAble, CallbackListener { class SidebarMenuManager implements UsageInformationAble, CallbackListener {
use UsageInformationTrait; use UsageInformationTrait;
@ -24,8 +31,14 @@ class SidebarMenuManager implements UsageInformationAble, CallbackListener {
private $maniaControl; private $maniaControl;
private $menuEntries = array(); private $menuEntries = array();
private $yPositions = array(); private $yPositions = array();
private $registeredClasses = array();
function __construct(ManiaControl $maniaControl) { /**
* SidebarMenuManager constructor.
*
* @param \ManiaControl\ManiaControl $maniaControl
*/
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SIDEBAR_POSX, 156); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SIDEBAR_POSX, 156);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SIDEBAR_POSY_SHOOTMANIA, -37); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SIDEBAR_POSY_SHOOTMANIA, -37);
@ -56,6 +69,7 @@ class SidebarMenuManager implements UsageInformationAble, CallbackListener {
* *
* @param string $id * @param string $id
* @return array|null * @return array|null
* @api
*/ */
public function getEntryPosition($id) { public function getEntryPosition($id) {
$itemSize = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_ITEMSIZE); $itemSize = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_ITEMSIZE);
@ -79,38 +93,66 @@ class SidebarMenuManager implements UsageInformationAble, CallbackListener {
return null; return null;
} }
/** /**
* Registers an Entry to the SidebarMenu * Registers an Entry to the SidebarMenu
* Get the associated position with getEntryPosition($id) * Get the associated position with getEntryPosition($id)
* *
* @param int $order * @param SidebarMenuEntryRenderable $render
* @param string $id * @param $order
* @param $id
* @return bool
* @api * @api
*/ */
public function addMenuEntry($order, $id) { public function addMenuEntry(SidebarMenuEntryRenderable $render, $order, $id) {
if (isset($this->menuEntries[$order])) { if (isset($this->menuEntries[$order])) {
if ($this->menuEntries[$order] != $id) { if ($this->menuEntries[$order] != $id) {
$this->addMenuEntry($order + 1, $id); return $this->addMenuEntry($render, $order + 1, $id);
} }
} }
$this->menuEntries[$order] = $id; $this->menuEntries[$order] = $id;
ksort($this->menuEntries);
$this->yPositions = array(); $this->yPositions = array();
ksort($this->menuEntries);
$registered = false;
foreach ($this->registeredClasses as $class) {
$class->renderMenuIcon();
if ($class == $render) {
$registered = true;
}
}
if (!$registered) {
array_push($this->registeredClasses, $render);
$render->renderMenuIcon();
}
return true;
} }
/** /**
* Deletes an Entry from the SidebarMenu * @param \ManiaControl\Manialinks\SidebarMenuEntryRenderable $render
* * @param $id
* @param string $id * @param bool $unregisterClass
* @api
*/ */
public function deleteMenuEntry($id) { public function deleteMenuEntry(SidebarMenuEntryRenderable $render, $id, $unregisterClass = false) {
foreach ($this->menuEntries as $k => $entry) { foreach ($this->menuEntries as $k => $entry) {
if ($entry == $id) { if ($entry == $id) {
array_splice($this->menuEntries, $k, 1); array_splice($this->menuEntries, $k, 1);
$this->yPositions = array(); $this->yPositions = array();
} }
} }
if($unregisterClass){
foreach($this->registeredClasses as $k => $class){
if($class == $render){
array_splice($this->registeredClasses, $k, 1);
}
}
}
} }
} }

View File

@ -428,9 +428,9 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
private function showMapListKarma($best, Player $player) { private function showMapListKarma($best, Player $player) {
/** @var \MCTeam\KarmaPlugin $karmaPlugin */ /** @var \MCTeam\KarmaPlugin $karmaPlugin */
$karmaPlugin = $this->maniaControl->getPluginManager()->getPlugin(MapList::DEFAULT_KARMA_PLUGIN); $karmaPlugin = $this->maniaControl->getPluginManager()->getPlugin(MapList::DEFAULT_KARMA_PLUGIN);
$displayMxKarma = $this->maniaControl->getSettingManager()->getSettingValue($karmaPlugin, $karmaPlugin::SETTING_WIDGET_DISPLAY_MX);
if ($karmaPlugin) { if ($karmaPlugin) {
$displayMxKarma = $this->maniaControl->getSettingManager()->getSettingValue($karmaPlugin, $karmaPlugin::SETTING_WIDGET_DISPLAY_MX);
//Sort by Mx Karma in Maplist //Sort by Mx Karma in Maplist
if ($displayMxKarma) { //TODO if ($displayMxKarma) { //TODO

View File

@ -24,6 +24,7 @@ use ManiaControl\Commands\CommandListener;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkManager; use ManiaControl\Manialinks\ManialinkManager;
use ManiaControl\Manialinks\ManialinkPageAnswerListener; use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Manialinks\SidebarMenuEntryRenderable;
use ManiaControl\Manialinks\SidebarMenuManager; use ManiaControl\Manialinks\SidebarMenuManager;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager; use ManiaControl\Players\PlayerManager;
@ -46,7 +47,7 @@ use Maniaplanet\DedicatedServer\Xmlrpc\GameModeException;
* @copyright 2014-2017 ManiaControl Team * @copyright 2014-2017 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/ */
class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkPageAnswerListener, TimerListener, Plugin { class CustomVotesPlugin implements SidebarMenuEntryRenderable, CommandListener, CallbackListener, ManialinkPageAnswerListener, TimerListener, Plugin {
/* /*
* Constants * Constants
*/ */
@ -161,7 +162,7 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SPECTATOR_ALLOW_START_VOTE, true); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SPECTATOR_ALLOW_START_VOTE, true);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_VOTE_TIME, 40); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_VOTE_TIME, 40);
$this->maniaControl->getManialinkManager()->getSidebarMenuManager()->addMenuEntry(SidebarMenuManager::ORDER_PLAYER_MENU + 5, self::CUSTOMVOTES_MENU_ID); $this->maniaControl->getManialinkManager()->getSidebarMenuManager()->addMenuEntry($this,SidebarMenuManager::ORDER_PLAYER_MENU + 5, self::CUSTOMVOTES_MENU_ID);
//Define Votes //Define Votes
$this->defineVote("teambalance", "Vote for Team Balance"); $this->defineVote("teambalance", "Vote for Team Balance");
@ -371,6 +372,7 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
$this->destroyVote(); $this->destroyVote();
$this->maniaControl->getManialinkManager()->hideManialink(self::MLID_ICON); $this->maniaControl->getManialinkManager()->hideManialink(self::MLID_ICON);
$this->maniaControl->getManialinkManager()->getSidebarMenuManager()->deleteMenuEntry($this,self::CUSTOMVOTES_MENU_ID,true);
} }
/** /**
@ -796,6 +798,13 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
$this->constructMenu(); $this->constructMenu();
} }
/**
* Call here the function which updates the MenuIcon Manialink
*/
public function renderMenuIcon() {
$this->showIcon();
}
} }
/** /**

View File

@ -19,6 +19,7 @@ use ManiaControl\Commands\CommandListener;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\LabelLine; use ManiaControl\Manialinks\LabelLine;
use ManiaControl\Manialinks\ManialinkManager; use ManiaControl\Manialinks\ManialinkManager;
use ManiaControl\Manialinks\SidebarMenuEntryRenderable;
use ManiaControl\Manialinks\SidebarMenuManager; use ManiaControl\Manialinks\SidebarMenuManager;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager; use ManiaControl\Players\PlayerManager;
@ -31,7 +32,7 @@ use ManiaControl\Plugins\Plugin;
* @copyright 2014-2017 ManiaControl Team * @copyright 2014-2017 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/ */
class DonationPlugin implements CallbackListener, CommandListener, Plugin { class DonationPlugin implements CallbackListener, CommandListener, Plugin, SidebarMenuEntryRenderable {
/* /*
* Constants * Constants
*/ */
@ -116,7 +117,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
// Define player stats // Define player stats
$this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_PLAYER_DONATIONS); $this->maniaControl->getStatisticManager()->defineStatMetaData(self::STAT_PLAYER_DONATIONS);
$this->maniaControl->getManialinkManager()->getSidebarMenuManager()->addMenuEntry(SidebarMenuManager::ORDER_PLAYER_MENU + 10, self::DONATIONPLUGIN_MENU_ID); $this->maniaControl->getManialinkManager()->getSidebarMenuManager()->addMenuEntry($this,SidebarMenuManager::ORDER_PLAYER_MENU, self::DONATIONPLUGIN_MENU_ID);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_DONATE_WIDGET_ACTIVATED, true); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_DONATE_WIDGET_ACTIVATED, true);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_DONATION_VALUES, "20,50,100,500,1000,2000"); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_DONATION_VALUES, "20,50,100,500,1000,2000");
@ -233,6 +234,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
*/ */
public function unload() { public function unload() {
$this->maniaControl->getManialinkManager()->hideManialink(self::MLID_DONATE_WIDGET); $this->maniaControl->getManialinkManager()->hideManialink(self::MLID_DONATE_WIDGET);
$this->maniaControl->getManialinkManager()->getSidebarMenuManager()->deleteMenuEntry($this,self::DONATIONPLUGIN_MENU_ID,true);
} }
/** /**
@ -529,4 +531,8 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
// Render and display xml // Render and display xml
$this->maniaControl->getManialinkManager()->displayWidget($maniaLink, $player, 'TopDons'); $this->maniaControl->getManialinkManager()->displayWidget($maniaLink, $player, 'TopDons');
} }
public function renderMenuIcon() {
$this->displayDonateWidget();
}
} }