The Battle for Wesnoth
1.21.0-dev
Loading...
Searching...
No Matches
gui
dialogs
multiplayer
mp_connect.hpp
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
#pragma once
17
18
#include "
gui/dialogs/modal_dialog.hpp
"
19
20
namespace
game_config
21
{
22
struct
server_info;
23
}
24
25
namespace
gui2
26
{
27
28
class
listbox;
29
30
namespace
dialogs
31
{
32
33
class
mp_connect
:
public
modal_dialog
34
{
35
/** The unit test needs to be able to test the mp_connect dialog. */
36
friend
modal_dialog
*
unit_test_mp_server_list
();
37
38
public
:
39
mp_connect
();
40
41
/** The execute function. See @ref modal_dialog for more information. */
42
DEFINE_SIMPLE_EXECUTE_WRAPPER
(
mp_connect
)
43
44
private
:
45
virtual
const
std::string&
window_id
()
const override
;
46
47
virtual
void
pre_show
()
override
;
48
49
// Signal handlers
50
51
void
on_address_change
();
52
void
on_server_add
();
53
void
on_server_delete
();
54
void
on_server_select
();
55
56
// Auxiliary functions
57
58
using
server_info
=
game_config::server_info
;
59
using
server_list
= std::vector<server_info>;
60
61
void
insert_into_server_listbox
(
listbox
&
listbox
,
const
server_info
& srv,
int
pos = -1);
62
63
void
select_first_match
();
64
65
class
selection
66
{
67
public
:
68
selection
(
mp_connect
* owner,
int
row
= -1)
69
:
owner_
(owner)
70
,
row_
(
row
)
71
{
72
}
73
74
bool
valid
()
const
75
{
76
return
owner_
&&
row_
>= 0;
77
}
78
79
bool
user_defined
()
const
;
80
81
unsigned
row
()
const
;
82
83
std::size_t
relative_index
()
const
;
84
85
server_list
&
parent_list
()
const
;
86
87
server_info
&
get
();
88
89
private
:
90
mp_connect
*
owner_
;
91
int
row_
;
92
93
void
must_be_valid
()
const
94
{
95
if
(!
valid
()) {
96
throw
std::out_of_range{
"Invalid MP server selection"
};
97
}
98
}
99
};
100
101
selection
current_selection
();
102
103
std::array<server_list*, 2>
server_lists
();
104
105
/** The host name of the selected server. */
106
field_text
*
host_name_
;
107
108
server_list
builtin_servers_
;
109
server_list
user_servers_
;
110
};
111
112
}
// namespace dialogs
113
}
// namespace gui2
gui2::dialogs::modal_dialog
Abstract base class for all modal dialogs.
Definition
modal_dialog.hpp:146
gui2::dialogs::mp_connect::selection
Definition
mp_connect.hpp:66
gui2::dialogs::mp_connect::selection::user_defined
bool user_defined() const
Definition
mp_connect.cpp:252
gui2::dialogs::mp_connect::selection::get
server_info & get()
Definition
mp_connect.cpp:246
gui2::dialogs::mp_connect::selection::selection
selection(mp_connect *owner, int row=-1)
Definition
mp_connect.hpp:68
gui2::dialogs::mp_connect::selection::row_
int row_
Definition
mp_connect.hpp:91
gui2::dialogs::mp_connect::selection::parent_list
server_list & parent_list() const
Definition
mp_connect.cpp:271
gui2::dialogs::mp_connect::selection::valid
bool valid() const
Definition
mp_connect.hpp:74
gui2::dialogs::mp_connect::selection::owner_
mp_connect * owner_
Definition
mp_connect.hpp:90
gui2::dialogs::mp_connect::selection::row
unsigned row() const
Definition
mp_connect.cpp:259
gui2::dialogs::mp_connect::selection::must_be_valid
void must_be_valid() const
Definition
mp_connect.hpp:93
gui2::dialogs::mp_connect::selection::relative_index
std::size_t relative_index() const
Definition
mp_connect.cpp:265
gui2::dialogs::mp_connect
Definition
mp_connect.hpp:34
gui2::dialogs::mp_connect::insert_into_server_listbox
void insert_into_server_listbox(listbox &listbox, const server_info &srv, int pos=-1)
Definition
mp_connect.cpp:102
gui2::dialogs::mp_connect::on_server_add
void on_server_add()
Definition
mp_connect.cpp:160
gui2::dialogs::mp_connect::on_server_select
void on_server_select()
Definition
mp_connect.cpp:216
gui2::dialogs::mp_connect::on_address_change
void on_address_change()
Definition
mp_connect.cpp:154
gui2::dialogs::mp_connect::unit_test_mp_server_list
friend modal_dialog * unit_test_mp_server_list()
The unit test needs to be able to test the mp_connect dialog.
gui2::dialogs::mp_connect::server_list
std::vector< server_info > server_list
Definition
mp_connect.hpp:59
gui2::dialogs::mp_connect::select_first_match
void select_first_match()
Definition
mp_connect.cpp:114
gui2::dialogs::mp_connect::current_selection
selection current_selection()
Definition
mp_connect.cpp:240
gui2::dialogs::mp_connect::server_lists
std::array< server_list *, 2 > server_lists()
Definition
mp_connect.cpp:76
gui2::dialogs::mp_connect::window_id
virtual const std::string & window_id() const override
The execute function.
gui2::dialogs::mp_connect::host_name_
field_text * host_name_
The host name of the selected server.
Definition
mp_connect.hpp:106
gui2::dialogs::mp_connect::user_servers_
server_list user_servers_
Definition
mp_connect.hpp:109
gui2::dialogs::mp_connect::mp_connect
mp_connect()
Definition
mp_connect.cpp:64
gui2::dialogs::mp_connect::on_server_delete
void on_server_delete()
Definition
mp_connect.cpp:198
gui2::dialogs::mp_connect::builtin_servers_
server_list builtin_servers_
Definition
mp_connect.hpp:108
gui2::dialogs::mp_connect::pre_show
virtual void pre_show() override
Actions to be taken before showing the window.
Definition
mp_connect.cpp:81
gui2::field_text
Specialized field class for text.
Definition
field.hpp:536
gui2::listbox
The listbox class.
Definition
listbox.hpp:41
modal_dialog.hpp
DEFINE_SIMPLE_EXECUTE_WRAPPER
#define DEFINE_SIMPLE_EXECUTE_WRAPPER(dialog)
Adds a bare-bonesstatic execute function to a dialog class that immediately invokes and return the re...
Definition
modal_dialog.hpp:112
dialogs
Various uncategorised dialogs.
game_config
Game configuration data as global variables.
Definition
build_info.cpp:68
gui2
Generic file dialog.
Definition
draw_manager.hpp:21
game_config::server_info
Definition
game_config.hpp:73
Generated by
1.9.8