title-version: add to options screen

develop
lethosor 2018-06-12 16:38:53 -04:00
parent 40d0d946a4
commit de0521e618
2 changed files with 40 additions and 18 deletions

@ -59,6 +59,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
- added ability to drag with left/right buttons
- added depth display for TWBT (when multilevel is enabled)
- made shift+click jump to lower levels visible with TWBT
- `title-version`: added version to options screen too
## API
- Removed Vermin module (unused and obsolete)

@ -14,6 +14,7 @@
#include "DFHackVersion.h"
#include "df/graphic.h"
#include "df/viewscreen_optionst.h"
#include "df/viewscreen_titlest.h"
#include "uicommon.h"
@ -25,34 +26,52 @@ DFHACK_PLUGIN("title-version");
DFHACK_PLUGIN_IS_ENABLED(is_enabled);
REQUIRE_GLOBAL(gps);
void draw_version(int start_x, int start_y) {
int x = start_x,
y = start_y;
OutputString(COLOR_WHITE, x, y, string("DFHack ") + DFHACK_VERSION);
if (!DFHACK_IS_RELEASE)
{
OutputString(COLOR_WHITE, x, y, " (dev)");
x = start_x; y++;
OutputString(COLOR_WHITE, x, y, "Git: ");
OutputString(COLOR_WHITE, x, y, DFHACK_GIT_DESCRIPTION);
}
if (DFHACK_IS_PRERELEASE)
{
x = start_x; y++;
OutputString(COLOR_LIGHTRED, x, y, "Pre-release build");
}
}
struct title_version_hook : df::viewscreen_titlest {
typedef df::viewscreen_titlest interpose_base;
DEFINE_VMETHOD_INTERPOSE(void, render, ())
{
INTERPOSE_NEXT(render)();
if (loading)
return;
int x = 0, y = 0;
OutputString(COLOR_WHITE, x, y, string("DFHack ") + DFHACK_VERSION);
if (!DFHACK_IS_RELEASE)
{
OutputString(COLOR_WHITE, x, y, " (dev)");
x = 0; y++;
OutputString(COLOR_WHITE, x, y, "Git: ");
OutputString(COLOR_WHITE, x, y, DFHACK_GIT_DESCRIPTION);
}
if (DFHACK_IS_PRERELEASE)
{
x = 0; y++;
OutputString(COLOR_LIGHTRED, x, y, "Pre-release build");
}
if (!loading)
draw_version(0, 0);
}
};
IMPLEMENT_VMETHOD_INTERPOSE(title_version_hook, render);
struct options_version_hook : df::viewscreen_optionst {
typedef df::viewscreen_optionst interpose_base;
DEFINE_VMETHOD_INTERPOSE(void, render, ())
{
INTERPOSE_NEXT(render)();
if (!msg_quit && !in_retire_adv && !msg_peasant &&
!in_retire_dwf_abandon_adv && !in_abandon_dwf && !ending_game)
draw_version(0, 0);
}
};
IMPLEMENT_VMETHOD_INTERPOSE(options_version_hook, render);
DFhackCExport command_result plugin_enable (color_ostream &out, bool enable)
{
if (!gps)
@ -60,7 +79,8 @@ DFhackCExport command_result plugin_enable (color_ostream &out, bool enable)
if (enable != is_enabled)
{
if (!INTERPOSE_HOOK(title_version_hook, render).apply(enable))
if (!INTERPOSE_HOOK(title_version_hook, render).apply(enable) ||
!INTERPOSE_HOOK(options_version_hook, render).apply(enable))
return CR_FAILURE;
is_enabled = enable;
@ -77,5 +97,6 @@ DFhackCExport command_result plugin_init (color_ostream &out, vector<PluginComma
DFhackCExport command_result plugin_shutdown (color_ostream &out)
{
INTERPOSE_HOOK(title_version_hook, render).remove();
INTERPOSE_HOOK(options_version_hook, render).remove();
return CR_OK;
}