From 42b63f714737a5eff3743e14311aca9a75b6624c Mon Sep 17 00:00:00 2001 From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54> Date: Fri, 4 Dec 2009 16:51:20 +0000 Subject: [PATCH] more hokey(s partially working) git-svn-id: http://svn.net-core.org/repos/t-engine4@94 51575b47-30f0-44d4-a5cc-537603b46e54 --- game/engine/Dialog.lua | 1 + game/engine/dialogs/UseTalents.lua | 19 +++++++++++++++++ game/engine/interface/ActorTalents.lua | 2 ++ game/modules/tome/class/Game.lua | 24 +++++++++++----------- game/modules/tome/class/Player.lua | 16 +++++++-------- game/modules/tome/class/TalentsDisplay.lua | 6 +++--- 6 files changed, 44 insertions(+), 24 deletions(-) diff --git a/game/engine/Dialog.lua b/game/engine/Dialog.lua index 8ccf90a6f5..77fd574663 100644 --- a/game/engine/Dialog.lua +++ b/game/engine/Dialog.lua @@ -74,6 +74,7 @@ function _M:keyCommands(t) game.key = engine.KeyCommand.new() game.key:addCommands(t) game.key:setCurrent() + self.key = game.key end function _M:mouseZones(t) diff --git a/game/engine/dialogs/UseTalents.lua b/game/engine/dialogs/UseTalents.lua index 7ffd38f8fd..b3681c7de8 100644 --- a/game/engine/dialogs/UseTalents.lua +++ b/game/engine/dialogs/UseTalents.lua @@ -5,12 +5,26 @@ module(..., package.seeall, class.inherit(engine.Dialog)) function _M:init(actor) self.actor = actor + actor.hotkey = actor.hotkey or {} engine.Dialog.init(self, "Use Talents: "..actor.name, game.w / 2, game.h / 2) self:generateList() self.talentsel = 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.talentsel = util.boundWrap(self.talentsel - 1, 1, #self.list) end, _DOWN = function() self.talentsel = util.boundWrap(self.talentsel + 1, 1, #self.list) end, _RETURN = function() self:use() end, @@ -32,6 +46,11 @@ function _M:init(actor) } end +function _M:defineHotkey(id) + self.actor.hotkey[id] = self.list[self.talentsel].talent + print("hotkey: ", id, "=>", self.list[self.talentsel].talent) +end + function _M:use() game:unregisterDialog(self) self.actor:useTalent(self.list[self.talentsel].talent) diff --git a/game/engine/interface/ActorTalents.lua b/game/engine/interface/ActorTalents.lua index a77b491fd9..6746b51df3 100644 --- a/game/engine/interface/ActorTalents.lua +++ b/game/engine/interface/ActorTalents.lua @@ -274,5 +274,7 @@ end --- Show usage dialog function _M:useTalents() local d = require("engine.dialogs.UseTalents").new(self) + -- Load the locales + d.key:loadLocaleConvertion("/data/locales/number_hotkey.lua") game:registerDialog(d) end diff --git a/game/modules/tome/class/Game.lua b/game/modules/tome/class/Game.lua index d9956294d6..86619ec847 100644 --- a/game/modules/tome/class/Game.lua +++ b/game/modules/tome/class/Game.lua @@ -269,18 +269,18 @@ function _M:setupCommands() 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, + _1 = function() self.player:activateHotkey(1) end, + _2 = function() self.player:activateHotkey(2) end, + _3 = function() self.player:activateHotkey(3) end, + _4 = function() self.player:activateHotkey(4) end, + _5 = function() self.player:activateHotkey(5) end, + _6 = function() self.player:activateHotkey(6) end, + _7 = function() self.player:activateHotkey(7) end, + _8 = function() self.player:activateHotkey(8) end, + _9 = function() self.player:activateHotkey(9) end, + _0 = function() self.player:activateHotkey(10) end, + _RIGHTPAREN = function() self.player:activateHotkey(11) end, + _EQUALS = function() self.player:activateHotkey(12) end, -- talent test _m = function() diff --git a/game/modules/tome/class/Player.lua b/game/modules/tome/class/Player.lua index 04f67399d0..243924288c 100644 --- a/game/modules/tome/class/Player.lua +++ b/game/modules/tome/class/Player.lua @@ -1,5 +1,6 @@ require "engine.class" require "mod.class.Actor" +local Dialog = require "engine.Dialog" local ActorTalents = require "engine.interface.ActorTalents" module(..., package.seeall, class.inherit(mod.class.Actor)) @@ -13,6 +14,7 @@ function _M:init(t) self.stamina_regen = self.stamina_regen or 1 self.regen_life = self.regen_life or 0.5 self.descriptor = {} + self.hotkey = {} end function _M:move(x, y, force) @@ -79,14 +81,10 @@ function _M:canSee(entity) 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 +function _M:activateHotkey(id) + if self.hotkey[id] then + self:useTalent(self.hotkey[id]) + else + Dialog:simplePopup("Hotkey not defined", "You may define a hotkey by pressing 'm' and following the inscructions there.") end end diff --git a/game/modules/tome/class/TalentsDisplay.lua b/game/modules/tome/class/TalentsDisplay.lua index bc7a9bf0d1..5f1e237864 100644 --- a/game/modules/tome/class/TalentsDisplay.lua +++ b/game/modules/tome/class/TalentsDisplay.lua @@ -20,9 +20,9 @@ function _M:display() a.changed = false local talents = {} - for tid, _ in pairs(a.talents) do - if a:getTalentFromId(tid).mode ~= "passive" then - talents[#talents+1] = tid + for i = 1, 12 do + if a.hotkey[i] then + talents[#talents+1] = a.hotkey[i] end end -- GitLab