From 445640f80c77f34f1eb3a6bf739c5cab5764ded0 Mon Sep 17 00:00:00 2001 From: lethosor Date: Tue, 25 Nov 2014 20:22:26 -0500 Subject: [PATCH] Allow commands invoked through command-prompt to access selected items/units/buildings Fixes #273 --- library/include/modules/Gui.h | 3 +++ library/modules/Gui.cpp | 6 +++--- plugins/command-prompt.cpp | 4 ++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/library/include/modules/Gui.h b/library/include/modules/Gui.h index 6acb0ce08..e2b137e2a 100644 --- a/library/include/modules/Gui.h +++ b/library/include/modules/Gui.h @@ -86,6 +86,7 @@ namespace DFHack // A unit is selected via 'v', 'k', unitjobs, or // a full-screen item view of a cage or suchlike DFHACK_EXPORT bool any_unit_hotkey(df::viewscreen *top); + DFHACK_EXPORT df::unit *getAnyUnit(df::viewscreen *top); DFHACK_EXPORT df::unit *getSelectedUnit(color_ostream &out, bool quiet = false); // An item is selected via 'v'->inventory, 'k', 't', or @@ -93,10 +94,12 @@ namespace DFHack // last case, the highlighted contained item is returned, not // the container itself. DFHACK_EXPORT bool any_item_hotkey(df::viewscreen *top); + DFHACK_EXPORT df::item *getAnyItem(df::viewscreen *top); DFHACK_EXPORT df::item *getSelectedItem(color_ostream &out, bool quiet = false); // A building is selected via 'q', 't' or 'i' (civzone) DFHACK_EXPORT bool any_building_hotkey(df::viewscreen *top); + DFHACK_EXPORT df::building *getAnyBuilding(df::viewscreen *top); DFHACK_EXPORT df::building *getSelectedBuilding(color_ostream &out, bool quiet = false); // Low-level API that gives full control over announcements and reports diff --git a/library/modules/Gui.cpp b/library/modules/Gui.cpp index fedb95954..5e142c798 100644 --- a/library/modules/Gui.cpp +++ b/library/modules/Gui.cpp @@ -773,7 +773,7 @@ df::job *Gui::getSelectedJob(color_ostream &out, bool quiet) return getSelectedWorkshopJob(out, quiet); } -static df::unit *getAnyUnit(df::viewscreen *top) +df::unit *Gui::getAnyUnit(df::viewscreen *top) { using namespace ui_sidebar_mode; using df::global::ui; @@ -904,7 +904,7 @@ df::unit *Gui::getSelectedUnit(color_ostream &out, bool quiet) return unit; } -static df::item *getAnyItem(df::viewscreen *top) +df::item *Gui::getAnyItem(df::viewscreen *top) { using namespace ui_sidebar_mode; using df::global::ui; @@ -1017,7 +1017,7 @@ df::item *Gui::getSelectedItem(color_ostream &out, bool quiet) return item; } -static df::building *getAnyBuilding(df::viewscreen *top) +df::building *Gui::getAnyBuilding(df::viewscreen *top) { using namespace ui_sidebar_mode; using df::global::ui; diff --git a/plugins/command-prompt.cpp b/plugins/command-prompt.cpp index 36df35cd6..cf1e78763 100644 --- a/plugins/command-prompt.cpp +++ b/plugins/command-prompt.cpp @@ -50,6 +50,10 @@ public: void help() { } int8_t movies_okay() { return 0; } + df::unit* getSelectedUnit() { return Gui::getAnyUnit(parent); } + df::item* getSelectedItem() { return Gui::getAnyItem(parent); } + df::building* getSelectedBuilding() { return Gui::getAnyBuilding(parent); } + std::string getFocusString() { return "commandprompt"; } viewscreen_commandpromptst(std::string entry):is_response(false) {