Allow commands invoked through command-prompt to access selected items/units/buildings

Fixes #273
develop
lethosor 2014-11-25 20:22:26 -05:00
parent d0b0f03060
commit 445640f80c
3 changed files with 10 additions and 3 deletions

@ -86,6 +86,7 @@ namespace DFHack
// A unit is selected via 'v', 'k', unitjobs, or // A unit is selected via 'v', 'k', unitjobs, or
// a full-screen item view of a cage or suchlike // a full-screen item view of a cage or suchlike
DFHACK_EXPORT bool any_unit_hotkey(df::viewscreen *top); 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); DFHACK_EXPORT df::unit *getSelectedUnit(color_ostream &out, bool quiet = false);
// An item is selected via 'v'->inventory, 'k', 't', or // 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 // last case, the highlighted contained item is returned, not
// the container itself. // the container itself.
DFHACK_EXPORT bool any_item_hotkey(df::viewscreen *top); 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); DFHACK_EXPORT df::item *getSelectedItem(color_ostream &out, bool quiet = false);
// A building is selected via 'q', 't' or 'i' (civzone) // A building is selected via 'q', 't' or 'i' (civzone)
DFHACK_EXPORT bool any_building_hotkey(df::viewscreen *top); 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); DFHACK_EXPORT df::building *getSelectedBuilding(color_ostream &out, bool quiet = false);
// Low-level API that gives full control over announcements and reports // Low-level API that gives full control over announcements and reports

@ -773,7 +773,7 @@ df::job *Gui::getSelectedJob(color_ostream &out, bool quiet)
return getSelectedWorkshopJob(out, 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 namespace ui_sidebar_mode;
using df::global::ui; using df::global::ui;
@ -904,7 +904,7 @@ df::unit *Gui::getSelectedUnit(color_ostream &out, bool quiet)
return unit; return unit;
} }
static df::item *getAnyItem(df::viewscreen *top) df::item *Gui::getAnyItem(df::viewscreen *top)
{ {
using namespace ui_sidebar_mode; using namespace ui_sidebar_mode;
using df::global::ui; using df::global::ui;
@ -1017,7 +1017,7 @@ df::item *Gui::getSelectedItem(color_ostream &out, bool quiet)
return item; return item;
} }
static df::building *getAnyBuilding(df::viewscreen *top) df::building *Gui::getAnyBuilding(df::viewscreen *top)
{ {
using namespace ui_sidebar_mode; using namespace ui_sidebar_mode;
using df::global::ui; using df::global::ui;

@ -50,6 +50,10 @@ public:
void help() { } void help() { }
int8_t movies_okay() { return 0; } 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"; } std::string getFocusString() { return "commandprompt"; }
viewscreen_commandpromptst(std::string entry):is_response(false) viewscreen_commandpromptst(std::string entry):is_response(false)
{ {