SimpleWindow clearControls() and isShown()

This commit is contained in:
2022-08-10 13:48:26 +00:00
parent 4661bfe43d
commit f88501a0e3

View File

@@ -5,13 +5,15 @@
// TODO tooltip support with left-click and right-click action // TODO tooltip support with left-click and right-click action
// icons and explanations // icons and explanations
(defNew [:String title (defNew [&opt :String _title
&opt :FlxColor bgColor :FlxColor bgColor
:FlxColor _textColor :FlxColor _textColor
:Float percentWidth :Float percentWidth
:Float percentHeight] :Float percentHeight]
[&mut :Float nextControlY 0 [:String title (or _title "")
&mut :Float nextControlY 0
:FlxColor titleColor (or _textColor FlxColor.WHITE)
&mut :FlxColor textColor (or _textColor FlxColor.WHITE) &mut :FlxColor textColor (or _textColor FlxColor.WHITE)
:FlxTypedGroup<FlxSprite> controls (new FlxTypedGroup) :FlxTypedGroup<FlxSprite> controls (new FlxTypedGroup)
:FlxKeyShortcutHandler<ShortcutAction> keyHandler (new FlxKeyShortcutHandler)] :FlxKeyShortcutHandler<ShortcutAction> keyHandler (new FlxKeyShortcutHandler)]
@@ -37,9 +39,9 @@
// TODO show which shortcuts' prefixes are partially highlighted? // TODO show which shortcuts' prefixes are partially highlighted?
) )
(method makeText [:String text &opt :Action onClick] (method makeText [:String text &opt :FlxColor color :Action onClick]
(let [ftext (new FlxText x nextControlY 0 text textSize)] (let [ftext (new FlxText x nextControlY 0 text textSize)]
(set ftext.color textColor) (set ftext.color (or color textColor))
(set ftext.cameras this.cameras) (set ftext.cameras this.cameras)
(controls.add ftext) (controls.add ftext)
(+= nextControlY ftext.height) (+= nextControlY ftext.height)
@@ -52,9 +54,17 @@
// TODO makeButton // TODO makeButton
// TODO make inputText // TODO make inputText
(prop &mut _shown false)
(method show [] (prop &mut _shown false)
(method isShown [] _shown)
(method clearControls []
(controls.clear)
(keyHandler.clear)
(set nextControlY y)
(makeText title titleColor))
(method :Void show []
(unless _shown (unless _shown
(FlxG.state.add this) (FlxG.state.add this)
(FlxG.state.add controls) (FlxG.state.add controls)
@@ -62,7 +72,7 @@
(keyHandler.start) (keyHandler.start)
(set _shown true))) (set _shown true)))
(method hide [] (method :Void hide []
(when _shown (when _shown
(FlxG.state.remove this) (FlxG.state.remove this)
(FlxG.state.remove controls) (FlxG.state.remove controls)