GUI2/MP Method Selection: used an enum instead of ints for choices results
This commit is contained in:
parent
480fc920dc
commit
bc36c7ee65
3 changed files with 13 additions and 10 deletions
|
@ -75,7 +75,7 @@ void mp_method_selection::post_show(window& window)
|
|||
{
|
||||
if(get_retval() == retval::OK) {
|
||||
listbox& list = find_widget<listbox>(&window, "method_list", false);
|
||||
choice_ = list.get_selected_row();
|
||||
choice_ = static_cast<choice>(list.get_selected_row());
|
||||
|
||||
text_box& user_widget = find_widget<text_box>(&window, "user_name", false);
|
||||
user_widget.save_to_history();
|
||||
|
|
|
@ -24,7 +24,10 @@ namespace dialogs
|
|||
class mp_method_selection : public modal_dialog
|
||||
{
|
||||
public:
|
||||
mp_method_selection() : user_name_(), choice_(-1)
|
||||
/** Corresponds to each connection option. */
|
||||
enum class choice { JOIN = 0, CONNECT, HOST, LOCAL };
|
||||
|
||||
mp_method_selection() : user_name_(), choice_()
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -33,7 +36,7 @@ public:
|
|||
return user_name_;
|
||||
}
|
||||
|
||||
int get_choice() const
|
||||
choice get_choice() const
|
||||
{
|
||||
return choice_;
|
||||
}
|
||||
|
@ -43,7 +46,7 @@ private:
|
|||
std::string user_name_;
|
||||
|
||||
/** The selected method to `connect' to the MP server. */
|
||||
int choice_;
|
||||
choice choice_;
|
||||
|
||||
/** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */
|
||||
virtual const std::string& window_id() const override;
|
||||
|
|
|
@ -496,28 +496,28 @@ void title_screen::button_callback_multiplayer(window& window)
|
|||
return;
|
||||
}
|
||||
|
||||
const int res = dlg.get_choice();
|
||||
const auto res = dlg.get_choice();
|
||||
|
||||
if(res == 2 && preferences::mp_server_warning_disabled() < 2) {
|
||||
if(res == decltype(dlg)::choice::HOST && preferences::mp_server_warning_disabled() < 2) {
|
||||
if(!gui2::dialogs::mp_host_game_prompt::execute()) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
switch(res) {
|
||||
case 0:
|
||||
case decltype(dlg)::choice::JOIN:
|
||||
game_.select_mp_server(preferences::builtin_servers_list().front().address);
|
||||
window.set_retval(MP_CONNECT);
|
||||
break;
|
||||
case 1:
|
||||
case decltype(dlg)::choice::CONNECT:
|
||||
game_.select_mp_server("");
|
||||
window.set_retval(MP_CONNECT);
|
||||
break;
|
||||
case 2:
|
||||
case decltype(dlg)::choice::HOST:
|
||||
game_.select_mp_server("localhost");
|
||||
window.set_retval(MP_HOST);
|
||||
break;
|
||||
case 3:
|
||||
case decltype(dlg)::choice::LOCAL:
|
||||
window.set_retval(MP_LOCAL);
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue