summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Gavrilov2012-09-20 11:11:20 +0400
committerAlexander Gavrilov2012-09-20 11:11:20 +0400
commitc39a33722316ee91f7a42abcd76149788dd19196 (patch)
treee057fabb61758db013f91f633ca5a97bbbd166a2
parent7ce772ae0ea69ab26009a27d71bd681382ecfac7 (diff)
downloaddfhack-c39a33722316ee91f7a42abcd76149788dd19196.tar.gz
dfhack-c39a33722316ee91f7a42abcd76149788dd19196.tar.bz2
dfhack-c39a33722316ee91f7a42abcd76149788dd19196.tar.xz
Add unit/item/job/building getter hook vmethods to dfhack_viewscreen.
-rw-r--r--LUA_API.rst8
-rw-r--r--Lua API.html10
-rw-r--r--library/include/modules/Screen.h18
-rw-r--r--library/modules/Gui.cpp11
-rw-r--r--library/modules/Screen.cpp41
m---------library/xml0
-rw-r--r--plugins/manipulator.cpp7
7 files changed, 95 insertions, 0 deletions
diff --git a/LUA_API.rst b/LUA_API.rst
index 898ab79c..d9b75c48 100644
--- a/LUA_API.rst
+++ b/LUA_API.rst
@@ -1467,6 +1467,14 @@ Supported callbacks and fields are:
If this method is omitted, the screen is dismissed on receival of the ``LEAVESCREEN`` key.
+* ``function screen:onGetSelectedUnit()``
+* ``function screen:onGetSelectedItem()``
+* ``function screen:onGetSelectedJob()``
+* ``function screen:onGetSelectedBuilding()``
+
+ Implement these to provide a return value for the matching
+ ``dfhack.gui.getSelected...`` function.
+
Internal API
------------
diff --git a/Lua API.html b/Lua API.html
index 97770ff7..0da65b5f 100644
--- a/Lua API.html
+++ b/Lua API.html
@@ -1611,6 +1611,16 @@ options; if multiple interpretations exist, the table will contain multiple keys
</dl>
<p>If this method is omitted, the screen is dismissed on receival of the <tt class="docutils literal">LEAVESCREEN</tt> key.</p>
</li>
+<li><p class="first"><tt class="docutils literal">function screen:onGetSelectedUnit()</tt></p>
+</li>
+<li><p class="first"><tt class="docutils literal">function screen:onGetSelectedItem()</tt></p>
+</li>
+<li><p class="first"><tt class="docutils literal">function screen:onGetSelectedJob()</tt></p>
+</li>
+<li><p class="first"><tt class="docutils literal">function screen:onGetSelectedBuilding()</tt></p>
+<p>Implement these to provide a return value for the matching
+<tt class="docutils literal"><span class="pre">dfhack.gui.getSelected...</span></tt> function.</p>
+</li>
</ul>
</div>
<div class="section" id="internal-api">
diff --git a/library/include/modules/Screen.h b/library/include/modules/Screen.h
index 4f47205f..fdad6c8a 100644
--- a/library/include/modules/Screen.h
+++ b/library/include/modules/Screen.h
@@ -33,6 +33,14 @@ distribution.
#include "df/graphic.h"
#include "df/viewscreen.h"
+namespace df
+{
+ struct job;
+ struct item;
+ struct unit;
+ struct building;
+}
+
/**
* \defgroup grp_screen utilities for painting to the screen
* @ingroup grp_screen
@@ -134,6 +142,7 @@ namespace DFHack
virtual ~dfhack_viewscreen();
static bool is_instance(df::viewscreen *screen);
+ static dfhack_viewscreen *try_cast(df::viewscreen *screen);
virtual void logic();
virtual void render();
@@ -146,6 +155,10 @@ namespace DFHack
virtual std::string getFocusString() = 0;
virtual void onShow() {};
virtual void onDismiss() {};
+ virtual df::unit *getSelectedUnit() { return NULL; }
+ virtual df::item *getSelectedItem() { return NULL; }
+ virtual df::job *getSelectedJob() { return NULL; }
+ virtual df::building *getSelectedBuilding() { return NULL; }
};
class DFHACK_EXPORT dfhack_lua_viewscreen : public dfhack_viewscreen {
@@ -178,5 +191,10 @@ namespace DFHack
virtual void onShow();
virtual void onDismiss();
+
+ virtual df::unit *getSelectedUnit();
+ virtual df::item *getSelectedItem();
+ virtual df::job *getSelectedJob();
+ virtual df::building *getSelectedBuilding();
};
}
diff --git a/library/modules/Gui.cpp b/library/modules/Gui.cpp
index 10a20dc2..bc7deedc 100644
--- a/library/modules/Gui.cpp
+++ b/library/modules/Gui.cpp
@@ -691,6 +691,8 @@ df::job *Gui::getSelectedJob(color_ostream &out, bool quiet)
return job;
}
+ else if (auto dfscreen = dfhack_viewscreen::try_cast(top))
+ return dfscreen->getSelectedJob();
else
return getSelectedWorkshopJob(out, quiet);
}
@@ -781,6 +783,9 @@ static df::unit *getAnyUnit(df::viewscreen *top)
return NULL;
}
+ if (auto dfscreen = dfhack_viewscreen::try_cast(top))
+ return dfscreen->getSelectedUnit();
+
if (!Gui::dwarfmode_hotkey(top))
return NULL;
@@ -875,6 +880,9 @@ static df::item *getAnyItem(df::viewscreen *top)
return NULL;
}
+ if (auto dfscreen = dfhack_viewscreen::try_cast(top))
+ return dfscreen->getSelectedItem();
+
if (!Gui::dwarfmode_hotkey(top))
return NULL;
@@ -942,6 +950,9 @@ static df::building *getAnyBuilding(df::viewscreen *top)
using df::global::world;
using df::global::ui_sidebar_menus;
+ if (auto dfscreen = dfhack_viewscreen::try_cast(top))
+ return dfscreen->getSelectedBuilding();
+
if (!Gui::dwarfmode_hotkey(top))
return NULL;
diff --git a/library/modules/Screen.cpp b/library/modules/Screen.cpp
index 9f258fe0..8057d17a 100644
--- a/library/modules/Screen.cpp
+++ b/library/modules/Screen.cpp
@@ -50,6 +50,10 @@ using namespace DFHack;
#include "df/tile_page.h"
#include "df/interfacest.h"
#include "df/enabler.h"
+#include "df/unit.h"
+#include "df/item.h"
+#include "df/job.h"
+#include "df/building.h"
using namespace df::enums;
using df::global::init;
@@ -322,6 +326,11 @@ bool dfhack_viewscreen::is_instance(df::viewscreen *screen)
return dfhack_screens.count(screen) != 0;
}
+dfhack_viewscreen *dfhack_viewscreen::try_cast(df::viewscreen *screen)
+{
+ return is_instance(screen) ? static_cast<dfhack_viewscreen*>(screen) : NULL;
+}
+
void dfhack_viewscreen::check_resize()
{
auto size = Screen::getWindowSize();
@@ -637,3 +646,35 @@ void dfhack_lua_viewscreen::onDismiss()
lua_pushstring(Lua::Core::State, "onDismiss");
safe_call_lua(do_notify, 1, 0);
}
+
+df::unit *dfhack_lua_viewscreen::getSelectedUnit()
+{
+ Lua::StackUnwinder frame(Lua::Core::State);
+ lua_pushstring(Lua::Core::State, "onGetSelectedUnit");
+ safe_call_lua(do_notify, 1, 1);
+ return Lua::GetDFObject<df::unit>(Lua::Core::State, -1);
+}
+
+df::item *dfhack_lua_viewscreen::getSelectedItem()
+{
+ Lua::StackUnwinder frame(Lua::Core::State);
+ lua_pushstring(Lua::Core::State, "onGetSelectedItem");
+ safe_call_lua(do_notify, 1, 1);
+ return Lua::GetDFObject<df::item>(Lua::Core::State, -1);
+}
+
+df::job *dfhack_lua_viewscreen::getSelectedJob()
+{
+ Lua::StackUnwinder frame(Lua::Core::State);
+ lua_pushstring(Lua::Core::State, "onGetSelectedJob");
+ safe_call_lua(do_notify, 1, 1);
+ return Lua::GetDFObject<df::job>(Lua::Core::State, -1);
+}
+
+df::building *dfhack_lua_viewscreen::getSelectedBuilding()
+{
+ Lua::StackUnwinder frame(Lua::Core::State);
+ lua_pushstring(Lua::Core::State, "onGetSelectedBuilding");
+ safe_call_lua(do_notify, 1, 1);
+ return Lua::GetDFObject<df::building>(Lua::Core::State, -1);
+}
diff --git a/library/xml b/library/xml
-Subproject 8a78bfa218817765b0a80431e0cf25435ffb217
+Subproject eb4af94c7e737d99c194381749ac6743e146913
diff --git a/plugins/manipulator.cpp b/plugins/manipulator.cpp
index 2b3fc86f..033ad8b8 100644
--- a/plugins/manipulator.cpp
+++ b/plugins/manipulator.cpp
@@ -338,6 +338,8 @@ public:
std::string getFocusString() { return "unitlabors"; }
+ df::unit *getSelectedUnit();
+
viewscreen_unitlaborsst(vector<df::unit*> &src, int cursor_pos);
~viewscreen_unitlaborsst() { };
@@ -986,6 +988,11 @@ void viewscreen_unitlaborsst::render()
}
}
+df::unit *viewscreen_unitlaborsst::getSelectedUnit()
+{
+ return units[sel_row]->unit;
+}
+
struct unitlist_hook : df::viewscreen_unitlistst
{
typedef df::viewscreen_unitlistst interpose_base;