The Battle for Wesnoth  1.17.0-dev
mp_method_selection.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2018 by Mark de Wever <koraq@xs4all.nl>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #define GETTEXT_DOMAIN "wesnoth-lib"
16 
18 
19 #include "desktop/open.hpp"
22 #include "gui/widgets/button.hpp"
23 #include "gui/widgets/listbox.hpp"
24 #include "gui/widgets/settings.hpp"
25 #include "gui/widgets/text_box.hpp"
26 #include "gui/widgets/window.hpp"
28 
29 namespace gui2::dialogs
30 {
31 
32 REGISTER_DIALOG(mp_method_selection)
33 
34 static const std::string forum_registration_url = "https://forums.wesnoth.org/ucp.php?mode=register";
35 
37 {
38  user_name_ = preferences::login();
39 
40  text_box* user_widget = find_widget<text_box>(&window, "user_name", false, true);
41  user_widget->set_value(user_name_);
43 
44  window.keyboard_capture(user_widget);
45 
46  listbox* list = find_widget<listbox>(&window, "method_list", false, true);
47  window.add_to_keyboard_chain(list);
48 
49  connect_signal_mouse_left_click(find_widget<button>(&window, "register", false),
51 }
52 
54 {
55  if(get_retval() == retval::OK) {
56  listbox& list = find_widget<listbox>(&window, "method_list", false);
57  choice_ = static_cast<choice>(list.get_selected_row());
58 
59  text_box& user_widget = find_widget<text_box>(&window, "user_name", false);
60  user_widget.save_to_history();
61 
62  user_name_ = user_widget.get_value();
64  }
65 }
66 
67 } // namespace dialogs
const std::size_t max_login_size
Max length of a player name.
Definition: multiplayer.hpp:28
std::string user_name_
The name to use on the MP server.
void set_maximum_length(const std::size_t maximum_length)
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
std::string get_value() const
This file contains the window object, this object is a top level container which has the event manage...
void save_to_history()
Saves the text in the widget to the history.
Definition: text_box.hpp:148
STL namespace.
int get_selected_row() const
Returns the first selected row.
Definition: listbox.cpp:276
Class for a single line text area.
Definition: text_box.hpp:140
The listbox class.
Definition: listbox.hpp:42
Desktop environment interaction functions.
This file contains the settings handling of the widget library.
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal_function &signal)
Connects a signal handler for a left mouse button click.
Definition: dispatcher.cpp:171
void set_login(const std::string &login)
static const std::string forum_registration_url
std::string login()
bool open_object([[maybe_unused]] const std::string &path_or_url)
Definition: open.cpp:46
choice
Corresponds to each connection option.
virtual void set_value(const std::string &text)
The set_value is virtual for the password_box class.
int get_retval() const
Returns the cached window exit code.
This shows the dialog to select the kind of MP game the user wants to play.
choice choice_
The selected method to `connect&#39; to the MP server.
Dialog was closed with the OK button.
Definition: retval.hpp:34
base class of top level items, the only item which needs to store the final canvases to draw on...
Definition: window.hpp:64