diff --git a/NEWS b/NEWS index ac3c4393e..31525ef4d 100644 --- a/NEWS +++ b/NEWS @@ -114,6 +114,7 @@ DFHack Future plug: - lists all plugins - shows state and number of commands in plugins + prospect: works from within command-prompt quicksave: Restricted to fortress mode remotefortressreader: Exposes more information search: diff --git a/library/include/modules/Gui.h b/library/include/modules/Gui.h index e2b137e2a..0546eb643 100644 --- a/library/include/modules/Gui.h +++ b/library/include/modules/Gui.h @@ -156,6 +156,15 @@ namespace DFHack /// Get the current top-level view-screen DFHACK_EXPORT df::viewscreen *getCurViewscreen(bool skip_dismissed = false); + DFHACK_EXPORT df::viewscreen *getViewscreenByIdentity(virtual_identity id, int n = 1); + + /// Get the top-most viewscreen of the given type from the top `n` viewscreens (or all viewscreens if n < 1) + /// returns NULL if none match + template + inline T *getViewscreenByType (int n = 1) { + return strict_virtual_cast(getViewscreenByIdentity(T::_identity, n)); + } + inline std::string getCurFocus(bool skip_dismissed = false) { return getFocusString(getCurViewscreen(skip_dismissed)); } diff --git a/library/modules/Gui.cpp b/library/modules/Gui.cpp index 5e142c798..5df53e242 100644 --- a/library/modules/Gui.cpp +++ b/library/modules/Gui.cpp @@ -1326,6 +1326,21 @@ df::viewscreen *Gui::getCurViewscreen(bool skip_dismissed) return ws; } +df::viewscreen *Gui::getViewscreenByIdentity (virtual_identity id, int n) +{ + bool limit = (n > 0); + df::viewscreen *screen = Gui::getCurViewscreen(); + while (screen) + { + if (limit && n-- <= 0) + break; + if (id.is_instance(screen)) + return screen; + screen = screen->parent; + } + return NULL; +} + df::coord Gui::getViewportPos() { if (!df::global::window_x || !df::global::window_y || !df::global::window_z) diff --git a/plugins/prospector.cpp b/plugins/prospector.cpp index 5497735e7..522630afe 100644 --- a/plugins/prospector.cpp +++ b/plugins/prospector.cpp @@ -18,6 +18,7 @@ using namespace std; #include "Console.h" #include "Export.h" #include "PluginManager.h" +#include "modules/Gui.h" #include "modules/MapCache.h" #include "MiscUtils.h" @@ -575,7 +576,8 @@ command_result prospector (color_ostream &con, vector & parameters) CoreSuspender suspend; // Embark screen active: estimate using world geology data - if (VIRTUAL_CAST_VAR(screen, df::viewscreen_choose_start_sitest, Core::getTopViewscreen())) + auto screen = Gui::getViewscreenByType(0); + if (screen) return embark_prospector(con, screen, showHidden, showValue); if (!Maps::IsValid())