FlxKeyShortcutHandler
This commit is contained in:
@@ -12,9 +12,8 @@ import flixel.math.FlxRandom;
|
||||
import flixel.math.FlxPoint;
|
||||
import kiss.Prelude;
|
||||
import kiss.List;
|
||||
import kiss_tools.KeyShortcutHandler;
|
||||
import kiss_tools.FlxKeyShortcutHandler;
|
||||
import HabitModel;
|
||||
import flixel.input.keyboard.FlxKey;
|
||||
import hx.strings.Strings;
|
||||
|
||||
@:build(kiss.Kiss.build())
|
||||
|
@@ -4,13 +4,12 @@
|
||||
// Hold left-click to hide the habit text and see the image clearly:
|
||||
(when entryTexts (if FlxG.mouse.pressed (remove entryTexts) (add entryTexts)))
|
||||
// Handle keyboard input:
|
||||
(let [:FlxKey id (FlxG.keys.firstJustPressed)]
|
||||
(unless (= id -1)
|
||||
(shortcutHandler.handleKey (.toLowerCase (id.toString))))))
|
||||
(when shortcutHandler
|
||||
(shortcutHandler.update)))
|
||||
|
||||
(prop &mut :FlxTypedGroup<FlxText> entryTexts null)
|
||||
(prop &mut :FlxTypedGroup<FlxSprite> rewardBlockers null)
|
||||
(prop &mut :KeyShortcutHandler<Entry> shortcutHandler null)
|
||||
(prop &mut :FlxKeyShortcutHandler<Entry> shortcutHandler null)
|
||||
|
||||
(prop &mut :HabitModel model null)
|
||||
|
||||
@@ -21,7 +20,7 @@
|
||||
|
||||
(method setModel [m]
|
||||
(set model m)
|
||||
(set shortcutHandler (new KeyShortcutHandler))
|
||||
(set shortcutHandler (new FlxKeyShortcutHandler))
|
||||
|
||||
(let [p (m.totalPoints)
|
||||
&mut i 0
|
||||
|
10
projects/kiss-tools/src/kiss_tools/FlxKeyShortcutHandler.hx
Normal file
10
projects/kiss-tools/src/kiss_tools/FlxKeyShortcutHandler.hx
Normal file
@@ -0,0 +1,10 @@
|
||||
package kiss_tools;
|
||||
|
||||
import kiss.Prelude;
|
||||
import kiss.List;
|
||||
import kiss_tools.KeyShortcutHandler;
|
||||
import flixel.input.keyboard.FlxKey;
|
||||
import flixel.FlxG;
|
||||
|
||||
@:build(kiss.Kiss.build())
|
||||
class FlxKeyShortcutHandler<T> extends KeyShortcutHandler<T> {}
|
@@ -0,0 +1,39 @@
|
||||
(var KEY_MAP [
|
||||
=>"ZERO" "0"
|
||||
=>"ONE" "1"
|
||||
=>"TWO" "2"
|
||||
=>"THREE" "3"
|
||||
=>"FOUR" "4"
|
||||
=>"FIVE" "5"
|
||||
=>"SIX" "6"
|
||||
=>"SEVEN" "7"
|
||||
=>"EIGHT" "8"
|
||||
=>"NINE" "9"
|
||||
=>"NUMPADZERO" "0"
|
||||
=>"NUMPADONE" "1"
|
||||
=>"NUMPADTWO" "2"
|
||||
=>"NUMPADTHREE" "3"
|
||||
=>"NUMPADFOUR" "4"
|
||||
=>"NUMPADFIVE" "5"
|
||||
=>"NUMPADSIX" "6"
|
||||
=>"NUMPADSEVEN" "7"
|
||||
=>"NUMPADEIGHT" "8"
|
||||
=>"NUMPADNINE" "9"
|
||||
// TODO there are probably other keys worth converting
|
||||
])
|
||||
|
||||
(defNew []
|
||||
(super)
|
||||
// TODO generic error handlers
|
||||
)
|
||||
|
||||
// automatically pass the last pressed key to handle key
|
||||
(method update []
|
||||
(let [:FlxKey id (FlxG.keys.firstJustPressed)]
|
||||
(unless (= id -1)
|
||||
(handleKey
|
||||
(case (id.toString)
|
||||
((when (KEY_MAP.exists key) key)
|
||||
(dictGet KEY_MAP key))
|
||||
(key (.toLowerCase key))
|
||||
(otherwise (throw "FlxKey.toString returned null!")))))))
|
Reference in New Issue
Block a user