NAT use SimpleWindow. Close #108
This commit is contained in:
@@ -1,9 +0,0 @@
|
|||||||
package kiss_flixel;
|
|
||||||
|
|
||||||
import kiss.Prelude;
|
|
||||||
import kiss.List;
|
|
||||||
import kiss_tools.KeyShortcutHandler;
|
|
||||||
import flixel.util.FlxColor;
|
|
||||||
|
|
||||||
@:build(kiss.Kiss.build())
|
|
||||||
class KeyShortcutWindow<T> extends SimpleWindow {}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
// Wraps a given generic KeyShortcutHandler within
|
|
||||||
// the FlxKeyShortcutHandler that every SimpleWindow has,
|
|
||||||
// using the window to display available mappings
|
|
||||||
// from the currently active prefix map
|
|
||||||
(defNew [&prop :KeyShortcutHandler<T> innerKeyShortcuts
|
|
||||||
&prop :T->String elementToStringWithoutBrackets
|
|
||||||
&opt :String title
|
|
||||||
:FlxColor bgColor
|
|
||||||
:FlxColor textColor
|
|
||||||
:Float percentWidth
|
|
||||||
:Float percentHeight]
|
|
||||||
(super title bgColor textColor percentWidth percentHeight)
|
|
||||||
(set innerKeyShortcuts.onSelectPrefixMap ->map {
|
|
||||||
(clearControls)
|
|
||||||
(doFor =>key keyBehavior map
|
|
||||||
(case keyBehavior
|
|
||||||
((Final item)
|
|
||||||
(makeText "[${key}] - $(elementToString item)" null ->_ (innerKeyShortcuts.onSelectItem item)))
|
|
||||||
((Prefix innerMap)
|
|
||||||
(makeText "[${key}] - $(count innerMap) more options" null ->_ (innerKeyShortcuts.onSelectPrefixMap innerMap)))
|
|
||||||
(null null)))}))
|
|
||||||
|
|
||||||
(method &override :Void show []
|
|
||||||
(super.show)
|
|
||||||
(innerKeyShortcuts.start))
|
|
||||||
|
|
||||||
(method &override :Void hide []
|
|
||||||
(super.hide)
|
|
||||||
(innerKeyShortcuts.cancel))
|
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
->[archive e pos &opt ui]
|
->[archive e pos &opt ui]
|
||||||
(unless (sprites.exists e.id)
|
(unless (sprites.exists e.id)
|
||||||
(let [sprite (new EntrySprite this _playgroundKey pos archive e controller)]
|
(let [sprite (new EntrySprite this _playgroundKey pos archive e controller)]
|
||||||
|
(set sprite.cameras [FlxG.camera])
|
||||||
(sprite.enableDragToSelect
|
(sprite.enableDragToSelect
|
||||||
->:Void {
|
->:Void {
|
||||||
(controller.AddSelectEntry e)
|
(controller.AddSelectEntry e)
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import flixel.input.mouse.FlxMouseEventManager;
|
|||||||
using StringTools;
|
using StringTools;
|
||||||
using kiss_flixel.DebugLayer;
|
using kiss_flixel.DebugLayer;
|
||||||
using kiss_flixel.CameraTools;
|
using kiss_flixel.CameraTools;
|
||||||
|
using kiss_flixel.SimpleWindow;
|
||||||
import kiss_tools.KeyShortcutHandler;
|
import kiss_tools.KeyShortcutHandler;
|
||||||
import kiss_tools.FlxKeyShortcutHandler;
|
import kiss_tools.FlxKeyShortcutHandler;
|
||||||
import nat.systems.PlaygroundSystem;
|
import nat.systems.PlaygroundSystem;
|
||||||
|
|||||||
@@ -28,21 +28,18 @@
|
|||||||
this)))
|
this)))
|
||||||
|
|
||||||
|
|
||||||
(prop &mut :FlxGroup uiGroup (new FlxGroup))
|
(prop screenCamera (new FlxCamera 0 0 FlxG.width FlxG.height))
|
||||||
(add uiGroup)
|
(prop &mut :SimpleWindow uiWindow (new SimpleWindow 0.5 0.5 true "escape"))
|
||||||
|
(set uiWindow.cameras [screenCamera])
|
||||||
|
(set uiWindow.keyboardEnabled false)
|
||||||
|
|
||||||
(prop :FlxTypedGroup<EntrySprite> entryGroup (new FlxTypedGroup<EntrySprite>))
|
(prop :FlxTypedGroup<EntrySprite> entryGroup (new FlxTypedGroup<EntrySprite>))
|
||||||
(add entryGroup)
|
(add entryGroup)
|
||||||
|
|
||||||
(prop debugLayer (new DebugLayer))
|
(prop debugLayer (new DebugLayer))
|
||||||
|
(set debugLayer.cameras [FlxG.camera])
|
||||||
(add debugLayer)
|
(add debugLayer)
|
||||||
|
|
||||||
(prop uiCamera (new FlxCamera 0 0 FlxG.width FlxG.height))
|
|
||||||
(prop screenCamera (new FlxCamera 0 0 FlxG.width FlxG.height))
|
|
||||||
(set uiCamera.bgColor FlxColor.TRANSPARENT)
|
|
||||||
(FlxG.cameras.add uiCamera false)
|
|
||||||
|
|
||||||
(set uiGroup.cameras [uiCamera])
|
|
||||||
|
|
||||||
(FlxG.camera.calculateScrollBounds entryGroup SCROLL_BOUND_MARGIN))
|
(FlxG.camera.calculateScrollBounds entryGroup SCROLL_BOUND_MARGIN))
|
||||||
|
|
||||||
@@ -71,15 +68,8 @@
|
|||||||
(set textInput.caretIndex textInput.text.length))))
|
(set textInput.caretIndex textInput.text.length))))
|
||||||
|
|
||||||
(when FlxG.keys.justPressed.ESCAPE
|
(when FlxG.keys.justPressed.ESCAPE
|
||||||
(cond
|
(when sh.currentMap
|
||||||
((and textInput textInput.hasFocus)
|
(sh.cancel)))
|
||||||
(set textInput.callback null)
|
|
||||||
(hideUI textInput)
|
|
||||||
// This part is hacky...
|
|
||||||
(set lastUI textInputLabel)
|
|
||||||
(hideUI textInputLabel))
|
|
||||||
(sh.currentMap
|
|
||||||
(sh.cancel))))
|
|
||||||
(when FlxG.keys.justPressed.DELETE
|
(when FlxG.keys.justPressed.DELETE
|
||||||
(Sys.exit 0))
|
(Sys.exit 0))
|
||||||
|
|
||||||
@@ -92,11 +82,6 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Scroll the UI with the mouse:
|
|
||||||
(var UI_SCROLL_FACTOR 2)
|
|
||||||
(+= uiCamera.scroll.y (* FlxG.mouse.wheel UI_SCROLL_FACTOR))
|
|
||||||
// TODO allow changing the a scroll factor
|
|
||||||
|
|
||||||
// Control the UI camera with WASD, and the playground camera with arrow keys:
|
// Control the UI camera with WASD, and the playground camera with arrow keys:
|
||||||
(var KEYBOARD_SCROLL_SPEED 800)
|
(var KEYBOARD_SCROLL_SPEED 800)
|
||||||
|
|
||||||
@@ -124,19 +109,7 @@
|
|||||||
(-= .z (dictGet positions (spriteSystem.getPlaygroundKey)) 1)))
|
(-= .z (dictGet positions (spriteSystem.getPlaygroundKey)) 1)))
|
||||||
(when FlxG.keys.justPressed.PLUS
|
(when FlxG.keys.justPressed.PLUS
|
||||||
(withWritableComponents archive e [positions Positions]
|
(withWritableComponents archive e [positions Positions]
|
||||||
(+= .z (dictGet positions (spriteSystem.getPlaygroundKey)) 1))))
|
(+= .z (dictGet positions (spriteSystem.getPlaygroundKey)) 1))))))
|
||||||
|
|
||||||
// don't move the ui camera before ui has been placed -- new UI elements could appear offscreen
|
|
||||||
(when (> uiGroup.length 0)
|
|
||||||
(unless (and textInput textInput.hasFocus)
|
|
||||||
(uiCamera.updateKeyControl
|
|
||||||
elapsed
|
|
||||||
KEYBOARD_SCROLL_SPEED
|
|
||||||
// TODO support dvorak
|
|
||||||
->{FlxG.keys.pressed.A}
|
|
||||||
->{FlxG.keys.pressed.D}
|
|
||||||
->{FlxG.keys.pressed.W}
|
|
||||||
->{FlxG.keys.pressed.S})))))
|
|
||||||
|
|
||||||
(method :Void typeCommand []
|
(method :Void typeCommand []
|
||||||
(enterText
|
(enterText
|
||||||
@@ -151,9 +124,8 @@
|
|||||||
(prop &mut :FlxInputText textInput null)
|
(prop &mut :FlxInputText textInput null)
|
||||||
|
|
||||||
(method :Void enterText [prompt resolve maxLength]
|
(method :Void enterText [prompt resolve maxLength]
|
||||||
(set textInputLabel (new FlxText 0 0 300 prompt TEXT_SIZE))
|
(displayMessage prompt)
|
||||||
(showUI textInputLabel)
|
(set textInput (new FlxInputText 0 0 FlxG.width "" TEXT_SIZE))
|
||||||
(set textInput (new FlxInputText 0 0 300 "" TEXT_SIZE))
|
|
||||||
(set textInput.hasFocus true)
|
(set textInput.hasFocus true)
|
||||||
(set textInput.callback
|
(set textInput.callback
|
||||||
->:Void [text action]
|
->:Void [text action]
|
||||||
@@ -161,15 +133,11 @@
|
|||||||
(when textInput
|
(when textInput
|
||||||
(case [text action]
|
(case [text action]
|
||||||
([text FlxInputText.ENTER_ACTION]
|
([text FlxInputText.ENTER_ACTION]
|
||||||
(set textInput.callback null)
|
(clearUI)
|
||||||
(hideUI textInput)
|
|
||||||
// This part is hacky...
|
|
||||||
(set lastUI textInputLabel)
|
|
||||||
(hideUI textInputLabel)
|
|
||||||
(resolve text))
|
(resolve text))
|
||||||
//([_ FlxInputText.])
|
//([_ FlxInputText.])
|
||||||
(otherwise {}))))
|
(otherwise {}))))
|
||||||
(showUI textInput))
|
(uiWindow.addControl textInput))
|
||||||
|
|
||||||
(method :Void enterNumber [prompt resolve min max &opt inStepsOf]
|
(method :Void enterNumber [prompt resolve min max &opt inStepsOf]
|
||||||
(enterText prompt
|
(enterText prompt
|
||||||
@@ -231,41 +199,17 @@
|
|||||||
|
|
||||||
(FlxG.camera.calculateScrollBounds entryGroup SCROLL_BOUND_MARGIN))
|
(FlxG.camera.calculateScrollBounds entryGroup SCROLL_BOUND_MARGIN))
|
||||||
|
|
||||||
(prop &mut :Int uiY 0)
|
|
||||||
|
|
||||||
(prop &mut :FlxSprite lastUI null)
|
|
||||||
|
|
||||||
(method :Void showUI [:FlxSprite ui]
|
|
||||||
(set ui.y uiY)
|
|
||||||
(uiGroup.add ui)
|
|
||||||
(set lastUI ui)
|
|
||||||
(+= uiY ui.height)
|
|
||||||
(when (> uiY FlxG.height) (+= uiCamera.scroll.y ui.height)))
|
|
||||||
|
|
||||||
(method :Void hideUI [:FlxSprite ui]
|
|
||||||
(uiGroup.remove ui)
|
|
||||||
(ui.kill)
|
|
||||||
(when (= lastUI ui) (-= uiY ui.height)))
|
|
||||||
|
|
||||||
(method :Void displayMessage [:String message]
|
(method :Void displayMessage [:String message]
|
||||||
(let [messageText (new FlxText 0 0 0 (message.replace "\n" "|") TEXT_SIZE)]
|
(uiWindow.makeText message)
|
||||||
(showUI messageText)))
|
(uiWindow.show))
|
||||||
|
|
||||||
(method :Void clearUI []
|
(method :Void clearUI []
|
||||||
(when textInput
|
(uiWindow.clearControls)
|
||||||
(set textInput.callback null))
|
(uiWindow.hide))
|
||||||
(uiGroup.kill)
|
|
||||||
(set uiGroup (new FlxGroup))
|
|
||||||
(set uiGroup.cameras [uiCamera])
|
|
||||||
(add uiGroup)
|
|
||||||
(set uiY 0)
|
|
||||||
(set uiCamera.scroll.x 0)
|
|
||||||
(set uiCamera.scroll.y 0))
|
|
||||||
|
|
||||||
(method :Void reportError [:String error]
|
(method :Void reportError [:String error]
|
||||||
(let [text (new FlxText 0 0 0 (error.replace "\n" "|"))]
|
(uiWindow.makeText error FlxColor.RED)
|
||||||
(text.setFormat null 8 FlxColor.RED)
|
(uiWindow.show))
|
||||||
(showUI text)))
|
|
||||||
|
|
||||||
(method :Void onSelectionChanged [:Array<Entry> selectedEntries :Array<Entry> lastSelectedEntries]
|
(method :Void onSelectionChanged [:Array<Entry> selectedEntries :Array<Entry> lastSelectedEntries]
|
||||||
(doFor e (selectedEntries.concat lastSelectedEntries)
|
(doFor e (selectedEntries.concat lastSelectedEntries)
|
||||||
|
|||||||
Reference in New Issue
Block a user