The Battle for Wesnoth  1.15.2+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
30 {
31 namespace dialogs
32 {
33 /*WIKI
34  * @page = GUIWindowDefinitionWML
35  * @order = 2_mp_method_selection
36  *
37  * == MP method selection ==
38  *
39  * This shows the dialog to select the kind of MP game the user wants to play.
40  *
41  * @begin{table}{dialog_widgets}
42  *
43  * user_name & & text_box & m &
44  * This text contains the name the user on the MP server. This widget
45  * will get a fixed maximum length by the engine. $
46  *
47  * method_list & & listbox & m &
48  * The list with possible game methods. $
49  *
50  * @end{table}
51  */
52 
53 REGISTER_DIALOG(mp_method_selection)
54 
55 static const std::string forum_registration_url = "https://forums.wesnoth.org/ucp.php?mode=register";
56 
58 {
59  user_name_ = preferences::login();
60 
61  text_box* user_widget = find_widget<text_box>(&window, "user_name", false, true);
62  user_widget->set_value(user_name_);
64 
65  window.keyboard_capture(user_widget);
66 
67  listbox* list = find_widget<listbox>(&window, "method_list", false, true);
68  window.add_to_keyboard_chain(list);
69 
70  connect_signal_mouse_left_click(find_widget<button>(&window, "register", false),
72 }
73 
75 {
76  if(get_retval() == retval::OK) {
77  listbox& list = find_widget<listbox>(&window, "method_list", false);
78  choice_ = list.get_selected_row();
79 
80  text_box& user_widget = find_widget<text_box>(&window, "user_name", false);
81  user_widget.save_to_history();
82 
83  user_name_ = user_widget.get_value();
85  }
86 }
87 
88 } // namespace dialogs
89 } // namespace gui2
const std::size_t max_login_size
Definition: multiplayer.hpp:27
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
Inherited from modal_dialog.
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:129
STL namespace.
int get_selected_row() const
Returns the first selected row.
Definition: listbox.cpp:272
Class for a single line text area.
Definition: text_box.hpp:121
Generic file dialog.
Definition: field-fwd.hpp:22
The listbox class.
Definition: listbox.hpp:40
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:233
void set_login(const std::string &login)
int choice_
The selected method to `connect&#39; to the MP server.
static const std::string forum_registration_url
Various uncategorised dialogs.
std::string login()
bool open_object(const std::string &path_or_url)
Opens the specified object with the default application configured for its type.
Definition: open.cpp:55
-file mapgen.hpp
virtual void set_value(const std::string &text)
The set_value is virtual for the password_box class.
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:62