From 10fbc37087ba4982b14dc47f63d0c8d1cfd5635a Mon Sep 17 00:00:00 2001 From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54> Date: Mon, 13 Feb 2012 13:05:32 +0000 Subject: [PATCH] Letter keys work again in inventory/equipment screen git-svn-id: http://svn.net-core.org/repos/t-engine4@4854 51575b47-30f0-44d4-a5cc-537603b46e54 --- game/engines/default/engine/ui/EquipDoll.lua | 12 ++++++++++++ game/engines/default/engine/ui/Inventory.lua | 17 +++++++++-------- game/modules/tome/dialogs/ShowEquipInven.lua | 9 +++++++++ game/modules/tome/dialogs/ShowEquipment.lua | 9 +-------- game/modules/tome/dialogs/ShowInventory.lua | 4 ++-- game/modules/tome/dialogs/ShowStore.lua | 10 ++++------ 6 files changed, 37 insertions(+), 24 deletions(-) diff --git a/game/engines/default/engine/ui/EquipDoll.lua b/game/engines/default/engine/ui/EquipDoll.lua index c318b140db..2a30d752f8 100644 --- a/game/engines/default/engine/ui/EquipDoll.lua +++ b/game/engines/default/engine/ui/EquipDoll.lua @@ -36,6 +36,10 @@ function _M:init(t) Base.init(self, t) end +function _M:on_focus(v) + game:onTickEnd(function() self.key:unicodeInput(v) end) +end + function _M:generate() self.mouse:reset() self.key:reset() @@ -74,6 +78,12 @@ function _M:generate() } end +function _M:keyTrigger(c) + if self.chars and self.chars[c] then + self.chars[c].ui.key:triggerVirtual("ACCEPT") + end +end + function _M:setInnerFocus(id) if self.focus_ui and self.focus_ui.ui.can_focus then self.focus_ui.ui:setFocus(false) end @@ -164,10 +174,12 @@ function _M:generateEquipDollFrames() -- self.base_doll_y = (self.ih - self.h) / 2 self.base_doll_y = 0 + self.chars = {} for i, ui in ipairs(uis) do ui.y = ui.y + self.base_doll_y ui.ui.mouse.delegate_offset_x = ui.x ui.ui.mouse.delegate_offset_y = ui.y + self.chars[self:makeKeyChar(i)] = ui end self.uis = uis diff --git a/game/engines/default/engine/ui/Inventory.lua b/game/engines/default/engine/ui/Inventory.lua index 3fb9aa6b07..c817e98e8d 100644 --- a/game/engines/default/engine/ui/Inventory.lua +++ b/game/engines/default/engine/ui/Inventory.lua @@ -92,14 +92,6 @@ function _M:generate() end) self.key = self.c_inven.key self.key:addCommands{ - __TEXTINPUT = function(c) - local list - if self.focus_ui and self.focus_ui.ui == self.c_inven then list = self.c_inven.c_inven.list - end - if list and list.chars[c] then - self:use(list[list.chars[c]]) - end - end, _TAB = function() self.c_tabs.sel_j = 1 self.c_tabs.sel_i = util.boundWrap(self.c_tabs.sel_i+1, 1, #self.tabslist) self.c_tabs:onUse("left") self.c_tabs:onSelect("key") end, [{"_TAB","ctrl"}] = function() self.c_tabs.sel_j = 1 self.c_tabs.sel_i = util.boundWrap(self.c_tabs.sel_i-1, 1, #self.tabslist) self.c_tabs:onUse("left", false) self.c_tabs:onSelect("key") end, } @@ -115,6 +107,15 @@ function _M:generate() self.c_inven:onSelect() end +function _M:keyTrigger(c) + if not self.focus_ui or not self.focus_ui.ui == self.c_inven then return end + + if self.inven_list.chars[c] then + self.c_inven.sel = self.inven_list.chars[c] + self.c_inven.key:triggerVirtual("ACCEPT") + end +end + function _M:switchTab(filter) if not self.c_tabs then return end diff --git a/game/modules/tome/dialogs/ShowEquipInven.lua b/game/modules/tome/dialogs/ShowEquipInven.lua index 2571f2a748..93b8f0127d 100644 --- a/game/modules/tome/dialogs/ShowEquipInven.lua +++ b/game/modules/tome/dialogs/ShowEquipInven.lua @@ -85,6 +85,15 @@ function _M:init(title, actor, filter, action, on_select) end, EXIT = function() game:unregisterDialog(self) end, } + self.key:addCommands{ + __TEXTINPUT = function(c) + if self.focus_ui and self.focus_ui.ui == self.c_doll then + self.c_doll:keyTrigger(c) + elseif self.focus_ui and self.focus_ui.ui == self.c_inven then + self.c_inven:keyTrigger(c) + end + end, + } self.key.any_key = function(sym) -- Control resets the tooltip diff --git a/game/modules/tome/dialogs/ShowEquipment.lua b/game/modules/tome/dialogs/ShowEquipment.lua index af562c4130..8954f82483 100644 --- a/game/modules/tome/dialogs/ShowEquipment.lua +++ b/game/modules/tome/dialogs/ShowEquipment.lua @@ -54,16 +54,9 @@ function _M:init(title, actor, filter, action) self:setupUI() self.key:addCommands{ - __TEXTINPUT = function(c) - if self.list and self.list.chars[c] then - self:use(self.list[self.list.chars[c]]) - end - end, + __TEXTINPUT = function(c) self.c_doll:keyTrigger(c) end, } self.key:addBinds{ - ACCEPT = function() --- self:use(self.c_list.list[self.c_list.sel]) - end, EXIT = function() game:unregisterDialog(self) end, } end diff --git a/game/modules/tome/dialogs/ShowInventory.lua b/game/modules/tome/dialogs/ShowInventory.lua index ba14039c1d..7926a0a66c 100644 --- a/game/modules/tome/dialogs/ShowInventory.lua +++ b/game/modules/tome/dialogs/ShowInventory.lua @@ -55,8 +55,8 @@ function _M:init(title, inven, filter, action, actor) self.key:addCommands{ __TEXTINPUT = function(c) - if self.list and self.list.chars[c] then - self:use(self.list[self.list.chars[c]]) + if self.focus_ui and self.focus_ui.ui == self.c_inven then + self.c_inven:keyTrigger(c) end end, } diff --git a/game/modules/tome/dialogs/ShowStore.lua b/game/modules/tome/dialogs/ShowStore.lua index 51a5a0d39e..b11d1af5bb 100644 --- a/game/modules/tome/dialogs/ShowStore.lua +++ b/game/modules/tome/dialogs/ShowStore.lua @@ -73,12 +73,10 @@ function _M:init(title, store_inven, actor_inven, store_filter, actor_filter, ac self.key:addCommands{ __TEXTINPUT = function(c) - local list - if self.focus_ui and self.focus_ui.ui == self.c_inven then list = self.c_inven.c_inven.list - elseif self.focus_ui and self.focus_ui.ui == self.c_store then list = self.c_store.c_inven.list - end - if list and list.chars[c] then - self:use(list[list.chars[c]]) + if self.focus_ui and self.focus_ui.ui == self.c_store then + self.c_store:keyTrigger(c) + elseif self.focus_ui and self.focus_ui.ui == self.c_inven then + self.c_inven:keyTrigger(c) end end, } -- GitLab