The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
campaign_settings.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2016 by Nathan Walker <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #define GETTEXT_DOMAIN "wesnoth-lib"
16 
17 #include "saved_game.hpp"
18 #include "gettext.hpp"
21 #include "gui/widgets/button.hpp"
22 #include "gui/widgets/label.hpp"
23 #ifdef GUI2_EXPERIMENTAL_LISTBOX
24 #include "gui/widgets/list.hpp"
25 #else
26 #include "gui/widgets/listbox.hpp"
27 #endif
28 #include "gui/widgets/settings.hpp"
30 #include "gui/widgets/window.hpp"
31 
32 #include "utils/functional.hpp"
33 
34 namespace gui2
35 {
36 
37 /*WIKI
38  * @page = GUIWindowDefinitionWML
39  * @order = 2_campaign_settings
40  *
41  * == Campaign settings ==
42  *
43  * This shows the dialog which allows the user to select an era
44  * and modifications for the selected campaign, and to show
45  * dialogs for additional level configuration.
46  *
47  * @begin{table}{dialog_widgets}
48  *
49  * title & & label & m &
50  * Dialog title label. $
51  *
52  * mp_configure & & toggle_button & m &
53  * Option to show the multiplayer configure dialog. $
54  *
55  * mp_connect & & toggle_button & m &
56  * Option to show the multiplayer connect dialog. $
57  *
58  * era_label & & label & m &
59  * The label for the era list. $
60  *
61  * era_list & & listbox & m &
62  * List of available eras. $
63  *
64  * -era & & label & o &
65  * The name of the era. One can be selected at a time. $
66  *
67  * mod_label & & label & m &
68  * The label for the modification list. $
69  *
70  * modification_list & & listbox & m &
71  * List of available modifications. $
72  *
73  * -mod & & toggle_button & o &
74  * The name of the modification. Each can be enabled or disabled. $
75  *
76  * @end{table}
77  */
78 
79 REGISTER_DIALOG(campaign_settings)
80 
82  : engine_(eng)
83 { }
84 
85 
87 {
88  tlistbox& list = find_widget<tlistbox>(&window, "era_list", false);
90 }
91 
93 {
95  // force toggle mod.
97 }
98 
100 {
101  tlistbox& era_list = find_widget<tlistbox>(&window, "era_list", false);
102  tlistbox& mod_list = find_widget<tlistbox>(&window, "modification_list", false);
103  tlabel& era_label = find_widget<tlabel>(&window, "era_label", false);
104  tlabel& mod_label = find_widget<tlabel>(&window, "mod_label", false);
105 
106  era_list.clear();
107 
110  std::map<std::string, string_map> row;
112 
113  column["label"] = era;
114  row.insert(std::make_pair("era", column));
115 
116  era_list.add_row(row);
117  }
119  }
120  else {
121  era_label.set_label(_("Era:\n\nNot allowed."));
122  era_list.set_active(false);
123  }
124 
125  mod_list.clear();
126 
127  {
128  int i = 0;
130  std::map<std::string, string_map> row;
132 
133  column["label"] = mod->name;
134  row.insert(std::make_pair("mod", column));
135 
136  mod_list.add_row(row);
137 
138  std::vector<std::string> enabled = engine_.active_mods();
139  mod_list.select_row(i,
140  std::find(enabled.begin(), enabled.end(), mod->id)
141  != enabled.end());
142 
143  ++i;
144  }
145  if (i == 0) {
146  mod_label.set_label(_("Modifications:\n\nNone found."));
147  mod_list.set_active(false);
148  }
149  }
150 }
151 
153 {
154  find_widget<ttoggle_button>(&window, "mp_connect", false).set_value(
156 
157  update_lists(window);
158 
159  tlistbox& era_list = find_widget<tlistbox>(&window, "era_list", false);
160  tlistbox& mod_list = find_widget<tlistbox>(&window, "modification_list", false);
161 
162  ttoggle_button& connect_toggle = find_widget<ttoggle_button>(&window, "mp_connect", false);
163 
164  const config::attribute_value& show_connect = engine_.current_level().data()["show_connect"];
165  if (show_connect.blank() || show_connect.str() == "user") {
166  connect_toggle.set_active(true);
167  } else {
168  connect_toggle.set_value(show_connect.to_bool());
169  connect_toggle.set_active(false);
170  }
171 
172  era_list.set_callback_item_change(
173  std::bind(&tcampaign_settings::change_era, this, std::ref(window)));
174  mod_list.set_callback_item_change(
175  std::bind(&tcampaign_settings::change_mod, this, _1, std::ref(window)));
176 }
177 
179 {
181  find_widget<ttoggle_button>(&window, "mp_connect", false).get_value_bool();
182 }
183 
184 } // end namespace gui2
void set_current_mod_index(const size_t index)
saved_game & get_state()
GLenum GLsizei const GLuint GLboolean enabled
Definition: glew.h:2497
std::string era()
const std::vector< extras_metadata_ptr > & get_const_extras_by_type(const MP_EXTRA extra_type) const
virtual void set_active(const bool active) override
See tcontrol::set_active.
Definition: container.cpp:188
level & current_level() const
This file contains the window object, this object is a top level container which has the event manage...
bool select_row(const unsigned row, const bool select=true)
Selectes a row.
Definition: listbox.cpp:228
REGISTER_DIALOG(label_settings)
size_t current_era_index() const
void set_current_era_index(const size_t index, bool force=false)
Label showing a text.
Definition: label.hpp:29
bool toggle_current_mod(bool force=false)
Variant for storing WML attributes.
Definition: config.hpp:223
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:62
Class for a toggle button.
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
void pre_show(twindow &window)
Inherited from tdialog.
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:82
This file contains the settings handling of the widget library.
void add_row(const string_map &item, const int index=-1)
When an item in the list is selected by the user we need to update the state.
Definition: listbox.cpp:74
const config & data() const
std::vector< std::string > & active_mods()
std::map< std::string, t_string > string_map
Definition: generator.hpp:23
virtual bool allow_era_choice() const
GLenum GLenum GLvoid GLvoid * column
Definition: glew.h:3805
std::vector< std::string > extras_menu_item_names(const MP_EXTRA extra_type, bool escape_markup=true) const
GLuint index
Definition: glew.h:1782
The listbox class.
Definition: listbox.hpp:39
size_t i
Definition: function.cpp:1057
GLenum GLenum GLvoid * row
Definition: glew.h:3805
GLenum GLint ref
Definition: glew.h:1813
bool find(E event, F functor)
Tests whether an event handler is available.
void change_mod(size_t index, twindow &window)
void post_show(twindow &window)
Inherited from tdialog.
void set_callback_item_change(const std::function< void(size_t)> &callback)
Definition: listbox.hpp:219
ng::create_engine & engine_
mp_game_settings & mp_settings()
Multiplayer parameters for this game.
Definition: saved_game.hpp:58
int get_selected_row() const
Returns the first selected row.
Definition: listbox.cpp:237
void change_era(twindow &window)
GLsizei const GLcharARB ** string
Definition: glew.h:4503
void update_lists(twindow &window)
void clear()
Removes all the rows in the listbox, clearing it.
Definition: listbox.cpp:131