Skip to content

Commit

Permalink
MP Lobby: use exit hook for quit confirmation
Browse files Browse the repository at this point in the history
By design, this extends the confirmation popup to exiting the lobby with the Log Out button too (previously, only
the Esc key triggered it. However, given the proximity of the button to other control buttons, it's not inconceivable
that someone might click it by accident, so the confirmation is useful.
  • Loading branch information
Vultraz committed Mar 16, 2017
1 parent 45a6065 commit 8675bbb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
20 changes: 7 additions & 13 deletions src/gui/dialogs/lobby/lobby.cpp
Expand Up @@ -654,16 +654,13 @@ void lobby_main::update_selected_game()
player_list_dirty_ = true;
}

void lobby_main::signal_handler_key_down(SDL_Keycode key, bool& handled, bool& halt)
bool lobby_main::exit_hook(window& window)
{
if(key == SDLK_ESCAPE) {
if(quit()) {
window_->set_retval(window::OK);
window_->close();
}
handled = true;
halt = true;
if(window.get_retval() == window::CANCEL) {
return quit();
}

return true;
}

void lobby_main::pre_show(window& window)
Expand Down Expand Up @@ -694,12 +691,9 @@ void lobby_main::pre_show(window& window)
std::bind(&lobby_main::player_filter_callback, this, _1));

window.set_enter_disabled(true);
window.set_escape_disabled(true);

// A new key handler to deal with escape in a different manner.
window.connect_signal<event::SDL_KEY_DOWN>(
std::bind(&lobby_main::signal_handler_key_down, this, _5, _3, _4),
event::dispatcher::front_pre_child);
// Exit hook to add a confirmation when quitting the Lobby.
window.set_exit_hook(std::bind(&lobby_main::exit_hook, this, std::ref(window)));

window_ = &window;

Expand Down
2 changes: 1 addition & 1 deletion src/gui/dialogs/lobby/lobby.hpp
Expand Up @@ -158,7 +158,7 @@ class lobby_main : public modal_dialog, public quit_confirmation, private plugin

void skip_replay_changed_callback(window& window);

void signal_handler_key_down(SDL_Keycode key, bool& handled, bool& halt);
bool exit_hook(window& window);

static bool logout_prompt();

Expand Down

1 comment on commit 8675bbb

@CelticMinstrel
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I recall correctly, you were the one who didn't originally want a confirmation from the Log Out button, so I guess this is just fine.

Please sign in to comment.