embark-assistant: add in-game key to activate

Closes #1384
develop
lethosor 2019-08-25 21:32:29 -04:00
parent 0f4162acc9
commit 417212814d
2 changed files with 59 additions and 7 deletions

@ -262,6 +262,9 @@ enable \
# enable mouse controls and sand indicator in embark screen # enable mouse controls and sand indicator in embark screen
embark-tools enable sticky sand mouse embark-tools enable sticky sand mouse
# enable option to enter embark assistant
enable embark-assistant
########### ###########
# Scripts # # Scripts #
########### ###########

@ -1,11 +1,13 @@
#include <time.h>
#include "Core.h" #include "Core.h"
#include <Console.h> #include "Console.h"
#include <Export.h> #include "Export.h"
#include <PluginManager.h> #include "PluginManager.h"
#include <time.h> #include "modules/Gui.h"
#include <modules/Gui.h> #include "modules/Screen.h"
#include <modules/Screen.h> #include "../uicommon.h"
#include "DataDefs.h" #include "DataDefs.h"
#include "df/coord2d.h" #include "df/coord2d.h"
@ -27,6 +29,7 @@
#include "survey.h" #include "survey.h"
DFHACK_PLUGIN("embark-assistant"); DFHACK_PLUGIN("embark-assistant");
DFHACK_PLUGIN_IS_ENABLED(is_enabled);
using namespace DFHack; using namespace DFHack;
using namespace df::enums; using namespace df::enums;
@ -134,11 +137,41 @@ command_result embark_assistant (color_ostream &out, std::vector <std::string> &
//======================================================================================= //=======================================================================================
struct start_site_hook : df::viewscreen_choose_start_sitest {
typedef df::viewscreen_choose_start_sitest interpose_base;
DEFINE_VMETHOD_INTERPOSE(void, render, ())
{
INTERPOSE_NEXT(render)();
if (embark_assist::main::state)
return;
int x = 60;
int y = Screen::getWindowSize().y - 2;
OutputString(COLOR_LIGHTRED, x, y, " " + Screen::getKeyDisplay(interface_key::CUSTOM_A));
OutputString(COLOR_WHITE, x, y, ": Embark Assistant");
}
DEFINE_VMETHOD_INTERPOSE(void, feed, (std::set<df::interface_key> *input))
{
if (!embark_assist::main::state && input->count(interface_key::CUSTOM_A))
{
Core::getInstance().setHotkeyCmd("embark-assistant");
return;
}
INTERPOSE_NEXT(feed)(input);
}
};
IMPLEMENT_VMETHOD_INTERPOSE(start_site_hook, render);
IMPLEMENT_VMETHOD_INTERPOSE(start_site_hook, feed);
//=======================================================================================
DFhackCExport command_result plugin_init (color_ostream &out, std::vector <PluginCommand> &commands) DFhackCExport command_result plugin_init (color_ostream &out, std::vector <PluginCommand> &commands)
{ {
commands.push_back(PluginCommand( commands.push_back(PluginCommand(
"embark-assistant", "Embark site selection support.", "embark-assistant", "Embark site selection support.",
embark_assistant, true, /* true means that the command can't be used from non-interactive user interface */ embark_assistant, false, /* false means that the command can be used from non-interactive user interface */
// Extended help string. Used by CR_WRONG_USAGE and the help command: // Extended help string. Used by CR_WRONG_USAGE and the help command:
" This command starts the embark-assist plugin that provides embark site\n" " This command starts the embark-assist plugin that provides embark site\n"
" selection help. It has to be called while the pre-embark screen is\n" " selection help. It has to be called while the pre-embark screen is\n"
@ -160,6 +193,22 @@ DFhackCExport command_result plugin_shutdown (color_ostream &out)
//======================================================================================= //=======================================================================================
DFhackCExport command_result plugin_enable (color_ostream &out, bool enable)
{
if (is_enabled != enable)
{
if (!INTERPOSE_HOOK(start_site_hook, render).apply(enable) ||
!INTERPOSE_HOOK(start_site_hook, feed).apply(enable))
{
return CR_FAILURE;
}
is_enabled = enable;
}
return CR_OK;
}
//=======================================================================================
DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event) DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event)
{ {
switch (event) { switch (event) {