Skip to content
Snippets Groups Projects
Commit 4e345ac9 authored by dg's avatar dg
Browse files

convert dialogs to keybind

git-svn-id: http://svn.net-core.org/repos/t-engine4@232 51575b47-30f0-44d4-a5cc-537603b46e54
parent b1393ee4
No related branches found
No related tags found
No related merge requests found
......@@ -52,3 +52,24 @@ defineAction{
group = "actions",
name = "Switch graphical modes",
}
defineAction{
default = { "uni:?" },
type = "HELP",
group = "actions",
name = "Help",
}
defineAction{
default = { "sym:13:false:false:false:false", "sym:271:false:false:false:false" },
type = "ACCEPT",
group = "actions",
name = "Accept action",
}
defineAction{
default = { "sym:27:false:false:false:false" },
type = "EXIT",
group = "actions",
name = "Exit menu",
}
require "engine.class"
require "engine.Tiles"
require "engine.KeyCommand"
require "engine.KeyBind"
--- Handles dialog windows
module(..., package.seeall, class.make)
......@@ -75,10 +75,11 @@ end
function _M:drawDialog(s)
end
function _M:keyCommands(t)
function _M:keyCommands(t, b)
self.old_key = game.key
game.key = engine.KeyCommand.new()
game.key:addCommands(t)
game.key = engine.KeyBind.new()
if t then game.key:addCommands(t) end
if b then game.key:addBinds(b) end
game.key:setCurrent()
self.key = game.key
end
......
......@@ -275,3 +275,11 @@ _UNDO = 322 -- Atari keyboard has Undo
__DEFAULT = -10000
__TEXTINPUT = -10001
-- Reverse sym calc
_M.sym_to_name = {}
for k, e in pairs(_M) do
if type(k) == "string" and type(e) == "number" then
_M.sym_to_name[e] = k
end
end
......@@ -95,7 +95,15 @@ end
-- @param mods a table with the mod keys needed, i.e: {"ctrl", "alt"}
-- @param fct the function to call when the key is pressed
function _M:addBinds(t)
local later = {}
for virtual, fct in pairs(t) do
self:addBind(virtual, fct)
if type(fct) == "function" then
self:addBind(virtual, fct)
else
later[virtual] = fct
end
end
for virtual, fct in pairs(later) do
self:addBind(virtual, self.virtuals[fct])
end
end
......@@ -15,18 +15,19 @@ function _M:init(title, actor, filter, action)
self.scroll = 1
self.max = math.floor((self.ih - 5) / self.font_h) - 1
self:keyCommands{
_UP = function() self.sel = util.boundWrap(self.sel - 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) end,
_DOWN = function() self.sel = util.boundWrap(self.sel + 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) end,
_RETURN = function() self:use() end,
_ESCAPE = function() game:unregisterDialog(self) end,
self:keyCommands({
__TEXTINPUT = function(c)
if self.chars[c] then
self.sel = self.chars[c]
self:use()
end
end,
}
}, {
MOVE_UP = function() self.sel = util.boundWrap(self.sel - 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) end,
MOVE_DOWN = function() self.sel = util.boundWrap(self.sel + 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) end,
ACCEPT = function() self:use() end,
EXIT = function() game:unregisterDialog(self) end,
})
self:mouseZones{
{ x=2, y=5, w=350, h=self.font_h*self.max, fct=function(button, x, y, xrel, yrel, tx, ty)
self.sel = util.bound(self.scroll + math.floor(ty / self.font_h), 1, #self.list)
......
......@@ -15,18 +15,19 @@ function _M:init(title, inven, filter, action)
self.scroll = 1
self.max = math.floor((self.ih - 5) / self.font_h) - 1
self:keyCommands{
_UP = function() self.sel = util.boundWrap(self.sel - 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) end,
_DOWN = function() self.sel = util.boundWrap(self.sel + 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) end,
_RETURN = function() self:use() end,
_ESCAPE = function() game:unregisterDialog(self) end,
self:keyCommands({
__TEXTINPUT = function(c)
if c:find("^[a-z]$") then
self.sel = util.bound(1 + string.byte(c) - string.byte('a'), 1, #self.list)
self:use()
end
end,
}
},{
MOVE_UP = function() self.sel = util.boundWrap(self.sel - 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) end,
MOVE_DOWN = function() self.sel = util.boundWrap(self.sel + 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) end,
ACCEPT = function() self:use() end,
EXIT = function() game:unregisterDialog(self) end,
})
self:mouseZones{
{ x=2, y=5, w=350, h=self.font_h*self.max, fct=function(button, x, y, xrel, yrel, tx, ty)
self.sel = util.bound(self.scroll + math.floor(ty / self.font_h), 1, #self.list)
......
......@@ -15,11 +15,7 @@ function _M:init(title, x, y, filter, action)
self.scroll = 1
self.max = math.floor((self.ih - 5) / self.font_h) - 1
self:keyCommands{
_UP = function() self.sel = util.boundWrap(self.sel - 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) end,
_DOWN = function() self.sel = util.boundWrap(self.sel + 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) end,
_RETURN = function() self:use() end,
_ESCAPE = function() game:unregisterDialog(self) end,
self:keyCommands({
_ASTERISK = function() while self:use() do end end,
__TEXTINPUT = function(c)
if c:find("^[a-z]$") then
......@@ -27,7 +23,12 @@ function _M:init(title, x, y, filter, action)
self:use()
end
end,
}
},{
MOVE_UP = function() self.sel = util.boundWrap(self.sel - 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) end,
MOVE_DOWN = function() self.sel = util.boundWrap(self.sel + 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) end,
ACCEPT = function() self:use() end,
EXIT = function() game:unregisterDialog(self) end,
})
self:mouseZones{
{ x=2, y=5, w=350, h=self.font_h*self.max, fct=function(button, x, y, xrel, yrel, tx, ty)
self.sel = util.bound(self.scroll + math.floor(ty / self.font_h), 1, #self.list)
......
......@@ -14,31 +14,32 @@ function _M:init(actor)
self.scroll = 1
self.max = math.floor((self.ih - 5) / self.font_h) - 1
self:keyCommands{
_1 = function() self:defineHotkey(1) end,
_2 = function() self:defineHotkey(2) end,
_3 = function() self:defineHotkey(3) end,
_4 = function() self:defineHotkey(4) end,
_5 = function() self:defineHotkey(5) end,
_6 = function() self:defineHotkey(6) end,
_7 = function() self:defineHotkey(7) end,
_8 = function() self:defineHotkey(8) end,
_9 = function() self:defineHotkey(9) end,
_0 = function() self:defineHotkey(10) end,
_RIGHTPAREN = function() self:defineHotkey(11) end,
_EQUALS = function() self:defineHotkey(12) end,
_UP = function() self.sel = util.boundWrap(self.sel - 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) self.changed = true end,
_DOWN = function() self.sel = util.boundWrap(self.sel + 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) self.changed = true end,
_RETURN = function() self:use() end,
_ESCAPE = function() game:unregisterDialog(self) end,
self:keyCommands({
__TEXTINPUT = function(c)
if c:find("^[a-z]$") then
self.sel = util.bound(1 + string.byte(c) - string.byte('a'), 1, #self.list)
self:use()
end
end,
}
},{
HOTKEY_1 = function() self:defineHotkey(1) end,
HOTKEY_2 = function() self:defineHotkey(2) end,
HOTKEY_3 = function() self:defineHotkey(3) end,
HOTKEY_4 = function() self:defineHotkey(4) end,
HOTKEY_5 = function() self:defineHotkey(5) end,
HOTKEY_6 = function() self:defineHotkey(6) end,
HOTKEY_7 = function() self:defineHotkey(7) end,
HOTKEY_8 = function() self:defineHotkey(8) end,
HOTKEY_9 = function() self:defineHotkey(9) end,
HOTKEY_10 = function() self:defineHotkey(10) end,
HOTKEY_11 = function() self:defineHotkey(11) end,
HOTKEY_12 = function() self:defineHotkey(12) end,
MOVE_UP = function() self.sel = util.boundWrap(self.sel - 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) self.changed = true end,
MOVE_DOWN = function() self.sel = util.boundWrap(self.sel + 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) self.changed = true end,
ACCEPT = function() self:use() end,
EXIT = function() game:unregisterDialog(self) end,
})
self:mouseZones{
{ x=2, y=5, w=350, h=self.font_h*self.max, fct=function(button, x, y, xrel, yrel, tx, ty)
self.sel = util.bound(self.scroll + math.floor(ty / self.font_h), 1, #self.list)
......
......@@ -11,12 +11,13 @@ function _M:init(actor)
self.sel = 1
self:keyCommands{
_UP = function() self.changed = true; self.sel = util.boundWrap(self.sel - 1, 1, 6) end,
_DOWN = function() self.changed = true; self.sel = util.boundWrap(self.sel + 1, 1, 6) end,
_LEFT = function() self.changed = true; self:incStat(-1) end,
_RIGHT = function() self.changed = true; self:incStat(1) end,
_ESCAPE = function()
self:keyCommands(nil, {
MOVE_UP = function() self.changed = true; self.sel = util.boundWrap(self.sel - 1, 1, 6) end,
MOVE_DOWN = function() self.changed = true; self.sel = util.boundWrap(self.sel + 1, 1, 6) end,
MOVE_LEFT = function() self.changed = true; self:incStat(-1) end,
MOVE_RIGHT = function() self.changed = true; self:incStat(1) end,
ACCEPT = "EXIT",
EXIT = function()
game:unregisterDialog(self)
-- if talents to spend, do it now
......@@ -25,7 +26,7 @@ function _M:init(actor)
game:registerDialog(dt)
end
end,
}
})
self:mouseZones{
{ x=2, y=25, w=130, h=self.font_h*6, fct=function(button, x, y, xrel, yrel, tx, ty)
self.changed = true
......
......@@ -14,13 +14,14 @@ function _M:init(actor)
self.scroll = 1
self.max = math.floor((self.ih - 45) / self.font_h) - 1
self:keyCommands{
_UP = function() self.sel = util.boundWrap(self.sel - 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) self.changed = true end,
_DOWN = function() self.sel = util.boundWrap(self.sel + 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) self.changed = true end,
_LEFT = function() self:learn(false) self.changed = true end,
_RIGHT = function() self:learn(true) self.changed = true end,
_ESCAPE = function() game:unregisterDialog(self) end,
}
self:keyCommands(nil, {
MOVE_UP = function() self.sel = util.boundWrap(self.sel - 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) self.changed = true end,
MOVE_DOWN = function() self.sel = util.boundWrap(self.sel + 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) self.changed = true end,
MOVE_LEFT = function() self:learn(false) self.changed = true end,
MOVE_RIGHT = function() self:learn(true) self.changed = true end,
ACCEPT = "EXIT",
EXIT = function() game:unregisterDialog(self) end,
})
self:mouseZones{
{ x=2, y=45, w=350, h=self.font_h*self.max, fct=function(button, x, y, xrel, yrel, tx, ty)
self.changed = true
......
......@@ -6,20 +6,21 @@ module(..., package.seeall, class.inherit(engine.Dialog))
function _M:init()
engine.Dialog.init(self, "Realy exit ToME?", 300, 100)
self:keyCommands{
_y = function()
self:keyCommands({
__DEFAULT = function()
game:unregisterDialog(self)
game.quit_dialog = false
end,
}, {
ACCEPT = function()
local save = Savefile.new(game.save_name)
save:saveGame(game)
save:close()
util.showMainMenu()
end,
__DEFAULT = function()
game:unregisterDialog(self)
game.quit_dialog = false
end,
}
})
end
function _M:drawDialog(s, w, h)
s:drawColorStringCentered(self.font, "Press Y to quit, any other keys to stay", 2, 2, self.iw - 2, self.ih - 2)
s:drawColorStringCentered(self.font, "Press enter to quit, any other keys to stay", 2, 2, self.iw - 2, self.ih - 2)
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