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

target mode with mouse

git-svn-id: http://svn.net-core.org/repos/t-engine4@49 51575b47-30f0-44d4-a5cc-537603b46e54
parent 55822dd1
No related branches found
No related tags found
No related merge requests found
...@@ -120,6 +120,20 @@ function _M:display() ...@@ -120,6 +120,20 @@ function _M:display()
engine.GameTurnBased.display(self) engine.GameTurnBased.display(self)
end end
function _M:targetMode(v, msg)
if not v then
Map:setViewerFaction(nil)
if msg then self.log("Tactical display disabled. Press 't' or right mouse click to enable.") end
self.level.map.changed = true
self.target:setActive(false)
else
Map:setViewerFaction("players")
if msg then self.log("Tactical display enabled. Press 't' to disable.") end
self.level.map.changed = true
self.target:setActive(true)
end
end
function _M:setupCommands() function _M:setupCommands()
self.key:addCommands self.key:addCommands
{ {
...@@ -202,15 +216,9 @@ function _M:setupCommands() ...@@ -202,15 +216,9 @@ function _M:setupCommands()
-- Toggle tactical displau -- Toggle tactical displau
_t = function() _t = function()
if Map.view_faction then if Map.view_faction then
Map:setViewerFaction(nil) self:targetMode(false, true)
self.log("Tactical display disabled.")
self.level.map.changed = true
self.target:setActive(false)
else else
Map:setViewerFaction("players") self:targetMode(true, true)
self.log("Tactical display enabled.")
self.level.map.changed = true
self.target:setActive(true)
-- Find nearest target -- Find nearest target
self.target:scan(5) self.target:scan(5)
end end
...@@ -268,8 +276,24 @@ function _M:setupCommands() ...@@ -268,8 +276,24 @@ function _M:setupCommands()
end end
function _M:setupMouse() function _M:setupMouse()
-- self.mouse:registerZoneClick(Map.display_x, Map.display_y, Map.viewport.width, Map.viewport.height, function() self.mouse:registerZoneClick(Map.display_x, Map.display_y, Map.viewport.width, Map.viewport.height, function(button, mx, my)
-- end) -- Compute map coordonates
if button == "right" then
local tmx, tmy = math.floor(mx / self.level.map.tile_w) + self.level.map.mx, math.floor(my / self.level.map.tile_h) + self.level.map.my
local actor = self.level.map(tmx, tmy, Map.ACTOR)
if actor and self.level.map.seens(tmx, tmy) then
self.target.target.entity = actor
self:targetMode(true, true)
else
self.target.target.entity = nil
self.target.target.x = tmx
self.target.target.y = tmy
self:targetMode(true, true)
end
end
end)
self.mouse:registerZoneClick(self.log.display_x, self.log.display_y, self.w, self.h, function(button) self.mouse:registerZoneClick(self.log.display_x, self.log.display_y, self.w, self.h, function(button)
if button == "wheelup" then self.log:scrollUp(1) end if button == "wheelup" then self.log:scrollUp(1) end
if button == "wheeldown" then self.log:scrollUp(-1) end if button == "wheeldown" then self.log:scrollUp(-1) end
......
...@@ -121,7 +121,7 @@ void on_event(SDL_Event *event) ...@@ -121,7 +121,7 @@ void on_event(SDL_Event *event)
docall(L, 7, 0); docall(L, 7, 0);
} }
break; break;
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP:
if (current_mousehandler != LUA_NOREF) if (current_mousehandler != LUA_NOREF)
{ {
lua_rawgeti(L, LUA_REGISTRYINDEX, current_mousehandler); lua_rawgeti(L, LUA_REGISTRYINDEX, current_mousehandler);
...@@ -286,7 +286,7 @@ int main(int argc, char *argv[]) ...@@ -286,7 +286,7 @@ int main(int argc, char *argv[])
switch(event.type) switch(event.type)
{ {
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP:
case SDL_KEYDOWN: case SDL_KEYDOWN:
/* handle key presses */ /* handle key presses */
on_event(&event); on_event(&event);
......
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