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

Mouse events now receive a last parameter called "event" which can be either "button" or "motion"

WARNING: You must update your Game:setupMouse() method to provide this new event, see the example module


git-svn-id: http://svn.net-core.org/repos/t-engine4@1264 51575b47-30f0-44d4-a5cc-537603b46e54
parent fb1ad158
No related branches found
No related tags found
No related merge requests found
......@@ -39,7 +39,7 @@ function _M:receiveMouse(button, x, y, isup)
for i, m in ipairs(self.areas) do
if (not m.mode or m.mode.button) and (x >= m.x1 and x < m.x2 and y >= m.y1 and y < m.y2) then
m.fct(button, x, y, nil, nil, x-m.x1, y-m.y1)
m.fct(button, x, y, nil, nil, x-m.x1, y-m.y1, "button")
break
end
end
......@@ -48,7 +48,7 @@ end
function _M:receiveMouseMotion(button, x, y, xrel, yrel)
for i, m in ipairs(self.areas) do
if (not m.mode or m.mode.move) and (x >= m.x1 and x < m.x2 and y >= m.y1 and y < m.y2) then
m.fct(button, x, y, xrel, yrel, x-m.x1, y-m.y1)
m.fct(button, x, y, xrel, yrel, x-m.x1, y-m.y1, "motion")
break
end
end
......
......@@ -108,15 +108,15 @@ end
-- </ul>
-- @param key the Key object to which to pass the event if not treated, this should be your game default key handler probably
-- @param allow_move true if this will allow player movement (you should use it to check that you are not in targetting mode)
function _M:mouseHandleDefault(key, allow_move, button, mx, my, xrel, yrel)
function _M:mouseHandleDefault(key, allow_move, button, mx, my, xrel, yrel, event)
local tmx, tmy = game.level.map:getMouseTile(mx, my)
-- Move
if button == "left" and not core.key.modState("shift") and not moving_around and not xrel and not yrel then
if button == "left" and not core.key.modState("shift") and not moving_around and not xrel and not yrel and event == "button" then
if allow_move then self:mouseMove(tmx, tmy) end
-- Move map around
elseif button == "left" and xrel and yrel and core.key.modState("shift") then
elseif button == "left" and xrel and yrel and core.key.modState("shift") and event == "motion" then
self:mouseScrollMap(game.level.map, xrel, yrel)
moving_around = true
-- Zoom map
......@@ -125,7 +125,7 @@ function _M:mouseHandleDefault(key, allow_move, button, mx, my, xrel, yrel)
-- elseif button == "wheeldown" then
-- game.level.map:setZoom(-0.1, tmx, tmy)
-- Pass any other buttons to the keybinder
elseif button ~= "none" and not xrel and not yrel then
elseif button ~= "none" and not xrel and not yrel and event == "button" then
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
......
......@@ -766,15 +766,15 @@ end
function _M:setupMouse(reset)
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)
self.mouse:registerZone(Map.display_x, Map.display_y, Map.viewport.width, Map.viewport.height, function(button, mx, my, xrel, yrel, bx, by, event)
-- Handle targeting
if self:targetMouse(button, mx, my, xrel, yrel) then return end
-- Handle Use menu
if button == "right" and not xrel and not yrel then self:mouseRightClick(mx, my) return end
if button == "right" and not xrel and not yrel and event == "button" then self:mouseRightClick(mx, my) return end
-- Handle the mouse movement/scrolling
self.player:mouseHandleDefault(self.key, self.key == self.normal_key, button, mx, my, xrel, yrel)
self.player:mouseHandleDefault(self.key, self.key == self.normal_key, button, mx, my, xrel, yrel, event)
end)
-- Scroll message log
self.mouse:registerZone(self.logdisplay.display_x, self.logdisplay.display_y, self.w, self.h, function(button)
......@@ -782,8 +782,8 @@ function _M:setupMouse(reset)
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, not xrel, function(text) self.tooltip:displayAtMap(nil, nil, self.w, self.h, text) end)
self.mouse:registerZone(self.hotkeys_display.display_x, self.hotkeys_display.display_y, self.w, self.h, function(button, mx, my, xrel, yrel, bx, by, event)
self.hotkeys_display:onMouse(button, mx, my, event == "button", function(text) self.tooltip:displayAtMap(nil, nil, self.w, self.h, text) end)
end)
-- Use icons
self.mouse:registerZone(self.icons.display_x, self.icons.display_y, self.icons.w, self.icons.h, function(button, mx, my, xrel, yrel, bx, by)
......
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