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\Manialinks\ManialinkManager;
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Manialinks\SidebarMenuEntryRenderable;
use ManiaControl\Manialinks\SidebarMenuManager;
use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager;
@ -29,7 +30,7 @@ use ManiaControl\Settings\SettingManager;
* @copyright 2014-2017 ManiaControl Team
* @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;
/*
@ -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(SettingManager::CB_SETTING_CHANGED, $this, 'handleSettingChanged');
$this->maniaControl->getManialinkManager()->getSidebarMenuManager()->addMenuEntry(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_ADMIN_MENU, self::ADMIN_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();
}
/**
* Call here the function which updates the MenuIcon Manialink
*/
public function renderMenuIcon() {
$this->rebuildAndShowMenu();
}
}

View File

@ -3,7 +3,19 @@
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 {
public function reloadMenuIcon();
interface SidebarMenuEntryRenderable {
/**
* 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\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 {
use UsageInformationTrait;
@ -22,10 +29,16 @@ class SidebarMenuManager implements UsageInformationAble, CallbackListener {
/* @var $maniaControl ManiaControl */
private $maniaControl;
private $menuEntries = array();
private $yPositions = array();
private $menuEntries = 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->getSettingManager()->initSetting($this, self::SETTING_SIDEBAR_POSX, 156);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SIDEBAR_POSY_SHOOTMANIA, -37);
@ -56,6 +69,7 @@ class SidebarMenuManager implements UsageInformationAble, CallbackListener {
*
* @param string $id
* @return array|null
* @api
*/
public function getEntryPosition($id) {
$itemSize = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_ITEMSIZE);
@ -79,38 +93,66 @@ class SidebarMenuManager implements UsageInformationAble, CallbackListener {
return null;
}
/**
* Registers an Entry to the SidebarMenu
* Get the associated position with getEntryPosition($id)
*
* @param int $order
* @param string $id
* @param SidebarMenuEntryRenderable $render
* @param $order
* @param $id
* @return bool
* @api
*/
public function addMenuEntry($order, $id) {
public function addMenuEntry(SidebarMenuEntryRenderable $render, $order, $id) {
if (isset($this->menuEntries[$order])) {
if ($this->menuEntries[$order] != $id) {
$this->addMenuEntry($order + 1, $id);
return $this->addMenuEntry($render, $order + 1, $id);
}
}
$this->menuEntries[$order] = $id;
$this->yPositions = array();
ksort($this->menuEntries);
$this->yPositions = array();
$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 string $id
* @param \ManiaControl\Manialinks\SidebarMenuEntryRenderable $render
* @param $id
* @param bool $unregisterClass
* @api
*/
public function deleteMenuEntry($id) {
public function deleteMenuEntry(SidebarMenuEntryRenderable $render, $id, $unregisterClass = false) {
foreach ($this->menuEntries as $k => $entry) {
if ($entry == $id) {
array_splice($this->menuEntries, $k, 1);
$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) {
/** @var \MCTeam\KarmaPlugin $karmaPlugin */
$karmaPlugin = $this->maniaControl->getPluginManager()->getPlugin(MapList::DEFAULT_KARMA_PLUGIN);
$displayMxKarma = $this->maniaControl->getSettingManager()->getSettingValue($karmaPlugin, $karmaPlugin::SETTING_WIDGET_DISPLAY_MX);
if ($karmaPlugin) {
$displayMxKarma = $this->maniaControl->getSettingManager()->getSettingValue($karmaPlugin, $karmaPlugin::SETTING_WIDGET_DISPLAY_MX);
//Sort by Mx Karma in Maplist
if ($displayMxKarma) { //TODO