2013-11-28 03:47:08 +01:00
|
|
|
<?php
|
|
|
|
|
2014-07-25 15:45:10 +02:00
|
|
|
namespace ManiaControl\Configurator;
|
2013-11-28 03:47:08 +01:00
|
|
|
|
2013-11-28 04:48:04 +01:00
|
|
|
use FML\Controls\Frame;
|
2013-11-28 17:36:39 +01:00
|
|
|
use FML\Controls\Labels\Label_Text;
|
|
|
|
use FML\Controls\Quad;
|
2013-11-28 04:48:04 +01:00
|
|
|
use FML\Controls\Quads\Quad_BgRaceScore2;
|
2013-12-14 23:32:21 +01:00
|
|
|
use FML\Controls\Quads\Quad_Icons64x64_1;
|
2014-01-05 19:00:11 +01:00
|
|
|
use FML\Controls\Quads\Quad_UIConstruction_Buttons;
|
|
|
|
use FML\ManiaLink;
|
2014-03-29 16:23:04 +01:00
|
|
|
use ManiaControl\Admin\AuthenticationManager;
|
2014-01-05 19:00:11 +01:00
|
|
|
use ManiaControl\Callbacks\CallbackListener;
|
|
|
|
use ManiaControl\Callbacks\CallbackManager;
|
2013-12-31 13:21:45 +01:00
|
|
|
use ManiaControl\Commands\CommandListener;
|
2014-01-05 19:00:11 +01:00
|
|
|
use ManiaControl\ManiaControl;
|
|
|
|
use ManiaControl\Manialinks\ManialinkManager;
|
|
|
|
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
|
|
|
use ManiaControl\Players\Player;
|
2014-07-25 15:32:46 +02:00
|
|
|
use ManiaControl\Server\ServerOptionsMenu;
|
2018-10-06 21:01:33 +02:00
|
|
|
use ManiaControl\Server\ServerUIPropertiesMenu;
|
2014-07-25 17:47:46 +02:00
|
|
|
use ManiaControl\Server\VoteRatiosMenu;
|
2013-11-28 17:36:39 +01:00
|
|
|
|
2013-11-28 03:47:08 +01:00
|
|
|
/**
|
2014-04-12 12:14:37 +02:00
|
|
|
* Class managing ingame ManiaControl Configuration
|
2013-11-28 03:47:08 +01:00
|
|
|
*
|
2014-05-02 17:50:30 +02:00
|
|
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
2019-01-05 21:02:24 +01:00
|
|
|
* @copyright 2014-2019 ManiaControl Team
|
2014-05-02 17:50:30 +02:00
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
2013-11-28 03:47:08 +01:00
|
|
|
*/
|
2013-12-31 13:21:45 +01:00
|
|
|
class Configurator implements CallbackListener, CommandListener, ManialinkPageAnswerListener {
|
2014-04-12 12:14:37 +02:00
|
|
|
/*
|
2013-11-28 03:47:08 +01:00
|
|
|
* Constants
|
|
|
|
*/
|
2014-05-02 17:50:30 +02:00
|
|
|
const ACTION_TOGGLEMENU = 'Configurator.ToggleMenuAction';
|
|
|
|
const ACTION_SAVECONFIG = 'Configurator.SaveConfigAction';
|
2014-07-24 23:12:56 +02:00
|
|
|
const ACTION_SELECTMENU = 'Configurator.SelectMenu.';
|
2014-05-02 17:50:30 +02:00
|
|
|
const SETTING_MENU_POSX = 'Menu Widget Position: X';
|
|
|
|
const SETTING_MENU_POSY = 'Menu Widget Position: Y';
|
|
|
|
const SETTING_MENU_WIDTH = 'Menu Widget Width';
|
|
|
|
const SETTING_MENU_HEIGHT = 'Menu Widget Height';
|
|
|
|
const SETTING_MENU_STYLE = 'Menu Widget BackgroundQuad Style';
|
|
|
|
const SETTING_MENU_SUBSTYLE = 'Menu Widget BackgroundQuad Substyle';
|
2014-04-13 19:05:54 +02:00
|
|
|
const SETTING_PERMISSION_OPEN_CONFIGURATOR = 'Open Configurator';
|
2014-05-24 16:52:46 +02:00
|
|
|
const CACHE_MENU_SHOWN = 'MenuShown';
|
|
|
|
const MENU_NAME = 'Configurator';
|
2014-01-05 19:00:11 +01:00
|
|
|
|
2014-04-12 12:14:37 +02:00
|
|
|
/*
|
2014-07-25 16:28:47 +02:00
|
|
|
* Private properties
|
2013-11-28 03:47:08 +01:00
|
|
|
*/
|
2014-08-02 22:31:46 +02:00
|
|
|
/** @var ManiaControl $maniaControl */
|
2013-11-28 03:47:08 +01:00
|
|
|
private $maniaControl = null;
|
2014-07-25 16:28:47 +02:00
|
|
|
/** @var ServerOptionsMenu $serverOptionsMenu */
|
2014-07-25 15:32:46 +02:00
|
|
|
private $serverOptionsMenu = null;
|
2018-10-06 21:01:33 +02:00
|
|
|
/** @var ServerUIPropertiesMenu $serverUIPropertiesMenu */
|
|
|
|
private $serverUIPropertiesMenu = null;
|
2014-07-25 17:47:46 +02:00
|
|
|
/** @var ScriptSettings $scriptSettings */
|
|
|
|
private $scriptSettings = null;
|
|
|
|
/** @var VoteRatiosMenu $voteRatiosMenu */
|
|
|
|
private $voteRatiosMenu = null;
|
2014-07-25 16:28:47 +02:00
|
|
|
/** @var ManiaControlSettings $maniaControlSettings */
|
2014-01-05 19:00:11 +01:00
|
|
|
private $maniaControlSettings = null;
|
2014-06-22 19:23:33 +02:00
|
|
|
/** @var ConfiguratorMenu[] $menus */
|
2013-11-28 17:36:39 +01:00
|
|
|
private $menus = array();
|
2013-11-28 03:47:08 +01:00
|
|
|
|
|
|
|
/**
|
2014-07-25 16:28:47 +02:00
|
|
|
* Create a new configurator instance
|
2013-11-28 03:47:08 +01:00
|
|
|
*
|
2013-12-31 12:42:07 +01:00
|
|
|
* @param ManiaControl $maniaControl
|
2013-11-28 03:47:08 +01:00
|
|
|
*/
|
|
|
|
public function __construct(ManiaControl $maniaControl) {
|
|
|
|
$this->maniaControl = $maniaControl;
|
2013-12-31 13:21:45 +01:00
|
|
|
$this->addActionsMenuItem();
|
2014-01-05 19:00:11 +01:00
|
|
|
|
2014-08-03 01:34:18 +02:00
|
|
|
// Settings
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MENU_POSX, 0.);
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MENU_POSY, 3.);
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MENU_WIDTH, 170.);
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MENU_HEIGHT, 81.);
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MENU_STYLE, Quad_BgRaceScore2::STYLE);
|
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MENU_SUBSTYLE, Quad_BgRaceScore2::SUBSTYLE_HandleSelectable);
|
2014-08-03 01:34:18 +02:00
|
|
|
|
|
|
|
// Permissions
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_OPEN_CONFIGURATOR, AuthenticationManager::AUTH_LEVEL_ADMIN);
|
2014-08-03 01:34:18 +02:00
|
|
|
|
|
|
|
// Page answers
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_TOGGLEMENU, $this, 'handleToggleMenuAction');
|
|
|
|
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerListener(self::ACTION_SAVECONFIG, $this, 'handleSaveConfigAction');
|
2014-08-03 01:34:18 +02:00
|
|
|
|
|
|
|
// Callbacks
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_OPENED, $this, 'handleWidgetOpened');
|
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(ManialinkManager::CB_MAIN_WINDOW_CLOSED, $this, 'closeWidget');
|
2014-01-05 19:00:11 +01:00
|
|
|
|
2014-07-25 17:47:46 +02:00
|
|
|
// Create server options menu
|
2014-07-25 15:32:46 +02:00
|
|
|
$this->serverOptionsMenu = new ServerOptionsMenu($maniaControl);
|
|
|
|
$this->addMenu($this->serverOptionsMenu);
|
2014-01-05 19:00:11 +01:00
|
|
|
|
2018-10-06 21:01:33 +02:00
|
|
|
// Create server UI properties menu
|
|
|
|
$this->serverUIPropertiesMenu = new ServerUIPropertiesMenu($maniaControl);
|
|
|
|
$this->addMenu($this->serverUIPropertiesMenu);
|
|
|
|
|
2014-01-05 19:00:11 +01:00
|
|
|
// Create script settings
|
|
|
|
$this->scriptSettings = new ScriptSettings($maniaControl);
|
|
|
|
$this->addMenu($this->scriptSettings);
|
|
|
|
|
2014-07-25 17:47:46 +02:00
|
|
|
// Create vote ratios menu
|
|
|
|
$this->voteRatiosMenu = new VoteRatiosMenu($maniaControl);
|
|
|
|
$this->addMenu($this->voteRatiosMenu);
|
|
|
|
|
2014-01-05 19:00:11 +01:00
|
|
|
// Create Mania Control Settings
|
2014-01-05 19:01:48 +01:00
|
|
|
$this->maniaControlSettings = new ManiaControlSettings($maniaControl);
|
2014-01-05 19:00:11 +01:00
|
|
|
$this->addMenu($this->maniaControlSettings);
|
|
|
|
|
2014-08-03 01:34:18 +02:00
|
|
|
// Chat commands
|
2017-05-19 17:26:46 +02:00
|
|
|
$this->maniaControl->getCommandManager()->registerCommandListener(array('settings', 'config'), $this, 'handleConfigCommand', true, 'Loads Config panel.');
|
2013-12-31 13:21:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-02 17:50:30 +02:00
|
|
|
* Add Menu Item to the Actions Menu
|
2013-12-31 13:21:45 +01:00
|
|
|
*/
|
2014-05-02 17:50:30 +02:00
|
|
|
private function addActionsMenuItem() {
|
|
|
|
$itemQuad = new Quad_UIConstruction_Buttons();
|
2014-08-13 11:05:52 +02:00
|
|
|
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_Tools)->setAction(self::ACTION_TOGGLEMENU);
|
|
|
|
$this->maniaControl->getActionsMenu()->addAdminMenuItem($itemQuad, 100, 'Settings');
|
2013-11-28 17:36:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a configurator menu
|
|
|
|
*
|
2013-12-31 12:42:07 +01:00
|
|
|
* @param ConfiguratorMenu $menu
|
2013-11-28 17:36:39 +01:00
|
|
|
*/
|
|
|
|
public function addMenu(ConfiguratorMenu $menu) {
|
|
|
|
array_push($this->menus, $menu);
|
2013-11-28 04:48:04 +01:00
|
|
|
}
|
|
|
|
|
2013-12-30 20:12:53 +01:00
|
|
|
/**
|
2014-05-02 17:50:30 +02:00
|
|
|
* Handle Config Admin Command
|
2013-11-28 17:36:39 +01:00
|
|
|
*
|
2014-01-05 19:00:11 +01:00
|
|
|
* @param array $callback
|
2013-12-31 12:42:07 +01:00
|
|
|
* @param Player $player
|
2013-11-28 17:36:39 +01:00
|
|
|
*/
|
2014-05-02 17:50:30 +02:00
|
|
|
public function handleConfigCommand(array $callback, Player $player) {
|
2017-03-25 18:40:15 +01:00
|
|
|
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_OPEN_CONFIGURATOR)) {
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
|
2014-05-02 17:50:30 +02:00
|
|
|
return;
|
2013-11-28 17:36:39 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 17:50:30 +02:00
|
|
|
$this->showMenu($player);
|
2013-11-28 04:48:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-12-31 13:21:45 +01:00
|
|
|
* Show the Menu to the Player
|
2013-11-28 04:48:04 +01:00
|
|
|
*
|
2013-12-31 12:42:07 +01:00
|
|
|
* @param Player $player
|
2014-07-24 23:12:56 +02:00
|
|
|
* @param mixed $menuId
|
2013-11-28 04:48:04 +01:00
|
|
|
*/
|
2014-01-05 20:02:38 +01:00
|
|
|
public function showMenu(Player $player, $menuId = 0) {
|
2014-07-24 23:12:56 +02:00
|
|
|
if ($menuId instanceof ConfiguratorMenu) {
|
|
|
|
$menuId = $this->getMenuId($menuId->getTitle());
|
|
|
|
}
|
2014-04-30 05:27:23 +02:00
|
|
|
$manialink = $this->buildManialink($menuId, $player);
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getManialinkManager()->displayWidget($manialink, $player, self::MENU_NAME);
|
2014-05-24 16:52:46 +02:00
|
|
|
$player->setCache($this, self::CACHE_MENU_SHOWN, true);
|
2013-11-28 04:48:04 +01:00
|
|
|
}
|
|
|
|
|
2014-07-24 23:12:56 +02:00
|
|
|
/**
|
|
|
|
* Gets the Menu Id
|
|
|
|
*
|
|
|
|
* @param string $title
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getMenuId($title) {
|
|
|
|
$index = 0;
|
|
|
|
foreach ($this->menus as $menu) {
|
|
|
|
if ($menu === $title || $menu->getTitle() === $title) {
|
|
|
|
return $index;
|
|
|
|
}
|
|
|
|
$index++;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-11-28 04:48:04 +01:00
|
|
|
/**
|
2014-05-02 16:13:45 +02:00
|
|
|
* Build Menu ManiaLink if necessary
|
2013-11-28 04:48:04 +01:00
|
|
|
*
|
2014-05-02 17:50:30 +02:00
|
|
|
* @param int $menuIdShown
|
2014-05-02 16:13:45 +02:00
|
|
|
* @param Player $player
|
2014-01-05 20:02:38 +01:00
|
|
|
* @return \FML\ManiaLink
|
2013-11-28 04:48:04 +01:00
|
|
|
*/
|
2014-05-09 19:40:20 +02:00
|
|
|
private function buildManialink($menuIdShown = 0, Player $player = null) {
|
2014-08-13 11:05:52 +02:00
|
|
|
$menuPosX = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_POSX);
|
|
|
|
$menuPosY = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_POSY);
|
|
|
|
$menuWidth = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_WIDTH);
|
|
|
|
$menuHeight = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_HEIGHT);
|
|
|
|
$quadStyle = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_STYLE);
|
|
|
|
$quadSubstyle = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_SUBSTYLE);
|
2014-01-05 19:00:11 +01:00
|
|
|
|
|
|
|
$menuListWidth = $menuWidth * 0.3;
|
2019-01-07 17:16:29 +01:00
|
|
|
$menuItemHeight = 9.;
|
2014-01-05 19:00:11 +01:00
|
|
|
$subMenuWidth = $menuWidth - $menuListWidth;
|
|
|
|
$subMenuHeight = $menuHeight;
|
|
|
|
|
2013-12-15 12:41:43 +01:00
|
|
|
$manialink = new ManiaLink(ManialinkManager::MAIN_MLID);
|
2014-01-05 19:00:11 +01:00
|
|
|
|
2013-11-28 04:48:04 +01:00
|
|
|
$frame = new Frame();
|
2017-03-25 19:15:50 +01:00
|
|
|
$manialink->addChild($frame);
|
2017-03-25 18:40:15 +01:00
|
|
|
$frame->setPosition($menuPosX, $menuPosY, ManialinkManager::MAIN_MANIALINK_Z_VALUE);
|
2014-01-05 19:00:11 +01:00
|
|
|
|
2013-11-28 17:36:39 +01:00
|
|
|
$backgroundQuad = new Quad();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($backgroundQuad);
|
2017-03-25 18:40:15 +01:00
|
|
|
$backgroundQuad->setZ(-1)->setSize($menuWidth, $menuHeight)->setStyles($quadStyle, $quadSubstyle);
|
2014-01-05 19:00:11 +01:00
|
|
|
|
2013-11-28 17:36:39 +01:00
|
|
|
$menuItemsFrame = new Frame();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($menuItemsFrame);
|
2013-11-28 17:36:39 +01:00
|
|
|
$menuItemsFrame->setX($menuWidth * -0.5 + $menuListWidth * 0.5);
|
2017-03-25 18:40:15 +01:00
|
|
|
$menuItemsFrame->setZ(-1);
|
2014-01-05 19:00:11 +01:00
|
|
|
|
2013-11-28 17:36:39 +01:00
|
|
|
$itemsBackgroundQuad = new Quad();
|
2017-03-25 19:15:50 +01:00
|
|
|
$menuItemsFrame->addChild($itemsBackgroundQuad);
|
2015-07-15 01:05:50 +02:00
|
|
|
$backgroundQuad->setZ(-1);
|
2014-08-13 11:05:52 +02:00
|
|
|
$itemsBackgroundQuad->setSize($menuListWidth, $menuHeight)->setStyles($quadStyle, $quadSubstyle);
|
2014-01-05 19:00:11 +01:00
|
|
|
|
2013-11-28 17:36:39 +01:00
|
|
|
$menusFrame = new Frame();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($menusFrame);
|
2013-11-28 17:36:39 +01:00
|
|
|
$menusFrame->setX($menuWidth * -0.5 + $menuListWidth + $subMenuWidth * 0.5);
|
2014-01-05 19:00:11 +01:00
|
|
|
|
2013-11-28 17:36:39 +01:00
|
|
|
// Create script and features
|
2014-05-09 19:40:20 +02:00
|
|
|
$script = $manialink->getScript();
|
2014-01-05 19:00:11 +01:00
|
|
|
|
2014-01-05 20:34:48 +01:00
|
|
|
$menuItemY = $menuHeight * 0.42;
|
|
|
|
$menuId = 0;
|
2014-05-02 17:50:30 +02:00
|
|
|
foreach ($this->menus as $menu) {
|
2013-11-28 17:36:39 +01:00
|
|
|
// Add title
|
2014-07-24 23:12:56 +02:00
|
|
|
$menuItemLabel = new Label_Text();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($menuItemLabel);
|
2017-03-25 18:40:15 +01:00
|
|
|
$menuItemLabel->setX($menuWidth * -0.5 + $menuListWidth * 0.5);
|
|
|
|
$menuItemLabel->setZ(2)->setStyle(Label_Text::STYLE_TextCardRaceRank)->setY($menuItemY)->setSize($menuListWidth * 0.9, $menuItemHeight * 0.9)->setText($menu->getTitle())->setAction(self::ACTION_SELECTMENU . $menuId);
|
2014-01-05 19:00:11 +01:00
|
|
|
|
2014-07-24 23:12:56 +02:00
|
|
|
// Show the menu
|
2014-06-14 14:32:29 +02:00
|
|
|
if ($menuId === $menuIdShown) {
|
2014-04-30 05:27:23 +02:00
|
|
|
$menuControl = $menu->getMenu($subMenuWidth, $subMenuHeight, $script, $player);
|
2014-07-25 17:47:46 +02:00
|
|
|
if ($menuControl) {
|
2017-03-25 19:15:50 +01:00
|
|
|
$menusFrame->addChild($menuControl);
|
2014-07-25 17:47:46 +02:00
|
|
|
} else {
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getChat()->sendError('Error loading Menu!', $player);
|
2014-07-25 17:47:46 +02:00
|
|
|
}
|
2013-12-12 19:41:37 +01:00
|
|
|
}
|
2014-01-05 19:00:11 +01:00
|
|
|
|
2013-11-28 17:36:39 +01:00
|
|
|
$menuItemY -= $menuItemHeight * 1.1;
|
2014-01-05 20:02:38 +01:00
|
|
|
$menuId++;
|
2013-11-28 17:36:39 +01:00
|
|
|
}
|
2014-01-05 19:00:11 +01:00
|
|
|
|
2013-12-04 00:40:37 +01:00
|
|
|
// Add Close Quad (X)
|
|
|
|
$closeQuad = new Quad_Icons64x64_1();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($closeQuad);
|
2014-08-13 11:05:52 +02:00
|
|
|
$closeQuad->setPosition($menuWidth * 0.483, $menuHeight * 0.467, 3)->setSize(6, 6)->setSubStyle($closeQuad::SUBSTYLE_QuitRace)->setAction(ManialinkManager::ACTION_CLOSEWIDGET);
|
2014-01-05 19:00:11 +01:00
|
|
|
|
2013-11-28 17:36:39 +01:00
|
|
|
// Add close button
|
2014-07-24 23:12:56 +02:00
|
|
|
$closeButton = new Label_Text();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($closeButton);
|
2017-03-25 18:40:15 +01:00
|
|
|
$closeButton->setPosition($menuWidth * -0.5 + $menuListWidth * 0.29, $menuHeight * -0.43)->setSize($menuListWidth * 0.3, $menuListWidth * 0.1)->setStyle($closeButton::STYLE_TextButtonNavBack)->setTextPrefix('$999')->setText('Close')->setAction(self::ACTION_TOGGLEMENU);
|
2014-01-05 19:00:11 +01:00
|
|
|
|
2013-11-28 17:36:39 +01:00
|
|
|
// Add save button
|
2014-07-24 23:12:56 +02:00
|
|
|
$saveButton = new Label_Text();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($saveButton);
|
2017-03-25 18:40:15 +01:00
|
|
|
$saveButton->setPosition($menuWidth * -0.5 + $menuListWidth * 0.71, $menuHeight * -0.43)->setSize($menuListWidth * 0.3, $menuListWidth * 0.1)->setStyle($saveButton::STYLE_TextButtonNavBack)->setTextPrefix('$2af')->setText('Save')->setAction(self::ACTION_SAVECONFIG);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-01-05 20:02:38 +01:00
|
|
|
return $manialink;
|
|
|
|
}
|
|
|
|
|
2014-05-02 17:50:30 +02:00
|
|
|
/**
|
|
|
|
* Handle toggle menu action
|
|
|
|
*
|
|
|
|
* @param array $callback
|
|
|
|
* @param Player $player
|
|
|
|
*/
|
|
|
|
public function handleToggleMenuAction(array $callback, Player $player) {
|
|
|
|
$this->toggleMenu($player);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggle the Menu for the Player
|
|
|
|
*
|
|
|
|
* @param Player $player
|
|
|
|
*/
|
|
|
|
public function toggleMenu(Player $player) {
|
2014-05-24 16:52:46 +02:00
|
|
|
if ($player->getCache($this, self::CACHE_MENU_SHOWN)) {
|
2014-05-02 17:50:30 +02:00
|
|
|
$this->hideMenu($player);
|
|
|
|
} else {
|
|
|
|
$this->showMenu($player);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hide the Menu for the Player
|
|
|
|
*
|
|
|
|
* @param Player $player
|
|
|
|
*/
|
|
|
|
public function hideMenu(Player $player) {
|
2014-07-24 23:12:56 +02:00
|
|
|
$this->closeWidget($player);
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getManialinkManager()->closeWidget($player);
|
2014-05-02 17:50:30 +02:00
|
|
|
}
|
|
|
|
|
2014-07-24 23:12:56 +02:00
|
|
|
/**
|
|
|
|
* Handle widget being closed
|
|
|
|
*
|
|
|
|
* @param Player $player
|
|
|
|
*/
|
|
|
|
public function closeWidget(Player $player) {
|
|
|
|
$player->destroyCache($this, self::CACHE_MENU_SHOWN);
|
|
|
|
}
|
|
|
|
|
2014-05-02 17:50:30 +02:00
|
|
|
/**
|
|
|
|
* Save the config data received from the manialink
|
|
|
|
*
|
|
|
|
* @param array $callback
|
|
|
|
* @param Player $player
|
|
|
|
*/
|
|
|
|
public function handleSaveConfigAction(array $callback, Player $player) {
|
|
|
|
foreach ($this->menus as $menu) {
|
|
|
|
$menu->saveConfigData($callback[1], $player);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unset the player if he opened another Main Widget
|
|
|
|
*
|
|
|
|
* @param Player $player
|
2014-07-24 23:12:56 +02:00
|
|
|
* @param string $openedWidget
|
2014-05-02 17:50:30 +02:00
|
|
|
*/
|
|
|
|
public function handleWidgetOpened(Player $player, $openedWidget) {
|
2014-05-24 16:52:46 +02:00
|
|
|
if ($openedWidget !== self::MENU_NAME) {
|
|
|
|
$player->destroyCache($this, self::CACHE_MENU_SHOWN);
|
2014-05-02 17:50:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-05 20:02:38 +01:00
|
|
|
/**
|
|
|
|
* Handle ManialinkPageAnswer Callback
|
|
|
|
*
|
|
|
|
* @param array $callback
|
|
|
|
*/
|
|
|
|
public function handleManialinkPageAnswer(array $callback) {
|
|
|
|
$actionId = $callback[1][2];
|
|
|
|
$boolSelectMenu = (strpos($actionId, self::ACTION_SELECTMENU) === 0);
|
2014-02-13 00:46:41 +01:00
|
|
|
if (!$boolSelectMenu) {
|
2014-01-05 20:02:38 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-24 23:12:56 +02:00
|
|
|
$login = $callback[1][1];
|
2014-08-13 11:05:52 +02:00
|
|
|
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
|
2014-07-24 23:12:56 +02:00
|
|
|
|
|
|
|
if ($player) {
|
|
|
|
$actionArray = explode('.', $callback[1][2]);
|
|
|
|
$this->showMenu($player, intval($actionArray[2]));
|
|
|
|
}
|
2013-11-28 03:47:08 +01:00
|
|
|
}
|
|
|
|
}
|