Skip to content
Snippets Groups Projects
Commit 7be7e47c authored by dg's avatar dg
Browse files

Updated keyboard handling, should not double trigger anymore

git-svn-id: http://svn.net-core.org/repos/t-engine4@4358 51575b47-30f0-44d4-a5cc-537603b46e54
parent c546d76b
No related branches found
No related tags found
No related merge requests found
Showing
with 103 additions and 37 deletions
......@@ -18,34 +18,34 @@
-- darkgod@te4.org
defineAction{
default = { "uni:<", "uni:>" },
default = { "sym:=<:false:false:false:false", "sym:=>:false:false:false:false" },
type = "CHANGE_LEVEL",
group = "actions",
name = "Go to next/previous level",
}
defineAction{
default = { "uni:G" },
default = { "sym:=g:false:true:false:false" },
type = "LEVELUP",
group = "actions",
name = "Levelup window",
}
defineAction{
default = { "uni:m" },
default = { "sym:=m:false:false:false:false" },
type = "USE_TALENTS",
group = "actions",
name = "Use talents",
}
defineAction{
default = { "uni:j", "sym:_q:true:false:false:false" },
default = { "sym:=j:false:false:false:false", "sym:_q:true:false:false:false" },
type = "SHOW_QUESTS",
group = "actions",
name = "Show quests",
}
defineAction{
default = { "uni:r", "uni:R" },
default = { "sym:=r:false:false:false:false", "sym:=r:false:true:false:false" },
type = "REST",
group = "actions",
name = "Rest for a while",
......@@ -73,7 +73,7 @@ defineAction{
}
defineAction{
default = { "uni:l" },
default = { "sym:=l:false:false:false:false" },
type = "LOOK_AROUND",
group = "actions",
name = "Look around",
......@@ -87,14 +87,14 @@ defineAction{
}
defineAction{
default = { "sym:_t:true:false:false:false" },
default = { "sym:=t:true:false:false:false" },
type = "SHOW_TIME",
group = "actions",
name = "Show game calendar",
}
defineAction{
default = { "uni:c", "uni:C" },
default = { "sym:=c", "sym:=c:false:true:false:false" },
type = "SHOW_CHARACTER_SHEET",
group = "actions",
name = "Show character sheet",
......@@ -107,13 +107,6 @@ defineAction{
name = "Switch graphical modes",
}
defineAction{
default = { "uni:?" },
type = "HELP",
group = "actions",
name = "Help",
}
defineAction{
default = { "sym:_RETURN:false:false:false:false", "sym:_KP_ENTER:false:false:false:false" },
type = "ACCEPT",
......
......@@ -25,7 +25,7 @@ defineAction{
}
defineAction{
default = { "sym:_m:true:false:false:false" },
default = { "sym:=m:true:false:false:false" },
type = "SHOW_MESSAGE_LOG",
group = "actions",
name = "Show message log",
......
......@@ -18,53 +18,53 @@
-- darkgod@te4.org
defineAction{
default = { "uni:i", },
default = { "sym:=i:false:false:false:false", },
type = "SHOW_INVENTORY",
group = "inventory",
name = "Show inventory",
}
defineAction{
default = { "uni:e", },
default = { "sym:=e:false:false:false:false", },
type = "SHOW_EQUIPMENT",
group = "inventory",
name = "Show equipment",
}
defineAction{
default = { "uni:g" },
default = { "sym:=g:false:false:false:false" },
type = "PICKUP_FLOOR",
group = "actions",
name = "Pickup items",
}
defineAction{
default = { "uni:d" },
default = { "sym:=d:false:false:false:false" },
type = "DROP_FLOOR",
group = "actions",
name = "Drop items",
}
defineAction{
default = { "uni:w", },
default = { "sym:=w:false:false:false:false", },
type = "WEAR_ITEM",
group = "inventory",
name = "Wield/wear items",
}
defineAction{
default = { "uni:t", },
default = { "sym:=t:false:false:false:false", },
type = "TAKEOFF_ITEM",
group = "inventory",
name = "Takeoff items",
}
defineAction{
default = { "uni:u", },
default = { "sym:=u:false:false:false:false", },
type = "USE_ITEM",
group = "inventory",
name = "Use items",
}
defineAction{
default = { "uni:x", },
default = { "sym:=x:false:false:false:false", },
type = "QUICK_SWITCH_WEAPON",
group = "inventory",
name = "Quick switch weapons set",
......
......@@ -76,7 +76,7 @@ defineAction{
-- Running
defineAction{
default = { "uni:." },
default = { "sym:=.:false:false:false:false" },
type = "RUN",
group = "movement",
name = "Run",
......
......@@ -139,6 +139,8 @@ function _M:on_register()
self:next()
self:select(self.list[self.c_list.sel])
self.key:unicodeInput(true)
if __module_extra_info.no_quickbirth then return end
if self.quickbirth then
if __module_extra_info.auto_quickbirth then
......
......@@ -31,6 +31,7 @@ commands = {}
function _M:init()
engine.Dialog.init(self, "Lua Console", core.display.size())
game:onTickEnd(function() self.key:unicodeInput(true) end)
self:keyCommands{
_RETURN = function()
table.insert(self.commands, self.line)
......
......@@ -117,6 +117,7 @@ end
function _M:init()
engine.KeyCommand.init(self)
self.virtuals = {}
self.use_unicode = false
self:bindKeys()
end
......@@ -141,8 +142,8 @@ function _M:findBoundKeys(virtual)
return unpack(bs)
end
function _M:makeKeyString(sym, ctrl, shift, alt, meta, unicode)
return ("sym:%s:%s:%s:%s:%s"):format(tostring(self.sym_to_name[sym] or sym), tostring(ctrl), tostring(shift), tostring(alt), tostring(meta)), unicode and "uni:"..unicode
function _M:makeKeyString(sym, ctrl, shift, alt, meta, unicode, key)
return ("sym:%s:%s:%s:%s:%s"):format(tostring(self.sym_to_name[sym] or sym), tostring(ctrl), tostring(shift), tostring(alt), tostring(meta)), key and ("sym:=%s:%s:%s:%s:%s"):format(key, tostring(ctrl), tostring(shift), tostring(alt), tostring(meta)), unicode and "uni:"..unicode
end
function _M:makeGestureString(gesture)
......@@ -166,12 +167,14 @@ function _M:formatKeyString(ks)
shift = shift == "true" and true or false
alt = alt == "true" and true or false
meta = meta == "true" and true or false
if tonumber(sym) then
sym = tonumber(sym)
if sym:sub(1, 1) == "=" then
sym = sym:sub(2)
else
sym = _M[sym]
if tonumber(sym) then sym = tonumber(sym)
else sym = _M[sym]
end
sym = core.key.symName(sym)
end
sym = core.key.symName(sym)
if ctrl then sym = "[C]+"..sym end
if shift then sym = "[S]+"..sym end
......@@ -203,24 +206,32 @@ function _M:formatKeyString(ks)
end
function _M:receiveKey(sym, ctrl, shift, alt, meta, unicode, isup, key, ismouse)
if unicode and not self.use_unicode then return end
self:handleStatus(sym, ctrl, shift, alt, meta, unicode, isup)
if self.any_key then self.any_key(sym, ctrl, shift, alt, meta, unicode, isup, key) end
local ks, us
if not ismouse then ks, us = self:makeKeyString(sym, ctrl, shift, alt, meta, unicode)
if not ismouse then ks, kks, us = self:makeKeyString(sym, ctrl, shift, alt, meta, unicode, key)
else ks = self:makeMouseString(sym, ctrl, shift, alt, meta) end
-- print("[BIND]", sym, ctrl, shift, alt, meta, unicode, " :=: ", ks, us, " ?=? ", self.binds[ks], us and self.binds[us])
-- print("[BIND]", sym, ctrl, shift, alt, meta, unicode, " :=: ", ks, kks, us, " ?=? ", self.binds[ks], kks and self.binds[kks], us and self.binds[us])
if self.binds[ks] then
for virt, _ in pairs(self.binds[ks]) do if self.virtuals[virt] then
if isup and not _M.binds_def[virt].updown then return end
self.virtuals[virt](sym, ctrl, shift, alt, meta, unicode, isup)
self.virtuals[virt](sym, ctrl, shift, alt, meta, unicode, isup, key)
return true
end end
elseif kks and self.binds[kks] then
for virt, _ in pairs(self.binds[kks]) do if self.virtuals[virt] then
if isup and not _M.binds_def[virt].updown then return end
self.virtuals[virt](sym, ctrl, shift, alt, meta, unicode, isup, key)
return true
end end
elseif us and self.binds[us] then
for virt, _ in pairs(self.binds[us]) do if self.virtuals[virt] then
-- if isup and not _M.binds_def[virt].updown then return end
self.virtuals[virt](sym, ctrl, shift, alt, meta, unicode, isup)
self.virtuals[virt](sym, ctrl, shift, alt, meta, unicode, isup, key)
return true
end end
end
......@@ -228,6 +239,11 @@ function _M:receiveKey(sym, ctrl, shift, alt, meta, unicode, isup, key, ismouse)
return engine.KeyCommand.receiveKey(self, sym, ctrl, shift, alt, meta, unicode, isup, key)
end
--- Allow receiving unicode events
function _M:unicodeInput(v)
self.use_unicode = v
end
--- Reset all binds
function _M:reset()
self.virtuals = {}
......
......@@ -57,6 +57,10 @@ function _M:init(chat, id)
}
end
function _M:on_register()
game:onTickEnd(function() self.key:unicodeInput(true) end)
end
function _M:select(item)
local a = self.chat:get(self.cur_id).answers[item.answer]
if not a then return end
......
......@@ -135,6 +135,10 @@ function _M:init(title, actor, filter, action, on_select)
}
end
function _M:on_register()
game:onTickEnd(function() self.key:unicodeInput(true) end)
end
function _M:defineHotkey(id)
if not self.actor or not self.actor.hotkey then return end
......
......@@ -67,6 +67,10 @@ function _M:init(title, actor, filter, action)
}
end
function _M:on_register()
game:onTickEnd(function() self.key:unicodeInput(true) end)
end
function _M:select(item)
if item and self.uis[2] then
self.c_desc:switchItem(item, item.desc)
......
......@@ -65,6 +65,10 @@ function _M:init(title, inven, filter, action, actor)
}
end
function _M:on_register()
game:onTickEnd(function() self.key:unicodeInput(true) end)
end
function _M:select(item)
if item then
self.c_desc:switchItem(item, item.desc)
......
......@@ -73,6 +73,10 @@ function _M:init(title, x, y, filter, action, takeall, actor)
}
end
function _M:on_register()
game:onTickEnd(function() self.key:unicodeInput(true) end)
end
function _M:used()
if self.taking_all then return end
self:generateList()
......
......@@ -80,6 +80,10 @@ function _M:init(title, store_inven, actor_inven, store_filter, actor_filter, ac
}
end
function _M:on_register()
game:onTickEnd(function() self.key:unicodeInput(true) end)
end
function _M:updateStore()
self:generateList()
end
......
......@@ -114,6 +114,10 @@ Check out the keybinding screen in the game menu to bind hotkeys to a key (defau
}
end
function _M:on_register()
game:onTickEnd(function() self.key:unicodeInput(true) end)
end
function _M:defineHotkey(id)
if not self.actor.hotkey then return end
local item = self.list[self.c_list.sel]
......
......@@ -77,6 +77,17 @@ function _M:getInven(id)
end
end
--- Tells if an inventory still has room left
function _M:canAddToInven(id)
if type(id) == "number" then
return #self.inven[id] < self.inven[id].max
elseif type(id) == "string" then
return #self.inven[self["INVEN_"..id]] < self.inven[self["INVEN_"..id]].max
else
return id
end
end
--- Adds an object to an inventory
-- @return false if the object could not be added otherwise true and the inventory index where it is now
function _M:addObject(inven_id, o)
......
......@@ -87,12 +87,12 @@ end
--- Switch to previous hotkey page
function _M:prevHotkeyPage()
self.hotkey_page = util.boundWrap(self.hotkey_page - 1, 1, 3)
self.hotkey_page = util.boundWrap(self.hotkey_page - 1, 1, 4)
self.changed = true
end
--- Switch to next hotkey page
function _M:nextHotkeyPage()
self.hotkey_page = util.boundWrap(self.hotkey_page + 1, 1, 3)
self.hotkey_page = util.boundWrap(self.hotkey_page + 1, 1, 4)
self.changed = true
end
--- Switch to hotkey page
......
......@@ -31,4 +31,5 @@ function _M:setFocus(v)
if not v then
self.focus_decay = self.focus_decay_max
end
if self.on_focus then self:on_focus(v) end
end
......@@ -43,6 +43,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()
......
......@@ -44,6 +44,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()
......
......@@ -130,6 +130,12 @@ function table.listify(t)
return tt
end
function table.keys_to_values(t)
local tt = {}
for k, e in pairs(t) do tt[e] = k end
return tt
end
function table.keys(t)
local tt = {}
for k, e in pairs(t) do tt[#tt+1] = k end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment