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

Targetting ignores map padding, making it betetr with an heavily loaded UI

git-svn-id: http://svn.net-core.org/repos/t-engine4@5339 51575b47-30f0-44d4-a5cc-537603b46e54
parent df897b90
No related branches found
No related tags found
No related merge requests found
......@@ -724,28 +724,51 @@ function _M:centerViewAround(x, y)
end
--- Sets the current view area if x and y are out of bounds
function _M:moveViewSurround(x, y, marginx, marginy)
function _M:moveViewSurround(x, y, marginx, marginy, ignore_padding)
local omx, omy = self.mx, self.my
if marginx * 2 + viewport_padding_4 + viewport_padding_6 > self.viewport.mwidth then
self.mx = x - math.floor(self.viewport.mwidth / 2)
self.changed = true
elseif self.mx + marginx + self.viewport_padding_4 >= x then
self.mx = x - marginx - self.viewport_padding_4
self.changed = true
elseif self.mx + self.viewport.mwidth - marginx - self.viewport_padding_6 <= x then
self.mx = x - self.viewport.mwidth + marginx + self.viewport_padding_6
self.changed = true
end
if marginy * 2 + viewport_padding_2 + viewport_padding_8 > self.viewport.mheight then
self.my = y - math.floor(self.viewport.mheight / 2)
self.changed = true
elseif self.my + marginy + self.viewport_padding_8 >= y then
self.my = y - marginy - self.viewport_padding_8
self.changed = true
elseif self.my + self.viewport.mheight - marginy - self.viewport_padding_2 <= y then
self.my = y - self.viewport.mheight + marginy + self.viewport_padding_2
self.changed = true
if ignore_padding then
if marginx * 2 > self.viewport.mwidth then
self.mx = x - math.floor(self.viewport.mwidth / 2)
self.changed = true
elseif self.mx + marginx >= x then
self.mx = x - marginx
self.changed = true
elseif self.mx + self.viewport.mwidth - marginx <= x then
self.mx = x - self.viewport.mwidth + marginx
self.changed = true
end
if marginy * 2 > self.viewport.mheight then
self.my = y - math.floor(self.viewport.mheight / 2)
self.changed = true
elseif self.my + marginy >= y then
self.my = y - marginy
self.changed = true
elseif self.my + self.viewport.mheight - marginy <= y then
self.my = y - self.viewport.mheight + marginy
self.changed = true
end
else
if marginx * 2 + viewport_padding_4 + viewport_padding_6 > self.viewport.mwidth then
self.mx = x - math.floor(self.viewport.mwidth / 2)
self.changed = true
elseif self.mx + marginx + self.viewport_padding_4 >= x then
self.mx = x - marginx - self.viewport_padding_4
self.changed = true
elseif self.mx + self.viewport.mwidth - marginx - self.viewport_padding_6 <= x then
self.mx = x - self.viewport.mwidth + marginx + self.viewport_padding_6
self.changed = true
end
if marginy * 2 + viewport_padding_2 + viewport_padding_8 > self.viewport.mheight then
self.my = y - math.floor(self.viewport.mheight / 2)
self.changed = true
elseif self.my + marginy + self.viewport_padding_8 >= y then
self.my = y - marginy - self.viewport_padding_8
self.changed = true
elseif self.my + self.viewport.mheight - marginy - self.viewport_padding_2 <= y then
self.my = y - self.viewport.mheight + marginy + self.viewport_padding_2
self.changed = true
end
end
--[[
if self.mx + marginx >= x or self.mx + self.viewport.mwidth - marginx <= x then
......
......@@ -36,7 +36,7 @@ function _M:init()
-- Allow scrolling when targetting
self.target.on_set_target = function(self, how)
if self.key ~= self.targetmode_key then return end
local dx, dy = game.level.map:moveViewSurround(self.target.x, self.target.y, 1, 1)
local dx, dy = game.level.map:moveViewSurround(self.target.x, self.target.y, 1, 1, true)
if how == "mouse" then
local cx, cy = core.mouse.get()
core.mouse.set(cx - game.level.map.tile_w * dx, cy - game.level.map.tile_h * dy)
......
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