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

hotkeys

git-svn-id: http://svn.net-core.org/repos/t-engine4@93 51575b47-30f0-44d4-a5cc-537603b46e54
parent 173c242e
No related branches found
No related tags found
No related merge requests found
-- Convert unicode keys to other unicode keys depending on locale
-- This allows to support the number bar "hotkeys" without too much trouble
if locale == "frFR" then
return {
[_AMPERSAND] = _1,
[_WORLD_73] = _2,
[_QUOTEDBL] = _3,
[_QUOTE] = _4,
[_LEFTPAREN] = _5,
[_MINUS] = _6,
[_WORLD_72] = _7,
[_UNDERSCORE] = _8,
[_WORLD_71] = _9,
[_WORLD_64] = _0,
-- [_RIGHTPAREN] = _),
-- [_EQUALS] = _=,
}
else
-- Default to no convertion
return {}
end
......@@ -30,6 +30,8 @@ function _M:init(t)
self.color_bb = self.color_bb or -1
next_uid = next_uid + 1
self.changed = true
end
--- If we are cloned we need a new uid
......@@ -37,6 +39,8 @@ function _M:cloned()
self.uid = next_uid
__uids[self.uid] = self
next_uid = next_uid + 1
self.changed = true
end
_M.loadNoDelay = true
......@@ -46,6 +50,8 @@ function _M:loaded()
self.uid = next_uid
__uids[self.uid] = self
next_uid = next_uid + 1
self.changed = true
end
--- Change the entity's uid
......
......@@ -8,10 +8,14 @@ function _M:init()
engine.Key.init(self)
self.commands = {}
self.on_input = false
self.locale_convert = {}
-- Fullscreen toggle
self:addCommand(self._RETURN, {"alt"}, function() core.display.fullscreen() end)
end
--- Adds the profiler keybind (ctrl, alt, chift, p)
function _M:setupProfiler()
-- Profiler
self:addCommand(self._p, {"ctrl","alt","shift"}, function()
if not _G.profiling then
......@@ -26,6 +30,9 @@ function _M:init()
end
function _M:receiveKey(sym, ctrl, shift, alt, meta, unicode)
-- Convert locale
sym = self.locale_convert[sym] or sym
if not self.commands[sym] and not self.commands[self.__DEFAULT] then
if self.on_input and unicode then self.on_input(unicode) end
return
......@@ -107,3 +114,19 @@ end
function _M:setTextInput(fct)
self.on_input = fct
end
--- Loads a locale converter
-- WARNING: This only converts the "sym" key, *NOT* the unicode key
-- @param file the locale convertion file to load
function _M:loadLocaleConvertion(file)
local f, err = loadfile(file)
if not f and err then error(err) end
setfenv(f, setmetatable({
locale = "frFR",
}, {__index=engine.Key}))
conv = f() or {}
for k, e in pairs(conv) do
self.locale_convert[k] = e
end
end
......@@ -17,7 +17,7 @@ function _M:init(actor)
_ESCAPE = function() game:unregisterDialog(self) end,
__TEXTINPUT = function(c)
if c:find("^[a-z]$") then
self.talentsel = 1 + string.byte(c) - string.byte('a')
self.talentsel = util.bound(1 + string.byte(c) - string.byte('a'), 1, #self.list)
self:use()
end
end,
......@@ -57,8 +57,8 @@ function _M:drawDialog(s)
-- Description part
self:drawHBorder(s, self.iw / 2, 2, self.ih - 4)
local talentshelp = ([[Keyboard: #00FF00#up key/down key#FFFFFF# to select a stat; #00FF00#right key#FFFFFF# to learn; #00FF00#left key#FFFFFF# to unlearn.
Mouse: #00FF00#Left click#FFFFFF# to learn; #00FF00#right click#FFFFFF# to unlearn.
local talentshelp = ([[Keyboard: #00FF00#up key/down key#FFFFFF# to select a stat; #00FF00#enter#FFFFFF# to use.
Mouse: #00FF00#Left click#FFFFFF# to use.
]]):splitLines(self.iw / 2 - 10, self.font)
local lines = {}
......
......@@ -263,8 +263,25 @@ function _M:setupCommands()
}
self.normal_key = self.key
-- Load the locales
self.key:loadLocaleConvertion("/data/locales/number_hotkey.lua")
-- Activate profiler keybinds
self.key:setupProfiler()
self.key:addCommands
{
_1 = function() self.player:hotkey(1) end,
_2 = function() self.player:hotkey(2) end,
_3 = function() self.player:hotkey(3) end,
_4 = function() self.player:hotkey(4) end,
_5 = function() self.player:hotkey(5) end,
_6 = function() self.player:hotkey(6) end,
_7 = function() self.player:hotkey(7) end,
_8 = function() self.player:hotkey(8) end,
_9 = function() self.player:hotkey(9) end,
_0 = function() self.player:hotkey(10) end,
_RIGHTPAREN = function() self.player:hotkey(11) end,
_EQUALS = function() self.player:hotkey(12) end,
-- talent test
_m = function()
self.player:useTalents()
......
......@@ -77,3 +77,16 @@ end
function _M:canSee(entity)
if entity.x and entity.y and game.level.map.seens(entity.x, entity.y) then return true end
end
--- Uses an hotkeyed talent
function _M:hotkey(id)
local i = 1
for tid, _ in pairs(self.talents) do
if self:getTalentFromId(tid).mode ~= "passive" then
if i == id then
self:useTalent(tid)
end
i = i + 1
end
end
end
......@@ -19,15 +19,22 @@ function _M:display()
if not a.changed then return self.surface end
a.changed = false
local talents = {a.T_MANATHRUST, a.T_FIREFLASH, a.T_NOXIOUS_CLOUD, a.T_BLINK}
local talents = {}
for tid, _ in pairs(a.talents) do
if a:getTalentFromId(tid).mode ~= "passive" then
talents[#talents+1] = tid
end
end
self.surface:erase(self.bgcolor[1], self.bgcolor[2], self.bgcolor[3])
local acode = string.byte('1')
for i, tid in ipairs(talents) do
local t = a:getTalentFromId(tid)
local s
if a:isTalentCoolingDown(t) then
local txt = ("%s (%d)"):format(t.name, a:isTalentCoolingDown(t))
local txt = ("%s) %s (%d)"):format(string.char(acode + i - 1), t.name, a:isTalentCoolingDown(t))
local w, h = self.font:size(txt)
s = core.display.newSurface(w + 4, h + 4)
s:erase(40, 40, 40)
......@@ -35,12 +42,13 @@ function _M:display()
s:alpha(128)
s:drawString(self.font, txt, 2, 2, 255, 0, 0)
else
local w, h = self.font:size(t.name)
local txt = ("%s) %s"):format(string.char(acode + i - 1), t.name)
local w, h = self.font:size(txt)
s = core.display.newSurface(w + 4, h + 4)
s:erase(40, 40, 40)
s:alpha(255)
s:drawString(self.font, t.name, 2, 2, 0, 255, 0)
s:drawString(self.font, txt, 2, 2, 0, 255, 0)
end
self.surface:merge(s, 0, (i-1) * 20)
......
......@@ -196,7 +196,7 @@ void on_tick()
Frames++;
{
int t = SDL_GetTicks();
if (t - T0 >= 1000) {
if (t - T0 >= 5000) {
float seconds = (t - T0) / 1000.0;
float fps = Frames / seconds;
printf("%d ticks in %g seconds = %g TPS\n", Frames, seconds, fps);
......@@ -233,7 +233,7 @@ void on_redraw()
Frames++;
{
int t = SDL_GetTicks();
if (t - T0 >= 1000) {
if (t - T0 >= 5000) {
float seconds = (t - T0) / 1000.0;
float fps = Frames / seconds;
printf("%d frames in %g seconds = %g FPS\n", Frames, seconds, fps);
......
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