removed 'application' folder to have everything in the root directory
This commit is contained in:
173
core/Manialinks/CustomUIManager.php
Normal file
173
core/Manialinks/CustomUIManager.php
Normal file
@ -0,0 +1,173 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Manialinks;
|
||||
|
||||
use FML\CustomUI;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\TimerListener;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Players\Player;
|
||||
use ManiaControl\Players\PlayerManager;
|
||||
|
||||
/**
|
||||
* Class managing the Custom UI in TrackMania
|
||||
*
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class CustomUIManager implements CallbackListener, TimerListener {
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
const CUSTOMUI_MLID = 'CustomUI.MLID';
|
||||
|
||||
/*
|
||||
* Private properties
|
||||
*/
|
||||
/** @var ManiaControl $maniaControl */
|
||||
private $maniaControl = null;
|
||||
/** @var customUI $customUI */
|
||||
private $customUI = null;
|
||||
private $updateManialink = false;
|
||||
|
||||
/**
|
||||
* Create a custom UI manager instance
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
$this->prepareManialink();
|
||||
|
||||
// Callbacks
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerJoined');
|
||||
$this->maniaControl->getTimerManager()->registerTimerListening($this, 'handle1Second', 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the ManiaLink and CustomUI instances
|
||||
*/
|
||||
private function prepareManialink() {
|
||||
$this->customUI = new CustomUI();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle 1 Second Callback
|
||||
*/
|
||||
public function handle1Second() {
|
||||
if (!$this->updateManialink) {
|
||||
return;
|
||||
}
|
||||
$this->updateManialink = false;
|
||||
$this->updateManialink();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the CustomUI Manialink
|
||||
*
|
||||
* @param Player $player
|
||||
*/
|
||||
public function updateManialink(Player $player = null) {
|
||||
if ($player) {
|
||||
$this->maniaControl->getManialinkManager()->sendManialink($this->customUI, $player);
|
||||
return;
|
||||
}
|
||||
$this->maniaControl->getManialinkManager()->sendManialink($this->customUI);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle PlayerJoined Callback
|
||||
*
|
||||
* @param Player $player
|
||||
*/
|
||||
public function handlePlayerJoined(Player $player) {
|
||||
$this->updateManialink($player);
|
||||
|
||||
//TODO: validate necessity
|
||||
//send it again after 500ms
|
||||
$this->maniaControl->getTimerManager()->registerOneTimeListening($this, function () use (&$player) {
|
||||
$this->updateManialink($player);
|
||||
}, 500);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Showing of Notices
|
||||
*
|
||||
* @param bool $visible
|
||||
*/
|
||||
public function setNoticeVisible($visible) {
|
||||
$this->customUI->setNoticeVisible($visible);
|
||||
$this->updateManialink = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Showing of the Challenge Info
|
||||
*
|
||||
* @param bool $visible
|
||||
*/
|
||||
public function setChallengeInfoVisible($visible) {
|
||||
$this->customUI->setChallengeInfoVisible($visible);
|
||||
$this->updateManialink = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Showing of the Net Infos
|
||||
*
|
||||
* @param bool $visible
|
||||
*/
|
||||
public function setNetInfosVisible($visible) {
|
||||
$this->customUI->setNetInfosVisible($visible);
|
||||
$this->updateManialink = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Showing of the Chat
|
||||
*
|
||||
* @param bool $visible
|
||||
*/
|
||||
public function setChatVisible($visible) {
|
||||
$this->customUI->setChatVisible($visible);
|
||||
$this->updateManialink = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Showing of the Checkpoint List
|
||||
*
|
||||
* @param bool $visible
|
||||
*/
|
||||
public function setCheckpointListVisible($visible) {
|
||||
$this->customUI->setCheckpointListVisible($visible);
|
||||
$this->updateManialink = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Showing of Round Scores
|
||||
*
|
||||
* @param bool $visible
|
||||
*/
|
||||
public function setRoundScoresVisible($visible) {
|
||||
$this->customUI->setRoundScoresVisible($visible);
|
||||
$this->updateManialink = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Showing of the Scoretable
|
||||
*
|
||||
* @param bool $visible
|
||||
*/
|
||||
public function setScoretableVisible($visible) {
|
||||
$this->customUI->setScoretableVisible($visible);
|
||||
$this->updateManialink = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Global Showing
|
||||
*
|
||||
* @param bool $visible
|
||||
*/
|
||||
public function setGlobalVisible($visible) {
|
||||
$this->customUI->setGlobalVisible($visible);
|
||||
$this->updateManialink = true;
|
||||
}
|
||||
}
|
128
core/Manialinks/IconManager.php
Normal file
128
core/Manialinks/IconManager.php
Normal file
@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Manialinks;
|
||||
|
||||
use FML\Controls\Frame;
|
||||
use FML\Controls\Quad;
|
||||
use FML\ManiaLink;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\Callbacks;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Players\Player;
|
||||
use ManiaControl\Players\PlayerManager;
|
||||
|
||||
/**
|
||||
* Class managing Icons
|
||||
*
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class IconManager implements CallbackListener {
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
const DEFAULT_IMG_URL = 'http://images.maniacontrol.com/icons/';
|
||||
const PRELOAD_MLID = 'IconManager.Preload.MLID';
|
||||
|
||||
/*
|
||||
* Default icons
|
||||
*/
|
||||
const MX_ICON = 'ManiaExchange.png';
|
||||
const MX_ICON_MOVER = 'ManiaExchange_logo_press.png';
|
||||
|
||||
const MX_ICON_GREEN = 'ManiaExchangeGreen.png';
|
||||
const MX_ICON_GREEN_MOVER = 'ManiaExchange_logo_pressGreen.png';
|
||||
|
||||
/*
|
||||
* Private properties
|
||||
*/
|
||||
/** @var ManiaControl $maniaControl */
|
||||
private $maniaControl = null;
|
||||
private $icons = array();
|
||||
|
||||
/**
|
||||
* Construct a new icon manager instance
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
$this->addDefaultIcons();
|
||||
|
||||
// Callbacks
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::AFTERINIT, $this, 'handleAfterInit');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the set of default icons
|
||||
*/
|
||||
private function addDefaultIcons() {
|
||||
$this->addIcon(self::MX_ICON);
|
||||
$this->addIcon(self::MX_ICON_MOVER);
|
||||
$this->addIcon(self::MX_ICON_GREEN);
|
||||
$this->addIcon(self::MX_ICON_GREEN_MOVER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an Icon
|
||||
*
|
||||
* @param string $iconName
|
||||
* @param string $iconLink
|
||||
*/
|
||||
public function addIcon($iconName, $iconLink = self::DEFAULT_IMG_URL) {
|
||||
$this->icons[$iconName] = $iconLink . '/' . $iconName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an Icon by its Name
|
||||
*
|
||||
* @param string $iconName
|
||||
* @return string
|
||||
*/
|
||||
public function getIcon($iconName) {
|
||||
if (!isset($this->icons[$iconName])) {
|
||||
return null;
|
||||
}
|
||||
return $this->icons[$iconName];
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle OnInit Callback
|
||||
*/
|
||||
public function handleAfterInit() {
|
||||
$this->preloadIcons();
|
||||
}
|
||||
|
||||
/**
|
||||
* Preload Icons
|
||||
*
|
||||
* @param Player $player
|
||||
*/
|
||||
public function preloadIcons($player = null) {
|
||||
$maniaLink = new ManiaLink(self::PRELOAD_MLID);
|
||||
$frame = new Frame();
|
||||
$maniaLink->add($frame);
|
||||
$frame->setPosition(500, 500);
|
||||
|
||||
foreach ($this->icons as $iconUrl) {
|
||||
$iconQuad = new Quad();
|
||||
$iconQuad->setImage($iconUrl);
|
||||
$iconQuad->setSize(1, 1);
|
||||
$frame->add($iconQuad);
|
||||
}
|
||||
|
||||
// Send manialink
|
||||
$this->maniaControl->getManialinkManager()->sendManialink($maniaLink, $player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle PlayerConnect Callback
|
||||
*
|
||||
* @param Player $player
|
||||
*/
|
||||
public function handlePlayerConnect(Player $player) {
|
||||
$this->preloadIcons($player);
|
||||
}
|
||||
}
|
377
core/Manialinks/ManialinkManager.php
Normal file
377
core/Manialinks/ManialinkManager.php
Normal file
@ -0,0 +1,377 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Manialinks;
|
||||
|
||||
use FML\Controls\Control;
|
||||
use FML\Controls\Frame;
|
||||
use FML\Controls\Labels\Label_Text;
|
||||
use FML\ManiaLink;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\CallbackManager;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Players\Player;
|
||||
use Maniaplanet\DedicatedServer\Xmlrpc\GameModeException;
|
||||
use Maniaplanet\DedicatedServer\Xmlrpc\UnknownPlayerException;
|
||||
|
||||
/**
|
||||
* Manialink Manager Class
|
||||
*
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener {
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
const MAIN_MLID = 'Main.ManiaLinkId';
|
||||
const ACTION_CLOSEWIDGET = 'ManiaLinkManager.CloseWidget';
|
||||
const CB_MAIN_WINDOW_CLOSED = 'ManialinkManagerCallback.MainWindowClosed';
|
||||
const CB_MAIN_WINDOW_OPENED = 'ManialinkManagerCallback.MainWindowOpened';
|
||||
|
||||
/*
|
||||
* Public properties
|
||||
*/
|
||||
/** @var StyleManager $styleManager */
|
||||
/** @deprecated see getStyleManager() */
|
||||
public $styleManager = null;
|
||||
/** @var CustomUIManager $customUIManager */
|
||||
/** @deprecated see getCustomUIManager() */
|
||||
public $customUIManager = null;
|
||||
/** @var IconManager $iconManager */
|
||||
/** @deprecated see getIconManager() */
|
||||
public $iconManager = null;
|
||||
|
||||
/*
|
||||
* Private properties
|
||||
*/
|
||||
/** @var ManiaControl $maniaControl */
|
||||
private $maniaControl = null;
|
||||
// TODO: use listening class
|
||||
private $pageAnswerListeners = array();
|
||||
private $pageAnswerRegexListener = array();
|
||||
|
||||
/**
|
||||
* Construct a new manialink manager instance
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
// Children
|
||||
$this->styleManager = new StyleManager($maniaControl);
|
||||
$this->customUIManager = new CustomUIManager($maniaControl);
|
||||
$this->iconManager = new IconManager($maniaControl);
|
||||
|
||||
// Callbacks
|
||||
$this->registerManialinkPageAnswerListener(self::ACTION_CLOSEWIDGET, $this, 'closeWidgetCallback');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a new manialink page answer listener
|
||||
*
|
||||
* @param string $actionId
|
||||
* @param ManialinkPageAnswerListener $listener
|
||||
* @param string $method
|
||||
* @return bool
|
||||
*/
|
||||
public function registerManialinkPageAnswerListener($actionId, ManialinkPageAnswerListener $listener, $method) {
|
||||
if (!method_exists($listener, $method)) {
|
||||
trigger_error("Given listener for actionId '{$actionId}' doesn't have callback method '{$method}'!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!array_key_exists($actionId, $this->pageAnswerListeners) || !is_array($this->pageAnswerListeners[$actionId])) {
|
||||
// Init listeners array
|
||||
$this->pageAnswerListeners[$actionId] = array();
|
||||
}
|
||||
|
||||
// Register page answer listener
|
||||
array_push($this->pageAnswerListeners[$actionId], array($listener, $method));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the style manager
|
||||
*
|
||||
* @return StyleManager
|
||||
*/
|
||||
public function getStyleManager() {
|
||||
return $this->styleManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the custom UI manager
|
||||
*
|
||||
* @return CustomUIManager
|
||||
*/
|
||||
public function getCustomUIManager() {
|
||||
return $this->customUIManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the icon manager
|
||||
*
|
||||
* @return IconManager
|
||||
*/
|
||||
public function getIconManager() {
|
||||
return $this->iconManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a new manialink page answer reg ex listener
|
||||
*
|
||||
* @param string $actionIdRegex
|
||||
* @param ManialinkPageAnswerListener $listener
|
||||
* @param string $method
|
||||
* @return bool
|
||||
*/
|
||||
public function registerManialinkPageAnswerRegexListener($actionIdRegex, ManialinkPageAnswerListener $listener, $method) {
|
||||
if (!method_exists($listener, $method)) {
|
||||
trigger_error("Given listener for actionIdRegex '{$actionIdRegex}' doesn't have callback method '{$method}'!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!array_key_exists($actionIdRegex, $this->pageAnswerRegexListener) || !is_array($this->pageAnswerRegexListener[$actionIdRegex])) {
|
||||
// Init regex listeners array
|
||||
$this->pageAnswerRegexListener[$actionIdRegex] = array();
|
||||
}
|
||||
|
||||
// Register page answer regex listener
|
||||
array_push($this->pageAnswerRegexListener[$actionIdRegex], array($listener, $method));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a Manialink Page Answer Listener
|
||||
*
|
||||
* @param ManialinkPageAnswerListener $listener
|
||||
* @return bool
|
||||
*/
|
||||
public function unregisterManialinkPageAnswerListener(ManialinkPageAnswerListener $listener) {
|
||||
$removed = false;
|
||||
$allListeners = array_merge($this->pageAnswerListeners, $this->pageAnswerRegexListener);
|
||||
foreach ($allListeners as &$listeners) {
|
||||
foreach ($listeners as $key => &$listenerCallback) {
|
||||
if ($listenerCallback[0] !== $listener) {
|
||||
continue;
|
||||
}
|
||||
unset($listeners[$key]);
|
||||
$removed = true;
|
||||
}
|
||||
}
|
||||
return $removed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle ManialinkPageAnswer callback
|
||||
*
|
||||
* @param array $callback
|
||||
*/
|
||||
public function handleManialinkPageAnswer(array $callback) {
|
||||
$actionId = $callback[1][2];
|
||||
$login = $callback[1][1];
|
||||
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
|
||||
|
||||
if (array_key_exists($actionId, $this->pageAnswerListeners) && is_array($this->pageAnswerListeners[$actionId])) {
|
||||
// Inform page answer listeners
|
||||
foreach ($this->pageAnswerListeners[$actionId] as $listener) {
|
||||
call_user_func($listener, $callback, $player);
|
||||
}
|
||||
}
|
||||
|
||||
// Check regex listeners
|
||||
foreach ($this->pageAnswerRegexListener as $actionIdRegex => $pageAnswerRegexListeners) {
|
||||
if (preg_match($actionIdRegex, $actionId)) {
|
||||
// Inform page answer regex listeners
|
||||
foreach ($pageAnswerRegexListeners as $listener) {
|
||||
call_user_func($listener, $callback, $player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a ManiaLink Widget to a certain Player (Should only be used on Main Widgets)
|
||||
*
|
||||
* @param mixed $maniaLink
|
||||
* @param mixed $player
|
||||
* @param string $widgetName
|
||||
*/
|
||||
public function displayWidget($maniaLink, $player, $widgetName = null) {
|
||||
// render and display xml
|
||||
$this->sendManialink($maniaLink, $player);
|
||||
|
||||
if ($widgetName) {
|
||||
// TODO make check by manialinkId, getter is needed to avoid uses on non main widgets
|
||||
$this->disableAltMenu($player);
|
||||
// Trigger callback
|
||||
$player = $this->maniaControl->getPlayerManager()->getPlayer($player);
|
||||
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_MAIN_WINDOW_OPENED, $player, $widgetName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the given manialink to players
|
||||
*
|
||||
* @param string $manialinkText
|
||||
* @param mixed $logins
|
||||
* @param int $timeout
|
||||
* @param bool $hideOnClick
|
||||
* @return bool
|
||||
*/
|
||||
public function sendManialink($manialinkText, $logins = null, $timeout = 0, $hideOnClick = false) {
|
||||
$manialinkText = (string)$manialinkText;
|
||||
|
||||
if (!$manialinkText) {
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
if (!$logins) {
|
||||
return $this->maniaControl->getClient()->sendDisplayManialinkPage(null, $manialinkText, $timeout, $hideOnClick);
|
||||
}
|
||||
if (is_string($logins)) {
|
||||
$success = $this->maniaControl->getClient()->sendDisplayManialinkPage($logins, $manialinkText, $timeout, $hideOnClick);
|
||||
return $success;
|
||||
}
|
||||
if ($logins instanceof Player) {
|
||||
$success = $this->maniaControl->getClient()->sendDisplayManialinkPage($logins->login, $manialinkText, $timeout, $hideOnClick);
|
||||
return $success;
|
||||
}
|
||||
if (is_array($logins)) {
|
||||
$success = true;
|
||||
foreach ($logins as $login) {
|
||||
$subSuccess = $this->sendManialink($manialinkText, $login, $timeout, $hideOnClick);
|
||||
if (!$subSuccess) {
|
||||
$success = false;
|
||||
}
|
||||
}
|
||||
return $success;
|
||||
}
|
||||
} catch (UnknownPlayerException $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the alt menu for the player
|
||||
*
|
||||
* @param mixed $player
|
||||
* @return bool
|
||||
*/
|
||||
public function disableAltMenu($player) {
|
||||
$login = Player::parseLogin($player);
|
||||
try {
|
||||
$success = $this->maniaControl->getClient()->triggerModeScriptEvent('LibXmlRpc_DisableAltMenu', $login);
|
||||
} catch (GameModeException $e) {
|
||||
return false;
|
||||
}
|
||||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes a widget via the callback
|
||||
*
|
||||
* @param array $callback
|
||||
* @param Player $player
|
||||
*/
|
||||
public function closeWidgetCallback(array $callback, Player $player) {
|
||||
$this->closeWidget($player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes a Manialink Widget
|
||||
*
|
||||
* @param mixed $player
|
||||
* @param bool $widgetId
|
||||
*/
|
||||
public function closeWidget($player, $widgetId = false) {
|
||||
if (!$widgetId) {
|
||||
$this->hideManialink(self::MAIN_MLID, $player);
|
||||
$this->enableAltMenu($player);
|
||||
|
||||
// Trigger callback
|
||||
$player = $this->maniaControl->getPlayerManager()->getPlayer($player);
|
||||
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_MAIN_WINDOW_CLOSED, $player);
|
||||
} else {
|
||||
$this->hideManialink($widgetId, $player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide the Manialink with the given Id
|
||||
*
|
||||
* @param mixed $manialinkId
|
||||
* @param mixed $logins
|
||||
*/
|
||||
public function hideManialink($manialinkId, $logins = null) {
|
||||
if (is_array($manialinkId)) {
|
||||
foreach ($manialinkId as $mlId) {
|
||||
$this->hideManialink($mlId, $logins);
|
||||
}
|
||||
} else {
|
||||
$emptyManialink = new ManiaLink($manialinkId);
|
||||
$this->sendManialink($emptyManialink, $logins);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the alt menu for the player
|
||||
*
|
||||
* @param mixed $player
|
||||
* @return bool
|
||||
*/
|
||||
public function enableAltMenu($player) {
|
||||
$login = Player::parseLogin($player);
|
||||
try {
|
||||
$success = $this->maniaControl->getClient()->triggerModeScriptEvent('LibXmlRpc_EnableAltMenu', $login);
|
||||
} catch (GameModeException $e) {
|
||||
return false;
|
||||
}
|
||||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a line of labels
|
||||
*
|
||||
* @param Frame $frame
|
||||
* @param array $labelStrings
|
||||
* @param array $properties
|
||||
* @return Label_Text[]
|
||||
*/
|
||||
public function labelLine(Frame $frame, array $labelStrings, array $properties = array()) {
|
||||
// define standard properties
|
||||
$hAlign = (isset($properties['hAlign']) ? $properties['hAlign'] : Control::LEFT);
|
||||
$style = (isset($properties['style']) ? $properties['style'] : Label_Text::STYLE_TextCardSmall);
|
||||
$textSize = (isset($properties['textSize']) ? $properties['textSize'] : 1.5);
|
||||
$textColor = (isset($properties['textColor']) ? $properties['textColor'] : 'FFF');
|
||||
$profile = (isset($properties['profile']) ? $properties['profile'] : false);
|
||||
|
||||
$labels = array();
|
||||
foreach ($labelStrings as $text => $x) {
|
||||
$label = new Label_Text();
|
||||
$frame->add($label);
|
||||
$label->setHAlign($hAlign);
|
||||
$label->setX($x);
|
||||
$label->setStyle($style);
|
||||
$label->setTextSize($textSize);
|
||||
$label->setText($text);
|
||||
$label->setTextColor($textColor);
|
||||
|
||||
if ($profile) {
|
||||
$label->addPlayerProfileFeature($profile);
|
||||
}
|
||||
|
||||
array_push($labels, $label);
|
||||
}
|
||||
|
||||
return $labels;
|
||||
}
|
||||
}
|
13
core/Manialinks/ManialinkPageAnswerListener.php
Normal file
13
core/Manialinks/ManialinkPageAnswerListener.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Manialinks;
|
||||
|
||||
/**
|
||||
* Interface for Manialink Page Answer Listeners
|
||||
*
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
interface ManialinkPageAnswerListener {
|
||||
}
|
213
core/Manialinks/StyleManager.php
Normal file
213
core/Manialinks/StyleManager.php
Normal file
@ -0,0 +1,213 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Manialinks;
|
||||
|
||||
use FML\Controls\Frame;
|
||||
use FML\Controls\Label;
|
||||
use FML\Controls\Labels\Label_Text;
|
||||
use FML\Controls\Quad;
|
||||
use FML\Controls\Quads\Quad_BgRaceScore2;
|
||||
use FML\Controls\Quads\Quad_Bgs1InRace;
|
||||
use FML\Controls\Quads\Quad_Icons64x64_1;
|
||||
use FML\Script\Features\Paging;
|
||||
use FML\Script\Script;
|
||||
use ManiaControl\ManiaControl;
|
||||
|
||||
/**
|
||||
* Class managing default Control Styles
|
||||
*
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class StyleManager {
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
const SETTING_LABEL_DEFAULT_STYLE = 'Default Label Style';
|
||||
const SETTING_QUAD_DEFAULT_STYLE = 'Default Quad Style';
|
||||
const SETTING_QUAD_DEFAULT_SUBSTYLE = 'Default Quad SubStyle';
|
||||
|
||||
const SETTING_MAIN_WIDGET_DEFAULT_STYLE = 'Main Widget Default Quad Style';
|
||||
const SETTING_MAIN_WIDGET_DEFAULT_SUBSTYLE = 'Main Widget Default Quad SubStyle';
|
||||
const SETTING_LIST_WIDGETS_WIDTH = 'List Widgets Width';
|
||||
const SETTING_LIST_WIDGETS_HEIGHT = 'List Widgets Height';
|
||||
|
||||
const SETTING_ICON_DEFAULT_OFFSET_SM = 'Default Icon Offset in ShootMania';
|
||||
|
||||
/*
|
||||
* Private properties
|
||||
*/
|
||||
/** @var ManiaControl $maniaControl */
|
||||
private $maniaControl = null;
|
||||
|
||||
/**
|
||||
* Construct a new style manager instance
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
// Settings
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_LABEL_DEFAULT_STYLE, Label_Text::STYLE_TextTitle1);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_QUAD_DEFAULT_STYLE, Quad_Bgs1InRace::STYLE);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_QUAD_DEFAULT_SUBSTYLE, Quad_Bgs1InRace::SUBSTYLE_BgTitleShadow);
|
||||
|
||||
// Main Widget
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MAIN_WIDGET_DEFAULT_STYLE, Quad_BgRaceScore2::STYLE);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_MAIN_WIDGET_DEFAULT_SUBSTYLE, Quad_BgRaceScore2::SUBSTYLE_HandleSelectable);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_LIST_WIDGETS_WIDTH, 150.);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_LIST_WIDGETS_HEIGHT, 80.);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_ICON_DEFAULT_OFFSET_SM, 20.);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default Icon Offset for shootmania
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getDefaultIconOffsetSM() {
|
||||
return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_ICON_DEFAULT_OFFSET_SM);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default label style
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultLabelStyle() {
|
||||
return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_LABEL_DEFAULT_STYLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default quad style
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultQuadStyle() {
|
||||
return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_QUAD_DEFAULT_STYLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default quad substyle
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultQuadSubstyle() {
|
||||
return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_QUAD_DEFAULT_SUBSTYLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Default Description Label
|
||||
*
|
||||
* @return \FML\Controls\Label
|
||||
*/
|
||||
public function getDefaultDescriptionLabel() {
|
||||
$width = $this->getListWidgetsWidth();
|
||||
$height = $this->getListWidgetsHeight();
|
||||
|
||||
// Predefine Description Label
|
||||
$descriptionLabel = new Label();
|
||||
$descriptionLabel->setAlign($descriptionLabel::LEFT, $descriptionLabel::TOP)->setPosition($width * -0.5 + 10, $height * -0.5 + 5)->setSize($width * 0.7, 4)->setTextSize(2)->setVisible(false);
|
||||
|
||||
return $descriptionLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Default List Widgets Width
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getListWidgetsWidth() {
|
||||
return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_LIST_WIDGETS_WIDTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default list widget height
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getListWidgetsHeight() {
|
||||
return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_LIST_WIDGETS_HEIGHT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the Default List Frame
|
||||
*
|
||||
* @param mixed $script
|
||||
* @param mixed $paging
|
||||
* @return \FML\Controls\Frame
|
||||
*/
|
||||
public function getDefaultListFrame($script = null, $paging = null) {
|
||||
$args = func_get_args();
|
||||
$script = null;
|
||||
$paging = null;
|
||||
foreach ($args as $arg) {
|
||||
if ($arg instanceof Script) {
|
||||
$script = $arg;
|
||||
}
|
||||
if ($arg instanceof Paging) {
|
||||
$paging = $arg;
|
||||
}
|
||||
}
|
||||
|
||||
$width = $this->getListWidgetsWidth();
|
||||
$height = $this->getListWidgetsHeight();
|
||||
$quadStyle = $this->getDefaultMainWindowStyle();
|
||||
$quadSubstyle = $this->getDefaultMainWindowSubStyle();
|
||||
|
||||
// mainframe
|
||||
$frame = new Frame();
|
||||
$frame->setSize($width, $height)->setZ(35); //TODO place before scoreboards
|
||||
|
||||
// Background Quad
|
||||
$backgroundQuad = new Quad();
|
||||
$frame->add($backgroundQuad);
|
||||
$backgroundQuad->setZ(-2)->setSize($width, $height)->setStyles($quadStyle, $quadSubstyle);
|
||||
|
||||
// Add Close Quad (X)
|
||||
$closeQuad = new Quad_Icons64x64_1();
|
||||
$frame->add($closeQuad);
|
||||
$closeQuad->setPosition($width * 0.483, $height * 0.467, 3)->setSize(6, 6)->setSubStyle($closeQuad::SUBSTYLE_QuitRace)->setAction(ManialinkManager::ACTION_CLOSEWIDGET);
|
||||
|
||||
if ($script) {
|
||||
$pagerSize = 6.;
|
||||
$pagerPrev = new Quad_Icons64x64_1();
|
||||
$frame->add($pagerPrev);
|
||||
$pagerPrev->setPosition($width * 0.42, $height * -0.44, 2)->setSize($pagerSize, $pagerSize)->setSubStyle($pagerPrev::SUBSTYLE_ArrowPrev);
|
||||
|
||||
$pagerNext = new Quad_Icons64x64_1();
|
||||
$frame->add($pagerNext);
|
||||
$pagerNext->setPosition($width * 0.45, $height * -0.44, 2)->setSize($pagerSize, $pagerSize)->setSubStyle($pagerNext::SUBSTYLE_ArrowNext);
|
||||
|
||||
$pageCountLabel = new Label_Text();
|
||||
$frame->add($pageCountLabel);
|
||||
$pageCountLabel->setHAlign($pageCountLabel::RIGHT)->setPosition($width * 0.40, $height * -0.44, 1)->setStyle($pageCountLabel::STYLE_TextTitle1)->setTextSize(1.3);
|
||||
|
||||
if ($paging) {
|
||||
$paging->addButton($pagerNext)->addButton($pagerPrev)->setLabel($pageCountLabel);
|
||||
}
|
||||
}
|
||||
|
||||
return $frame;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default main window style
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultMainWindowStyle() {
|
||||
return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAIN_WIDGET_DEFAULT_STYLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default main window substyle
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultMainWindowSubStyle() {
|
||||
return $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MAIN_WIDGET_DEFAULT_SUBSTYLE);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user