This commit is contained in:
Steffen Schröder 2014-04-27 18:59:21 +02:00
parent 7145cd267b
commit c0e2ed7370
9 changed files with 270 additions and 254 deletions

View File

@ -27,13 +27,13 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
/* /*
* Constants * Constants
*/ */
const MLID_MENU = 'ActionsMenu.MLID'; const MLID_MENU = 'ActionsMenu.MLID';
const SETTING_MENU_POSX = 'Menu Position: X'; const SETTING_MENU_POSX = 'Menu Position: X';
const SETTING_MENU_POSY = 'Menu Position: Y'; const SETTING_MENU_POSY = 'Menu Position: Y';
const SETTING_MENU_ITEMSIZE = 'Menu Item Size'; const SETTING_MENU_ITEMSIZE = 'Menu Item Size';
const ACTION_OPEN_ADMIN_MENU = 'ActionsMenu.OpenAdminMenu'; const ACTION_OPEN_ADMIN_MENU = 'ActionsMenu.OpenAdminMenu';
const ACTION_OPEN_PLAYER_MENU = 'ActionsMenu.OpenPlayerMenu'; const ACTION_OPEN_PLAYER_MENU = 'ActionsMenu.OpenPlayerMenu';
/* /*
* Private Properties * Private Properties
*/ */
@ -49,12 +49,12 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
*/ */
public function __construct(ManiaControl $maniaControl) { public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// Init settings // Init settings
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_POSX, 156.); $this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_POSX, 156.);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_POSY, -17.); $this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_POSY, -17.);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_ITEMSIZE, 6.); $this->maniaControl->settingManager->initSetting($this, self::SETTING_MENU_ITEMSIZE, 6.);
// Register for callbacks // Register for callbacks
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_AFTERINIT, $this, 'handleAfterInit'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_AFTERINIT, $this, 'handleAfterInit');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerJoined'); $this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerJoined');
@ -65,14 +65,15 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
* Add a new Menu Item * Add a new Menu Item
* *
* @param Control $control * @param Control $control
* @param bool $playerAction * @param bool $playerAction
* @param int $order * @param int $order
* @param string $description * @param string $description
*/ */
public function addMenuItem(Control $control, $playerAction = true, $order = 0, $description = null) { public function addMenuItem(Control $control, $playerAction = true, $order = 0, $description = null) {
if($playerAction) { if ($playerAction) {
$this->addPlayerMenuItem($control, $order, $description); $this->addPlayerMenuItem($control, $order, $description);
} else { }
else {
$this->addAdminMenuItem($control, $order, $description); $this->addAdminMenuItem($control, $order, $description);
} }
} }
@ -80,13 +81,14 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
/** /**
* Removes a Menu Item * Removes a Menu Item
* *
* @param $order * @param $order
* @param bool $playerAction * @param bool $playerAction
*/ */
public function removeMenuItem($order, $playerAction = true) { public function removeMenuItem($order, $playerAction = true) {
if($playerAction) { if ($playerAction) {
unset($this->playerMenuItems[$order]); unset($this->playerMenuItems[$order]);
} else { }
else {
unset($this->adminMenuItems[$order]); unset($this->adminMenuItems[$order]);
} }
$this->rebuildAndShowMenu(); $this->rebuildAndShowMenu();
@ -96,11 +98,11 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
* Add a new Player Menu Item * Add a new Player Menu Item
* *
* @param Control $control * @param Control $control
* @param int $order * @param int $order
* @param string $description * @param string $description
*/ */
public function addPlayerMenuItem(Control $control, $order = 0, $description = null) { public function addPlayerMenuItem(Control $control, $order = 0, $description = null) {
if(!isset($this->playerMenuItems[$order])) { if (!isset($this->playerMenuItems[$order])) {
$this->playerMenuItems[$order] = array(); $this->playerMenuItems[$order] = array();
} }
array_push($this->playerMenuItems[$order], array($control, $description)); array_push($this->playerMenuItems[$order], array($control, $description));
@ -112,11 +114,11 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
* Add a new Admin Menu Item * Add a new Admin Menu Item
* *
* @param Control $control * @param Control $control
* @param int $order * @param int $order
* @param string $description * @param string $description
*/ */
public function addAdminMenuItem(Control $control, $order = 0, $description = null) { public function addAdminMenuItem(Control $control, $order = 0, $description = null) {
if(!isset($this->adminMenuItems[$order])) { if (!isset($this->adminMenuItems[$order])) {
$this->adminMenuItems[$order] = array(); $this->adminMenuItems[$order] = array();
} }
array_push($this->adminMenuItems[$order], array($control, $description)); array_push($this->adminMenuItems[$order], array($control, $description));
@ -136,12 +138,12 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
* Build and show the menus to everyone (if a menu get made after the init) * Build and show the menus to everyone (if a menu get made after the init)
*/ */
public function rebuildAndShowMenu() { public function rebuildAndShowMenu() {
if(!$this->initCompleted) { if (!$this->initCompleted) {
return; return;
} }
$players = $this->maniaControl->playerManager->getPlayers(); $players = $this->maniaControl->playerManager->getPlayers();
foreach($players as $player) { foreach ($players as $player) {
$manialink = $this->buildMenuIconsManialink($player); $manialink = $this->buildMenuIconsManialink($player);
$this->maniaControl->manialinkManager->sendManialink($manialink, $player->login); $this->maniaControl->manialinkManager->sendManialink($manialink, $player->login);
} }
} }
@ -163,55 +165,54 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
* @return ManiaLink * @return ManiaLink
*/ */
private function buildMenuIconsManialink(Player $player) { private function buildMenuIconsManialink(Player $player) {
$posX = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSX); $posX = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSX);
$posY = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSY); $posY = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSY);
$itemSize = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_ITEMSIZE); $itemSize = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_ITEMSIZE);
$shootManiaOffset = $this->maniaControl->manialinkManager->styleManager->getDefaultIconOffsetSM(); $shootManiaOffset = $this->maniaControl->manialinkManager->styleManager->getDefaultIconOffsetSM();
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle(); $quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadStyle();
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle(); $quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultQuadSubstyle();
$itemMarginFactorX = 1.3; $itemMarginFactorX = 1.3;
$itemMarginFactorY = 1.2; $itemMarginFactorY = 1.2;
//If game is shootmania lower the icons position by 20 // If game is shootmania lower the icons position by 20
if ($this->maniaControl->mapManager->getCurrentMap()->getGame() == 'sm') { if ($this->maniaControl->mapManager->getCurrentMap()->getGame() == 'sm') {
$posY -= $shootManiaOffset; $posY -= $shootManiaOffset;
} }
$manialink = new ManiaLink(self::MLID_MENU); $manialink = new ManiaLink(self::MLID_MENU);
$script = new Script(); $script = $manialink->getScript();
$manialink->setScript($script);
/* /*
* Admin Menu * Admin Menu
*/ */
if($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) { if ($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
// Admin Menu Icon Frame // Admin Menu Icon Frame
$iconFrame = new Frame(); $iconFrame = new Frame();
$manialink->add($iconFrame); $manialink->add($iconFrame);
$iconFrame->setPosition($posX, $posY); $iconFrame->setPosition($posX, $posY);
$backgroundQuad = new Quad(); $backgroundQuad = new Quad();
$iconFrame->add($backgroundQuad); $iconFrame->add($backgroundQuad);
$backgroundQuad->setSize($itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY); $backgroundQuad->setSize($itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY);
$backgroundQuad->setStyles($quadStyle, $quadSubstyle); $backgroundQuad->setStyles($quadStyle, $quadSubstyle);
$itemQuad = new Quad_Icons64x64_1(); $itemQuad = new Quad_Icons64x64_1();
$iconFrame->add($itemQuad); $iconFrame->add($itemQuad);
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_IconServers); $itemQuad->setSubStyle($itemQuad::SUBSTYLE_IconServers);
$itemQuad->setSize($itemSize, $itemSize); $itemQuad->setSize($itemSize, $itemSize);
// Admin Menu Description Label // Admin Menu Description Label
$descriptionFrame = new Frame(); $descriptionFrame = new Frame();
$manialink->add($descriptionFrame); $manialink->add($descriptionFrame);
$descriptionFrame->setPosition($posX - count($this->adminMenuItems) * $itemSize * 1.15 - 6, $posY); $descriptionFrame->setPosition($posX - count($this->adminMenuItems) * $itemSize * 1.15 - 6, $posY);
$descriptionLabel = new Label(); $descriptionLabel = new Label();
$descriptionFrame->add($descriptionLabel); $descriptionFrame->add($descriptionLabel);
$descriptionLabel->setAlign(Control::RIGHT, Control::TOP); $descriptionLabel->setAlign(Control::RIGHT, Control::TOP);
$descriptionLabel->setSize(40, 4); $descriptionLabel->setSize(40, 4);
$descriptionLabel->setTextSize(1.4); $descriptionLabel->setTextSize(1.4);
$descriptionLabel->setTextColor('fff'); $descriptionLabel->setTextColor('fff');
// Admin Menu // Admin Menu
$popoutFrame = new Frame(); $popoutFrame = new Frame();
$manialink->add($popoutFrame); $manialink->add($popoutFrame);
@ -219,38 +220,35 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
$popoutFrame->setHAlign(Control::RIGHT); $popoutFrame->setHAlign(Control::RIGHT);
$popoutFrame->setSize(4 * $itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY); $popoutFrame->setSize(4 * $itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY);
$popoutFrame->setVisible(false); $popoutFrame->setVisible(false);
$backgroundQuad = new Quad(); $backgroundQuad = new Quad();
$popoutFrame->add($backgroundQuad); $popoutFrame->add($backgroundQuad);
$backgroundQuad->setHAlign(Control::RIGHT); $backgroundQuad->setHAlign(Control::RIGHT);
$backgroundQuad->setStyles($quadStyle, $quadSubstyle); $backgroundQuad->setStyles($quadStyle, $quadSubstyle);
$backgroundQuad->setSize(count($this->adminMenuItems) * $itemSize * 1.15 + 2, $itemSize * $itemMarginFactorY); $backgroundQuad->setSize(count($this->adminMenuItems) * $itemSize * 1.15 + 2, $itemSize * $itemMarginFactorY);
$itemQuad->addToggleFeature($popoutFrame); $itemQuad->addToggleFeature($popoutFrame);
// Add items // Add items
$x = -1; $x = -1;
foreach($this->adminMenuItems as $menuItems) { foreach ($this->adminMenuItems as $menuItems) {
foreach($menuItems as $menuItem) { foreach ($menuItems as $menuItem) {
$menuQuad = $menuItem[0]; $menuQuad = $menuItem[0];
/** /** @var Quad $menuQuad */
*
* @var Quad $menuQuad
*/
$popoutFrame->add($menuQuad); $popoutFrame->add($menuQuad);
$menuQuad->setSize($itemSize, $itemSize); $menuQuad->setSize($itemSize, $itemSize);
$menuQuad->setX($x); $menuQuad->setX($x);
$menuQuad->setHAlign(Control::RIGHT); $menuQuad->setHAlign(Control::RIGHT);
$x -= $itemSize * 1.05; $x -= $itemSize * 1.05;
if($menuItem[1]) { if ($menuItem[1]) {
$description = '$s' . $menuItem[1]; $description = '$s' . $menuItem[1];
$menuQuad->addTooltipLabelFeature($descriptionLabel, $description); $menuQuad->addTooltipLabelFeature($descriptionLabel, $description);
} }
} }
} }
} }
/* /*
* Player Menu * Player Menu
*/ */
@ -258,29 +256,29 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
$iconFrame = new Frame(); $iconFrame = new Frame();
$manialink->add($iconFrame); $manialink->add($iconFrame);
$iconFrame->setPosition($posX, $posY - $itemSize * $itemMarginFactorY); $iconFrame->setPosition($posX, $posY - $itemSize * $itemMarginFactorY);
$backgroundQuad = new Quad(); $backgroundQuad = new Quad();
$iconFrame->add($backgroundQuad); $iconFrame->add($backgroundQuad);
$backgroundQuad->setSize($itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY); $backgroundQuad->setSize($itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY);
$backgroundQuad->setStyles($quadStyle, $quadSubstyle); $backgroundQuad->setStyles($quadStyle, $quadSubstyle);
$itemQuad = new Quad_Icons64x64_1(); $itemQuad = new Quad_Icons64x64_1();
$iconFrame->add($itemQuad); $iconFrame->add($itemQuad);
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_IconPlayers); $itemQuad->setSubStyle($itemQuad::SUBSTYLE_IconPlayers);
$itemQuad->setSize($itemSize, $itemSize); $itemQuad->setSize($itemSize, $itemSize);
// Player Menu Description Frame // Player Menu Description Frame
$descriptionFrame = new Frame(); $descriptionFrame = new Frame();
$manialink->add($descriptionFrame); $manialink->add($descriptionFrame);
$descriptionFrame->setPosition($posX - count($this->playerMenuItems) * $itemSize * 1.15 - 6, $posY - $itemSize * $itemMarginFactorY); $descriptionFrame->setPosition($posX - count($this->playerMenuItems) * $itemSize * 1.15 - 6, $posY - $itemSize * $itemMarginFactorY);
$descriptionLabel = new Label(); $descriptionLabel = new Label();
$descriptionFrame->add($descriptionLabel); $descriptionFrame->add($descriptionLabel);
$descriptionLabel->setAlign(Control::RIGHT, Control::TOP); $descriptionLabel->setAlign(Control::RIGHT, Control::TOP);
$descriptionLabel->setSize(40, 4); $descriptionLabel->setSize(40, 4);
$descriptionLabel->setTextSize(1.4); $descriptionLabel->setTextSize(1.4);
$descriptionLabel->setTextColor('fff'); $descriptionLabel->setTextColor('fff');
// Player Menu // Player Menu
$popoutFrame = new Frame(); $popoutFrame = new Frame();
$manialink->add($popoutFrame); $manialink->add($popoutFrame);
@ -288,36 +286,36 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
$popoutFrame->setHAlign(Control::RIGHT); $popoutFrame->setHAlign(Control::RIGHT);
$popoutFrame->setSize(4 * $itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY); $popoutFrame->setSize(4 * $itemSize * $itemMarginFactorX, $itemSize * $itemMarginFactorY);
$popoutFrame->setVisible(false); $popoutFrame->setVisible(false);
$backgroundQuad = new Quad(); $backgroundQuad = new Quad();
$popoutFrame->add($backgroundQuad); $popoutFrame->add($backgroundQuad);
$backgroundQuad->setHAlign(Control::RIGHT); $backgroundQuad->setHAlign(Control::RIGHT);
$backgroundQuad->setStyles($quadStyle, $quadSubstyle); $backgroundQuad->setStyles($quadStyle, $quadSubstyle);
$backgroundQuad->setSize(count($this->playerMenuItems) * $itemSize * 1.15 + 2, $itemSize * $itemMarginFactorY); $backgroundQuad->setSize(count($this->playerMenuItems) * $itemSize * 1.15 + 2, $itemSize * $itemMarginFactorY);
$itemQuad->addToggleFeature($popoutFrame);
$itemQuad->addToggleFeature($popoutFrame);
// Add items // Add items
$x = -1; $x = -1;
foreach($this->playerMenuItems as $menuItems) { foreach ($this->playerMenuItems as $menuItems) {
foreach($menuItems as $menuItem) { foreach ($menuItems as $menuItem) {
$menuQuad = $menuItem[0]; $menuQuad = $menuItem[0];
/** /** @var Quad $menuQuad */
*
* @var Quad $menuQuad
*/
$popoutFrame->add($menuQuad); $popoutFrame->add($menuQuad);
$menuQuad->setSize($itemSize, $itemSize); $menuQuad->setSize($itemSize, $itemSize);
$menuQuad->setX($x); $menuQuad->setX($x);
$menuQuad->setHAlign(Control::RIGHT); $menuQuad->setHAlign(Control::RIGHT);
$x -= $itemSize * 1.05; $x -= $itemSize * 1.05;
if($menuItem[1]) { if ($menuItem[1]) {
$description = '$s' . $menuItem[1]; $description = '$s' . $menuItem[1];
$menuQuad->addTooltipLabelFeature($descriptionLabel, $description); $menuQuad->addTooltipLabelFeature($descriptionLabel, $description);
} }
} }
} }
//if ($player->login === 'steeffeen') var_dump((string)$manialink);
return $manialink; return $manialink;
} }
} }

View File

@ -10,8 +10,4 @@ namespace ManiaControl\Callbacks;
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/ */
interface CallbackListener { interface CallbackListener {
/*
* Constants
*/
const CALLBACKLISTENER_INTERFACE = __CLASS__;
} }

View File

@ -10,8 +10,4 @@ namespace ManiaControl\Callbacks;
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/ */
interface TimerListener { interface TimerListener {
/*
* Constants
*/
const TIMERLISTENER_INTERFACE = __CLASS__;
} }

View File

@ -267,7 +267,7 @@ Void {$updatePageFunction}(Text _PagingId, Text _PageLabelId, Integer _BrowseAct
$script->addScriptFunction($updatePageFunction, $functionText); $script->addScriptFunction($updatePageFunction, $functionText);
return $this; return $this;
} }
/** /**
* Get the minimum Page * Get the minimum Page
* *
@ -323,6 +323,9 @@ Void {$updatePageFunction}(Text _PagingId, Text _PageLabelId, Integer _BrowseAct
* @return string * @return string
*/ */
protected function getPageButtonsArrayText() { protected function getPageButtonsArrayText() {
if (!$this->buttons) {
return Builder::getArray(array("" => 0), true);
}
$pageButtons = array(); $pageButtons = array();
foreach ($this->buttons as $pageButton) { foreach ($this->buttons as $pageButton) {
$pageButtons[$pageButton->getControl()->getId()] = $pageButton->getBrowseAction(); $pageButtons[$pageButton->getControl()->getId()] = $pageButton->getBrowseAction();

View File

@ -81,7 +81,7 @@ class Script {
else { else {
$scriptFunction = new ScriptFunction($name, $text); $scriptFunction = new ScriptFunction($name, $text);
} }
array_push($this->functions, $scriptFunction); $this->functions[$scriptFunction->getName()] = $scriptFunction;
return $this; return $this;
} }

View File

@ -38,6 +38,15 @@ class ScriptFunction {
return $this; return $this;
} }
/**
* Get the Name
*
* @return string
*/
public function getName() {
return $this->name;
}
/** /**
* Set the Text * Set the Text
* *

View File

@ -10,8 +10,4 @@ namespace ManiaControl\Manialinks;
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/ */
interface ManialinkPageAnswerListener { interface ManialinkPageAnswerListener {
/*
* Constants
*/
const MANIALINKPAGEANSWERLISTENER_INTERFACE = __CLASS__;
} }

View File

@ -159,12 +159,19 @@ class StyleManager {
* *
* @return Frame $frame * @return Frame $frame
*/ */
public function getDefaultListFrame(Script $script = null, $pagesId = '') { public function getDefaultListFrame() {
$paging = null; $args = func_get_args();
if ($script) { $script = null;
$paging = new Paging(); $paging = null;
$script->addFeature($paging); foreach ($args as $arg) {
} if ($arg instanceof Script) {
$script = $arg;
}
if ($arg instanceof Paging) {
$paging = $arg;
}
}
$width = $this->getListWidgetsWidth(); $width = $this->getListWidgetsWidth();
$height = $this->getListWidgetsHeight(); $height = $this->getListWidgetsHeight();
$quadStyle = $this->getDefaultMainWindowStyle(); $quadStyle = $this->getDefaultMainWindowStyle();
@ -189,7 +196,7 @@ class StyleManager {
$closeQuad->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_QuitRace); $closeQuad->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_QuitRace);
$closeQuad->setAction(ManialinkManager::ACTION_CLOSEWIDGET); $closeQuad->setAction(ManialinkManager::ACTION_CLOSEWIDGET);
if ($pagesId && isset($script)) { if ($script) {
$pagerSize = 6.; $pagerSize = 6.;
$pagerPrev = new Quad_Icons64x64_1(); $pagerPrev = new Quad_Icons64x64_1();
$frame->add($pagerPrev); $frame->add($pagerPrev);

View File

@ -37,23 +37,23 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
/* /*
* Constants * Constants
*/ */
const ACTION_UPDATE_MAP = 'MapList.UpdateMap'; const ACTION_UPDATE_MAP = 'MapList.UpdateMap';
const ACTION_ERASE_MAP = 'MapList.EraseMap'; const ACTION_ERASE_MAP = 'MapList.EraseMap';
const ACTION_SWITCH_MAP = 'MapList.SwitchMap'; const ACTION_SWITCH_MAP = 'MapList.SwitchMap';
const ACTION_START_SWITCH_VOTE = 'MapList.StartMapSwitchVote'; const ACTION_START_SWITCH_VOTE = 'MapList.StartMapSwitchVote';
const ACTION_QUEUED_MAP = 'MapList.QueueMap'; const ACTION_QUEUED_MAP = 'MapList.QueueMap';
const ACTION_UNQUEUE_MAP = 'MapList.UnQueueMap'; const ACTION_UNQUEUE_MAP = 'MapList.UnQueueMap';
const ACTION_CHECK_UPDATE = 'MapList.CheckUpdate'; const ACTION_CHECK_UPDATE = 'MapList.CheckUpdate';
const ACTION_CLEAR_MAPQUEUE = 'MapList.ClearMapQueue'; const ACTION_CLEAR_MAPQUEUE = 'MapList.ClearMapQueue';
const MAX_MAPS_PER_PAGE = 15; const MAX_MAPS_PER_PAGE = 15;
const DEFAULT_KARMA_PLUGIN = 'KarmaPlugin'; const DEFAULT_KARMA_PLUGIN = 'KarmaPlugin';
const DEFAULT_CUSTOM_VOTE_PLUGIN = 'CustomVotesPlugin'; const DEFAULT_CUSTOM_VOTE_PLUGIN = 'CustomVotesPlugin';
/* /*
* Private Properties * Private Properties
*/ */
private $maniaControl = null; private $maniaControl = null;
private $mapListShown = array(); private $mapListShown = array();
private $mapsInListShown = array(); private $mapsInListShown = array();
/** /**
@ -63,7 +63,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
*/ */
public function __construct(ManiaControl $maniaControl) { public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
// Register for Callbacks // Register for Callbacks
$this->maniaControl->callbackManager->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_CLOSED, $this, 'closeWidget'); $this->maniaControl->callbackManager->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_CLOSED, $this, 'closeWidget');
$this->maniaControl->callbackManager->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_OPENED, $this, 'handleWidgetOpened'); $this->maniaControl->callbackManager->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_OPENED, $this, 'handleWidgetOpened');
@ -72,7 +72,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_MAPS_UPDATED, $this, 'updateWidget'); $this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_MAPS_UPDATED, $this, 'updateWidget');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_KARMA_UPDATED, $this, 'updateWidget'); $this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_KARMA_UPDATED, $this, 'updateWidget');
$this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'updateWidget'); $this->maniaControl->callbackManager->registerCallbackListener(MapManager::CB_BEGINMAP, $this, 'updateWidget');
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_CHECK_UPDATE, $this, 'checkUpdates'); $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_CHECK_UPDATE, $this, 'checkUpdates');
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_CLEAR_MAPQUEUE, $this, 'clearMapQueue'); $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_CLEAR_MAPQUEUE, $this, 'clearMapQueue');
} }
@ -80,78 +80,74 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
/** /**
* Clears the Map Queue * Clears the Map Queue
* *
* @param array $chatCallback * @param array $chatCallback
* @param Player $player * @param Player $player
*/ */
public function clearMapQueue(array $chatCallback, Player $player) { public function clearMapQueue(array $chatCallback, Player $player) {
//Clears the Map Queue // Clears the Map Queue
$this->maniaControl->mapManager->mapQueue->clearMapQueue($player); $this->maniaControl->mapManager->mapQueue->clearMapQueue($player);
} }
/** /**
* Check for Map Updates * Check for Map Updates
* *
* @param array $chatCallback * @param array $chatCallback
* @param Player $player * @param Player $player
*/ */
public function checkUpdates(array $chatCallback, Player $player) { public function checkUpdates(array $chatCallback, Player $player) {
//Update Mx Infos // Update Mx Infos
$this->maniaControl->mapManager->mxManager->fetchManiaExchangeMapInformations(); $this->maniaControl->mapManager->mxManager->fetchManiaExchangeMapInformations();
//Reshow the Maplist // Reshow the Maplist
$this->showMapList($player); $this->showMapList($player);
} }
/** /**
* Displayes a MapList on the screen * Displayes a MapList on the screen
* *
* @param Player $player * @param Player $player
*/ */
public function showMapList(Player $player, $maps = null) { public function showMapList(Player $player, $maps = null) {
$width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth(); $width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth();
$height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight(); $height = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight();
$this->mapListShown[$player->login] = true; $this->mapListShown[$player->login] = true;
// Get Maps // Get Maps
if(is_null($maps) && $maps != 'redirect') { if (is_null($maps) && $maps != 'redirect') {
$mapList = $this->maniaControl->mapManager->getMaps(); $mapList = $this->maniaControl->mapManager->getMaps();
} else { }
if(array_key_exists($player->login, $this->mapsInListShown) && $maps == 'redirect') { else {
if (array_key_exists($player->login, $this->mapsInListShown) && $maps == 'redirect') {
$mapList = $this->mapsInListShown[$player->login]; $mapList = $this->mapsInListShown[$player->login];
} else { }
else {
$mapList = $maps; $mapList = $maps;
} }
} }
$this->mapsInListShown[$player->login] = $mapList; $this->mapsInListShown[$player->login] = $mapList;
$pagesId = ''; // Create ManiaLink
if (count($mapList) > self::MAX_MAPS_PER_PAGE) {
$pagesId = 'MapListPages';
}
//Create ManiaLink
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID); $maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
$script = $maniaLink->getScript(); $script = $maniaLink->getScript();
$paging = new Paging(); $paging = new Paging();
$script->addFeature($paging); $script->addFeature($paging);
// Main frame // Main frame
$frame = $this->maniaControl->manialinkManager->styleManager->getDefaultListFrame($script, $pagesId); $frame = $this->maniaControl->manialinkManager->styleManager->getDefaultListFrame($script, $paging);
$maniaLink->add($frame); $maniaLink->add($frame);
//Admin Buttons // Admin Buttons
if ($this->maniaControl->authenticationManager->checkPermission($player, MapQueue::SETTING_PERMISSION_CLEAR_MAPQUEUE)) { if ($this->maniaControl->authenticationManager->checkPermission($player, MapQueue::SETTING_PERMISSION_CLEAR_MAPQUEUE)) {
//Clear Map-Queue // Clear Map-Queue
$label = new Label_Button(); $label = new Label_Button();
$frame->add($label); $frame->add($label);
$label->setText("Clear Map-Queue"); $label->setText("Clear Map-Queue");
$label->setTextSize(1); $label->setTextSize(1);
$label->setPosition($width / 2 - 8, -$height / 2 + 9); $label->setPosition($width / 2 - 8, -$height / 2 + 9);
$label->setHAlign(Control::RIGHT); $label->setHAlign(Control::RIGHT);
$quad = new Quad_BgsPlayerCard(); $quad = new Quad_BgsPlayerCard();
$frame->add($quad); $frame->add($quad);
$quad->setPosition($width / 2 - 5, -$height / 2 + 9, 0.01); $quad->setPosition($width / 2 - 5, -$height / 2 + 9, 0.01);
@ -160,16 +156,16 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$quad->setSize(29, 4); $quad->setSize(29, 4);
$quad->setAction(self::ACTION_CLEAR_MAPQUEUE); $quad->setAction(self::ACTION_CLEAR_MAPQUEUE);
} }
if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_CHECK_UPDATE)) { if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_CHECK_UPDATE)) {
//Check Update // Check Update
$label = new Label_Button(); $label = new Label_Button();
$frame->add($label); $frame->add($label);
$label->setText("Check MX Updates"); $label->setText("Check MX Updates");
$label->setTextSize(1); $label->setTextSize(1);
$label->setPosition($width / 2 - 41, -$height / 2 + 9, 0.01); $label->setPosition($width / 2 - 41, -$height / 2 + 9, 0.01);
$label->setHAlign(Control::RIGHT); $label->setHAlign(Control::RIGHT);
$quad = new Quad_BgsPlayerCard(); $quad = new Quad_BgsPlayerCard();
$frame->add($quad); $frame->add($quad);
$quad->setPosition($width / 2 - 37, -$height / 2 + 9, 0.01); $quad->setPosition($width / 2 - 37, -$height / 2 + 9, 0.01);
@ -177,7 +173,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$quad->setHAlign(Control::RIGHT); $quad->setHAlign(Control::RIGHT);
$quad->setSize(35, 4); $quad->setSize(35, 4);
$quad->setAction(self::ACTION_CHECK_UPDATE); $quad->setAction(self::ACTION_CHECK_UPDATE);
$mxQuad = new Quad(); $mxQuad = new Quad();
$frame->add($mxQuad); $frame->add($mxQuad);
$mxQuad->setSize(3, 3); $mxQuad->setSize(3, 3);
@ -187,29 +183,32 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$mxQuad->setZ(0.01); $mxQuad->setZ(0.01);
$mxQuad->setAction(self::ACTION_CHECK_UPDATE); $mxQuad->setAction(self::ACTION_CHECK_UPDATE);
} }
// Headline // Headline
$headFrame = new Frame(); $headFrame = new Frame();
$frame->add($headFrame); $frame->add($headFrame);
$headFrame->setY($height / 2 - 5); $headFrame->setY($height / 2 - 5);
$x = -$width / 2; $x = -$width / 2;
$array = array('Id' => $x + 5, 'Mx Id' => $x + 10, 'Map Name' => $x + 20, 'Author' => $x + 68, 'Karma' => $x + 115, 'Actions' => $width / 2 - 15); $array = array('Id' => $x + 5, 'Mx Id' => $x + 10, 'Map Name' => $x + 20, 'Author' => $x + 68, 'Karma' => $x + 115,
'Actions' => $width / 2 - 15);
$this->maniaControl->manialinkManager->labelLine($headFrame, $array); $this->maniaControl->manialinkManager->labelLine($headFrame, $array);
//Predefine description Label // Predefine description Label
$descriptionLabel = $this->maniaControl->manialinkManager->styleManager->getDefaultDescriptionLabel(); $descriptionLabel = $this->maniaControl->manialinkManager->styleManager->getDefaultDescriptionLabel();
$frame->add($descriptionLabel); $frame->add($descriptionLabel);
$queuedMaps = $this->maniaControl->mapManager->mapQueue->getQueuedMapsRanking(); $queuedMaps = $this->maniaControl->mapManager->mapQueue->getQueuedMapsRanking();
/** /**
*
* @var KarmaPlugin $karmaPlugin * @var KarmaPlugin $karmaPlugin
*/ */
$karmaPlugin = $this->maniaControl->pluginManager->getPlugin(self::DEFAULT_KARMA_PLUGIN); $karmaPlugin = $this->maniaControl->pluginManager->getPlugin(self::DEFAULT_KARMA_PLUGIN);
$id = 1; $id = 1;
$y = $height / 2 - 10; $y = $height / 2 - 10;
$pageFrames = array(); $pageFrames = array();
/** /**
*
* @var Map $map * @var Map $map
*/ */
$currentMap = $this->maniaControl->mapManager->getCurrentMap(); $currentMap = $this->maniaControl->mapManager->getCurrentMap();
@ -217,8 +216,8 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$mxIconHover = $this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON_MOVER); $mxIconHover = $this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON_MOVER);
$mxIconGreen = $this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON_GREEN); $mxIconGreen = $this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON_GREEN);
$mxIconGreenHover = $this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON_GREEN_MOVER); $mxIconGreenHover = $this->maniaControl->manialinkManager->iconManager->getIcon(IconManager::MX_ICON_GREEN_MOVER);
foreach($mapList as $map) { foreach ($mapList as $map) {
if (!isset($pageFrame)) { if (!isset($pageFrame)) {
$pageFrame = new Frame(); $pageFrame = new Frame();
$frame->add($pageFrame); $frame->add($pageFrame);
@ -227,16 +226,16 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
} }
array_push($pageFrames, $pageFrame); array_push($pageFrames, $pageFrame);
$y = $height / 2 - 10; $y = $height / 2 - 10;
$paging->addPage($pageFrame); $paging->addPage($pageFrame);
} }
// Map Frame // Map Frame
$mapFrame = new Frame(); $mapFrame = new Frame();
$pageFrame->add($mapFrame); $pageFrame->add($mapFrame);
$mapFrame->setZ(0.1); $mapFrame->setZ(0.1);
$mapFrame->setY($y); $mapFrame->setY($y);
if ($id % 2 != 0) { if ($id % 2 != 0) {
$lineQuad = new Quad_BgsPlayerCard(); $lineQuad = new Quad_BgsPlayerCard();
$mapFrame->add($lineQuad); $mapFrame->add($lineQuad);
@ -244,7 +243,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$lineQuad->setSubStyle($lineQuad::SUBSTYLE_BgPlayerCardBig); $lineQuad->setSubStyle($lineQuad::SUBSTYLE_BgPlayerCardBig);
$lineQuad->setZ(0.001); $lineQuad->setZ(0.001);
} }
if ($currentMap === $map) { if ($currentMap === $map) {
$currentQuad = new Quad_Icons64x64_1(); $currentQuad = new Quad_Icons64x64_1();
$mapFrame->add($currentQuad); $mapFrame->add($currentQuad);
@ -253,11 +252,11 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$currentQuad->setSize(4, 4); $currentQuad->setSize(4, 4);
$currentQuad->setSubStyle($currentQuad::SUBSTYLE_ArrowBlue); $currentQuad->setSubStyle($currentQuad::SUBSTYLE_ArrowBlue);
} }
$mxId = '-'; $mxId = '-';
if (isset($map->mx->id)) { if (isset($map->mx->id)) {
$mxId = $map->mx->id; $mxId = $map->mx->id;
$mxQuad = new Quad(); $mxQuad = new Quad();
$mapFrame->add($mxQuad); $mapFrame->add($mxQuad);
$mxQuad->setSize(3, 3); $mxQuad->setSize(3, 3);
@ -266,9 +265,9 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$mxQuad->setX($x + 65); $mxQuad->setX($x + 65);
$mxQuad->setUrl($map->mx->pageurl); $mxQuad->setUrl($map->mx->pageurl);
$mxQuad->setZ(0.01); $mxQuad->setZ(0.01);
$description = 'View $<' . $map->name . '$> on Mania-Exchange'; $description = 'View $<' . $map->name . '$> on Mania-Exchange';
$mxQuad->addTooltipLabelFeature($descriptionLabel, $description); $mxQuad->addTooltipLabelFeature($descriptionLabel, $description);
if ($map->updateAvailable()) { if ($map->updateAvailable()) {
$mxQuad = new Quad(); $mxQuad = new Quad();
$mapFrame->add($mxQuad); $mapFrame->add($mxQuad);
@ -278,29 +277,30 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$mxQuad->setX($x + 62); $mxQuad->setX($x + 62);
$mxQuad->setUrl($map->mx->pageurl); $mxQuad->setUrl($map->mx->pageurl);
$mxQuad->setZ(0.01); $mxQuad->setZ(0.01);
$description = 'Update for $<' . $map->name . '$> available on Mania-Exchange!'; $description = 'Update for $<' . $map->name . '$> available on Mania-Exchange!';
$mxQuad->addTooltipLabelFeature($descriptionLabel, $description); $mxQuad->addTooltipLabelFeature($descriptionLabel, $description);
//Update Button // Update Button
if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)) { if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)) {
$mxQuad->setAction(self::ACTION_UPDATE_MAP . '.' . $map->uid); $mxQuad->setAction(self::ACTION_UPDATE_MAP . '.' . $map->uid);
} }
} }
} }
// Display Maps // Display Maps
$array = array($id => $x + 5, $mxId => $x + 10, Formatter::stripDirtyCodes($map->name) => $x + 20, $map->authorNick => $x + 68); $array = array($id => $x + 5, $mxId => $x + 10, Formatter::stripDirtyCodes($map->name) => $x + 20, $map->authorNick => $x + 68);
$labels = $this->maniaControl->manialinkManager->labelLine($mapFrame, $array); $labels = $this->maniaControl->manialinkManager->labelLine($mapFrame, $array);
if (isset($labels[3])) { if (isset($labels[3])) {
/** @var Label $label */ /**
$label = $labels[3]; * @var Label $label
$description = '$<' . $map->name . '$> made by $<' . $map->authorLogin . '$>'; */
$label->addTooltipLabelFeature($descriptionLabel, $description); $label = $labels[3];
$description = '$<' . $map->name . '$> made by $<' . $map->authorLogin . '$>';
$label->addTooltipLabelFeature($descriptionLabel, $description);
} }
// TODO action detailed map info including mx info // TODO action detailed map info including mx info
// Map-Queue-Map-Label // Map-Queue-Map-Label
if (isset($queuedMaps[$map->uid])) { if (isset($queuedMaps[$map->uid])) {
$label = new Label_Text(); $label = new Label_Text();
@ -311,19 +311,20 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$label->setTextSize(1.5); $label->setTextSize(1.5);
$label->setText($queuedMaps[$map->uid]); $label->setText($queuedMaps[$map->uid]);
$label->setTextColor('fff'); $label->setTextColor('fff');
//Checks if the Player who openend the Widget has queued the map // Checks if the Player who openend the Widget has queued the map
$queuer = $this->maniaControl->mapManager->mapQueue->getQueuer($map->uid); $queuer = $this->maniaControl->mapManager->mapQueue->getQueuer($map->uid);
if ($queuer->login == $player->login) { if ($queuer->login == $player->login) {
$description = 'Remove $<' . $map->name . '$> from the Map Queue'; $description = 'Remove $<' . $map->name . '$> from the Map Queue';
$label->addTooltipLabelFeature($descriptionLabel, $description); $label->addTooltipLabelFeature($descriptionLabel, $description);
$label->setAction(self::ACTION_UNQUEUE_MAP . '.' . $map->uid); $label->setAction(self::ACTION_UNQUEUE_MAP . '.' . $map->uid);
} else {
$description = '$<' . $map->name . '$> is on Map-Queue Position: ' . $queuedMaps[$map->uid];
$label->addTooltipLabelFeature($descriptionLabel, $description);
} }
else {
} else { $description = '$<' . $map->name . '$> is on Map-Queue Position: ' . $queuedMaps[$map->uid];
$label->addTooltipLabelFeature($descriptionLabel, $description);
}
}
else {
// Map-Queue-Map-Button // Map-Queue-Map-Button
$queueLabel = new Label_Button(); $queueLabel = new Label_Button();
$mapFrame->add($queueLabel); $mapFrame->add($queueLabel);
@ -333,11 +334,11 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$queueLabel->setAction(self::ACTION_QUEUED_MAP . '.' . $map->uid); $queueLabel->setAction(self::ACTION_QUEUED_MAP . '.' . $map->uid);
$queueLabel->setText('+'); $queueLabel->setText('+');
$queueLabel->setTextColor('09f'); $queueLabel->setTextColor('09f');
$description = 'Add $<' . $map->name . '$> to the Map Queue'; $description = 'Add $<' . $map->name . '$> to the Map Queue';
$queueLabel->addTooltipLabelFeature($descriptionLabel, $description); $queueLabel->addTooltipLabelFeature($descriptionLabel, $description);
} }
if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_REMOVE_MAP)) { if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_REMOVE_MAP)) {
// erase map quad // erase map quad
$eraseLabel = new Label_Button(); $eraseLabel = new Label_Button();
@ -348,13 +349,13 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$eraseLabel->setTextSize(1); $eraseLabel->setTextSize(1);
$eraseLabel->setText('x'); $eraseLabel->setText('x');
$eraseLabel->setTextColor('a00'); $eraseLabel->setTextColor('a00');
$confirmFrame = $this->buildConfirmFrame($maniaLink, $y, $id, $map->uid); $confirmFrame = $this->buildConfirmFrame($maniaLink, $y, $id, $map->uid);
$eraseLabel->addToggleFeature($confirmFrame); $eraseLabel->addToggleFeature($confirmFrame);
$description = 'Remove Map: $<' . $map->name . '$>'; $description = 'Remove Map: $<' . $map->name . '$>';
$eraseLabel->addToggleFeature($descriptionLabel, $description); $eraseLabel->addTooltipLabelFeature($descriptionLabel, $description);
} }
if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)) { if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)) {
// Switch to map // Switch to map
$switchLabel = new Label_Button(); $switchLabel = new Label_Button();
@ -365,15 +366,15 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$switchLabel->setTextSize(2); $switchLabel->setTextSize(2);
$switchLabel->setText('»'); $switchLabel->setText('»');
$switchLabel->setTextColor('0f0'); $switchLabel->setTextColor('0f0');
$confirmFrame = $this->buildConfirmFrame($maniaLink, $y, $id); $confirmFrame = $this->buildConfirmFrame($maniaLink, $y, $id);
$switchLabel->addToggleFeature($confirmFrame); $switchLabel->addToggleFeature($confirmFrame);
$description = 'Switch Directly to Map: $<' . $map->name . '$>'; $description = 'Switch Directly to Map: $<' . $map->name . '$>';
$switchLabel->addTooltipLabelFeature($descriptionLabel, $description); $switchLabel->addTooltipLabelFeature($descriptionLabel, $description);
}
} else if ($this->maniaControl->pluginManager->isPluginActive(self::DEFAULT_CUSTOM_VOTE_PLUGIN)) { else if ($this->maniaControl->pluginManager->isPluginActive(self::DEFAULT_CUSTOM_VOTE_PLUGIN)) {
//Switch Map Voting // Switch Map Voting
$switchLabel = new Label_Button(); $switchLabel = new Label_Button();
$mapFrame->add($switchLabel); $mapFrame->add($switchLabel);
$switchLabel->setX($width / 2 - 10); $switchLabel->setX($width / 2 - 10);
@ -382,13 +383,13 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$switchLabel->setTextSize(2); $switchLabel->setTextSize(2);
$switchLabel->setText('»'); $switchLabel->setText('»');
$switchLabel->setTextColor('0f0'); $switchLabel->setTextColor('0f0');
$switchLabel->setAction(self::ACTION_START_SWITCH_VOTE . '.' . ($id - 1)); $switchLabel->setAction(self::ACTION_START_SWITCH_VOTE . '.' . ($id - 1));
$description = 'Start Map-Switch Vote: $<' . $map->name . '$>'; $description = 'Start Map-Switch Vote: $<' . $map->name . '$>';
$switchLabel->addTooltipLabelFeature($descriptionLabel, $description); $switchLabel->addTooltipLabelFeature($descriptionLabel, $description);
} }
// Display Karma bar // Display Karma bar
if ($karmaPlugin) { if ($karmaPlugin) {
$karma = $karmaPlugin->getMapKarma($map); $karma = $karmaPlugin->getMapKarma($map);
@ -404,7 +405,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$karmaGauge->setRatio($karma + 0.15 - $karma * 0.15); $karmaGauge->setRatio($karma + 0.15 - $karma * 0.15);
$karmaColor = ColorUtil::floatToStatusColor($karma); $karmaColor = ColorUtil::floatToStatusColor($karma);
$karmaGauge->setColor($karmaColor . '9'); $karmaGauge->setColor($karmaColor . '9');
$karmaLabel = new Label(); $karmaLabel = new Label();
$mapFrame->add($karmaLabel); $mapFrame->add($karmaLabel);
$karmaLabel->setZ(2); $karmaLabel->setZ(2);
@ -416,13 +417,14 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$karmaLabel->setText(' ' . round($karma * 100.) . '% (' . $votes['count'] . ')'); $karmaLabel->setText(' ' . round($karma * 100.) . '% (' . $votes['count'] . ')');
} }
} }
$y -= 4; $y -= 4;
if ($id % self::MAX_MAPS_PER_PAGE == 0) { if ($id % self::MAX_MAPS_PER_PAGE == 0) {
unset($pageFrame); unset($pageFrame);
} }
$id++; $id++;
} }
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'MapList'); $this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'MapList');
} }
@ -430,31 +432,31 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
* Builds the confirmation frame * Builds the confirmation frame
* *
* @param ManiaLink $maniaLink * @param ManiaLink $maniaLink
* @param $y * @param $y
* @param $id * @param $id
* @param bool $mapUid * @param bool $mapUid
* @return Frame * @return Frame
*/ */
public function buildConfirmFrame(Manialink $maniaLink, $y, $id, $mapUid = false) { public function buildConfirmFrame(Manialink $maniaLink, $y, $id, $mapUid = false) {
$width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth(); $width = $this->maniaControl->manialinkManager->styleManager->getListWidgetsWidth();
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowStyle(); $quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowStyle();
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowSubStyle(); $quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowSubStyle();
$confirmFrame = new Frame(); $confirmFrame = new Frame();
$maniaLink->add($confirmFrame); $maniaLink->add($confirmFrame);
$confirmFrame->setPosition($width / 2 + 6, $y); $confirmFrame->setPosition($width / 2 + 6, $y);
$confirmFrame->setVisible(false); $confirmFrame->setVisible(false);
$quad = new Quad(); $quad = new Quad();
$confirmFrame->add($quad); $confirmFrame->add($quad);
$quad->setStyles($quadStyle, $quadSubstyle); $quad->setStyles($quadStyle, $quadSubstyle);
$quad->setSize(12, 4); $quad->setSize(12, 4);
$quad = new Quad_BgsPlayerCard(); $quad = new Quad_BgsPlayerCard();
$confirmFrame->add($quad); $confirmFrame->add($quad);
$quad->setSubStyle($quad::SUBSTYLE_BgCardSystem); $quad->setSubStyle($quad::SUBSTYLE_BgCardSystem);
$quad->setSize(11, 3.5); $quad->setSize(11, 3.5);
$label = new Label_Button(); $label = new Label_Button();
$confirmFrame->add($label); $confirmFrame->add($label);
$label->setAlign(Control::CENTER, Control::CENTER); $label->setAlign(Control::CENTER, Control::CENTER);
@ -462,19 +464,20 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$label->setTextSize(1); $label->setTextSize(1);
$label->setScale(0.90); $label->setScale(0.90);
$label->setX(-1.3); $label->setX(-1.3);
$buttLabel = new Label_Button(); $buttLabel = new Label_Button();
$confirmFrame->add($buttLabel); $confirmFrame->add($buttLabel);
$buttLabel->setPosition(3.2, 0.4, 0.2); $buttLabel->setPosition(3.2, 0.4, 0.2);
$buttLabel->setSize(3, 3); $buttLabel->setSize(3, 3);
$buttLabel->setAlign(Control::CENTER, Control::CENTER); $buttLabel->setAlign(Control::CENTER, Control::CENTER);
if (!$mapUid) { if (!$mapUid) {
$quad->setAction(self::ACTION_SWITCH_MAP . '.' . ($id - 1)); $quad->setAction(self::ACTION_SWITCH_MAP . '.' . ($id - 1));
$buttLabel->setText('»'); $buttLabel->setText('»');
$buttLabel->setTextColor('0f0'); $buttLabel->setTextColor('0f0');
$buttLabel->setTextSize(2); $buttLabel->setTextSize(2);
} else { }
else {
$buttLabel->setTextSize(1); $buttLabel->setTextSize(1);
$buttLabel->setText('x'); $buttLabel->setText('x');
$buttLabel->setTextColor('a00'); $buttLabel->setTextColor('a00');
@ -487,10 +490,10 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
* Unset the player if he opened another Main Widget * Unset the player if he opened another Main Widget
* *
* @param Player $player * @param Player $player
* @param $openedWidget * @param $openedWidget
*/ */
public function handleWidgetOpened(Player $player, $openedWidget) { public function handleWidgetOpened(Player $player, $openedWidget) {
//unset when another main widget got opened // unset when another main widget got opened
if ($openedWidget != 'MapList') { if ($openedWidget != 'MapList') {
unset($this->mapListShown[$player->login]); unset($this->mapListShown[$player->login]);
} }
@ -521,18 +524,18 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
* @param array $callback * @param array $callback
*/ */
public function handleManialinkPageAnswer(array $callback) { public function handleManialinkPageAnswer(array $callback) {
$actionId = $callback[1][2]; $actionId = $callback[1][2];
$actionArray = explode('.', $actionId); $actionArray = explode('.', $actionId);
if (count($actionArray) <= 2) { if (count($actionArray) <= 2) {
return; return;
} }
$action = $actionArray[0] . '.' . $actionArray[1]; $action = $actionArray[0] . '.' . $actionArray[1];
$login = $callback[1][1]; $login = $callback[1][1];
$player = $this->maniaControl->playerManager->getPlayer($login); $player = $this->maniaControl->playerManager->getPlayer($login);
$mapId = (int)$actionArray[2]; $mapId = (int) $actionArray[2];
switch($action) { switch ($action) {
case self::ACTION_UPDATE_MAP: case self::ACTION_UPDATE_MAP:
$mapUid = $actionArray[2]; $mapUid = $actionArray[2];
$this->maniaControl->mapManager->updateMap($player, $mapUid); $this->maniaControl->mapManager->updateMap($player, $mapUid);
@ -545,43 +548,49 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
case self::ACTION_SWITCH_MAP: case self::ACTION_SWITCH_MAP:
try { try {
$this->maniaControl->client->jumpToMapIndex($mapId); $this->maniaControl->client->jumpToMapIndex($mapId);
} catch(Exception $e) { }
catch (Exception $e) {
// TODO: is it even possible that an exception other than connection errors will be thrown? - remove try-catch? // TODO: is it even possible that an exception other than connection errors will be thrown? - remove try-catch?
$this->maniaControl->chat->sendError("Error while Jumping to Map Index"); $this->maniaControl->chat->sendError("Error while Jumping to Map Index");
break; break;
} }
$mapList = $this->maniaControl->mapManager->getMaps(); $mapList = $this->maniaControl->mapManager->getMaps();
$map = $mapList[$mapId]; $map = $mapList[$mapId];
$message = '$<' . $player->nickname . '$> skipped to Map $z$<' . $map->name . '$>!'; $message = '$<' . $player->nickname . '$> skipped to Map $z$<' . $map->name . '$>!';
$this->maniaControl->chat->sendSuccess($message); $this->maniaControl->chat->sendSuccess($message);
$this->maniaControl->log($message, true); $this->maniaControl->log($message, true);
$this->playerCloseWidget($player); $this->playerCloseWidget($player);
break; break;
case self::ACTION_START_SWITCH_VOTE: case self::ACTION_START_SWITCH_VOTE:
/** @var $votesPlugin CustomVotesPlugin */ /**
* @var $votesPlugin CustomVotesPlugin
*/
$votesPlugin = $this->maniaControl->pluginManager->getPlugin(self::DEFAULT_CUSTOM_VOTE_PLUGIN); $votesPlugin = $this->maniaControl->pluginManager->getPlugin(self::DEFAULT_CUSTOM_VOTE_PLUGIN);
$mapList = $this->maniaControl->mapManager->getMaps(); $mapList = $this->maniaControl->mapManager->getMaps();
$map = $mapList[$mapId]; $map = $mapList[$mapId];
$message = '$<' . $player->nickname . '$>$s started a vote to switch to $<' . $map->name . '$>!'; $message = '$<' . $player->nickname . '$>$s started a vote to switch to $<' . $map->name . '$>!';
/** @var Map $map */ /**
* @var Map $map
*/
$votesPlugin->defineVote('switchmap', "Goto " . $map->name, true, $message); $votesPlugin->defineVote('switchmap', "Goto " . $map->name, true, $message);
$self = $this; $self = $this;
$votesPlugin->startVote($player, 'switchmap', function ($result) use (&$self, &$votesPlugin, &$map) { $votesPlugin->startVote($player, 'switchmap', function ($result) use(&$self, &$votesPlugin, &$map) {
$self->maniaControl->chat->sendInformation('$sVote Successfully -> Map switched!'); $self->maniaControl->chat->sendInformation('$sVote Successfully -> Map switched!');
$votesPlugin->undefineVote('switchmap'); $votesPlugin->undefineVote('switchmap');
try { try {
$index = $self->maniaControl->mapManager->getMapIndex($map); $index = $self->maniaControl->mapManager->getMapIndex($map);
$self->maniaControl->client->jumpToMapIndex($index); $self->maniaControl->client->jumpToMapIndex($index);
} catch(Exception $e) { }
//TODO temp added 19.04.2014 catch (Exception $e) {
// TODO temp added 19.04.2014
$self->maniaControl->errorHandler->triggerDebugNotice("Exception line 557 MapList.php" . $e->getMessage()); $self->maniaControl->errorHandler->triggerDebugNotice("Exception line 557 MapList.php" . $e->getMessage());
$self->maniaControl->chat->sendError("Error while Switching Map"); $self->maniaControl->chat->sendError("Error while Switching Map");
} }
}); });
@ -601,12 +610,13 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
* Reopen the widget on Map Begin, MapListChanged, etc. * Reopen the widget on Map Begin, MapListChanged, etc.
*/ */
public function updateWidget() { public function updateWidget() {
foreach($this->mapListShown as $login => $shown) { foreach ($this->mapListShown as $login => $shown) {
if ($shown) { if ($shown) {
$player = $this->maniaControl->playerManager->getPlayer($login); $player = $this->maniaControl->playerManager->getPlayer($login);
if ($player) { if ($player) {
$this->showMapList($player); $this->showMapList($player);
} else { }
else {
unset($this->mapListShown[$login]); unset($this->mapListShown[$login]);
} }
} }
@ -617,12 +627,13 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
* Reopen the widget on MapQueue changed * Reopen the widget on MapQueue changed
*/ */
public function updateWidgetQueue() { public function updateWidgetQueue() {
foreach($this->mapListShown as $login => $shown) { foreach ($this->mapListShown as $login => $shown) {
if ($shown) { if ($shown) {
$player = $this->maniaControl->playerManager->getPlayer($login); $player = $this->maniaControl->playerManager->getPlayer($login);
if ($player) { if ($player) {
$this->showMapList($player, 'redirect'); $this->showMapList($player, 'redirect');
} else { }
else {
unset($this->mapListShown[$login]); unset($this->mapListShown[$login]);
} }
} }