WIP KeyShortcutWindow for NAT flixel
This commit is contained in:
@@ -0,0 +1,9 @@
|
|||||||
|
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 {}
|
29
projects/kiss-flixel/src/kiss_flixel/KeyShortcutWindow.kiss
Normal file
29
projects/kiss-flixel/src/kiss_flixel/KeyShortcutWindow.kiss
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
// 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))
|
@@ -30,11 +30,14 @@
|
|||||||
(set currentMap null)
|
(set currentMap null)
|
||||||
(tryCall onFinishOrCancel))
|
(tryCall onFinishOrCancel))
|
||||||
|
|
||||||
|
(method clear []
|
||||||
|
(rootMap.clear))
|
||||||
|
|
||||||
(method handleKey [:String key]
|
(method handleKey [:String key]
|
||||||
(unless currentMap (tryCallOrThrow onBadKey "Tried to handle key $key without calling start() first" key null))
|
(unless currentMap (tryCallOrThrow onBadKey "Tried to handle key $key without calling start() first" key null))
|
||||||
(if (= cancelKey key)
|
(if (= cancelKey key)
|
||||||
(cancel)
|
(cancel)
|
||||||
(case (dictGet currentMap key)
|
(case ~(dictGet currentMap key)
|
||||||
((Final item)
|
((Final item)
|
||||||
(tryCall onSelectItem item)
|
(tryCall onSelectItem item)
|
||||||
(cancel))
|
(cancel))
|
||||||
|
@@ -19,6 +19,7 @@ import flixel.addons.plugin.FlxMouseControl;
|
|||||||
import flixel.input.mouse.FlxMouseEventManager;
|
import flixel.input.mouse.FlxMouseEventManager;
|
||||||
using StringTools;
|
using StringTools;
|
||||||
using kiss_flixel.CameraTools;
|
using kiss_flixel.CameraTools;
|
||||||
|
import kiss_flixel.KeyShortcutWindow;
|
||||||
import kiss_tools.KeyShortcutHandler;
|
import kiss_tools.KeyShortcutHandler;
|
||||||
import kiss_tools.FlxKeyShortcutHandler;
|
import kiss_tools.FlxKeyShortcutHandler;
|
||||||
import nat.systems.PlaygroundSystem;
|
import nat.systems.PlaygroundSystem;
|
||||||
|
@@ -109,13 +109,10 @@
|
|||||||
(clearUI))
|
(clearUI))
|
||||||
|
|
||||||
(prop &mut :Bool confirmQuit false)
|
(prop &mut :Bool confirmQuit false)
|
||||||
(defAlias &ident sh (cast shortcutHandler FlxKeyShortcutHandler<Dynamic>))
|
(prop &mut :KeyShortcutWindow<Entry> shw)
|
||||||
(method &override :Void update [:Float elapsed]
|
(method &override :Void update [:Float elapsed]
|
||||||
(super.update elapsed)
|
(super.update elapsed)
|
||||||
|
|
||||||
(when sh.currentMap
|
|
||||||
(sh.update))
|
|
||||||
|
|
||||||
(when (and FlxG.keys.justPressed.V FlxG.keys.pressed.CONTROL)
|
(when (and FlxG.keys.justPressed.V FlxG.keys.pressed.CONTROL)
|
||||||
(when (and textInput textInput.hasFocus)
|
(when (and textInput textInput.hasFocus)
|
||||||
(whenLet [text (Clipboard.generalClipboard.getData ClipboardFormats.TEXT_FORMAT)]
|
(whenLet [text (Clipboard.generalClipboard.getData ClipboardFormats.TEXT_FORMAT)]
|
||||||
@@ -132,8 +129,8 @@
|
|||||||
// This part is hacky...
|
// This part is hacky...
|
||||||
(set lastUI textInputLabel)
|
(set lastUI textInputLabel)
|
||||||
(hideUI textInputLabel))
|
(hideUI textInputLabel))
|
||||||
(~sh.currentMap
|
((and shw (shw.isShown))
|
||||||
(sh.cancel))
|
(shw.hide))
|
||||||
(confirmQuit
|
(confirmQuit
|
||||||
(Sys.exit 0))
|
(Sys.exit 0))
|
||||||
(true
|
(true
|
||||||
@@ -169,10 +166,12 @@
|
|||||||
(FlxG.camera.updateScrollWheelZoom elapsed 1)
|
(FlxG.camera.updateScrollWheelZoom elapsed 1)
|
||||||
|
|
||||||
// Don't check keys that can be used in shortcuts outside this block:
|
// Don't check keys that can be used in shortcuts outside this block:
|
||||||
(unless (or sh.currentMap (and textInput textInput.hasFocus))
|
(unless (or (and shw (shw.isShown)) (and textInput textInput.hasFocus))
|
||||||
(when FlxG.keys.justPressed.SEMICOLON
|
(when FlxG.keys.justPressed.SEMICOLON
|
||||||
(set confirmQuit false)
|
(set confirmQuit false)
|
||||||
(sh.start)
|
(set shw (new KeyShortcutWindow shortcutHandler ->[:Entry e] (readComponentOr e Name "unnamed entry")))
|
||||||
|
(set shw.cameras [uiCamera])
|
||||||
|
(shw.show)
|
||||||
(return))
|
(return))
|
||||||
// +/- keys to change an entry's z
|
// +/- keys to change an entry's z
|
||||||
(doFor e (controller.getSelectedEntries)
|
(doFor e (controller.getSelectedEntries)
|
||||||
|
Reference in New Issue
Block a user