From a77b901f78e0cbea172383c81db67e96e67b86d2 Mon Sep 17 00:00:00 2001 From: kremsy Date: Fri, 21 Apr 2017 21:09:21 +0200 Subject: [PATCH] not working ui property manager update start --- .../Common/UIPropertiesBaseStructure.php | 11 +++- core/Manialinks/CustomUIManager.php | 52 ++++++++++++++++++- core/Script/ModeScriptEventManager.php | 6 ++- .../core/Manialinks/CustomUIManagerTest.php | 38 ++++++++++++++ 4 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 phpunittests/core/Manialinks/CustomUIManagerTest.php diff --git a/core/Callbacks/Structures/Common/UIPropertiesBaseStructure.php b/core/Callbacks/Structures/Common/UIPropertiesBaseStructure.php index 79a5206c..e367619a 100644 --- a/core/Callbacks/Structures/Common/UIPropertiesBaseStructure.php +++ b/core/Callbacks/Structures/Common/UIPropertiesBaseStructure.php @@ -24,7 +24,7 @@ class UIPropertiesBaseStructure extends BaseResponseStructure { */ public function __construct(ManiaControl $maniaControl, $data) { parent::__construct($maniaControl, $data); - + $this->uiPropertiesXML = $data[1]; $this->uiPropertiesJson = $data[2]; } @@ -55,4 +55,13 @@ class UIPropertiesBaseStructure extends BaseResponseStructure { public function getUiPropertiesObject() { return json_decode($this->uiPropertiesJson); } + + /** + * Gets the UI Properties as JSON Decoded Array + * + * @return mixed + */ + public function getUiPropertiesArray() { + return json_decode($this->uiPropertiesJson, true); + } } \ No newline at end of file diff --git a/core/Manialinks/CustomUIManager.php b/core/Manialinks/CustomUIManager.php index 5f310030..0cfae11a 100644 --- a/core/Manialinks/CustomUIManager.php +++ b/core/Manialinks/CustomUIManager.php @@ -4,6 +4,8 @@ namespace ManiaControl\Manialinks; use FML\CustomUI; use ManiaControl\Callbacks\CallbackListener; +use ManiaControl\Callbacks\Callbacks; +use ManiaControl\Callbacks\Structures\Common\UIPropertiesBaseStructure; use ManiaControl\Callbacks\TimerListener; use ManiaControl\General\UsageInformationAble; use ManiaControl\General\UsageInformationTrait; @@ -20,7 +22,7 @@ use ManiaControl\Players\PlayerManager; */ class CustomUIManager implements CallbackListener, TimerListener, UsageInformationAble { use UsageInformationTrait; - + /* * Constants */ @@ -35,6 +37,13 @@ class CustomUIManager implements CallbackListener, TimerListener, UsageInformati private $customUI = null; private $updateManialink = false; + /** + * ShootMania UI Properties + * + * @var \ManiaControl\Callbacks\Structures\Common\UIPropertiesBaseStructure + */ + private $shootManiaUIProperties; + /** * Create a custom UI manager instance * @@ -47,6 +56,36 @@ class CustomUIManager implements CallbackListener, TimerListener, UsageInformati // Callbacks $this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerJoined'); $this->maniaControl->getTimerManager()->registerTimerListening($this, 'handle1Second', 1000); + + + //Initilize on Init the Properties + $this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::AFTERINIT, $this, function () { + $this->maniaControl->getModeScriptEventManager()->getShootmaniaUIProperties(); + }); + + //Update the Structure if its Changed + $this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::SM_UIPROPERTIES, $this, function (UIPropertiesBaseStructure $structure) { + $this->shootManiaUIProperties = $structure; + + //var_dump("UI_PROP"); + //var_dump($structure->getUiPropertiesXML()); + }); + } + + /** + * Enable the Notices + */ + public function enableNotices() { //TODO what happens if you set severall at once, than you propably mistakly use the old JSON, so there is the need to update internal json + $xml = str_replace("", "", $this->shootManiaUIProperties->getUiPropertiesXML()); + $this->maniaControl->getModeScriptEventManager()->setShootmaniaUIProperties($xml); + } + + /** + * Disables the Notices + */ + public function disableNotices() { + $xml = str_replace("", "", $this->shootManiaUIProperties->getUiPropertiesXML()); + $this->maniaControl->getModeScriptEventManager()->setShootmaniaUIProperties($xml); } /** @@ -98,6 +137,8 @@ class CustomUIManager implements CallbackListener, TimerListener, UsageInformati /** * Set Showing of Notices * + * @see \ManiaControl\Manialinks\CustomUIManager::enableNotices() + * @deprecated * @param bool $visible */ public function setNoticeVisible($visible) { @@ -174,4 +215,13 @@ class CustomUIManager implements CallbackListener, TimerListener, UsageInformati $this->customUI->setGlobalVisible($visible); $this->updateManialink = true; } + + /** + * Get the Shootmania UI Properties + * + * @return \ManiaControl\Callbacks\Structures\Common\UIPropertiesBaseStructure + */ + public function getShootManiaUIProperties() { + return $this->shootManiaUIProperties; + } } diff --git a/core/Script/ModeScriptEventManager.php b/core/Script/ModeScriptEventManager.php index 272b68d7..0accc389 100644 --- a/core/Script/ModeScriptEventManager.php +++ b/core/Script/ModeScriptEventManager.php @@ -372,9 +372,11 @@ class ModeScriptEventManager implements UsageInformationAble { * * @api * @param string Json-Encoded Xml UI Property String + * @return \ManiaControl\Script\InvokeScriptCallback You can directly set a callable on it via setCallable() to get the updated Properties */ public function setShootmaniaUIProperties($properties) { - $this->maniaControl->getClient()->triggerModeScriptEvent(' Shootmania.UI.SetProperties', array($properties)); + $this->maniaControl->getClient()->triggerModeScriptEvent('Shootmania.UI.SetProperties', array($properties)); + return $this->getShootmaniaUIProperties(); } /** @@ -428,9 +430,11 @@ class ModeScriptEventManager implements UsageInformationAble { * * @api * @param string Json-Encoded Xml UI Property String + * @return \ManiaControl\Script\InvokeScriptCallback You can directly set a callable on it via setCallable() to get the updated Properties */ public function setTrackmaniaUIProperties($properties) { $this->maniaControl->getClient()->triggerModeScriptEvent('Trackmania.UI.GetProperties', array($properties)); + return $this->getTrackmaniaUIProperties(); } /** diff --git a/phpunittests/core/Manialinks/CustomUIManagerTest.php b/phpunittests/core/Manialinks/CustomUIManagerTest.php new file mode 100644 index 00000000..c7362414 --- /dev/null +++ b/phpunittests/core/Manialinks/CustomUIManagerTest.php @@ -0,0 +1,38 @@ + + * @copyright 2014-2017 ManiaControl Team + * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 + */ +class CustomUIManagerTest extends PHPUnit_Framework_TestCase { + public function testUiProperties() { //Not Working Yet + $maniaControl = new ManiaControl(); + $maniaControl->connect(); + + $customUiManager = $maniaControl->getManialinkManager()->getCustomUIManager(); + $maniaControl->run(3); + + //Connect Again and Disable Notices + $maniaControl->connect(); + $customUiManager->disableNotices(); + + $maniaControl->run(3); + + $this->assertFalse($customUiManager->getShootManiaUIProperties()->getUiPropertiesObject()->notices->visible); + + //Connect Again and Disable Notices + $maniaControl->connect(); + $customUiManager->enableNotices(); + + $maniaControl->run(3); + + var_dump($customUiManager->getShootManiaUIProperties()->getUiPropertiesObject()->notices); + $this->assertTrue($customUiManager->getShootManiaUIProperties()->getUiPropertiesObject()->notices->visible); + + } +}