|
|
|
@ -8,6 +8,7 @@
|
|
|
|
|
#include "modules/World.h"
|
|
|
|
|
#include "modules/Gui.h"
|
|
|
|
|
|
|
|
|
|
#include "LuaTools.h"
|
|
|
|
|
#include "PluginManager.h"
|
|
|
|
|
|
|
|
|
|
DFHACK_PLUGIN("hotkeys");
|
|
|
|
@ -54,6 +55,8 @@ static void find_active_keybindings(df::viewscreen *screen)
|
|
|
|
|
valid_keys.push_back("F" + int_to_string(i));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
valid_keys.push_back("`");
|
|
|
|
|
|
|
|
|
|
auto current_focus = Gui::getFocusString(screen);
|
|
|
|
|
for (int shifted = 0; shifted < 2; shifted++)
|
|
|
|
|
{
|
|
|
|
@ -120,6 +123,29 @@ static void invoke_command(const size_t index)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static std::string get_help(const std::string &command, bool full_help)
|
|
|
|
|
{
|
|
|
|
|
auto L = Lua::Core::State;
|
|
|
|
|
color_ostream_proxy out(Core::getInstance().getConsole());
|
|
|
|
|
Lua::StackUnwinder top(L);
|
|
|
|
|
|
|
|
|
|
if (!lua_checkstack(L, 2) ||
|
|
|
|
|
!Lua::PushModulePublic(out, L, "helpdb",
|
|
|
|
|
full_help ? "get_entry_long_help" : "get_entry_short_help"))
|
|
|
|
|
return "Help text unavailable.";
|
|
|
|
|
|
|
|
|
|
Lua::Push(L, command);
|
|
|
|
|
|
|
|
|
|
if (!Lua::SafeCall(out, L, 1, 1))
|
|
|
|
|
return "Help text unavailable.";
|
|
|
|
|
|
|
|
|
|
const char *s = lua_tostring(L, -1);
|
|
|
|
|
if (!s)
|
|
|
|
|
return "Help text unavailable.";
|
|
|
|
|
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ViewscreenHotkeys : public dfhack_viewscreen
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
@ -219,20 +245,9 @@ public:
|
|
|
|
|
if (first[0] == '#')
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Plugin *plugin = Core::getInstance().getPluginManager()->getPluginByCommand(first);
|
|
|
|
|
if (plugin)
|
|
|
|
|
{
|
|
|
|
|
for (size_t i = 0; i < plugin->size(); i++)
|
|
|
|
|
{
|
|
|
|
|
auto pc = plugin->operator[](i);
|
|
|
|
|
if (pc.name == first)
|
|
|
|
|
{
|
|
|
|
|
OutputString(COLOR_BROWN, x, y, "Help", true, help_start);
|
|
|
|
|
string help_text = get_help(first, show_usage);
|
|
|
|
|
vector <string> lines;
|
|
|
|
|
string help_text = pc.description;
|
|
|
|
|
if (show_usage)
|
|
|
|
|
help_text += "\n\n" + pc.usage;
|
|
|
|
|
|
|
|
|
|
split_string(&lines, help_text, "\n");
|
|
|
|
|
for (auto it = lines.begin(); it != lines.end() && y < gps->dimy - 4; it++)
|
|
|
|
|
{
|
|
|
|
@ -242,10 +257,6 @@ public:
|
|
|
|
|
OutputString(COLOR_WHITE, x, y, *wit, true, help_start);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual std::string getFocusString()
|
|
|
|
|