mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-06-15 21:04:08 +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:
parent
770dd20613
commit
2a96937c89
29
dialogs.cpp
29
dialogs.cpp
@ -65,7 +65,24 @@ namespace dialog {
|
|||||||
|
|
||||||
item& lastItem() { return items[items.size() - 1]; }
|
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) {
|
string keyname(int k) {
|
||||||
if(k == 0) return "";
|
if(k == 0) return "";
|
||||||
@ -417,6 +434,16 @@ namespace dialog {
|
|||||||
highlight_text = items[i].body;
|
highlight_text = items[i].body;
|
||||||
uni = sym = 0;
|
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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user