integrate hotkeys with helpdb

develop
myk002 2022-07-15 09:44:24 -07:00
parent c9a87511bd
commit f3539f06c8
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
2 changed files with 35 additions and 24 deletions

@ -130,7 +130,7 @@ if(BUILD_SUPPORTED)
dfhack_plugin(forceequip forceequip.cpp) dfhack_plugin(forceequip forceequip.cpp)
dfhack_plugin(generated-creature-renamer generated-creature-renamer.cpp) dfhack_plugin(generated-creature-renamer generated-creature-renamer.cpp)
dfhack_plugin(getplants getplants.cpp) dfhack_plugin(getplants getplants.cpp)
dfhack_plugin(hotkeys hotkeys.cpp) dfhack_plugin(hotkeys hotkeys.cpp LINK_LIBRARIES lua)
dfhack_plugin(infiniteSky infiniteSky.cpp) dfhack_plugin(infiniteSky infiniteSky.cpp)
dfhack_plugin(isoworldremote isoworldremote.cpp PROTOBUFS isoworldremote) dfhack_plugin(isoworldremote isoworldremote.cpp PROTOBUFS isoworldremote)
dfhack_plugin(jobutils jobutils.cpp) dfhack_plugin(jobutils jobutils.cpp)

@ -8,6 +8,7 @@
#include "modules/World.h" #include "modules/World.h"
#include "modules/Gui.h" #include "modules/Gui.h"
#include "LuaTools.h"
#include "PluginManager.h" #include "PluginManager.h"
DFHACK_PLUGIN("hotkeys"); 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("F" + int_to_string(i));
} }
valid_keys.push_back("`");
auto current_focus = Gui::getFocusString(screen); auto current_focus = Gui::getFocusString(screen);
for (int shifted = 0; shifted < 2; shifted++) 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 class ViewscreenHotkeys : public dfhack_viewscreen
{ {
public: public:
@ -219,20 +245,9 @@ public:
if (first[0] == '#') if (first[0] == '#')
return; 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); OutputString(COLOR_BROWN, x, y, "Help", true, help_start);
string help_text = get_help(first, show_usage);
vector <string> lines; vector <string> lines;
string help_text = pc.description;
if (show_usage)
help_text += "\n\n" + pc.usage;
split_string(&lines, help_text, "\n"); split_string(&lines, help_text, "\n");
for (auto it = lines.begin(); it != lines.end() && y < gps->dimy - 4; it++) 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); OutputString(COLOR_WHITE, x, y, *wit, true, help_start);
} }
} }
break;
}
}
}
} }
virtual std::string getFocusString() virtual std::string getFocusString()