summaryrefslogtreecommitdiff
path: root/library/lua
diff options
context:
space:
mode:
authorAlexander Gavrilov2012-08-25 10:37:03 +0400
committerAlexander Gavrilov2012-08-25 10:37:03 +0400
commit41ad42d0fdeae7d387186e66d9eb4117a3cf9e7d (patch)
treeb4bc91a1b977eb4bf39d7c618ff169b774176c44 /library/lua
parent21904fd607d0f2037782e28ff7284300663931ab (diff)
downloaddfhack-41ad42d0fdeae7d387186e66d9eb4117a3cf9e7d.tar.gz
dfhack-41ad42d0fdeae7d387186e66d9eb4117a3cf9e7d.tar.bz2
dfhack-41ad42d0fdeae7d387186e66d9eb4117a3cf9e7d.tar.xz
Expose the liquids plugin engine to lua, and make a wrapper gui script.
Diffstat (limited to 'library/lua')
-rw-r--r--library/lua/gui.lua5
-rw-r--r--library/lua/gui/dwarfmode.lua52
2 files changed, 54 insertions, 3 deletions
diff --git a/library/lua/gui.lua b/library/lua/gui.lua
index ac032166..9e189ea1 100644
--- a/library/lua/gui.lua
+++ b/library/lua/gui.lua
@@ -18,7 +18,7 @@ function simulateInput(screen,...)
error('Invalid keycode: '..arg)
end
end
- if type(arg) == 'number' then
+ if type(kv) == 'number' then
keys[#keys+1] = kv
end
end
@@ -277,6 +277,9 @@ end
function Screen:onDismiss()
end
+function Screen:onDestroy()
+end
+
function Screen:onResize(w,h)
self:updateLayout()
end
diff --git a/library/lua/gui/dwarfmode.lua b/library/lua/gui/dwarfmode.lua
index c1a8bcb9..1f7ae1b0 100644
--- a/library/lua/gui/dwarfmode.lua
+++ b/library/lua/gui/dwarfmode.lua
@@ -6,6 +6,9 @@ local gui = require('gui')
local utils = require('utils')
local dscreen = dfhack.screen
+
+local g_cursor = df.global.cursor
+local g_sel_rect = df.global.selection_rect
local world_map = df.global.world.map
AREA_MAP_WIDTH = 23
@@ -43,8 +46,8 @@ function getPanelLayout()
end
function getCursorPos()
- if df.global.cursor.x ~= -30000 then
- return copyall(df.global.cursor)
+ if g_cursor ~= -30000 then
+ return copyall(g_cursor)
end
end
@@ -56,6 +59,51 @@ function clearCursorPos()
df.global.cursor = xyz2pos(nil)
end
+function getSelection()
+ local p1, p2
+ if g_sel_rect.start_x ~= -30000 then
+ p1 = xyz2pos(g_sel_rect.start_x, g_sel_rect.start_y, g_sel_rect.start_z)
+ end
+ if g_sel_rect.end_x ~= -30000 then
+ p2 = xyz2pos(g_sel_rect.end_x, g_sel_rect.end_y, g_sel_rect.end_z)
+ end
+ return p1, p2
+end
+
+function setSelectionStart(pos)
+ g_sel_rect.start_x = pos.x
+ g_sel_rect.start_y = pos.y
+ g_sel_rect.start_z = pos.z
+end
+
+function setSelectionEnd(pos)
+ g_sel_rect.end_x = pos.x
+ g_sel_rect.end_y = pos.y
+ g_sel_rect.end_z = pos.z
+end
+
+function clearSelection()
+ g_sel_rect.start_x = -30000
+ g_sel_rect.start_y = -30000
+ g_sel_rect.start_z = -30000
+ g_sel_rect.end_x = -30000
+ g_sel_rect.end_y = -30000
+ g_sel_rect.end_z = -30000
+end
+
+function getSelectionRange(p1, p2)
+ local r1 = xyz2pos(
+ math.min(p1.x, p2.x), math.min(p1.y, p2.y), math.min(p1.z, p2.z)
+ )
+ local r2 = xyz2pos(
+ math.max(p1.x, p2.x), math.max(p1.y, p2.y), math.max(p1.z, p2.z)
+ )
+ local sz = xyz2pos(
+ r2.x - r1.x + 1, r2.y - r1.y + 1, r2.z - r1.z + 1
+ )
+ return r1, sz, r2
+end
+
Viewport = defclass(Viewport)
function Viewport.make(map,x,y,z)