Custom UI Manager

This commit is contained in:
Steffen Schröder 2013-12-30 14:52:48 +01:00
parent 9bb2495756
commit 2e8a18692c
4 changed files with 325 additions and 155 deletions

View File

@ -2,6 +2,8 @@
namespace FML\Elements;
use FML\Types\Renderable;
/**
* Class representing the Custom_UI
*
@ -119,7 +121,7 @@ class CustomUI implements Renderable {
foreach ($settings as $setting => $value) {
if ($value === null) continue;
$xmlElement = $domDocument->createElement($setting);
$xmlElement->setAttribute('visible', ($value ? 1 : 0));
$xmlElement->setAttribute('visible', ($value ? 'true' : 'false'));
$xml->appendChild($xmlElement);
}
return $xml;

View File

@ -0,0 +1,174 @@
<?php
namespace ManiaControl\Manialinks;
use ManiaControl\ManiaControl;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager;
use FML\ManiaLink;
use FML\Elements\CustomUI;
use FML\Controls\Quad;
use FML\ManiaLinks;
/**
* Class managing the Custom UI Settings
*
* @author steeffeen & kremsy
*/
class CustomUIManager implements CallbackListener {
/**
* Constants
*/
const CUSTOMUI_MLID = 'CustomUI.MLID';
/**
* Private Properties
*/
private $maniaControl = null;
private $manialinks = null;
private $customUI = null;
private $updateManialink = false;
/**
* Create a Custom UI Manager
*
* @param ManiaControl $maniaControl
*/
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
$this->prepareManialink();
// Register for callbacks
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_1_SECOND, $this, 'handle1Second');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERJOINED, $this, 'handlePlayerJoined');
}
/**
* Create the ManiaLink and CustomUI instances
*/
private function prepareManialink() {
$this->customUI = new CustomUI();
}
/**
* Update the CustomUI Manialink
*
* @param Player $player
*/
private function updateManialink(Player $player = null) {
// TODO: improve rendering after FML update
$domDocument = new \DOMDocument();
$element = $this->customUI->render($domDocument);
$domDocument->appendChild($element);
$manialinkText = $domDocument->saveXML();
if ($player) {
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $player->login);
return;
}
$this->maniaControl->manialinkManager->sendManialink($manialinkText);
}
/**
* Handle 1Second Callback
*
* @param array $callback
*/
public function handle1Second(array $callback) {
if (!$this->updateManialink) return;
$this->updateManialink = false;
$this->updateManialink();
}
/**
* Handle PlayerJoined Callback
*
* @param array $callback
*/
public function handlePlayerJoined(array $callback) {
$player = $callback[1];
$this->updateManialink($player);
}
/**
* 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;
}
}

View File

@ -2,17 +2,18 @@
namespace ManiaControl\Manialinks;
use FML\Controls\Control;
use FML\Controls\Frame;
use FML\Controls\Labels\Label_Text;
use FML\ManiaLink;
use ManiaControl\ManiaControl;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Players\Player;
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Players\Player;
use FML\ManiaLink;
use FML\Controls\Control;
use FML\Controls\Frame;
use FML\Controls\Labels\Label_Text;
require_once __DIR__ . '/StyleManager.php';
require_once __DIR__ . '/CustomUIManager.php';
require_once __DIR__ . '/../FML/autoload.php';
/**
@ -22,7 +23,7 @@ require_once __DIR__ . '/../FML/autoload.php';
*/
class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener {
/*
/**
* Constants
*/
const MAIN_MLID = 'Main.ManiaLinkId';
@ -33,6 +34,8 @@ class ManialinkManager implements ManialinkPageAnswerListener,CallbackListener {
* Public properties
*/
public $styleManager = null;
public $customUIManager = null;
/**
* Private properties
*/
@ -48,10 +51,10 @@ class ManialinkManager implements ManialinkPageAnswerListener,CallbackListener {
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
$this->styleManager = new StyleManager($maniaControl);
$this->customUIManager = new CustomUIManager($maniaControl);
// Register for callbacks
$this->registerManialinkPageAnswerListener(self::ACTION_CLOSEWIDGET , $this,
'closeWidgetCallback');
$this->registerManialinkPageAnswerListener(self::ACTION_CLOSEWIDGET, $this, 'closeWidgetCallback');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this,
'handleManialinkPageAnswer');
}
@ -178,6 +181,7 @@ class ManialinkManager implements ManialinkPageAnswerListener,CallbackListener {
/**
* Displays a ManiaLink Widget to a certain Player
*
* @param String $maniaLink
* @param Player $player
*/
@ -188,9 +192,9 @@ class ManialinkManager implements ManialinkPageAnswerListener,CallbackListener {
$this->disableAltMenu($player);
}
/**
* Closes a widget via the callback
*
* @param array $callback
* @param Player $player
*/
@ -200,6 +204,7 @@ class ManialinkManager implements ManialinkPageAnswerListener,CallbackListener {
/**
* Closes the Manialink Widget and enables the Alt Menu
*
* @param Player $player
*/
public function closeWidget(Player $player) {
@ -214,6 +219,7 @@ class ManialinkManager implements ManialinkPageAnswerListener,CallbackListener {
/**
* Adds a line of labels
*
* @param Frame $frame
* @param array $labelStrings
* @param array $properties

View File

@ -1,5 +1,4 @@
<?php
use FML\Controls\Control;
use FML\Controls\Frame;
use FML\Controls\Labels\Label_Text;
@ -14,13 +13,13 @@ use ManiaControl\Players\PlayerManager;
use ManiaControl\Plugins\Plugin;
use ManiaControl\Callbacks\CallbackManager;
/**
* ManiaControl Widget Plugin
*
* @author kremsy
*/
class WidgetPlugin implements CallbackListener, Plugin {
/**
* Constants
*/
@ -29,7 +28,6 @@ class WidgetPlugin implements CallbackListener, Plugin {
const PLUGIN_NAME = 'WidgetPlugin';
const PLUGIN_AUTHOR = 'kremsy';
// MapWidget Properties
const MLID_MAPWIDGET = 'WidgetPlugin.MapWidget';
const SETTING_MAP_WIDGET_ACTIVATED = 'Map-Widget Activated';
@ -54,21 +52,23 @@ class WidgetPlugin implements CallbackListener, Plugin {
const SETTING_NEXTMAP_WIDGET_WIDTH = 'Nextmap-Widget-Size: Width';
const SETTING_NEXTMAP_WIDGET_HEIGHT = 'Nextmap-Widget-Size: Height';
/**
* Private properties
* Private Properties
*/
private $maniaControl = null;
/**
* Load the plugin
*
* @param \ManiaControl\ManiaControl $maniaControl
* @param ManiaControl $maniaControl
* @return bool
*/
public function load(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
// Set CustomUI Setting
$this->maniaControl->manialinkManager->customUIManager->setChallengeInfoVisible(false);
// Register for callbacks
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'handleOnInit');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_BEGINMAP, $this, 'handleOnBeginMap');
@ -105,7 +105,6 @@ class WidgetPlugin implements CallbackListener, Plugin {
unset($this->maniaControl);
}
public function displayClockWidget($login = false) {
$pos_x = $this->maniaControl->settingManager->getSetting($this, self::SETTING_CLOCK_WIDGET_POSX);
$pos_y = $this->maniaControl->settingManager->getSetting($this, self::SETTING_CLOCK_WIDGET_POSY);
@ -143,12 +142,11 @@ class WidgetPlugin implements CallbackListener, Plugin {
// Send manialink
$manialinkText = $maniaLink->render()->saveXML();
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $login);
}
/**
* Displays the Next Map (Only at the end of the Map)
*
* @param bool $login
*/
public function displayNextMapWidget($login = false) {
@ -184,7 +182,8 @@ class WidgetPlugin implements CallbackListener, Plugin {
$map = $this->maniaControl->client->getResponse();
$name = $map['Name'];
$author = $map['Author'];
}else{
}
else {
$requester = $jukedMap[0];
$map = $jukedMap[1];
$name = $map->name;
@ -224,7 +223,6 @@ class WidgetPlugin implements CallbackListener, Plugin {
$label->setText($author);
$label->setTextColor("FFF");
if ($requester != null) {
$label = new Label_Text();
$frame->add($label);
@ -242,25 +240,15 @@ class WidgetPlugin implements CallbackListener, Plugin {
// Send manialink
$manialinkText = $maniaLink->render()->saveXML();
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $login);
}
/**
* Displays the Map Widget
* @param $login
*
* @param
* $login
*/
public function displayMapWidget($login = false) {
$xml = "<manialinks><manialink id='0'><quad></quad></manialink>
<custom_ui>
<challenge_info visible='false'/>
</custom_ui>
</manialinks>";
$this->maniaControl->manialinkManager->sendManialink($xml);
$pos_x = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_POSX);
$pos_y = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_POSY);
$width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_WIDTH);
@ -306,7 +294,6 @@ class WidgetPlugin implements CallbackListener, Plugin {
$label->setText($map->authorLogin);
$label->setTextColor("FFF");
// Send manialink
$manialinkText = $maniaLink->render()->saveXML();
$this->maniaControl->manialinkManager->sendManialink($manialinkText, $login);
@ -314,7 +301,9 @@ class WidgetPlugin implements CallbackListener, Plugin {
/**
* Closes a Widget
* @param $widgetId
*
* @param
* $widgetId
*/
public function closeWidget($widgetId) {
$emptyManialink = new ManiaLink($widgetId);
@ -337,7 +326,6 @@ class WidgetPlugin implements CallbackListener, Plugin {
}
}
/**
* Handle on Begin Map
*
@ -379,9 +367,9 @@ class WidgetPlugin implements CallbackListener, Plugin {
}
}
/**
* Aktualize the clock widget every minute
*
* @param array $callback
*/
public function handleEveryMinute(array $callback) {