KeyShortcutHandler allow special keys
This commit is contained in:
@@ -86,12 +86,7 @@
|
|||||||
(entryWindow.hide)
|
(entryWindow.hide)
|
||||||
(entryWindow.show))))
|
(entryWindow.show))))
|
||||||
|
|
||||||
(when (and FlxG.keys.justPressed.SPACE !entryNameText)
|
|
||||||
(defAndCall method toggleBackgroundColor
|
|
||||||
(set save.data.backgroundIndex #{(save.data.backgroundIndex + 1) % backgroundOptions.length;}#)
|
|
||||||
(save.flush)
|
|
||||||
// setModel so the entry text gets remade in inverted/lightened colors when necessary
|
|
||||||
(refreshModel)))
|
|
||||||
|
|
||||||
(#when debug
|
(#when debug
|
||||||
(when FlxG.keys.justPressed.SEMICOLON
|
(when FlxG.keys.justPressed.SEMICOLON
|
||||||
@@ -262,7 +257,13 @@
|
|||||||
(map (m.activeTodoEntries) makeText)
|
(map (m.activeTodoEntries) makeText)
|
||||||
(set entryWindow.textColor FlxColor.GRAY)
|
(set entryWindow.textColor FlxColor.GRAY)
|
||||||
(when m.rewardFiles
|
(when m.rewardFiles
|
||||||
(_makeText "[SPACE] Cycle background color" 0))
|
(_makeText "{space} Cycle background color" 0
|
||||||
|
->_
|
||||||
|
(defAndCall method toggleBackgroundColor
|
||||||
|
(set save.data.backgroundIndex #{(save.data.backgroundIndex + 1) % backgroundOptions.length;}#)
|
||||||
|
(save.flush)
|
||||||
|
// setModel so the entry text gets remade in inverted/lightened colors when necessary
|
||||||
|
(refreshModel))))
|
||||||
(when windowWasShown
|
(when windowWasShown
|
||||||
(entryWindow.show))
|
(entryWindow.show))
|
||||||
|
|
||||||
|
@@ -47,17 +47,27 @@
|
|||||||
(tryCallOrThrow onBadKey "Key $key is not defined in $currentMap and no onBadKey event was given" key currentMap)))))
|
(tryCallOrThrow onBadKey "Key $key is not defined in $currentMap and no onBadKey event was given" key currentMap)))))
|
||||||
|
|
||||||
// Extract [k]eyboard [s]hortcuts from a string:
|
// Extract [k]eyboard [s]hortcuts from a string:
|
||||||
(method extractKeyboardShortcuts [str &opt :Stream stream :String shortcuts]
|
(method extractKeyboardShortcuts [str &opt :Stream stream :Array<String> shortcuts]
|
||||||
(unless stream (set stream (Stream.fromString str)))
|
(unless stream (set stream (Stream.fromString str)))
|
||||||
(unless shortcuts (set shortcuts ""))
|
(unless shortcuts (set shortcuts []))
|
||||||
(case (stream.takeUntilAndDrop "[")
|
(case (stream.takeUntilOneOf ["[" "{"] false)
|
||||||
((Some _)
|
((Some _)
|
||||||
(case (stream.takeUntilAndDrop "]")
|
(case (stream.takeChars 1)
|
||||||
((Some newShortcuts)
|
((Some "[")
|
||||||
(extractKeyboardShortcuts str stream (+ shortcuts newShortcuts)))
|
(case (stream.takeUntilAndDrop "]")
|
||||||
(otherwise
|
((Some newShortcuts)
|
||||||
(tryCallOrThrow onBadShortcut "unclosed [ in $str" str null)
|
(extractKeyboardShortcuts str stream (shortcuts.concat (newShortcuts.split ""))))
|
||||||
"")))
|
(otherwise
|
||||||
|
(tryCallOrThrow onBadShortcut "unclosed [ in $str" str null)
|
||||||
|
[])))
|
||||||
|
((Some "{")
|
||||||
|
(case (stream.takeUntilAndDrop "}")
|
||||||
|
((Some newShortcut)
|
||||||
|
(extractKeyboardShortcuts str stream (shortcuts.concat [newShortcut])))
|
||||||
|
(otherwise
|
||||||
|
(tryCallOrThrow onBadShortcut "unclosed { in $str" str null)
|
||||||
|
[])))
|
||||||
|
(otherwise (throw "takeUntilOneOf lied"))))
|
||||||
(otherwise
|
(otherwise
|
||||||
shortcuts)))
|
shortcuts)))
|
||||||
|
|
||||||
@@ -85,4 +95,4 @@
|
|||||||
|
|
||||||
(method :Void registerItem [description :T item]
|
(method :Void registerItem [description :T item]
|
||||||
(whenLet [keyboardShortcut (extractKeyboardShortcuts description)]
|
(whenLet [keyboardShortcut (extractKeyboardShortcuts description)]
|
||||||
(registerShortcut (keyboardShortcut.split "") description item)))
|
(registerShortcut keyboardShortcut description item)))
|
Reference in New Issue
Block a user