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

Example module now uses the same mouse movement code as ToME

Tooltips show up over other UI elements


git-svn-id: http://svn.net-core.org/repos/t-engine4@918 51575b47-30f0-44d4-a5cc-537603b46e54
parent 55a9e8fe
No related branches found
No related tags found
No related merge requests found
......@@ -116,6 +116,8 @@ function _M:onResolutionChange()
self:setupDisplayMode()
self.flash:resize(0, 0, self.w, 20)
self.logdisplay:resize(0, self.h * 0.8, self.w * 0.5, self.h * 0.2)
-- Reset mouse bindings to account for new size
self:setupMouse(reset)
end
function _M:setupDisplayMode()
......@@ -450,21 +452,42 @@ function _M:setupCommands()
self.key:setCurrent()
end
function _M:setupMouse()
function _M:setupMouse(reset)
-- Those 2 locals will be "absorbed" into the mosue event handler function, this is a closure
local derivx, derivy = 0, 0
local moving_around = false
if reset then self.mouse:reset() end
self.mouse:registerZone(Map.display_x, Map.display_y, Map.viewport.width, Map.viewport.height, function(button, mx, my, xrel, yrel)
-- Move tooltip
self.tooltip_x, self.tooltip_y = mx, my
local tmx, tmy = self.level.map:getMouseTile(mx, my)
-- Target stuff
if button == "right" then
self.player:mouseMove(tmx, tmy)
if self.key == self.targetmode_key then
-- Target with mouse
if button == "none" and xrel and yrel then
self.target:setSpot(tmx, tmy)
-- Cancel target
elseif button ~= "left" and not xrel and not yrel then
self:targetMode(false, false)
self.tooltip_x, self.tooltip_y = nil, nil
-- Accept target
elseif not xrel and not yrel then
self.target.target.entity = nil
self.target.target.x = nil
self.target.target.y = nil
self:targetMode(false, false)
self.tooltip_x, self.tooltip_y = nil, nil
end
return
end
-- Move
if button == "left" and not core.key.modState("shift") and not moving_around and not xrel and not yrel then
if self.key == self.normal_key then self.player:mouseMove(tmx, tmy) end
-- Move map around
elseif button == "left" and xrel and yrel then
elseif button == "left" and xrel and yrel and core.key.modState("shift") then
derivx = derivx + xrel
derivy = derivy + yrel
game.level.map.changed = true
......@@ -483,7 +506,19 @@ function _M:setupMouse()
derivy = derivy + game.level.map.tile_h
end
game.level.map._map:setScroll(game.level.map.mx, game.level.map.my)
moving_around = true
elseif button ~= "none" and not xrel and not yrel then
self.key:receiveKey(
button,
core.key.modState("ctrl") and true or false,
core.key.modState("shift") and true or false,
core.key.modState("alt") and true or false,
core.key.modState("meta") and true or false,
nil, false, true
)
end
if not xrel and not yrel then moving_around = false end
end)
-- Scroll message log
self.mouse:registerZone(self.logdisplay.display_x, self.logdisplay.display_y, self.w, self.h, function(button)
......
......@@ -432,15 +432,6 @@ function _M:display()
self.level.map.display_y + self.level.map.viewport.height - znsy
)
-- Display a tooltip if available
if self.tooltip_x then self.tooltip:displayAtMap(self.level.map:getMouseTile(self.tooltip_x , self.tooltip_y)) end
-- Move target around
if self.old_tmx ~= tmx or self.old_tmy ~= tmy then
self.target.target.x, self.target.target.y = tmx, tmy
end
self.old_tmx, self.old_tmy = tmx, tmy
-- Minimap display
self.level.map:minimapDisplay(0, 20, util.bound(self.player.x - 25, 0, self.level.map.w - 50), util.bound(self.player.y - 25, 0, self.level.map.h - 50), 50, 50, 1)
end
......@@ -456,6 +447,18 @@ function _M:display()
end
if self.player then self.player.changed = false end
-- Tooltip is displayed over all else
if self.level and self.level.map and self.level.map.finished then
-- Display a tooltip if available
if self.tooltip_x then self.tooltip:displayAtMap(self.level.map:getMouseTile(self.tooltip_x , self.tooltip_y)) end
-- Move target around
if self.old_tmx ~= tmx or self.old_tmy ~= tmy then
self.target.target.x, self.target.target.y = tmx, tmy
end
self.old_tmx, self.old_tmy = tmx, tmy
end
engine.GameTurnBased.display(self)
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