35 #define DBG_MP LOG_STREAM(debug, log_mp_connect)
36 #define LOG_MP LOG_STREAM(info, log_mp_connect)
41 const std::vector<ng::controller_option>& controller_options)
43 std::vector<std::string>
names;
45 names.push_back(
option.second);
54 std::stringstream
buf;
56 buf <<
_(
"(") << income <<
_(
")");
57 }
else if (income > 0) {
58 buf <<
_(
"+") << income;
68 gold_lock_(engine_->cfg()[
"gold_lock"].to_bool(
69 parent_->force_lock_settings())),
70 income_lock_(engine_->cfg()[
"income_lock"].to_bool(
71 parent_->force_lock_settings())),
72 team_lock_(engine_->cfg()[
"team_lock"].to_bool(
73 parent_->force_lock_settings())),
74 color_lock_(engine_->cfg()[
"color_lock"].to_bool(
75 parent_->force_lock_settings())),
77 label_player_number_(parent.video(),
std::to_string(engine_->
index() + 1),
79 label_original_controller_(parent.video(), engine_->reserved_for(),
84 combo_controller_(new
gui::combo_drag(parent.video(),
85 std::vector<
std::
string>(), parent.combo_control_group_)),
86 combo_ai_algorithm_(parent.video(),
std::vector<
std::
string>()),
87 combo_faction_(parent.video(),
std::vector<
std::
string>()),
88 label_leader_name_(parent.video(), engine_->cfg()[
"name"],
font::
SIZE_SMALL),
89 combo_leader_(parent.video(),
std::vector<
std::
string>()),
90 combo_gender_(parent.video(),
std::vector<
std::
string>()),
91 combo_team_(parent.video(), engine_->player_teams()),
92 combo_color_(parent.video(), engine->get_colors()),
93 slider_gold_(parent.video()),
94 slider_income_(parent.video())
96 DBG_MP <<
"initializing side" << std::endl;
137 gold_lock_(a.gold_lock_),
138 income_lock_(a.income_lock_),
139 team_lock_(a.team_lock_),
140 color_lock_(a.color_lock_),
141 changed_(a.changed_),
142 label_player_number_(a.label_player_number_),
143 label_original_controller_(a.label_original_controller_),
144 label_gold_(a.label_gold_),
145 label_income_(a.label_income_),
146 combo_controller_(a.combo_controller_),
147 combo_ai_algorithm_(a.combo_ai_algorithm_),
148 combo_faction_(a.combo_faction_),
149 label_leader_name_(a.label_leader_name_),
150 combo_leader_(a.combo_leader_),
151 combo_gender_(a.combo_gender_),
152 combo_team_(a.combo_team_),
153 combo_color_(a.combo_color_),
154 slider_gold_(a.slider_gold_),
155 slider_income_(a.slider_income_)
166 if ((drop_target = combo_controller_->get_drop_target()) > -1) {
167 if (
engine_->swap_sides_on_drop_target(drop_target)) {
169 parent_->sides_[drop_target].changed_ =
true;
172 parent_->sides_[drop_target].update_ui();
174 }
else if (combo_controller_->changed() &&
175 combo_controller_->selected() >= 0) {
177 changed_ =
engine_->controller_changed(combo_controller_->selected());
178 update_controller_ui();
180 if (combo_controller_->hidden()) {
181 combo_controller_->hide(
false);
184 if (parent_->params().saved_game) {
188 if (combo_color_.changed() && combo_color_.selected() >= 0) {
189 engine_->set_color(combo_color_.selected());
190 update_faction_combo();
191 engine_->flg().reset_leader_combo(combo_leader_,
engine_->get_color());
192 engine_->flg().reset_gender_combo(combo_gender_,
engine_->get_color());
195 if (combo_faction_.changed() && combo_faction_.selected() >= 0) {
196 engine_->flg().set_current_faction(combo_faction_.selected());
197 engine_->flg().reset_leader_combo(combo_leader_,
engine_->get_color());
198 engine_->flg().reset_gender_combo(combo_gender_,
engine_->get_color());
201 if (combo_ai_algorithm_.changed() && combo_ai_algorithm_.selected() >= 0) {
203 parent_->ai_algorithms_[combo_ai_algorithm_.selected()]->id);
206 if (combo_leader_.changed() && combo_leader_.selected() >= 0) {
207 engine_->flg().set_current_leader(combo_leader_.selected());
208 engine_->flg().reset_gender_combo(combo_gender_,
engine_->get_color());
211 if (combo_gender_.changed() && combo_gender_.selected() >= 0) {
212 engine_->flg().set_current_gender(combo_gender_.selected());
215 if (combo_team_.changed() && combo_team_.selected() >= 0) {
216 engine_->set_team(combo_team_.selected());
219 if (slider_gold_.value() !=
engine_->gold() && slider_gold_.enabled()) {
220 engine_->set_gold(slider_gold_.value());
222 label_gold_.set_text(std::to_string(
engine_->gold()));
224 if (slider_income_.value() !=
engine_->income() && slider_income_.enabled()) {
225 engine_->set_income(slider_income_.value());
243 update_faction_combo();
244 engine_->flg().reset_leader_combo(combo_leader_,
engine_->get_color());
245 engine_->flg().reset_gender_combo(combo_gender_,
engine_->get_color());
247 update_controller_ui();
249 combo_team_.set_selected(
engine_->team());
250 combo_color_.set_selected(
engine_->color());
251 slider_gold_.set_value(
engine_->gold());
252 label_gold_.set_text(std::to_string(
engine_->gold()));
253 slider_income_.set_value(
engine_->income());
254 std::stringstream
buf;
256 buf <<
_(
"(") <<
engine_->income() <<
_(
")");
257 }
else if (
engine_->income() > 0) {
262 label_income_.set_text(buf.str());
268 int label_y_offset = (combo_leader_.height() - label_leader_name_.height()) / 2;
270 pane.
add_widget(&label_player_number_, 0, 5 + pos);
273 pane.
add_widget(&label_original_controller_, 20 +
274 (combo_controller_->width() - label_original_controller_.width()) / 2,
275 35 + pos + label_y_offset);
276 pane.
add_widget(&combo_ai_algorithm_, 20, 35 + pos);
278 pane.
add_widget(&combo_faction_, 135, 5 + pos);
280 (combo_faction_.width() - label_leader_name_.width()) / 2,
281 35 + pos + label_y_offset);
283 pane.
add_widget(&combo_leader_, 250, 5 + pos);
284 pane.
add_widget(&combo_gender_, 250, 35 + pos);
287 pane.
add_widget(&combo_color_, 365, 35 + pos);
290 pane.
add_widget(&label_gold_, 475 + 5, 35 + pos + label_y_offset);
292 pane.
add_widget(&slider_income_, 475 + slider_gold_.width(), 5 +
pos);
293 pane.
add_widget(&label_income_, 475 + 5 + slider_gold_.width(),
294 35 + pos + label_y_offset);
299 std::vector<std::string> factions;
300 for (
const config* faction :
engine_->flg().choosable_factions()) {
310 factions.push_back(name);
314 combo_faction_.enable(factions.size() > 1 && !parent_->params().saved_game);
316 combo_faction_.set_items(factions);
317 combo_faction_.set_selected(
engine_->flg().current_faction_index());
324 engine_->controller_options()));
325 combo_controller_->set_selected(
engine_->current_controller_index());
326 combo_controller_->enable(
engine_->controller_options().size() > 1);
329 assert(!parent_->ai_algorithms_.empty());
332 std::vector<std::string> ais;
334 ais.push_back(desc->
text);
335 if (desc->
id ==
engine_->ai_algorithm()) {
340 combo_ai_algorithm_.set_items(ais);
341 combo_ai_algorithm_.set_selected(sel);
344 engine_->set_ai_algorithm(parent_->ai_algorithms_[sel]->id);
348 if (!parent_->hidden()) {
351 combo_ai_algorithm_.hide(
false);
353 label_original_controller_.hide(
true);
356 combo_ai_algorithm_.hide(
true);
358 label_original_controller_.hide(
false);
359 label_original_controller_.set_text(
engine_->reserved_for());
362 combo_ai_algorithm_.hide(
true);
369 mp::
ui(v, wesnothd_connection,
_(
"Game Lobby: ") + game_name, game_config, c, gamelist),
391 DBG_MP <<
"setting up connect dialog" << std::endl;
403 throw config::error(
_(
"The scenario is invalid because it has no id."));
414 _(
"The scenario is invalid because it has no sides."));
418 int side_pos_y_offset = 0;
424 s.add_widgets_to_scrollpane(
scroll_pane_, side_pos_y_offset);
425 side_pos_y_offset += 60;
463 bool changed =
false;
499 DBG_MP << (hide ?
"hiding" :
"showing" ) <<
500 " children widgets" << std::endl;
528 #ifdef OK_BUTTON_ON_RIGHT
532 size_t right = ca.x + ca.w;
534 size_t bottom = ca.y + ca.h;
538 bottom - right_button->
height());
551 bottom - left_button->
height() + 4);
553 SDL_Rect scroll_pane_rect;
554 scroll_pane_rect.x = ca.x;
555 scroll_pane_rect.y = ca.y + 50;
556 scroll_pane_rect.w = ca.w;
580 DBG_MP <<
"play party full sound" << std::endl;
587 DBG_MP <<
"updating player list state" << std::endl;
591 ?
_(
"Waiting for players to join...")
592 :
_(
"Waiting for players to choose factions..."));
601 std::vector<std::string> playerlist;
603 playerlist.push_back(user);
static std::string get_income_string(int income)
bool can_start_game() const
gui::slider slider_income_
gui::label leader_gender_title_label_
const std::string & set_text(const std::string &text)
ng::side_engine_ptr engine_
void set_value(int value)
static l_noret error(LoadState *S, const char *why)
boost::scoped_ptr< plugins_context > plugins_context_
void process_event_impl(const process_event_data &)
virtual void layout_children(const SDL_Rect &rect)
Lays the children out.
result get_result()
Returns the result of the current widget.
void set_increment(int increment)
const config & level() const
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
gui::label type_title_label_
void update_faction_combo()
bool plugin_event_helper(const process_event_data &)
connect(CVideo &v, twesnothd_connection *wesnothd_connection, const std::string &game_name, const config &game_config, chat &c, config &gamelist, ng::connect_engine &engine)
void update_and_send_diff(bool update_time_of_day=false)
const std::set< std::string > & connected_users() const
bool sides_available() const
void add_widgets_to_scrollpane(gui::scrollpane &pane, int pos)
virtual void process_network_data(const config &data)
Processes any pending network data.
virtual void hide_children(bool hide=true)
Hides or shows all gui::widget children of this widget.
This module controls the multiplayer lobby.
static UNUSEDNOWARN std::string _(const char *str)
gui::scrollpane scroll_pane_
A class that represents a TCP/IP connection to the wesnothd server.
result set_result(result res)
Sets the result of this dialog, to be checked by get_result().
std::vector< side_engine_ptr > & side_engines()
static std::vector< description * > get_available_ais()
Returns a list of available AIs.
virtual void process_event()
GLboolean GLboolean GLboolean GLboolean a
static lg::log_domain log_mp_connect("mp/connect")
gui::combo combo_faction_
ng::connect_engine & engine_
config & add_child(const std::string &key)
virtual void enable(bool new_val=true)
GLenum GLuint GLsizei const char * buf
void send_to_server(const config &cfg) override
gui::label waiting_label_
GLuint const GLuint * names
void append_to_title(const std::string &name)
void send_chat_message(const std::string &message, bool allies_only=false)
gui::label gold_title_label_
SDL_Rect client_area() const
gui::drop_group_manager_ptr combo_control_group_
Game configuration data as global variables.
void set_user_list(const std::vector< std::string > &, bool silent)
Sets the user list.
const SDL_Color LOBBY_COLOR
config & gamelist()
Returns the current gamelist.
virtual void process_network_data(const config &data)
Processes any pending network data.
std::vector< std::string > controller_options_names(const std::vector< ng::controller_option > &controller_options)
std::vector< ai::description * > ai_algorithms_
GLuint const GLchar * name
std::pair< ng::controller, std::string > controller_option
void set_user_menu_items(const std::vector< std::string > &list)
virtual void layout_children(const SDL_Rect &rect)
Lays the children out.
gui::label team_color_title_label_
gui::label income_title_label_
char const COLUMN_SEPARATOR
virtual void hide_children(bool hide=true)
Hides or shows all gui::widget children of this widget.
void update_controller_ui()
Managing the AIs configuration - headers.
void swap(game_board &one, game_board &other)
config & child(const std::string &key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
Standard logging facilities (interface).
const std::function< std::string(const config &, const std::string &) > get_str
twesnothd_connection * wesnothd_connection_
this class memorizes a chat session.
void update_playerlist_state(bool silent=true)
A config object defines a single node in a WML file, with access to child nodes.
gui::label faction_name_title_label_
GLsizei const GLcharARB ** string
a base class for the different multiplayer base dialogs: game list, create game, wait game...
side(connect &parent, ng::side_engine_ptr engine)
std::pair< bool, bool > process_network_data(const config &data)
virtual void gamelist_updated(bool silent=true)
Called each time the gamelist_ variable is updated.
const mp_game_settings & params()