From b12a74b6f7761280622ea2645bc0fe5575dd3d91 Mon Sep 17 00:00:00 2001 From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54> Date: Tue, 5 Oct 2010 19:50:42 +0000 Subject: [PATCH] Correctly index quick keys in inventory dialogs git-svn-id: http://svn.net-core.org/repos/t-engine4@1426 51575b47-30f0-44d4-a5cc-537603b46e54 --- .../default/engine/dialogs/ShowEquipInven.lua | 8 ++++---- .../default/engine/dialogs/ShowEquipment.lua | 4 ++-- .../default/engine/dialogs/ShowInventory.lua | 5 ++--- .../default/engine/dialogs/ShowPickupFloor.lua | 2 +- game/engines/default/engine/dialogs/ShowStore.lua | 8 ++++---- game/engines/default/engine/ui/Dialog.lua | 14 ++++++++++++++ 6 files changed, 27 insertions(+), 14 deletions(-) diff --git a/game/engines/default/engine/dialogs/ShowEquipInven.lua b/game/engines/default/engine/dialogs/ShowEquipInven.lua index d8224e857c..767bb2463e 100644 --- a/game/engines/default/engine/dialogs/ShowEquipInven.lua +++ b/game/engines/default/engine/dialogs/ShowEquipInven.lua @@ -150,7 +150,7 @@ function _M:generateList() self.equip_list = {} local list = self.equip_list local chars = {} - local i = 0 + local i = 1 self.max_h = 0 for inven_id = 1, #self.actor.inven_def do if self.actor.inven[inven_id] and self.actor.inven_def[inven_id].is_worn then @@ -160,7 +160,7 @@ function _M:generateList() for item, o in ipairs(self.actor.inven[inven_id]) do if not self.filter or self.filter(o) then - local char = string.char(string.byte('a') + i) + local char = self:makeKeyChar(i) local zone = Textzone.new{width=self.iw, height=self.ih, text=o:getDesc()} list[#list+1] = { zone=zone, id=#list+1, char=char, name=o:getName{do_color=true}, object=o, inven=inven_id, item=item, cat=o.subtype, encumberance=o.encumber } self.max_h = math.max(self.max_h, #o:getDesc():splitLines(self.iw - 10, self.font)) @@ -177,10 +177,10 @@ function _M:generateList() self.inven_list = {} local list = self.inven_list local chars = {} - local i = 0 + local i = 1 for item, o in ipairs(self.actor:getInven("INVEN")) do if not self.filter or self.filter(o) then - local char = string.char(string.byte('a') + i) + local char = self:makeKeyChar(i) local zone = Textzone.new{width=self.iw, height=self.ih, text=o:getDesc()} list[#list+1] = { zone=zone, id=#list+1, char=char, name=o:getName{do_color=true}, object=o, inven=self.actor.INVEN_INVEN, item=item, cat=o.subtype, encumberance=o.encumber } self.max_h = math.max(self.max_h, #o:getDesc():splitLines(self.iw - 10, self.font)) diff --git a/game/engines/default/engine/dialogs/ShowEquipment.lua b/game/engines/default/engine/dialogs/ShowEquipment.lua index 13a96d8703..b935fbf736 100644 --- a/game/engines/default/engine/dialogs/ShowEquipment.lua +++ b/game/engines/default/engine/dialogs/ShowEquipment.lua @@ -82,7 +82,7 @@ function _M:generateList() local list = {} local chars = {} list.chars = chars - local i = 0 + local i = 1 for inven_id = 1, #self.actor.inven_def do if self.actor.inven[inven_id] and self.actor.inven_def[inven_id].is_worn then local zone = Textzone.new{width=self.c_desc.w, height=self.c_desc.h, text=self.actor.inven_def[inven_id].description} @@ -90,7 +90,7 @@ function _M:generateList() for item, o in ipairs(self.actor.inven[inven_id]) do if not self.filter or self.filter(o) then - local char = string.char(string.byte('a') + i) + local char = self:makeKeyChar(i) local zone = Textzone.new{width=self.c_desc.w, height=self.c_desc.h, text=o:getDesc()} list[#list+1] = { zone=zone, id=#list+1, char=char, name=o:getName{do_color=true}, object=o, inven=inven_id, item=item, cat=o.subtype, encumberance=o.encumber } chars[char] = #list diff --git a/game/engines/default/engine/dialogs/ShowInventory.lua b/game/engines/default/engine/dialogs/ShowInventory.lua index b68068f35b..cfca5ff67d 100644 --- a/game/engines/default/engine/dialogs/ShowInventory.lua +++ b/game/engines/default/engine/dialogs/ShowInventory.lua @@ -79,11 +79,10 @@ function _M:generateList() -- Makes up the list local list = {} list.chars = {} - local i = 0 for item, o in ipairs(self.inven) do if not self.filter or self.filter(o) then - local char = string.char(string.byte('a') + i) - list.chars[char] = i + local char = self:makeKeyChar(item) + list.chars[char] = item local zone = Textzone.new{width=self.c_desc.w, height=self.c_desc.h, text=o:getDesc()} list[#list+1] = { char=char, zone=zone, name=o:getDisplayString()..o:getName(), color=o:getDisplayColor(), object=o, item=item, cat=o.subtype, encumberance=o.encumber } i = i + 1 diff --git a/game/engines/default/engine/dialogs/ShowPickupFloor.lua b/game/engines/default/engine/dialogs/ShowPickupFloor.lua index 2f5d9c71dc..2b0b5b4cda 100644 --- a/game/engines/default/engine/dialogs/ShowPickupFloor.lua +++ b/game/engines/default/engine/dialogs/ShowPickupFloor.lua @@ -107,7 +107,7 @@ function _M:generateList() local o = game.level.map:getObject(self.x, self.y, idx) if not o then break end if not self.filter or self.filter(o) then - local char = string.char(string.byte('a') + i) + local char = self:makeKeyChar(i) list.chars[char] = i local zone = Textzone.new{width=self.c_desc.w, height=self.c_desc.h, text=o:getDesc()} list[#list+1] = { char=char, zone=zone, name=o:getDisplayString()..o:getName(), color=o:getDisplayColor(), object=o, item=i, cat=o.subtype, encumberance=o.encumber } diff --git a/game/engines/default/engine/dialogs/ShowStore.lua b/game/engines/default/engine/dialogs/ShowStore.lua index ea92f27de9..9222dab9bc 100644 --- a/game/engines/default/engine/dialogs/ShowStore.lua +++ b/game/engines/default/engine/dialogs/ShowStore.lua @@ -104,11 +104,11 @@ function _M:generateList() -- Makes up the list local list = {} list.chars = {} - local i = 0 + local i = 1 self.max_h = 0 for item, o in ipairs(self.store_inven) do if not self.store_filter or self.store_filter(o) then - local char = string.char(string.byte('a') + i) + local char = self:makeKeyChar(i) local zone = Textzone.new{width=self.iw, height=self.ih, text=o:getDesc()} list[#list+1] = { zone=zone, id=#list+1, char=char, name=o:getDisplayString()..o:getName(), color=o:getDisplayColor(), object=o, item=item, cat=o.subtype, cost=o.cost } self.max_h = math.max(self.max_h, #o:getDesc():splitLines(self.iw - 10, self.font)) @@ -121,10 +121,10 @@ function _M:generateList() -- Makes up the list local list = {} list.chars = {} - local i = 0 + local i = 1 for item, o in ipairs(self.actor_inven) do if not self.actor_filter or self.actor_filter(o) then - local char = string.char(string.byte('a') + i) + local char = self:makeKeyChar(i) local zone = Textzone.new{width=self.iw, height=self.ih, text=o:getDesc()} list[#list+1] = { zone=zone, id=#list+1, char=char, name=o:getDisplayString()..o:getName(), color=o:getDisplayColor(), object=o, item=item, cat=o.subtype, cost=o.cost } self.max_h = math.max(self.max_h, #o:getDesc():splitLines(self.iw - 10, self.font)) diff --git a/game/engines/default/engine/ui/Dialog.lua b/game/engines/default/engine/ui/Dialog.lua index 67c4f5af83..c12eef9525 100644 --- a/game/engines/default/engine/ui/Dialog.lua +++ b/game/engines/default/engine/ui/Dialog.lua @@ -298,6 +298,20 @@ function _M:display() end function _M:unload() end +function _M:makeKeyChar(i) + i = i - 1 + if i <= 26 then + return string.char(string.byte('a') + i) + elseif i <= 52 then + return string.char(string.byte('A') + i) + elseif i <= 62 then + return string.char(string.byte('0') + i) + else + -- Invalid + return " " + end +end + function _M:toScreen(x, y) -- Draw with only the texture if self.__showup then -- GitLab