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