dfhack/plugins/tweak/tweaks/embark-profile-name.h

25 lines
941 B
C

2015-08-25 08:12:31 -06:00
#include "df/viewscreen_setupdwarfgamest.h"
2020-04-02 10:52:12 -06:00
2015-08-25 08:12:31 -06:00
struct embark_profile_name_hook : df::viewscreen_setupdwarfgamest {
typedef df::viewscreen_setupdwarfgamest interpose_base;
2020-04-02 10:52:12 -06:00
2020-04-04 04:17:10 -06:00
DEFINE_VMETHOD_INTERPOSE(void, feed, (std::set<df::interface_key> *input)) {
2015-08-25 08:12:31 -06:00
int ch = -1;
2020-04-04 04:17:10 -06:00
for (auto it = input->begin(); ch == -1 && it != input->end(); ++it) {
ch = Screen::keyToChar(*it);
2015-08-25 08:12:31 -06:00
}
2020-04-02 10:52:12 -06:00
// Intercept all printable characters except space.
// If space is intercepted the shift-space abort key will not work.
2020-04-04 04:17:10 -06:00
if (in_save_profile && ch >= 33 && ch <= 126) {
profile_name.push_back((char)ch);
2020-04-02 10:52:12 -06:00
} else {
2020-04-04 04:17:10 -06:00
if (input->count(df::interface_key::LEAVESCREEN)) {
input->insert(df::interface_key::SETUPGAME_SAVE_PROFILE_ABORT);
2020-04-04 04:12:51 -06:00
}
2020-04-04 04:17:10 -06:00
INTERPOSE_NEXT(feed)(input);
2015-08-25 08:12:31 -06:00
}
}
};
2020-04-02 10:52:12 -06:00
2020-04-04 04:17:10 -06:00
IMPLEMENT_VMETHOD_INTERPOSE(embark_profile_name_hook, feed);