diff --git a/core/Server/ServerOptionsMenu.php b/core/Server/ServerOptionsMenu.php index 1d5bbff9..d1a5560b 100644 --- a/core/Server/ServerOptionsMenu.php +++ b/core/Server/ServerOptionsMenu.php @@ -294,10 +294,7 @@ class ServerOptionsMenu implements CallbackListener, ConfiguratorMenu, TimerList foreach ($serverOptionsArray as $name => $value) { // Continue on CurrentMaxPlayers... - $pos = strpos($name, 'Current'); // TODO: display 'Current...' somewhere - if ($pos !== false) { - continue; - } + if (str_contains($name, 'Current')) continue; // TODO: display 'Current...' somewhere if ($index % 13 === 0) { $pageFrame = new Frame(); @@ -331,6 +328,25 @@ class ServerOptionsMenu implements CallbackListener, ConfiguratorMenu, TimerList $optionsFrame->setY($posY - $optionHeight * 1.5); $posY -= $optionHeight * 3.; $index += 3; + } else if (str_contains($name, 'Password')) { + $entry->setTextFormat("Password"); + $entry->setId($name); + + $quad = new Quad(); + $quad->setPosition(-4, 0, -0.01)->setSize(4, 4); + $checkBox = new CheckBox(null, false, $quad); + $checkBox->setEnabledDesign("UICommon64_1", "Eye_light"); + $checkBox->setDisabledDesign("UICommon64_1", "Eye_light"); + $checkBox->setCustomScript(" + declare CMlEntry Entry <=> (Quad_CheckBox.Parent.Parent.GetFirstChild(\"$name\") as CMlEntry); + if (Entry != Null) { + if (Quad_CheckBox.StyleSelected) { + Entry.TextFormat = CMlEntry::ETextFormat::Basic; + } else { + Entry.TextFormat = CMlEntry::ETextFormat::Password; + } + }"); + $optionsFrame->addChild($checkBox); } } diff --git a/libs/FML/Components/CheckBox.php b/libs/FML/Components/CheckBox.php index a5ca4fdc..54f4367f 100644 --- a/libs/FML/Components/CheckBox.php +++ b/libs/FML/Components/CheckBox.php @@ -143,6 +143,30 @@ class CheckBox implements Renderable, ScriptFeatureable return $this->feature->getDisabledDesign(); } + /** + * Set script launched when clicking on the checkbox + * + * @api + * @param string $customScript script + * @return static + */ + public function setCustomScript(string $customScript) + { + $this->feature->setCustomScript($customScript); + return $this; + } + + /** + * Get script launched when clicking on the checkbox + * + * @api + * @return string + */ + public function getCustomScript() + { + return $this->feature->getCustomScript(); + } + /** * Set the disabled design * diff --git a/libs/FML/Script/Features/CheckBoxFeature.php b/libs/FML/Script/Features/CheckBoxFeature.php index 8e57bda0..a5157f34 100644 --- a/libs/FML/Script/Features/CheckBoxFeature.php +++ b/libs/FML/Script/Features/CheckBoxFeature.php @@ -53,6 +53,11 @@ class CheckBoxFeature extends ScriptFeature */ protected $disabledDesign = null; + /** + * @var string $customScript Script executed when clicking on the checkbox + */ + protected $customScript = ""; + /** * Construct a new CheckBox Feature * @@ -199,6 +204,30 @@ class CheckBoxFeature extends ScriptFeature return $this; } + /** + * Get script launched when clicking on the checkbox + * + * @api + * @return string + */ + public function getCustomScript() + { + return $this->customScript; + } + + /** + * Set script launched when clicking on the checkbox + * + * @api + * @param string $customScript script + * @return static + */ + public function setCustomScript(string $customScript) + { + $this->customScript = $customScript; + return $this; + } + /** * @see ScriptFeature::prepare() */ @@ -290,6 +319,7 @@ EntryId = \"{$entryId}\"; if (Event.ControlId == \"{$quadId}\") { declare Quad_CheckBox <=> (Event.Control as CMlQuad); " . self::FUNCTION_UPDATE_QUAD_DESIGN . "(Quad_CheckBox); + " . $this->customScript . " }"; }