NAT playground Scrollable UI stream

This commit is contained in:
2021-09-17 22:03:50 -06:00
parent 6ddaead44b
commit 6bde91857c
2 changed files with 65 additions and 20 deletions

View File

@@ -12,6 +12,7 @@ import flixel.addons.ui.FlxInputText;
import flixel.addons.ui.FlxUIPopup; import flixel.addons.ui.FlxUIPopup;
import flixel.text.FlxText; import flixel.text.FlxText;
import flixel.util.FlxColor; import flixel.util.FlxColor;
import flixel.FlxCamera;
using StringTools; using StringTools;

View File

@@ -8,7 +8,14 @@
(new Archive archiveDir) (new Archive archiveDir)
this)) this))
(add messages) (prop &mut :FlxGroup uiGroup (new FlxGroup))
(add uiGroup)
(prop uiCamera (new FlxCamera 0 0 FlxG.width FlxG.height))
(set uiCamera.bgColor FlxColor.TRANSPARENT)
(FlxG.cameras.add uiCamera false)
(set uiGroup.cameras [uiCamera])
// TODO make a button that can be clicked to run typeCommand() // TODO make a button that can be clicked to run typeCommand()
// TODO make sprites for entries that have images // TODO make sprites for entries that have images
@@ -22,11 +29,25 @@
(typeCommand)) (typeCommand))
(when (and textInput !textInput.alive) (when (and textInput !textInput.alive)
(set textInput.callback null) (set textInput.callback null)
(set textInput null))) (set textInput null))
// Scroll the UI with the mouse:
(var UI_SCROLL_FACTOR 2)
(+= uiCamera.y (* FlxG.mouse.wheel UI_SCROLL_FACTOR))
// TODO allow changing the a scroll factor
// And with the up/down keys:
(var KEYBOARD_SCROLL_SPEED 200)
(when (> uiGroup.length 0)
(when FlxG.keys.pressed.DOWN
(-= uiCamera.y (/ KEYBOARD_SCROLL_SPEED 60)))
(when FlxG.keys.pressed.UP
(+= uiCamera.y (/ KEYBOARD_SCROLL_SPEED 60)))))
(method :Void typeCommand [] (method :Void typeCommand []
(enterText (enterText
"command to run" "command to run:"
->commandName (controller.tryRunCommand commandName) ->commandName (controller.tryRunCommand commandName)
Math.POSITIVE_INFINITY)) Math.POSITIVE_INFINITY))
@@ -34,19 +55,26 @@
(method :Void setController [controller] (set this.controller controller)) (method :Void setController [controller] (set this.controller controller))
(prop &mut :FlxText textInputLabel null)
(prop &mut :FlxInputText textInput null) (prop &mut :FlxInputText textInput null)
(method :Void enterText [prompt resolve maxLength] (method :Void enterText [prompt resolve maxLength]
(set textInput (new FlxInputText 0 0 300 prompt)) (set textInputLabel (new FlxText 0 0 300 prompt))
(textInput.screenCenter) (showUI textInputLabel)
(set textInput (new FlxInputText 0 0 300 ""))
(set textInput.hasFocus true)
(set textInput.callback (set textInput.callback
->:Void [text action] ->:Void [text action]
(case [text action] (case [text action]
([text FlxInputText.ENTER_ACTION] ([text FlxInputText.ENTER_ACTION]
(textInput.kill) (hideUI textInput)
// This part is hacky...
(set lastUI textInputLabel)
(hideUI textInputLabel)
(resolve text)) (resolve text))
//([_ FlxInputText.])
(otherwise {}))) (otherwise {})))
(add textInput)) (showUI textInput))
(method :Void enterNumber [prompt resolve min max &opt inStepsOf] (method :Void enterNumber [prompt resolve min max &opt inStepsOf]
(resolve 0)) (resolve 0))
@@ -80,22 +108,38 @@
(doFor e changeSet (doFor e changeSet
(print (archive.fullString e)))) (print (archive.fullString e))))
(prop &mut :Int messageY 0) (prop &mut :Int uiY 0)
(prop &mut :FlxGroup messages (new FlxGroup))
(method :Void displayMessage [message] (prop &mut :FlxSprite lastUI null)
(messages.add (new FlxText 0 messageY 0 message))
(+= messageY 8)) (method :Void showUI [:FlxSprite ui]
(set ui.y uiY)
(uiGroup.add ui)
(set lastUI ui)
(+= uiY ui.height)
(when (> uiY FlxG.height) (-= uiCamera.y ui.height)))
(method :Void hideUI [:FlxSprite ui]
(uiGroup.remove ui)
(ui.kill)
(when (= lastUI ui) (-= uiY ui.height)))
(method :Void displayMessage [:String message]
(let [messageText (new FlxText 0 0 0 (message.replace "\n" "|"))]
(showUI messageText)))
// TODO add a UI way to call this // TODO add a UI way to call this
(method :Void clearMessages [] (method :Void clearUI []
(messages.kill) (uiGroup.kill)
(set messages (new FlxGroup)) (set uiGroup (new FlxGroup))
(set messageY 0)) (add uiGroup)
(set uiY 0)
(set uiCamera.y 0))
// TODO add a way to scroll through messages/move the camera // TODO add a way to scroll through messages/move the camera
(method :Void reportError [error] (method :Void reportError [:String error]
(let [text (new FlxText 0 messageY 0 error)] (let [text (new FlxText 0 0 0 (error.replace "\n" "|"))]
(text.setFormat null 8 FlxColor.RED) (text.setFormat null 8 FlxColor.RED)
(messages.add text) (showUI text)))
(+= messageY 8)))