From 76ab41dd97b3c60332e8087010d37f10ff0dc403 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Wed, 15 Feb 2023 15:24:33 -0700 Subject: [PATCH] enter numbers and positions --- .../nat-godot-playground/scripts/GodotUI.hx | 1 + .../nat-godot-playground/scripts/GodotUI.kiss | 44 ++++++++++++++++--- .../scripts/RootNode.kiss | 12 ++++- 3 files changed, 51 insertions(+), 6 deletions(-) diff --git a/projects/nat-godot-playground/scripts/GodotUI.hx b/projects/nat-godot-playground/scripts/GodotUI.hx index b90ff933..513d2b54 100644 --- a/projects/nat-godot-playground/scripts/GodotUI.hx +++ b/projects/nat-godot-playground/scripts/GodotUI.hx @@ -2,6 +2,7 @@ package; import kiss.Prelude; import kiss_tools.KeyShortcutHandler; +import cs.NativeArray; @:build(kiss.Kiss.build()) class GodotUI implements ArchiveUI {} \ No newline at end of file diff --git a/projects/nat-godot-playground/scripts/GodotUI.kiss b/projects/nat-godot-playground/scripts/GodotUI.kiss index 75652169..fe1251f0 100644 --- a/projects/nat-godot-playground/scripts/GodotUI.kiss +++ b/projects/nat-godot-playground/scripts/GodotUI.kiss @@ -14,11 +14,43 @@ (let [lineEdit (new LineEdit)] (unless (= maxLength Math.POSITIVE_INFINITY) (set lineEdit.maxLength (Std.int maxLength))) - (set rootNode.resolveString resolve) + (set rootNode.resolveString + ->[:String text] { + (rootNode.uiContainer.removeChild lineEdit) + (displayMessage text) + (resolve text) + }) (lineEdit.connect "text_entered" rootNode "_on_LineEdit_text_entered") - (rootNode.uiContainer.addChild lineEdit))) + (rootNode.uiContainer.addChild lineEdit) + (lineEdit.grabFocus))) -(method :Void enterNumber [:String prompt :Float->Void resolve :Float min :Float max &opt :Null inStepsOf &opt :Null allowNaN] (throw "TODO Not implemented!")) +(method :Void enterNumber [:String prompt :Float->Void resolve :Float min :Float max &opt :Null inStepsOf &opt :Null allowNaN] + (displayMessage prompt) + (let [spinBox (new SpinBox) + nanButton (new Button) + submitButton (new Button) + resolve + ->[:Float num] + { + (set rootNode.resolveFloat null) + (rootNode.uiContainer.removeChild spinBox) + (when allowNaN (rootNode.uiContainer.removeChild nanButton)) + (rootNode.uiContainer.removeChild submitButton) + (displayMessage "$num") + (resolve num) + }] + (set rootNode.resolveFloat resolve) + (set spinBox.minValue min) + (set spinBox.maxValue max) + (rootNode.uiContainer.addChild spinBox) + (when allowNaN + (set nanButton.text "NaN") + (nanButton.connect "pressed" rootNode "_on_NaNButton_pressed") + (rootNode.uiContainer.addChild nanButton)) + (set submitButton.text "Submit") + (submitButton.connect "pressed" rootNode "_on_SubmitNumberButton_pressed" (new godot.collections.Array (NativeArray.make spinBox))) + (rootNode.uiContainer.addChild submitButton) + (submitButton.grabFocus))) (method :Void chooseEntry [:String prompt :Archive archive :Entry->Void resolve] (throw "TODO Not implemented!")) @@ -32,12 +64,14 @@ (set label.text message) (rootNode.uiContainer.addChild label))) -(method :Void reportError [:String error] (throw "TODO Not implemented!")) +(method :Void reportError [:String error] + (displayMessage "Error! $error")) (method :Void onSelectionChanged [:Array selectedEntries :Array lastSelectedEntries] (throw "TODO Not implemented!")) (method :Void choosePosition [:String prompt :Position->Void resolve] - (throw "TODO Not implemented!")) + (displayMessage prompt) + (set rootNode.resolvePosition resolve)) (method :Option cursorPosition [] (let [pos (.getMousePosition (rootNode.getViewport))] diff --git a/projects/nat-godot-playground/scripts/RootNode.kiss b/projects/nat-godot-playground/scripts/RootNode.kiss index ff6d5fb4..4e6305e7 100644 --- a/projects/nat-godot-playground/scripts/RootNode.kiss +++ b/projects/nat-godot-playground/scripts/RootNode.kiss @@ -41,12 +41,14 @@ (when ui.controller (.switchPlaygroundKey (ui.playgroundSystem) .name (pgTabs.getChild tab)))) (prop &mut :String->Void resolveString null) + (method :Void _on_LineEdit_text_entered [:String text] (let [rs resolveString] (set resolveString null) (rs text))) (prop &mut :Position->Void resolvePosition null) + (method &override &public :Void _Input [:InputEvent event] (typeCase [event] ([:InputEventMouseButton mouseButtonEvent] @@ -54,4 +56,12 @@ (whenLet [rp resolvePosition] (set resolvePosition null) (rp (GodotUI.vector2ToPosition (.getMousePosition (getViewport))))))) - (otherwise))) \ No newline at end of file + (otherwise))) + +(prop &mut :Float->Void resolveFloat) + +(method :Void _on_NaNButton_pressed [] + (resolveFloat Math.NaN)) + +(method :Void _on_SubmitNumberButton_pressed [:SpinBox spinBox] + (resolveFloat spinBox.value)) \ No newline at end of file