From 3e93b5b67dc8614390c32e581ebd46a7c5e31659 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Mon, 27 Apr 2015 17:27:23 -0600 Subject: [PATCH] * Allow hot keys to be case insensitive * Start of better demo --- core/menu_view.js | 17 +++++++++---- core/toggle_menu_view.js | 4 ++-- mods/art/demo_edit_text_view1.ans | Bin 0 -> 422 bytes mods/menu.json | 38 +++++++++++++++++++++++++++++- 4 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 mods/art/demo_edit_text_view1.ans diff --git a/core/menu_view.js b/core/menu_view.js index 3f66d675..21a47dbe 100644 --- a/core/menu_view.js +++ b/core/menu_view.js @@ -25,7 +25,9 @@ function MenuView(options) { this.items = []; } - this.setHotKeys(options.hotkeys); + this.caseInsensitiveHotKeys = miscUtil.valueWithDefault(options.caseInsensitiveHotKeys, true); + + this.setHotKeys(options.hotKeys); this.focusedItemIndex = options.focusedItemIndex || 0; this.focusedItemIndex = this.items.length >= this.focusedItemIndex ? this.focusedItemIndex : 0; @@ -103,9 +105,16 @@ MenuView.prototype.setItems = function(items) { } }; -MenuView.prototype.setHotKeys = function(hotkeys) { - if(_.isObject(hotkeys)) { - this.hotkeys = hotkeys; +MenuView.prototype.setHotKeys = function(hotKeys) { + if(_.isObject(hotKeys)) { + if(this.caseInsensitiveHotKeys) { + this.hotKeys = {}; + for(var key in hotKeys) { + this.hotKeys[key.toLowerCase()] = hotKeys[key]; + } + } else { + this.hotKeys = hotKeys; + } } } diff --git a/core/toggle_menu_view.js b/core/toggle_menu_view.js index f519b8c6..a5e7d21a 100644 --- a/core/toggle_menu_view.js +++ b/core/toggle_menu_view.js @@ -60,13 +60,13 @@ ToggleMenuView.prototype.setFocus = function(focused) { }; ToggleMenuView.prototype.onKeyPress = function(key, isSpecial) { - if(isSpecial || !this.hotkeys) { + if(isSpecial || !this.hotKeys) { return; } assert(1 === key.length); - var keyIndex = this.hotkeys[key]; + var keyIndex = this.hotKeys[this.caseInsensitiveHotKeys ? key.toLowerCase() : key]; if(!_.isUndefined(keyIndex)) { this.focusedItemIndex = keyIndex; this.updateSelection(); diff --git a/mods/art/demo_edit_text_view1.ans b/mods/art/demo_edit_text_view1.ans new file mode 100644 index 0000000000000000000000000000000000000000..6307d29ea11b9173b060c57566bb5a074ddac0fc GIT binary patch literal 422 zcmb`CJqv>{5QcRtf>XD;WN|;g5bC62KZZh~)()YAsMJ7GK>{uP^}VD;>fSpzcrWig zcX22rAtXU8Y>NTg;<_p*jBYO>ZS#xq~#({Hozo`>6MX%C(aMGV~P|Y|S#yQFR zdaN7SjSh{cQ)ZB020^7DDyJX0SsDJAv{I(kDLv-}fHM9meDER&{n#}P!!(b^!qBnY MX9rSk(~p|!8`1DtdjJ3c literal 0 HcmV?d00001 diff --git a/mods/menu.json b/mods/menu.json index d803cc26..83969d24 100644 --- a/mods/menu.json +++ b/mods/menu.json @@ -199,6 +199,41 @@ } } }, + "demoEditTextView" : { + "art" : "demo_edit_text_view1.ans", + "options" : { "cls" : true }, + "form" : { + "0" : { + "BT4ET1ET2ET3" : { + "mci" : { + "ET1" : { + "maxLength" : 20 + }, + "ET2" : { + "maxLength" : 20 + }, + "ET3" : { + "fillChar" : " ", + "maxLength" : 20 + }, + "BT4" : { + "text" : "Back", + "submit" : true + } + }, + "submit" : { + "*" : [ + { + "value" : 4, + "action" : "@menu:demoMain" + } + ] + } + } + } + } + } + /* "demoEditTextView" : { "art" : "demo_edit_text_view.ans", "options" : { "cls" : true }, @@ -219,11 +254,12 @@ }, "TM6" : { "items" : [ "Yes", "No" ], - "hotkeys" : { "y" : 0, "n" : 1 } + "hotkeys" : { "Y" : 0, "n" : 1 } } } } } } } + */ } \ No newline at end of file