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

clickable hotkey zone

git-svn-id: http://svn.net-core.org/repos/t-engine4@437 51575b47-30f0-44d4-a5cc-537603b46e54
parent 2b271311
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@ function _M:init(actor, x, y, w, h, bgcolor)
self.bgcolor = bgcolor
self.font = core.display.newFont("/data/font/VeraMono.ttf", 10)
self.font_h = self.font:lineSkip()
self.clics = {}
self:resize(x, y, w, h)
end
......@@ -45,6 +46,7 @@ function _M:display()
local x = 0
local y = 0
self.clics = {}
for ii, ts in ipairs(hks) do
local s
......@@ -76,8 +78,9 @@ function _M:display()
txt = ("%2d) %-"..(self.max_char_w-4-24).."s Key: %s"):format(i, txt, ts[4])
local w, h = self.font:size(txt)
s = core.display.newSurface(w + 4, h + 4)
s:alpha(255)
if self.cur_sel and self.cur_sel == i then s:erase(0, 50, 120) end
s:drawString(self.font, txt, 2, 2, color[1], color[2], color[3])
self.clics[i] = {x,y,w+4,h+4}
self.surface:merge(s, x, y)
if y + self.font_h * 2 > self.h then
......@@ -90,3 +93,21 @@ function _M:display()
return self.surface
end
--- Call when a mouse event arrives in this zone
-- This is optional, only if you need mouse support
function _M:onMouse(button, mx, my)
mx, my = mx - self.display_x, my - self.display_y
for i, zone in pairs(self.clics) do
if mx >= zone[1] and mx < zone[1] + zone[3] and my >= zone[2] and my < zone[2] + zone[4] then
if button == "left" then
self.actor:activateHotkey(i)
else
self.actor.changed = true
self.cur_sel = i
end
return
end
end
self.cur_sel = nil
end
......@@ -93,9 +93,9 @@ function _M:generateList()
end
function _M:drawDialog(s)
if not self.list[self.sel].item then
if self.list[self.sel] and not self.list[self.sel].item then
lines = self.actor.inven_def[self.list[self.sel].inven].description:splitLines(self.iw / 2 - 10, self.font)
elseif self.list[self.sel] and self.list[self.sel].object then
elseif self.list[self.sel] and self.list[self.sel] and self.list[self.sel].object then
lines = self.list[self.sel].object:getDesc():splitLines(self.iw - 10, self.font)
else
lines = {}
......
......@@ -613,6 +613,10 @@ function _M:setupMouse()
if button == "wheelup" then self.logdisplay:scrollUp(1) end
if button == "wheeldown" then self.logdisplay:scrollUp(-1) end
end, {button=true})
-- Use hotkeys with mouse
self.mouse:registerZone(self.hotkeys_display.display_x, self.hotkeys_display.display_y, self.w, self.h, function(button, mx, my, xrel, yrel)
self.hotkeys_display:onMouse(button, mx, my)
end)
self.mouse:setCurrent()
end
......
......@@ -216,10 +216,11 @@ function _M:runCheck()
end
function _M:doDrop(inven, item)
if self.zone.short_name ~= "wilderness" then game.logPlayer(self, "You can not drop on the world map.") return end
if game.zone.short_name ~= "wilderness" then game.logPlayer(self, "You can not drop on the world map.") return end
self:dropFloor(inven, item, true, true)
self:sortInven()
self:useEnergy()
self.changed = true
end
function _M:doWear(inven, item, o)
......@@ -232,6 +233,7 @@ function _M:doWear(inven, item, o)
end
self:sortInven()
self:useEnergy()
self.changed = true
end
function _M:doTakeoff(inven, item, o)
......@@ -240,6 +242,7 @@ function _M:doTakeoff(inven, item, o)
end
self:sortInven()
self:useEnergy()
self.changed = true
end
function _M:playerPickup()
......@@ -248,11 +251,13 @@ function _M:playerPickup()
self:showPickupFloor(nil, nil, function(o, item)
self:pickupFloor(item, true)
self:sortInven()
self.changed = true
end)
else
self:pickupFloor(1, true)
self:sortInven()
self:useEnergy()
self.changed = true
end
end
......@@ -279,6 +284,8 @@ function _M:playerTakeoff()
end
function _M:playerUseItem(object, item)
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)
self.changed = true
local ret, no_id = o:use(self)
......@@ -295,6 +302,7 @@ function _M:playerUseItem(object, item)
end
end
self:breakStealth()
self.changed = true
end
if object and item then return use_fct(object, item) 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