/
multiplayer_connect.hpp
161 lines (123 loc) · 4.19 KB
/
multiplayer_connect.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
Copyright (C) 2007 - 2015 by David White <dave@whitevine.net>
Part of the Battle for Wesnoth Project http://www.wesnoth.org
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
/** @file */
#ifndef MULTIPLAYER_CONNECT_H_INCLUDED
#define MULTIPLAYER_CONNECT_H_INCLUDED
#include "commandline_options.hpp"
#include "connect_engine.hpp"
#include "multiplayer_ui.hpp"
#include "widgets/combo_drag.hpp"
#include "widgets/scrollpane.hpp"
#include "widgets/slider.hpp"
namespace ai {
struct description;
}
namespace mp {
// Helper function to retrieve controller names.
std::vector<std::string> controller_options_names(
const std::vector<ng::controller_option>& controller_options);
class connect : public mp::ui
{
public:
class side {
public:
side(connect& parent, ng::side_engine_ptr engine);
side(const side& a);
~side();
void process_event();
// Returns true if this side changed since last call to this method.
bool changed();
void update_ui();
void add_widgets_to_scrollpane(gui::scrollpane& pane, int pos);
ng::side_engine_ptr engine() { return engine_; }
const ng::side_engine_ptr engine() const { return engine_; }
private:
// Update UI methods and their helper(s).
void update_faction_combo();
void update_controller_ui();
// The mp::connect widget owning this mp::connect::side.
connect* parent_;
ng::side_engine_ptr engine_;
// Flags for controlling which configuration widgets should be locked.
bool gold_lock_;
bool income_lock_;
bool team_lock_;
bool color_lock_;
bool changed_;
gui::label label_player_number_;
gui::label label_original_controller_;
gui::label label_gold_;
gui::label label_income_;
gui::combo_drag_ptr combo_controller_;
gui::combo combo_ai_algorithm_;
gui::combo combo_faction_;
gui::label label_leader_name_;
gui::combo combo_leader_;
gui::combo combo_gender_;
gui::combo combo_team_;
gui::combo combo_color_;
gui::slider slider_gold_;
gui::slider slider_income_;
};
typedef std::vector<side> side_list;
connect(game_display& disp, const std::string& game_name,
const config& game_config, chat& c, config& gamelist,
ng::connect_engine& engine);
~connect();
// Updates the current game state, resolves random factions, and sends a
// "start game" message to the network.
void start_game() { engine_.start_game(); }
void start_game_commandline(const commandline_options& cmdline_opts)
{ engine_.start_game_commandline(cmdline_opts); }
protected:
virtual void process_event();
virtual void layout_children(const SDL_Rect& rect);
virtual void hide_children(bool hide = true);
virtual void process_network_data(const config& data,
const network::connection sock);
virtual void process_network_error(network::error& error);
private:
connect(const connect&);
void operator=(const connect&);
// Updates the state of the player list, the launch button and of the start
// game label, to reflect the actual state.
void update_playerlist_state(bool silent = true);
const mp_game_settings& params() { return engine_.params(); }
bool force_lock_settings() const { return engine_.force_lock_settings(); }
std::vector<ai::description*> ai_algorithms_;
side_list sides_;
ng::connect_engine& engine_;
gui::label waiting_label_;
gui::label type_title_label_;
gui::label faction_name_title_label_;
gui::label leader_gender_title_label_;
gui::label team_color_title_label_;
gui::label gold_title_label_;
gui::label income_title_label_;
gui::scrollpane scroll_pane_;
gui::button launch_;
gui::button cancel_;
gui::drop_group_manager_ptr combo_control_group_;
struct process_event_data {
bool launch, quit;
process_event_data()
: launch(false), quit(false)
{}
process_event_data(bool l, bool q)
: launch(l), quit(q)
{}
};
void process_event_impl(const process_event_data &);
bool plugin_event_helper(const process_event_data &);
};
} // end namespace mp
#endif