diff options
| author | Alexander Gavrilov | 2012-08-25 10:37:03 +0400 |
|---|---|---|
| committer | Alexander Gavrilov | 2012-08-25 10:37:03 +0400 |
| commit | 41ad42d0fdeae7d387186e66d9eb4117a3cf9e7d (patch) | |
| tree | b4bc91a1b977eb4bf39d7c618ff169b774176c44 /library | |
| parent | 21904fd607d0f2037782e28ff7284300663931ab (diff) | |
| download | dfhack-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')
| -rw-r--r-- | library/include/modules/Gui.h | 3 | ||||
| -rw-r--r-- | library/lua/gui.lua | 5 | ||||
| -rw-r--r-- | library/lua/gui/dwarfmode.lua | 52 | ||||
| -rw-r--r-- | library/modules/Gui.cpp | 17 |
4 files changed, 74 insertions, 3 deletions
diff --git a/library/include/modules/Gui.h b/library/include/modules/Gui.h index 273d84ce..58f22241 100644 --- a/library/include/modules/Gui.h +++ b/library/include/modules/Gui.h @@ -97,6 +97,9 @@ namespace DFHack /* * Cursor and window coords */ + DFHACK_EXPORT df::coord getViewportPos(); + DFHACK_EXPORT df::coord getCursorPos(); + DFHACK_EXPORT bool getViewCoords (int32_t &x, int32_t &y, int32_t &z); DFHACK_EXPORT bool setViewCoords (const int32_t x, const int32_t y, const int32_t z); 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) diff --git a/library/modules/Gui.cpp b/library/modules/Gui.cpp index 91a17e99..0f28860b 100644 --- a/library/modules/Gui.cpp +++ b/library/modules/Gui.cpp @@ -998,6 +998,23 @@ df::viewscreen *Gui::getCurViewscreen(bool skip_dismissed) return ws; } +df::coord Gui::getViewportPos() +{ + if (!df::global::window_x || !df::global::window_y || !df::global::window_z) + return df::coord(0,0,0); + + return df::coord(*df::global::window_x, *df::global::window_y, *df::global::window_z); +} + +df::coord Gui::getCursorPos() +{ + using df::global::cursor; + if (!cursor) + return df::coord(); + + return df::coord(cursor->x, cursor->y, cursor->z); +} + bool Gui::getViewCoords (int32_t &x, int32_t &y, int32_t &z) { x = *df::global::window_x; |
