From ce499759e717c7b18edc642fcd0bfb7029d4f696 Mon Sep 17 00:00:00 2001 From: Beu Date: Thu, 3 Mar 2022 19:03:02 +0100 Subject: [PATCH] Add setting to change toggle button --- core/Manialinks/ToggleInterfaceManager.php | 26 ++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/core/Manialinks/ToggleInterfaceManager.php b/core/Manialinks/ToggleInterfaceManager.php index 0b4d748f..2313272f 100644 --- a/core/Manialinks/ToggleInterfaceManager.php +++ b/core/Manialinks/ToggleInterfaceManager.php @@ -7,6 +7,9 @@ use ManiaControl\Callbacks\Callbacks; use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Players\Player; use ManiaControl\Players\PlayerManager; +use ManiaControl\Settings\Setting; +use ManiaControl\Settings\SettingManager; + use FML\ManiaLink; @@ -23,6 +26,7 @@ class ToggleInterfaceManager implements CallbackListener { * Constants */ const MLID = 'ToggleInterface.KeyListener'; + const SETTING_KEYNAME = 'Key Name (or code) to toggle the ManiaControl UI'; /* * Private properties @@ -40,12 +44,16 @@ class ToggleInterfaceManager implements CallbackListener { public function __construct(ManiaControl $maniaControl) { $this->maniaControl = $maniaControl; + // Settings + $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_KEYNAME, "F9"); + + // Build Manialink $this->buildManiaLink(); // Callbacks $this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::AFTERINIT, $this, 'handleAfterInit'); $this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerJoined'); - //$this->maniaControl->getCallbackManager()->registerCallbackListener(SettingManager::CB_SETTING_CHANGED, $this, 'handleSettingChanged'); // TODO Setting Change Key + $this->maniaControl->getCallbackManager()->registerCallbackListener(SettingManager::CB_SETTING_CHANGED, $this, 'handleSettingChanged'); // TODO Setting Change Key } @@ -70,12 +78,26 @@ class ToggleInterfaceManager implements CallbackListener { $this->maniaControl->getManialinkManager()->sendManialink($this->manialink , $player, 0, false, false); } + /** + * Handle Setting Changed Callback + * + * @param Setting $setting + */ + public function handleSettingChanged(Setting $setting) { + if (!$setting->belongsToClass($this)) { + return; + } + + $this->buildManiaLink(); + $this->handleAfterInit(); + } + /** * Build the Manialink with only the Toggle Interface script feature */ private function buildManiaLink() { $manialink = new ManiaLink(self::MLID); - $manialink->getScript()->addFeature(new \FML\Script\Features\ToggleInterface("F9")); + $manialink->getScript()->addFeature(new \FML\Script\Features\ToggleInterface($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_KEYNAME))); $this->manialink = (string) $manialink; } }