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

can hotkey equiped activable items

git-svn-id: http://svn.net-core.org/repos/t-engine4@531 51575b47-30f0-44d4-a5cc-537603b46e54
parent aa8a960e
No related branches found
No related tags found
No related merge requests found
...@@ -85,7 +85,7 @@ function _M:display() ...@@ -85,7 +85,7 @@ function _M:display()
color = {0,255,0} color = {0,255,0}
end end
elseif ts[3] == "inventory" then elseif ts[3] == "inventory" then
local o = a:findInInventory(a:getInven("INVEN"), ts[1]) local o = a:findInAllInventories(ts[1])
local cnt = 0 local cnt = 0
if o then cnt = o:getNumber() end if o then cnt = o:getNumber() end
txt = ("%s (%d)"):format(ts[1], cnt) txt = ("%s (%d)"):format(ts[1], cnt)
......
...@@ -43,6 +43,43 @@ function _M:init(title, actor, filter, action) ...@@ -43,6 +43,43 @@ function _M:init(title, actor, filter, action)
end end
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,
HOTKEY_SECOND_1 = function() self:defineHotkey(13) end,
HOTKEY_SECOND_2 = function() self:defineHotkey(14) end,
HOTKEY_SECOND_3 = function() self:defineHotkey(15) end,
HOTKEY_SECOND_4 = function() self:defineHotkey(16) end,
HOTKEY_SECOND_5 = function() self:defineHotkey(17) end,
HOTKEY_SECOND_6 = function() self:defineHotkey(18) end,
HOTKEY_SECOND_7 = function() self:defineHotkey(19) end,
HOTKEY_SECOND_8 = function() self:defineHotkey(20) end,
HOTKEY_SECOND_9 = function() self:defineHotkey(21) end,
HOTKEY_SECOND_10 = function() self:defineHotkey(22) end,
HOTKEY_SECOND_11 = function() self:defineHotkey(23) end,
HOTKEY_SECOND_12 = function() self:defineHotkey(24) end,
HOTKEY_THIRD_1 = function() self:defineHotkey(25) end,
HOTKEY_THIRD_2 = function() self:defineHotkey(26) end,
HOTKEY_THIRD_3 = function() self:defineHotkey(27) end,
HOTKEY_THIRD_4 = function() self:defineHotkey(28) end,
HOTKEY_THIRD_5 = function() self:defineHotkey(29) end,
HOTKEY_THIRD_6 = function() self:defineHotkey(30) end,
HOTKEY_THIRD_7 = function() self:defineHotkey(31) end,
HOTKEY_THIRD_8 = function() self:defineHotkey(31) end,
HOTKEY_THIRD_9 = function() self:defineHotkey(33) end,
HOTKEY_THIRD_10 = function() self:defineHotkey(34) end,
HOTKEY_THIRD_11 = function() self:defineHotkey(35) end,
HOTKEY_THIRD_12 = function() self:defineHotkey(36) 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_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_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.list = self.equip_list self.sel = util.bound(self.sel, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) self.changed = true end, MOVE_LEFT = function() self.list = self.equip_list self.sel = util.bound(self.sel, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) self.changed = true end,
...@@ -60,6 +97,14 @@ function _M:init(title, actor, filter, action) ...@@ -60,6 +97,14 @@ function _M:init(title, actor, filter, action)
} }
end end
function _M:defineHotkey(id)
if not self.actor or not self.actor.hotkey then return end
self.actor.hotkey[id] = {"inventory", self.list[self.sel].object:getName{no_count=true}}
self:simplePopup("Hotkey "..id.." assigned", self.list[self.sel].object:getName{no_count=true}:capitalize().." assigned to hotkey "..id)
self.actor.changed = true
end
function _M:use() function _M:use()
if self.list[self.sel] and self.list[self.sel].item then if self.list[self.sel] and self.list[self.sel].item then
if self.action(self.list[self.sel].object, self.list[self.sel].inven, self.list[self.sel].item) then if self.action(self.list[self.sel].object, self.list[self.sel].inven, self.list[self.sel].item) then
......
...@@ -55,6 +55,12 @@ function _M:useObject(who) ...@@ -55,6 +55,12 @@ function _M:useObject(who)
local ret, no_power = self.use_power.use(self, who) local ret, no_power = self.use_power.use(self, who)
if not no_power then self.power = self.power - self.use_power.power end if not no_power then self.power = self.power - self.use_power.power end
return ret return ret
else
if self.power_regen and self.power_regen ~= 0 then
game.logPlayer(who, "%s is still recharging.", self:getName{no_count=true})
else
game.logPlayer(who, "%s can not be used anymore.", self:getName{no_count=true})
end
end end
elseif self.use_simple then elseif self.use_simple then
local ret = self.use_simple.use(self, who) local ret = self.use_simple.use(self, who)
......
...@@ -31,17 +31,17 @@ function _M:init(t) ...@@ -31,17 +31,17 @@ function _M:init(t)
end end
--- Uses an hotkeyed talent --- Uses an hotkeyed talent
-- This requires the ActorTalents interface to use talents and a method player:playerUseItem(o, item) to use inventory objects -- This requires the ActorTalents interface to use talents and a method player:playerUseItem(o, item, inven) to use inventory objects
function _M:activateHotkey(id) function _M:activateHotkey(id)
if self.hotkey[id] then if self.hotkey[id] then
if self.hotkey[id][1] == "talent" then if self.hotkey[id][1] == "talent" then
self:useTalent(self.hotkey[id][2]) self:useTalent(self.hotkey[id][2])
elseif self.hotkey[id][1] == "inventory" then elseif self.hotkey[id][1] == "inventory" then
local o, item = self:findInInventory(self:getInven("INVEN"), self.hotkey[id][2]) local o, item, inven = self:findInAllInventories(self.hotkey[id][2])
if not o then if not o then
Dialog:simplePopup("Item not found", "You do not have any "..self.hotkey[id][2]..".") Dialog:simplePopup("Item not found", "You do not have any "..self.hotkey[id][2]..".")
else else
self:playerUseItem(o, item) self:playerUseItem(o, item, inven)
end end
end end
else else
......
...@@ -361,10 +361,10 @@ function _M:playerTakeoff() ...@@ -361,10 +361,10 @@ function _M:playerTakeoff()
end) end)
end end
function _M:playerUseItem(object, item) function _M:playerUseItem(object, item, inven)
if game.zone.short_name == "wilderness" then game.logPlayer(self, "You can not use items on the world map.") return end if game.zone.short_name == "wilderness" then game.logPlayer(self, "You can not use items on the world map.") return end
local use_fct = function(o, item) local use_fct = function(o, item, inven)
self.changed = true self.changed = true
local ret, no_id = o:use(self) local ret, no_id = o:use(self)
if not no_id then if not no_id then
...@@ -374,19 +374,20 @@ function _M:playerUseItem(object, item) ...@@ -374,19 +374,20 @@ function _M:playerUseItem(object, item)
if o.multicharge and o.multicharge > 1 then if o.multicharge and o.multicharge > 1 then
o.multicharge = o.multicharge - 1 o.multicharge = o.multicharge - 1
else else
self:removeObject(self:getInven(self.INVEN_INVEN), item) self:removeObject(self:getInven(inven), item)
game.log("You have no more %s", o:getName{no_count=true, do_color=true}) game.log("You have no more %s", o:getName{no_count=true, do_color=true})
self:sortInven() self:sortInven(self:getInven(inven))
end end
return true
end end
self:breakStealth() self:breakStealth()
self.changed = true self.changed = true
end end
if object and item then return use_fct(object, item) end if object and item then return use_fct(object, item, inven) end
local titleupdator = self:getEncumberTitleUpdator("Use object") local titleupdator = self:getEncumberTitleUpdator("Use object")
self:showInventory(titleupdator(), self:getInven(self.INVEN_INVEN), self:showEquipInven(titleupdator(),
function(o) function(o)
return o:canUseObject() return o:canUseObject()
end, 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