Add an option to hide UI by default
This commit is contained in:
		@@ -27,6 +27,7 @@ class ToggleInterfaceManager implements CallbackListener {
 | 
				
			|||||||
	 */
 | 
						 */
 | 
				
			||||||
	const MLID                    = 'ToggleInterface.KeyListener';
 | 
						const MLID                    = 'ToggleInterface.KeyListener';
 | 
				
			||||||
	const SETTING_KEYNAME         = 'Key Name (or code) to toggle the ManiaControl UI';
 | 
						const SETTING_KEYNAME         = 'Key Name (or code) to toggle the ManiaControl UI';
 | 
				
			||||||
 | 
						const SETTING_DEFAULT_VISIBLE = 'Display by default the UI';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * Private properties
 | 
						 * Private properties
 | 
				
			||||||
@@ -46,6 +47,7 @@ class ToggleInterfaceManager implements CallbackListener {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		// Settings
 | 
							// Settings
 | 
				
			||||||
		$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_KEYNAME, "F9");
 | 
							$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_KEYNAME, "F9");
 | 
				
			||||||
 | 
							$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_DEFAULT_VISIBLE, True);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Build Manialink
 | 
							// Build Manialink
 | 
				
			||||||
		$this->buildManiaLink();
 | 
							$this->buildManiaLink();
 | 
				
			||||||
@@ -97,7 +99,7 @@ class ToggleInterfaceManager implements CallbackListener {
 | 
				
			|||||||
	 */
 | 
						 */
 | 
				
			||||||
	private function buildManiaLink() {
 | 
						private function buildManiaLink() {
 | 
				
			||||||
		$manialink = new ManiaLink(self::MLID);
 | 
							$manialink = new ManiaLink(self::MLID);
 | 
				
			||||||
		$manialink->getScript()->addFeature(new \FML\Script\Features\ToggleInterface($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_KEYNAME)));
 | 
							$manialink->getScript()->addFeature(new \FML\Script\Features\ToggleInterface($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_KEYNAME), $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_DEFAULT_VISIBLE)));
 | 
				
			||||||
		$this->manialink = (string) $manialink;
 | 
							$this->manialink = (string) $manialink;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -32,19 +32,25 @@ class ToggleInterface extends ScriptFeature
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    protected $keyCode = null;
 | 
					    protected $keyCode = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * @var int $defaultVisible if is visible by default
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    protected $defaultVisible = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Construct a new ToggleInterface
 | 
					     * Construct a new ToggleInterface
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @api
 | 
					     * @api
 | 
				
			||||||
     * @param string|int $keyNameOrCode (optional) Key name or code
 | 
					     * @param string|int $keyNameOrCode (optional) Key name or code
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function __construct($keyNameOrCode = null)
 | 
					    public function __construct($keyNameOrCode = null, $defaultVisible = true)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (is_string($keyNameOrCode)) {
 | 
					        if (is_string($keyNameOrCode)) {
 | 
				
			||||||
            $this->setKeyName($keyNameOrCode);
 | 
					            $this->setKeyName($keyNameOrCode);
 | 
				
			||||||
        } else if (is_int($keyNameOrCode)) {
 | 
					        } else if (is_int($keyNameOrCode)) {
 | 
				
			||||||
            $this->setKeyCode($keyNameOrCode);
 | 
					            $this->setKeyCode($keyNameOrCode);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        $this->setDefaultVisible($defaultVisible);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@@ -97,15 +103,40 @@ class ToggleInterface extends ScriptFeature
 | 
				
			|||||||
        return $this;
 | 
					        return $this;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Get the Default visibility property
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @api
 | 
				
			||||||
 | 
					     * @return boolean
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public function getDefaultVisible()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return $this->defaultVisible;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Set the Default visibility property
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @api
 | 
				
			||||||
 | 
					     * @param boolean $defaultVisible if is visible by default
 | 
				
			||||||
 | 
					     * @return static
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public function setDefaultVisible($defaultVisible)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $this->defaultVisible = $defaultVisible;
 | 
				
			||||||
 | 
					        return $this;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * @see ScriptFeature::prepare()
 | 
					     * @see ScriptFeature::prepare()
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function prepare(Script $script)
 | 
					    public function prepare(Script $script)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $script->appendGenericScriptLabel(ScriptLabel::ONINIT, $this->getOnInitScriptText());
 | 
					 | 
				
			||||||
        if ($this->keyCode != null || $this->keyName != null) {
 | 
					        if ($this->keyCode != null || $this->keyName != null) {
 | 
				
			||||||
 | 
					            $script->appendGenericScriptLabel(ScriptLabel::ONINIT, $this->getOnInitScriptText(true));
 | 
				
			||||||
            $script->appendGenericScriptLabel(ScriptLabel::KEYPRESS, $this->getKeyPressScriptText());
 | 
					            $script->appendGenericScriptLabel(ScriptLabel::KEYPRESS, $this->getKeyPressScriptText());
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
 | 
					            $script->appendGenericScriptLabel(ScriptLabel::ONINIT, $this->getOnInitScriptText());
 | 
				
			||||||
            $script->appendGenericScriptLabel(ScriptLabel::LOOP, $this->getLoopScriptText());
 | 
					            $script->appendGenericScriptLabel(ScriptLabel::LOOP, $this->getLoopScriptText());
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return $this;
 | 
					        return $this;
 | 
				
			||||||
@@ -116,14 +147,27 @@ class ToggleInterface extends ScriptFeature
 | 
				
			|||||||
     *
 | 
					     *
 | 
				
			||||||
     * @return string
 | 
					     * @return string
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    protected function getOnInitScriptText()
 | 
					    protected function getOnInitScriptText($isToggleScript = false)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $VarIsVisible = $this::VAR_ISVISIBLE;
 | 
					        $VarIsVisible = $this::VAR_ISVISIBLE;
 | 
				
			||||||
        $VarWasVisible = $this::VAR_WASVISIBLE;
 | 
					
 | 
				
			||||||
        return "
 | 
					        $maniascript = "
 | 
				
			||||||
declare Boolean {$VarIsVisible} for UI = True;
 | 
					declare Boolean {$VarIsVisible} for UI = True;
 | 
				
			||||||
declare Boolean Last_IsVisible = True;
 | 
					declare Boolean Last_IsVisible = True;
 | 
				
			||||||
";
 | 
					        ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if ($isToggleScript) {
 | 
				
			||||||
 | 
					            if ($this->getDefaultVisible()) {
 | 
				
			||||||
 | 
					                $defaultVisible = "True";
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                $defaultVisible = "False";
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            $maniascript .= "
 | 
				
			||||||
 | 
					{$VarIsVisible} = {$defaultVisible};
 | 
				
			||||||
 | 
					            ";
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return $maniascript;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@@ -143,7 +187,6 @@ declare Boolean Last_IsVisible = True;
 | 
				
			|||||||
            $keyValue    = Builder::getInteger($this->keyCode);
 | 
					            $keyValue    = Builder::getInteger($this->keyCode);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        $VarIsVisible = $this::VAR_ISVISIBLE;
 | 
					        $VarIsVisible = $this::VAR_ISVISIBLE;
 | 
				
			||||||
        $VarWasVisible = $this::VAR_WASVISIBLE;
 | 
					 | 
				
			||||||
        $scriptText = "
 | 
					        $scriptText = "
 | 
				
			||||||
if (Event.{$keyProperty} == {$keyValue}) {
 | 
					if (Event.{$keyProperty} == {$keyValue}) {
 | 
				
			||||||
    {$VarIsVisible} = !{$VarIsVisible};
 | 
					    {$VarIsVisible} = !{$VarIsVisible};
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user