41 #define DBG_NW LOG_STREAM(debug, log_network)
42 #define LOG_NW LOG_STREAM(info, log_network)
45 #define LOG_RG LOG_STREAM(info, log_enginerefac)
46 #define ERR_RG LOG_STREAM(err, log_enginerefac)
49 #define DBG_MP LOG_STREAM(debug, log_mp)
50 #define ERR_MP LOG_STREAM(err, log_mp)
55 const SDL_Rect leader_pane_position = {-260,-370,260,370};
56 const int leader_pane_border = 10;
78 if (combo_leader_.changed() && combo_leader_.selected() >= 0) {
79 flg_.set_current_leader(combo_leader_.selected());
81 flg_.reset_gender_combo(combo_gender_,
color_);
86 if (combo_gender_.changed() && combo_gender_.selected() >= 0) {
87 flg_.set_current_gender(combo_gender_.selected());
101 loc.y + leader_pane_border,loc.w - leader_pane_border * 2,
102 loc.h - leader_pane_border * 2);
105 std::string faction = flg_.current_faction()[
"faction"];
107 const std::string recruits = flg_.current_faction()[
"recruit"];
108 const std::vector<std::string> recruit_list =
utils::split(recruits);
109 std::ostringstream recruit_string;
111 if (!faction.empty() && faction[0] ==
font::IMAGE) {
113 if (p != std::string::npos && p < faction.size())
114 faction = faction.substr(p+1);
127 for(std::vector<std::string>::const_iterator
itor = recruit_list.begin();
128 itor != recruit_list.end(); ++
itor) {
133 if (
itor != recruit_list.begin())
134 recruit_string <<
", ";
138 SDL_Rect image_rect = {area.x,area.y,0,0};
142 if (!unit_image.
null()) {
143 image_rect.w = unit_image->w;
144 image_rect.h = unit_image->h;
145 sdl_blit(unit_image,
nullptr, screen, &image_rect);
149 faction, area.x + 110, area.y + 60);
155 leader_rect.y + 30 + (leader_rect.h - combo_leader_.height()) / 2);
158 area.y + 132 + 30 + (leader_rect.h - combo_leader_.height()) / 2,
160 combo_leader_.set_location(leader_rect.x + leader_rect.w + 16,
161 leader_rect.y + (leader_rect.h - combo_leader_.height()) / 2);
162 combo_gender_.set_location(leader_rect.x + leader_rect.w + 16,
163 gender_rect.y + (gender_rect.h - combo_gender_.height()) / 2);
178 if (selection >= 0) {
179 flg_.set_current_faction(selection);
181 flg_.reset_leader_combo(combo_leader_,
color_);
182 flg_.reset_gender_combo(combo_gender_,
color_);
190 h.push_back(&combo_leader_);
191 h.push_back(&combo_gender_);
198 ui(v, wesnothd_connection,
_(
"Game Lobby"), cfg, c, gamelist),
243 DBG_MP <<
"mp wait: could not download level data, quitting...";
246 }
else if (
level_[
"started"].to_bool()) {
256 ERR_MP <<
"Mp wait recieved a game that is not a multiplayer game\n";
271 const config *side_choice =
nullptr;
272 int side_num = -1, nb_sides = 0;
275 DBG_MP <<
"*** side " << nb_sides <<
"***\n" << sd.debug() <<
"***\n";
283 if (sd[
"controller"] ==
"human" && sd[
"player_id"].empty())
308 DBG_MP <<
"could not find a side, all " << count <<
" sides were unsuitable\n";
313 bool allow_changes = (*side_choice)[
"allow_changes"].to_bool(
true);
325 if (possible_sides.first == possible_sides.second) {
332 std::vector<const config*> era_factions;
333 for (
const config &side : possible_sides) {
334 era_factions.push_back(&side);
338 const bool lock_settings =
341 level_.
child(
"multiplayer")[
"mp_use_map_settings"].to_bool();
345 ng::flg_manager flg(era_factions, *side_choice, lock_settings, use_map_settings,
348 std::vector<std::string> choices;
360 choices.push_back(
IMAGE_PREFIX + icon +
"~RC(" + rgb +
">" +
363 choices.push_back(name);
368 std::vector<gui::preview_pane* > preview_panes;
370 preview_panes.push_back(&leader_selector);
373 _(
"Choose your faction:"),
_(
"Starting position: ") +
375 &choices, &preview_panes);
376 if(faction_choice < 0) {
383 change[
"change_faction"] =
true;
404 LOG_NW <<
"starting game\n";
436 if(!data[
"message"].empty()) {
441 if (data[
"failed"].to_bool()) {
444 }
else if(data.
child(
"stop_updates")) {
446 }
else if(data.
child(
"start_game")) {
447 LOG_NW <<
"received start_game message\n";
450 }
else if(data.
child(
"leave_game")) {
453 }
else if (
const config &
c = data.
child(
"scenario_diff")) {
454 LOG_NW <<
"received diff for scenario... applying...\n";
458 }
else if(
const config &change = data.
child(
"change_controller")) {
459 LOG_NW <<
"received change controller" << std::endl;
460 LOG_RG <<
"multiplayer_wait: [change_controller]" << std::endl;
464 if (
config & sidetochange =
get_scenario().find_child(
"side",
"side", change[
"side"])) {
465 LOG_RG <<
"found side : " << sidetochange.debug() << std::endl;
466 sidetochange.merge_with(change);
467 LOG_RG <<
"changed to : " << sidetochange.debug() << std::endl;
469 LOG_RG <<
"change_controller didn't find any side!" << std::endl;
473 LOG_NW <<
"got some sides. Current number of sides = "
487 std::string controller_type = side[
"controller"].str();
488 std::string reservation = side[
"reserved_for"].str();
491 if(controller_type ==
"ai") {
492 return _(
"Computer Player");
494 else if (controller_type ==
"null") {
495 return _(
"(Empty slot)");
497 else if (controller_type ==
"reserved") {
499 symbols[
"playername"] = reservation;
500 return vgettext(
"(Reserved for $playername)",symbols);
502 else if(owner.empty()) {
503 return _(
"(Vacant slot)");
505 else if (controller_type ==
"human" || controller_type ==
"network") {
509 ERR_RG <<
"Found unknown controller type:" << controller_type << std::endl;
519 std::vector<std::string> details;
520 std::set<std::string> playerlist;
524 if (!sd[
"allow_player"].to_bool(
true)) {
530 t_string side_name = sd[
"faction_name"];
539 if (side_unit[
"canrecruit"].to_bool()) {
540 leader_type = side_unit[
"type"].str();
545 if(!sd[
"player_id"].empty())
546 playerlist.insert(sd[
"player_id"]);
558 leader_image = utg.
image();
563 RCcolor = sd[
"side"].str();
569 if (!leader_image.empty()) {
573 std::string::size_type
p =
575 if(p != std::string::npos && p < side_name.
size()) {
585 std::stringstream str;
589 if(!leader_name.empty())
590 str <<
_(
"(") << leader_name <<
_(
")");
593 if (sd[
"allow_changes"].to_bool())
594 str << sd[
"gold"] <<
' ' <<
_n(
"multiplayer_starting_gold^Gold",
"multiplayer_starting_gold^Gold", sd[
"gold"].to_int()) <<
COLUMN_SEPARATOR;
596 int income_amt = sd[
"income"];
598 str <<
_(
"(") <<
_(
"Income") <<
' ';
601 str << sd[
"income"] <<
_(
")");
607 details.push_back(str.str());
615 set_user_list(std::vector<std::string>(playerlist.begin(), playerlist.end()),
true);
622 DBG_MP <<
"download_level_data()\n";
627 bool has_scenario_and_controllers =
false;
628 while (!has_scenario_and_controllers) {
634 DBG_MP <<
"download_level_data bad results\n";
638 if (revc.
child(
"leave_game")) {
641 else if(
config& next_scenario = revc.
child(
"next_scenario")) {
646 has_scenario_and_controllers =
true;
648 else if(
config& controllers = revc.
child(
"controllers")) {
656 has_scenario_and_controllers =
true;
661 DBG_MP <<
"download_level_data() success.\n";
const std::vector< const config * > & choosable_factions() const
surface get_image(const image::locator &i_locator, TYPE type)
function to get the surface corresponding to an image.
child_itors child_range(const std::string &key)
const unit_type & get_gender_unit_type(std::string gender) const
const t_string & type_name() const
The name of the unit in the current language setting.
std::vector< events::sdl_handler * > sdl_handler_vector
leader_preview_pane(CVideo &v, ng::flg_manager &flg, const std::string &color)
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
gui::button cancel_button_
static l_noret error(LoadState *S, const char *why)
boost::scoped_ptr< plugins_context > plugins_context_
virtual void layout_children(const SDL_Rect &rect)
Lays the children out.
result get_result()
Returns the result of the current widget.
static lg::log_domain log_mp("mp/main")
GLenum GLsizei GLenum GLenum const GLvoid * image
virtual void process_event()
unit_type_data unit_types
const std::string & image() const
void show_transient_message(CVideo &video, const std::string &title, const std::string &message, const std::string &image, const bool message_use_markup, const bool title_use_markup, const bool restore_background)
Shows a transient message to the user.
void process_event_impl(bool)
std::string get_color_string(int id)
GLint GLint GLint GLint GLint GLint y
void level_to_gamestate(const config &level, saved_game &state)
std::string debug() const
virtual void layout_children(const SDL_Rect &rect)
Lays the children out.
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
FLG stands for faction, leader and gender.
const SDL_Color NORMAL_COLOR
virtual void process_network_data(const config &data)
Processes any pending network data.
std::pair< const_child_iterator, const_child_iterator > const_child_itors
Variant for storing WML attributes.
static lg::log_domain log_network("network")
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.
sdl_handler_vector handler_members()
This module controls the multiplayer lobby.
bool has_child(const std::string &key) const
Determine whether a config has a child or not.
virtual void process_event()
static game_config_manager * get()
static UNUSEDNOWARN std::string _(const char *str)
const std::string & flag_rgb() const
std::map< std::string, t_string > string_map
void reset_leader_combo(gui::combo &combo_leader, const std::string &color) const
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().
static lg::log_domain log_enginerefac("enginerefac")
const std::string & current_gender() const
void add_color_info(const config &v)
const gui::label & title() const
bool download_level_data()
static UNUSEDNOWARN std::string _n(const char *str1, const char *str2, int n)
config & add_child(const std::string &key)
int show_dialog(CVideo &video, surface image, const std::string &caption, const std::string &message, DIALOG_TYPE type, const std::vector< std::string > *menu_items, const std::vector< preview_pane * > *preview_panes, const std::string &text_widget_label, std::string *text_widget_text, const int text_widget_max_chars, std::vector< check_item > *options, int xloc, int yloc, const dialog_frame::style *dialog_style, std::vector< dialog_button_info > *action_buttons, const menu::sorter *sorter, menu::style *menu_style)
void read_stats(const config &cfg)
void send_to_server(const config &cfg) override
void check_response(bool res, const config &data)
void reset_gender_combo(gui::combo &combo_gender, const std::string &color) const
void apply_diff(const config &diff, bool track=false)
A function to apply a diff config onto this config object.
GLuint GLuint GLsizei count
std::string get_RC_suffix(const std::string &unit_color, const std::string &color)
void append_to_title(const std::string &name)
SDL_Rect draw_text(surface &dst, const SDL_Rect &area, int size, const SDL_Color &color, const std::string &txt, int x, int y, bool use_tooltips, int style)
Function to draw text on a surface.
bool network_receive_dialog(CVideo &video, const std::string &msg, config &cfg, twesnothd_connection &wesnothd_connection)
void send_chat_message(const std::string &message, bool allies_only=false)
std::map< std::string, tfilter >::iterator itor
SDL_Rect client_area() const
SDL_Rect draw_wrapped_text(CVideo *gui, const SDL_Rect &area, int font_size, const SDL_Color &color, const std::string &text, int x, int y, int max_width)
Draw text on the screen, fit text to maximum width, no markup, no tooltips.
void set_user_list(const std::vector< std::string > &, bool silent)
Sets the user list.
const SDL_Color LOBBY_COLOR
std::pair< child_iterator, child_iterator > child_itors
config & gamelist()
Returns the current gamelist.
static t_string from_serialized(const std::string &string)
const config & current_faction() const
unsigned child_count(const std::string &key) const
const std::string random_enemy_picture("units/random-dice.png")
static std::string generate_user_description(const config &side)
void set_selection(int index)
GLuint const GLchar * name
const attribute_value * get(const std::string &key) const
Returns a pointer to the attribute with the given key or nullptr if it does not exist.
const std::string & current_leader() const
SDL_Rect create_rect(const int x, const int y, const int w, const int h)
Creates an empty SDL_Rect.
void load_game_config_for_game(const game_classification &classification)
Contains the SDL_Rect helper code.
bool has_attribute(const std::string &key) const
char const COLUMN_SEPARATOR
game_classification & classification()
virtual void draw_contents()
void join_game(bool observe)
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...
bool is_normal_mp_game() const
wait(CVideo &v, twesnothd_connection *wesnothd_connection, const config &cfg, saved_game &state, chat &c, config &gamelist, const bool first_scenario=true)
Standard logging facilities (interface).
const std::function< std::string(const config &, const std::string &) > get_str
twesnothd_connection * wesnothd_connection_
const unit_type * find(const std::string &key, unit_type::BUILD_STATUS status=unit_type::FULL) const
Finds a unit_type by its id() and makes sure it is built to the specified level.
std::vector< std::string > split(std::string const &val, const char c, const int flags)
Splits a (comma-)separated string into a vector of pieces.
this class memorizes a chat session.
const std::string & str() const
void sdl_blit(const surface &src, SDL_Rect *src_rect, surface &dst, SDL_Rect *dst_rect)
virtual void hide_children(bool hide=true)
Hides or shows all gui::widget children of this widget.
A config object defines a single node in a WML file, with access to child nodes.
std::string::size_type size() const
const bool first_scenario_
GLsizei const GLcharARB ** string
a base class for the different multiplayer base dialogs: game list, create game, wait game...
virtual void gamelist_updated(bool silent=true)
Called each time the gamelist_ variable is updated.