Add setting to change toggle button
This commit is contained in:
parent
e7903af87a
commit
ce499759e7
@ -7,6 +7,9 @@ use ManiaControl\Callbacks\Callbacks;
|
|||||||
use ManiaControl\Callbacks\CallbackListener;
|
use ManiaControl\Callbacks\CallbackListener;
|
||||||
use ManiaControl\Players\Player;
|
use ManiaControl\Players\Player;
|
||||||
use ManiaControl\Players\PlayerManager;
|
use ManiaControl\Players\PlayerManager;
|
||||||
|
use ManiaControl\Settings\Setting;
|
||||||
|
use ManiaControl\Settings\SettingManager;
|
||||||
|
|
||||||
|
|
||||||
use FML\ManiaLink;
|
use FML\ManiaLink;
|
||||||
|
|
||||||
@ -23,6 +26,7 @@ class ToggleInterfaceManager implements CallbackListener {
|
|||||||
* Constants
|
* Constants
|
||||||
*/
|
*/
|
||||||
const MLID = 'ToggleInterface.KeyListener';
|
const MLID = 'ToggleInterface.KeyListener';
|
||||||
|
const SETTING_KEYNAME = 'Key Name (or code) to toggle the ManiaControl UI';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Private properties
|
* Private properties
|
||||||
@ -40,12 +44,16 @@ class ToggleInterfaceManager implements CallbackListener {
|
|||||||
public function __construct(ManiaControl $maniaControl) {
|
public function __construct(ManiaControl $maniaControl) {
|
||||||
$this->maniaControl = $maniaControl;
|
$this->maniaControl = $maniaControl;
|
||||||
|
|
||||||
|
// Settings
|
||||||
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_KEYNAME, "F9");
|
||||||
|
|
||||||
|
// Build Manialink
|
||||||
$this->buildManiaLink();
|
$this->buildManiaLink();
|
||||||
|
|
||||||
// Callbacks
|
// Callbacks
|
||||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::AFTERINIT, $this, 'handleAfterInit');
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::AFTERINIT, $this, 'handleAfterInit');
|
||||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerJoined');
|
$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);
|
$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
|
* Build the Manialink with only the Toggle Interface script feature
|
||||||
*/
|
*/
|
||||||
private function buildManiaLink() {
|
private function buildManiaLink() {
|
||||||
$manialink = new ManiaLink(self::MLID);
|
$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;
|
$this->manialink = (string) $manialink;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user