The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
mp_method_selection.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2008 - 2025
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"
26
27namespace gui2::dialogs
28{
29
30REGISTER_DIALOG(mp_method_selection)
31
32/** Link to the wesnoth forum account registration page */
33static const std::string forum_registration_url = "https://forums.wesnoth.org/ucp.php?mode=register";
34
35void mp_method_selection::pre_show()
36{
37 text_box* user_widget = find_widget<text_box>("user_name", false, true);
38 user_widget->set_value(prefs::get().login());
40
41 listbox* list = find_widget<listbox>("method_list", false, true);
42 list->select_row(prefs::get().mp_connect_type());
43#if defined(__IPHONEOS__)
44 if(prefs::get().mp_connect_type() == static_cast<int>(choice::HOST)) {
45 list->select_row(static_cast<unsigned>(choice::LOCAL));
46 }
47 list->set_row_active(static_cast<unsigned>(choice::HOST), false);
48#endif
49
50 add_to_tab_order(list);
51 add_to_tab_order(user_widget);
52
53 connect_signal_mouse_left_click(find_widget<button>("register"),
55}
56
58{
59 prefs::get().set_mp_connect_type(find_widget<listbox>("method_list").get_selected_row());
60
61 if(get_retval() == retval::OK) {
62 text_box& user_widget = find_widget<text_box>("user_name");
63 user_widget.save_to_history();
64 prefs::get().set_login(user_widget.get_value());
65 }
66}
67
69{
70 return static_cast<choice>(prefs::get().mp_connect_type());
71}
72
73} // namespace dialogs
virtual void post_show() override
Actions to be taken after the window has been shown.
choice
Corresponds to each connection option.
The listbox class.
Definition listbox.hpp:41
void set_row_active(const unsigned row, const bool active)
Makes a row active or inactive.
Definition listbox.cpp:158
bool select_row(const unsigned row, const bool select=true)
Selects a 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
int get_retval()
Definition window.hpp:394
static prefs & get()
void set_login(const std::string &login)
#define REGISTER_DIALOG(window_id)
Wrapper for REGISTER_DIALOG2.
bool open_object(const std::string &path_or_url)
Opens the specified object with the default application configured for its type.
Definition open.cpp:50
static const std::string forum_registration_url
Link to the wesnoth forum account registration page.
@ 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.
STL namespace.
Desktop environment interaction functions.