summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorAlexander Gavrilov2012-08-22 22:28:52 +0400
committerAlexander Gavrilov2012-08-22 22:29:01 +0400
commitcf4b8a01966cc680b6f7c74db5f6bad30adc3e64 (patch)
treefbc8d0af3cffbaf5fb845aeee3c1d74796a937af /scripts
parent92c0b555dcf5656bf4e01c1d602e868dd62c3c03 (diff)
downloaddfhack-cf4b8a01966cc680b6f7c74db5f6bad30adc3e64.tar.gz
dfhack-cf4b8a01966cc680b6f7c74db5f6bad30adc3e64.tar.bz2
dfhack-cf4b8a01966cc680b6f7c74db5f6bad30adc3e64.tar.xz
Improve viewport manipulation utilities and support scroll in mechanisms.
I.e. allow the user to scroll around with cursor keys, provided that keeps the cursor still visible.
Diffstat (limited to 'scripts')
-rw-r--r--scripts/gui/mechanisms.lua37
1 files changed, 22 insertions, 15 deletions
diff --git a/scripts/gui/mechanisms.lua b/scripts/gui/mechanisms.lua
index b8c01b59..fe45d4ac 100644
--- a/scripts/gui/mechanisms.lua
+++ b/scripts/gui/mechanisms.lua
@@ -8,11 +8,19 @@ function getBuildingName(building)
return utils.call_with_string(building, 'getName')
end
+function getBuildingCenter(building)
+ return xyz2pos(building.centerx, building.centery, building.z)
+end
+
function listMechanismLinks(building)
local lst = {}
local function push(item, mode)
if item then
- lst[#lst+1] = { obj = item, name = getBuildingName(item), mode = mode }
+ lst[#lst+1] = {
+ obj = item, mode = mode,
+ name = getBuildingName(item),
+ center = getBuildingCenter(item)
+ }
end
end
@@ -55,7 +63,7 @@ end
function MechanismList:init(building)
local links = listMechanismLinks(building)
- links[1].viewport = guidm.getViewportPos()
+ links[1].viewport = self:getViewport()
links[1].cursor = guidm.getCursorPos()
if #links <= 1 then
links[1].mode = 'none'
@@ -95,18 +103,16 @@ function MechanismList:onRenderBody(dc)
dc:string("Enter", COLOR_LIGHTGREEN):string(": Switch")
end
-function MechanismList:zoomToLink(link)
- self:updateLayout()
-
+function MechanismList:zoomToLink(link,back)
df.global.world.selected_building = link.obj
- local cursor = link.cursor
- if not cursor then
- cursor = xyz2pos(link.obj.centerx, link.obj.centery, link.obj.z)
+ if back then
+ guidm.setCursorPos(link.cursor)
+ self:getViewport(link.viewport):set()
+ else
+ guidm.setCursorPos(link.center)
+ self:getViewport():reveal(link.center, 5, 0, 10):set()
end
- guidm.setCursorPos(cursor)
-
- guidm.revealInViewport(cursor, 5, link.viewport, self.df_layout)
end
function MechanismList:changeSelected(delta)
@@ -116,22 +122,23 @@ function MechanismList:changeSelected(delta)
end
function MechanismList:onInput(keys)
- if keys.STANDARDSCROLL_UP or keys.SECONDSCROLL_UP then
+ if keys.SECONDSCROLL_UP then
self:changeSelected(-1)
- elseif keys.STANDARDSCROLL_DOWN or keys.SECONDSCROLL_DOWN then
+ elseif keys.SECONDSCROLL_DOWN then
self:changeSelected(1)
elseif keys.LEAVESCREEN then
self:dismiss()
if self.selected ~= 1 then
- self:zoomToLink(self.links[1])
+ self:zoomToLink(self.links[1], true)
end
elseif keys.SELECT_ALL then
if self.selected > 1 then
self:init(self.links[self.selected].obj)
- self.invalidate()
end
elseif keys.SELECT then
self:dismiss()
+ elseif self:simulateViewScroll(keys) then
+ return
end
end