14 #define GETTEXT_DOMAIN "wesnoth-lib" 52 : connect_engine_(connect_engine)
53 , ai_algorithms_(
ai::configuration::get_available_ais())
54 , network_connection_(connection)
56 , state_changed_(false)
59 , player_list_(
nullptr)
61 set_show_even_without_video(
true);
63 assert(!ai_algorithms_.empty());
82 label& title = find_widget<label>(&window,
"title",
false);
99 chatbox& chat = find_widget<chatbox>(&window,
"chat",
false);
133 if(side->team() == side_engine->team() && side->index() > side_engine->index()) {
141 template<
typename... T>
144 static const std::map<std::string, string_map> empty_map;
150 if(team_node ==
nullptr) {
153 std::map<std::string, string_map> tree_data;
156 tree_item[
"label"] = (
formatter() <<
_(
"Team:") <<
" " << side->user_team_name()).str();
157 tree_data.emplace(
"tree_view_node_label", tree_item);
159 team_node = &tree.
add_node(
"team_header", tree_data);
165 assert(team_node &&
"No team node found!");
166 return team_node->
add_child(std::forward<T>(params)...);
171 std::map<std::string, string_map> data;
174 item[
"label"] = std::to_string(side->index() + 1);
175 data.emplace(
"side_number", item);
178 item[
"label"] =
"units/unknown-unit.png~RC(magenta>" + side->color_id() +
")";
179 data.emplace(
"leader_image", item);
181 item[
"label"] =
"icons/icon-random.png";
182 data.emplace(
"leader_gender", item);
196 const bool lock_gold = side->cfg()[
"gold_lock"].to_bool(fls);
197 const bool lock_income = side->cfg()[
"income_lock"].to_bool(fls);
198 const bool lock_team = side->cfg()[
"team_lock"].to_bool(fls);
199 const bool lock_color = side->cfg()[
"color_lock"].to_bool(fls);
209 std::vector<config> ai_options;
214 ai_options.emplace_back(
"label",
"Keep saved AI");
224 menu_button& ai_selection = find_widget<menu_button>(&row_grid,
"ai_controller",
false);
226 ai_selection.
set_values(ai_options, selection);
235 std::vector<config> controller_names;
236 for(
const auto&
controller : side->controller_options()) {
237 controller_names.emplace_back(
"label",
controller.second);
240 menu_button& controller_selection = find_widget<menu_button>(&row_grid,
"controller",
false);
242 controller_selection.
set_values(controller_names, side->current_controller_index());
243 controller_selection.
set_active(controller_names.size() > 1);
253 button& leader_select = find_widget<button>(&row_grid,
"select_leader",
false);
264 std::vector<config> team_names;
265 unsigned initial_team_selection = 0;
280 entry[
"team_index"] =
i;
282 team_names.push_back(std::move(entry));
287 if(side->team() ==
i) {
288 initial_team_selection = team_names.size() - 1;
292 menu_button& team_selection = find_widget<menu_button>(&row_grid,
"side_team",
false);
294 team_selection.
set_values(team_names, initial_team_selection);
304 std::vector<config> color_options;
305 for(
const auto& color : side->color_options()) {
306 color_options.emplace_back(
308 "icon", (
formatter() <<
"misc/status.png~RC(magenta>" << color <<
")").str()
312 menu_button& color_selection = find_widget<menu_button>(&row_grid,
"side_color",
false);
314 color_selection.
set_values(color_options, side->color());
324 const auto slider_setup_helper = [](
slider&
slider,
const int value) {
336 slider& slider_gold = find_widget<slider>(&row_grid,
"side_gold_slider",
false);
337 slider_setup_helper(slider_gold, side->gold());
340 &mp_staging::on_side_slider_change<&ng::side_engine::set_gold>,
this, side, std::ref(slider_gold)));
342 slider& slider_income = find_widget<slider>(&row_grid,
"side_income_slider",
false);
343 slider_setup_helper(slider_income, side->income());
346 &mp_staging::on_side_slider_change<&ng::side_engine::set_income>,
this, side, std::ref(slider_income)));
357 if(!saved_game && ums) {
368 menu_button& ai_selection = find_widget<menu_button>(&row_grid,
"ai_controller",
false);
369 menu_button& controller_selection = find_widget<menu_button>(&row_grid,
"controller",
false);
371 if(side->controller_changed(controller_selection.get_value())) {
388 side->set_ai_algorithm(
"use_saved");
398 side->set_color(find_widget<menu_button>(&row_grid,
"side_color",
false).get_value());
411 const unsigned team_index = team_menu.
get_value_config()[
"team_index"].to_unsigned();
413 if(team_index == side->team()) {
419 const std::string old_team = side->team_name();
420 side->set_team(team_index);
422 auto& tree = find_widget<tree_view>(
get_window(),
"side_list",
false);
433 if(old_team_node->
empty()) {
435 auto decor = old_team_node->
siblings().back();
437 tree.remove_node(old_team_node);
438 tree.remove_node(decor.get());
448 if(gui2::dialogs::faction_select::execute(side->flg(), side->color_id(), side->index() + 1)) {
455 template<
void(ng::s
ide_engine::*fptr)(
int)>
465 const std::string current_faction = side->flg().current_faction()[
"name"];
468 std::string current_leader = side->flg().current_leader() !=
"null" ? side->flg().current_leader() :
font::unicode_em_dash;
469 const std::string current_gender = side->flg().current_gender() !=
"null" ? side->flg().current_gender() :
font::unicode_em_dash;
472 std::string new_image;
474 if(side->flg().is_random_faction() || current_leader ==
"random") {
479 const unit_type&
type = ut->get_gender_unit_type(current_gender);
481 new_image =
formatter() << type.
image() <<
"~RC(magenta>" << side->color_id() <<
")";
487 find_widget<drawing>(&row_grid,
"leader_image",
false).set_label(new_image);
490 if(!side->cfg()[
"name"].empty()) {
491 current_leader =
formatter() << side->cfg()[
"name"] <<
" (<i>" << current_leader <<
"</i>)";
494 find_widget<label>(&row_grid,
"leader_type",
false).set_label(current_leader ==
"random" ?
_(
"Random") : current_leader);
495 find_widget<label>(&row_grid,
"leader_faction",
false).set_label(
"<span color='#a69275'>" + current_faction +
"</span>");
499 const std::string gender_icon =
formatter() <<
"icons/icon-" << current_gender <<
".png";
501 image& icon = find_widget<image>(&row_grid,
"leader_gender",
false);
508 find_widget<label>(
get_window(),
"status_label",
false).set_label(
510 ?
_(
"Waiting for players to join...")
511 :
_(
"Waiting for players to choose factions...")
531 find_widget<chatbox>(
get_window(),
"chat",
false).process_network_data(data);
536 bool quit_signal_received;
539 if(quit_signal_received) {
548 grid& row_grid = tree_entry.second->get_grid();
552 std::vector<config> controller_names;
553 for(
const auto&
controller : side->controller_options()) {
554 controller_names.emplace_back(
"label",
controller.second);
557 menu_button& controller_selection = find_widget<menu_button>(&row_grid,
"controller",
false);
559 controller_selection.
set_values(controller_names, side->current_controller_index());
560 controller_selection.
set_active(controller_names.size() > 1);
void active_window_changed()
Dialog was closed with the CANCEL button.
void update_status_label_and_buttons()
#define REGISTER_DIALOG(window_id)
Wrapper for REGISTER_DIALOG2.
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.
int get_side_node_position(ng::side_engine_ptr side) const
Find an appropriate position to insert a side node.
void add_side_node(ng::side_engine_ptr side)
bool has_child(config_key_type key) const
Determine whether a config has a child or not.
bool force_lock_settings() const
child_itors child_range(config_key_type key)
ng::connect_engine & connect_engine_
unit_type_data unit_types
void set_escape_disabled(const bool escape_disabled)
Disable the escape key.
std::size_t update_timer_
window * get_window() const
Returns a pointer to the dialog's window.
A label displays a text, the text can be wrapped but no scrollbars are provided.
bool receive_data(config &result)
Receives the next pending data pack from the server, if available.
static std::string _(const char *str)
const std::vector< team_data_pod > & team_data() const
void update_and_send_diff(bool update_time_of_day=false)
A single unit type that the player may recruit.
bool empty() const
Does the node have children?
virtual void set_active(const bool active) override
See styled_widget::set_active.
A small explanation about what's going on here: Each action has access to two game_info objects First...
void set_value_range(int min_value, int max_value)
void update_leader_display(ng::side_engine_ptr side, grid &row_grid)
virtual int get_maximum_value() const override
Inherited from integer_selector.
void connect_signal_notify_modified(dispatcher &dispatcher, const signal_notification_function &signal)
Connects a signal handler for getting a notification upon modification.
std::vector< side_engine_ptr > & side_engines()
This file contains the settings handling of the widget library.
const t_string & type_name() const
The name of the unit in the current language setting.
std::unique_ptr< plugins_context > plugins_context_
unsigned lobby_network_timer
std::unique_ptr< player_list_helper > player_list_
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal_function &signal)
Connects a signal handler for a left mouse button click.
void on_controller_select(ng::side_engine_ptr side, grid &row_grid)
A class that represents a TCP/IP connection to the wesnothd server.
virtual void send_chat_message(const std::string &message, bool allies_only) override
Inherited form chat_handler.
void load_log(std::map< std::string, chatroom_log > &log, bool show_lobby)
const mp_game_settings & params() const
A tree view is a control that holds several items of the same or different types. ...
void on_side_slider_change(ng::side_engine_ptr side, slider &slider)
virtual void pre_show(window &window) override
Inherited from modal_dialog.
Various uncategorised dialogs.
std::vector< ai::description * > ai_algorithms_
wesnothd_connection * network_connection_
void select_leader_callback(ng::side_engine_ptr side, grid &row_grid)
tree_view_node & add_side_to_team_node(ng::side_engine_ptr side, T &&... params)
std::size_t add_timer(const uint32_t interval, const std::function< void(std::size_t id)> &callback, const bool repeat)
Adds a new timer.
static t_string from_serialized(const std::string &string)
std::string get_color_string_pango(const std::string &id)
Returns the name of a color range, colored with its own color.
virtual int get_value() const override
Inherited from integer_selector.
std::shared_ptr< side_engine > side_engine_ptr
const std::string random_enemy_picture("units/random-dice.png")
void on_ai_select(ng::side_engine_ptr side, menu_button &ai_menu, const bool saved_game)
std::map< std::string, tree_view_node * > team_tree_map_
const std::string & image() const
std::string user_team_name
node_children_vector & siblings()
virtual void post_show(window &window) override
Inherited from modal_dialog.
A slider is a control that can select a value by moving a grip on a groove.
const std::string unicode_em_dash
Managing the AIs configuration - headers.
std::map< std::string, chatroom_log > default_chat_log
void set_wesnothd_connection(wesnothd_connection &c)
Functions to load and save images from/to disk.
virtual void set_value(int value) override
Inherited from integer_selector.
tree_view_node & add_sibling(const std::string &id, const std::map< std::string, string_map > &data)
Adds a sibbling for a node at the end of the list.
void on_color_select(ng::side_engine_ptr side, grid &row_grid)
Dialog was closed with the OK button.
bool can_start_game() const
A config object defines a single node in a WML file, with access to child nodes.
tree_view_node & add_child(const std::string &id, const std::map< std::string, string_map > &data, const int index=-1)
Constructs a new child node.
void set_retval(int retval)
Convenience wrapper to set the window's exit code.
base class of top level items, the only item which needs to store the final canvases to draw on...
std::map< ng::side_engine_ptr, tree_view_node * > side_tree_map_
lobby_chat_window * room_window_open(const std::string &room, const bool open_new, const bool allow_close=true)
Check if a room window for "room" is open, if open_new is true then it will be created if not found...
virtual int get_minimum_value() const override
Inherited from integer_selector.
bool sides_available() const
tree_view_node & add_node(const std::string &id, const std::map< std::string, string_map > &data, const int index=-1)
std::pair< std::string, unsigned > item
std::pair< bool, bool > process_network_data(const config &data)
bool remove_timer(const std::size_t id)
Removes a timer.
void on_team_select(ng::side_engine_ptr side, menu_button &team_menu)
void set_enter_disabled(const bool enter_disabled)
Disable the enter key.