Skip to content

Commit

Permalink
fix: more consistent right click handling in main menu
Browse files Browse the repository at this point in the history
As noted in #2528, a bunch of main menu popups or submenus weren't
correctly handling right clicks to exit. This should standardize the
behavior. (Caveats: I still don't really understand why right click is
best detected using `CK_MOUSE_CMD`, and I had do something a bit dodgy
to get good handling of this for the seed/arena text entry boxes. Also,
what would be much better is a click outside to close behavior, similar
to how webtiles mouse handling works, which would probably address the
touchscreen issues in that #2528.)
  • Loading branch information
rawlins committed Apr 26, 2022
1 parent 7bc237e commit 2679155
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
8 changes: 5 additions & 3 deletions crawl-ref/source/arena.cc
Expand Up @@ -758,7 +758,7 @@ namespace arena

static void handle_keypress(int ch)
{
if (key_is_escape(ch) || toalower(ch) == 'q')
if (key_is_escape(ch) || toalower(ch) == 'q' || ch == CK_MOUSE_CMD)
{
contest_cancelled = true;
return;
Expand Down Expand Up @@ -1486,8 +1486,9 @@ static void _choose_arena_teams(newgame_def& choice,
arena::skipped_arena_ui = false;
clear_message_store();

auto text = make_shared<Text>("Enter your choice of teams:\n ");
auto vbox = make_shared<Box>(ui::Widget::VERT);
vbox->add_child(make_shared<Text>("Enter your choice of teams:\n "));
vbox->add_child(text);
vbox->set_cross_alignment(Widget::Align::STRETCH);
auto teams_input = make_shared<ui::TextEntry>();
teams_input->set_sync_id("teams");
Expand All @@ -1507,7 +1508,8 @@ static void _choose_arena_teams(newgame_def& choice,
return done = (ev.key() == CK_ENTER);
});
popup->on_keydown_event([&](const KeyEvent& ev) {
return done = cancel = key_is_escape(ev.key());
done = cancel = key_is_escape(ev.key()) || ev.key() == CK_MOUSE_CMD;
return done;
});

ui::run_layout(move(popup), done, teams_input);
Expand Down
7 changes: 7 additions & 0 deletions crawl-ref/source/hints.cc
Expand Up @@ -262,6 +262,13 @@ void pick_hints(newgame_def& choice)

auto popup = make_shared<ui::Popup>(vbox);

popup->on_keydown_event([&](const KeyEvent& ev) {
auto key = ev.key();
if (key == CK_MOUSE_CMD)
return done = cancelled = true;
return false;
});

ui::run_layout(move(popup), done);

if (cancelled)
Expand Down
11 changes: 7 additions & 4 deletions crawl-ref/source/newgame.cc
Expand Up @@ -366,7 +366,7 @@ static bool _reroll_random(newgame_def& ng)
auto popup = make_shared<ui::Popup>(move(vbox));

bool done = false;
char c;
int c;
popup->on_keydown_event([&](const KeyEvent& ev) {
c = ev.key();
return done = true;
Expand All @@ -381,7 +381,9 @@ static bool _reroll_random(newgame_def& ng)
#endif
ui::run_layout(move(popup), done);

if (key_is_escape(c) || toalower(c) == 'q' || crawl_state.seen_hups)
// XX mouse interface in local tiles for `y` -- right now right click does
// `q` only
if (key_is_escape(c) || c == CK_MOUSE_CMD || toalower(c) == 'q' || crawl_state.seen_hups)
game_ended(game_exit::abort);
return toalower(c) == 'n' || c == '\t' || c == '!' || c == '#';
}
Expand Down Expand Up @@ -697,7 +699,7 @@ static keyfun_action _keyfun_seed_input(int &ch)
// lose focus. (TODO: maybe handle this better in TextEntry somehow?)
if (ch == CONTROL('K') || ch == CONTROL('D') || ch == CONTROL('W') ||
ch == CONTROL('U') || ch == CONTROL('A') || ch == CONTROL('E') ||
ch == CK_BKSP || ch == CK_ESCAPE ||
ch == CK_BKSP || ch == CK_ESCAPE || ch == CK_MOUSE_CMD ||
ch < 0 || // this should get all other special keys
isadigit(ch))
{
Expand Down Expand Up @@ -937,7 +939,7 @@ static void _choose_seed(newgame_def& ng, newgame_def& choice,
return false;
}
#endif
else if (key_is_escape(key))
else if (key_is_escape(key) || key == CK_MOUSE_CMD)
return done = cancel = true;
return false;
});
Expand Down Expand Up @@ -2250,6 +2252,7 @@ static void _prompt_gamemode_map(newgame_def& ng, newgame_def& ng_choice,
#endif
end(0);
break;
case CK_MOUSE_CMD:
CASE_ESCAPE
return done = cancel = true;
break;
Expand Down
7 changes: 7 additions & 0 deletions crawl-ref/source/ui.cc
Expand Up @@ -1991,6 +1991,13 @@ bool TextEntry::on_event(const Event& event)
case Event::Type::KeyDown:
{
const auto key = static_cast<const KeyEvent&>(event).key();
#ifdef USE_TILE_LOCAL
// exit a popup on right click with text entry focus. XX this seems
// like a bad way to handle it, but I'm not sure what a better way
// might be.
if (key == CK_MOUSE_CMD)
return false;
#endif
int ret = m_line_reader.process_key_core(key);
if (ret == CK_ESCAPE || ret == 0)
ui::set_focused_widget(nullptr);
Expand Down

0 comments on commit 2679155

Please sign in to comment.