1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-06-18 11:19:59 +00:00

dialog:: add_action to specify an action for the given key immediately after creating an item, rather than in the handler

This commit is contained in:
Zeno Rogue 2018-07-09 18:11:49 +02:00
parent 770dd20613
commit 2a96937c89

View File

@ -65,7 +65,24 @@ namespace dialog {
item& lastItem() { return items[items.size() - 1]; }
void init() { items.clear(); }
map<int, reaction_t> key_actions;
void add_action(reaction_t action) {
int& key = lastItem().key;
while(key_actions.count(key)) key++;
key_actions[key] = action;
}
void handler(int sym, int uni) {
dialog::handleNavigation(sym, uni);
if(doexiton(sym, uni)) popScreen();
};
void init() {
items.clear();
key_actions.clear();
keyhandler = dialog::handler;
}
string keyname(int k) {
if(k == 0) return "";
@ -417,6 +434,16 @@ namespace dialog {
highlight_text = items[i].body;
uni = sym = 0;
}
if(key_actions.count(sym)) {
key_actions[sym]();
sym = uni = 0;
return;
}
if(key_actions.count(uni)) {
key_actions[uni]();
sym = uni = 0;
return;
}
#endif
}