15 #define GETTEXT_DOMAIN "wesnoth-lib"
40 #include <boost/algorithm/string/replace.hpp>
75 , current_addon_(current_addon)
106 ERR_ED <<
"Caught a config error while parsing file " <<
pbl_ <<
"\n" <<
e.message;
110 text_box* name = find_widget<text_box>(&win,
"name",
false,
true);
114 find_widget<text_box>(&win,
"description",
false).set_value(pbl[
"description"]);
115 find_widget<text_box>(&win,
"icon",
false).set_value(pbl[
"icon"]);
116 if(!pbl[
"icon"].empty()) {
117 drawing& img = find_widget<drawing>(&win,
"preview",
false);
120 find_widget<text_box>(&win,
"author",
false).set_value(pbl[
"author"]);
121 find_widget<text_box>(&win,
"version",
false).set_value(pbl[
"version"]);
123 multimenu_button& dependencies = find_widget<multimenu_button>(&win,
"dependencies",
false);
126 if(
dirs_.size() > 0) {
130 for(
const std::string& dir :
dirs_) {
131 addons_list.emplace_back(
"label", dir,
"checkbox",
false);
135 std::vector<std::string> existing_dependencies =
utils::split(pbl[
"dependencies"].str(),
',');
136 for(
unsigned i = 0;
i <
dirs_.size();
i++) {
137 if(std::find(existing_dependencies.begin(), existing_dependencies.end(),
dirs_[
i]) != existing_dependencies.end()) {
142 if(pbl[
"forum_auth"].to_bool()) {
143 find_widget<toggle_button>(&win,
"forum_auth",
false).set_value(
true);
151 find_widget<text_box>(&win,
"email",
false).set_value(pbl[
"email"]);
152 find_widget<text_box>(&win,
"password",
false).set_value(pbl[
"passphrase"]);
158 find_widget<text_box>(&win,
"forum_thread",
false).set_value(pbl.
mandatory_child(
"feedback")[
"topic_id"]);
169 menu_button& types = find_widget<menu_button>(&win,
"type",
false);
170 std::vector<config> type_list;
171 type_list.emplace_back(
"label",
"");
172 type_list.emplace_back(
"label",
_(
"Core"));
173 type_list.emplace_back(
"label",
_(
"Campaign"));
174 type_list.emplace_back(
"label",
_(
"Hybrid Campaign"));
175 type_list.emplace_back(
"label",
_(
"Multiplayer Campaign"));
176 type_list.emplace_back(
"label",
_(
"Scenario"));
177 type_list.emplace_back(
"label",
_(
"Multiplayer Scenario"));
178 type_list.emplace_back(
"label",
_(
"Faction"));
179 type_list.emplace_back(
"label",
_(
"Era"));
180 type_list.emplace_back(
"label",
_(
"Map Pack"));
181 type_list.emplace_back(
"label",
_(
"Modification"));
182 type_list.emplace_back(
"label",
_(
"Media"));
183 type_list.emplace_back(
"label",
_(
"Other"));
187 multimenu_button& tags = find_widget<multimenu_button>(&win,
"tags",
false);
188 std::vector<config> tags_list;
189 tags_list.emplace_back(
"label",
_(
"Cooperative"),
"checkbox",
false);
190 tags_list.emplace_back(
"label",
_(
"Cosmetic"),
"checkbox",
false);
191 tags_list.emplace_back(
"label",
_(
"Difficulty"),
"checkbox",
false);
192 tags_list.emplace_back(
"label",
_(
"RNG"),
"checkbox",
false);
193 tags_list.emplace_back(
"label",
_(
"Survival"),
"checkbox",
false);
194 tags_list.emplace_back(
"label",
_(
"Terraforming"),
"checkbox",
false);
197 std::vector<std::string> chosen_tags =
utils::split(pbl[
"tags"].str(),
',');
199 if(std::find(chosen_tags.begin(), chosen_tags.end(),
tag_values[
i]) != chosen_tags.end()) {
204 listbox& translations = find_widget<listbox>(&win,
"translations",
false);
205 button& translations_delete = find_widget<button>(&win,
"translations_delete",
false);
211 {
"translations_description",
widget_item{{
"label",
child[
"description"].str()}}},
227 std::stringstream wml_stream;
237 if(
const std::string& name = find_widget<text_box>(
get_window(),
"name",
false).get_value(); !name.empty()) {
240 if(
const std::string& description = find_widget<text_box>(
get_window(),
"description",
false).get_value(); !description.empty()) {
241 cfg[
"description"] = description;
243 if(
const std::string& icon = find_widget<text_box>(
get_window(),
"icon",
false).get_value(); !icon.empty()) {
246 if(
const std::string& author = find_widget<text_box>(
get_window(),
"author",
false).get_value(); !author.empty()) {
247 cfg[
"author"] = author;
249 if(
const std::string& version = find_widget<text_box>(
get_window(),
"version",
false).get_value(); !version.empty()) {
250 cfg[
"version"] = version;
255 std::vector<std::string> chosen_deps;
256 for(
unsigned i = 0;
i < dep_states.size();
i++) {
257 if(dep_states[
i] == 1) {
258 chosen_deps.emplace_back(
dirs_[
i]);
261 if(chosen_deps.size() > 0) {
262 cfg[
"dependencies"] =
utils::join(chosen_deps,
",");
265 if(find_widget<toggle_button>(
get_window(),
"forum_auth",
false).get_value_bool()) {
266 cfg[
"forum_auth"] =
true;
268 if(
const std::string& email = find_widget<text_box>(
get_window(),
"email",
false).get_value(); !email.empty()) {
269 cfg[
"email"] = email;
271 if(
const std::string& passphrase = find_widget<text_box>(
get_window(),
"password",
false).get_value(); !passphrase.empty()) {
272 cfg[
"passphrase"] = passphrase;
276 if(
const std::string& topic_id = find_widget<text_box>(
get_window(),
"forum_thread",
false).get_value(); !topic_id.empty()) {
278 feedback[
"topic_id"] = topic_id;
281 if(
unsigned value = find_widget<menu_button>(
get_window(),
"type",
false).get_value(); value != 0) {
287 std::vector<std::string> chosen_tags;
288 for(
unsigned i = 0;
i < tag_states.size();
i++) {
289 if(tag_states[
i] == 1) {
290 chosen_tags.emplace_back(
dirs_[
i]);
293 if(chosen_tags.size() > 0) {
297 listbox& translations = find_widget<listbox>(
get_window(),
"translations",
false);
334 std::string description;
335 editor_edit_pbl_translation::execute(
language, title, description);
337 if(!
language.empty() && !title.empty()) {
338 listbox& translations = find_widget<listbox>(
get_window(),
"translations",
false);
341 {
"translations_title",
widget_item{{
"label", title}}},
342 {
"translations_description",
widget_item{{
"label", description}}},
351 listbox& translations = find_widget<listbox>(
get_window(),
"translations",
false);
354 button& translations_delete = find_widget<button>(
get_window(),
"translations_delete",
false);
362 std::unique_ptr<schema_validation::schema_validator> validator;
364 validator->set_create_exceptions(
false);
367 std::stringstream ss;
369 read(temp, ss.str(), validator.
get());
370 if(!validator->get_errors().empty()) {
373 gui2::show_message(
_(
"Success"),
_(
"No validation errors"), gui2::dialogs::message::button_style::auto_close);
379 std::string icon = find_widget<text_box>(
get_window(),
"icon",
false).get_value();
380 if(icon.find(
".png") != std::string::npos || icon.find(
".jpg") != std::string::npos || icon.find(
".webp") != std::string::npos) {
388 ERR_ED <<
"Failed to find icon file: " <<
path;
395 std::string topic = find_widget<text_box>(
get_window(),
"forum_thread",
false).get_value();
396 find_widget<label>(
get_window(),
"forum_url",
false).set_label(
"https://r.wesnoth.org/t" + topic);
410 find_widget<text_box>(
get_window(),
"icon",
false).set_value(icon);
411 find_widget<drawing>(
get_window(),
"preview",
false).set_label(icon);
416 find_widget<text_box>(
get_window(),
"icon",
false).set_value(uri);
417 find_widget<drawing>(
get_window(),
"preview",
false).set_label(uri);
Class for writing a config out to a file in pieces.
void write(const config &cfg)
A config object defines a single node in a WML file, with access to child nodes.
config & mandatory_child(config_key_type key, int n=0)
Returns the nth child with the given key, or throws an error if there is none.
bool has_child(config_key_type key) const
Determine whether a config has a child or not.
child_itors child_range(config_key_type key)
const attribute_value * get(config_key_type key) const
Returns a pointer to the attribute with the given key or nullptr if it does not exist.
config & add_child(config_key_type key)
void delete_translation()
editor_edit_pbl(const std::string &pbl, const std::string ¤t_addon)
void update_url_preview()
std::string current_addon_
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
virtual void pre_show(window &window) override
The execute function.
void update_icon_preview()
std::vector< std::string > dirs_
file_dialog & set_path(const std::string &value)
Sets the initial file selection.
file_dialog & set_title(const std::string &value)
Sets the current dialog title text.
std::string path() const
Gets the current file selection.
Abstract base class for all modal dialogs.
bool show(const unsigned auto_close_time=0)
Shows the window.
int get_retval() const
Returns the cached window exit code.
window * get_window()
Returns a pointer to the dialog's window.
A drawing is widget with a fixed size and gives access to the canvas of the widget in the window inst...
void set_active(const bool active)
Activates all children.
widget * find(const std::string &id, const bool must_be_active) override
See widget::find.
A label displays text that can be wrapped but no scrollbars are provided.
void set_link_aware(bool l)
grid & add_row(const widget_item &item, const int index=-1)
When an item in the list is selected by the user we need to update the state.
const grid * get_row_grid(const unsigned row) const
Returns the grid of the wanted row.
void remove_row(const unsigned row, unsigned count=1)
Removes a row in the listbox.
int get_selected_row() const
Returns the first selected row.
unsigned get_item_count() const
Returns the number of items in the listbox.
bool get_value_bool() const
virtual void set_value(const std::string &text)
The set_value is virtual for the password_box class.
Class for a single line text area.
base class of top level items, the only item which needs to store the final canvases to draw on.
void keyboard_capture(widget *widget)
Realization of serialization/validator.hpp abstract validator.
Main (common) editor header.
Declarations for File-IO.
static std::string _(const char *str)
std::map< std::string, addon_info > addons_list
#define REGISTER_DIALOG(window_id)
Wrapper for REGISTER_DIALOG2.
void get_files_in_dir(const std::string &dir, std::vector< std::string > *files, std::vector< std::string > *dirs, name_mode mode, filter_mode filter, reorder_mode reorder, file_tree_checksum *checksum)
Get a list of all files and/or directories in a given directory.
static bool file_exists(const bfs::path &fpath)
std::string get_wml_location(const std::string &filename, const std::string ¤t_dir)
Returns a complete path to the actual WML file or directory or an empty string if the file isn't pres...
std::string read_file_as_data_uri(const std::string &fname)
void write_file(const std::string &fname, const std::string &data, std::ios_base::openmode mode)
Throws io_exception if an error occurs.
std::string get_addons_dir()
std::string get_core_images_dir()
void remove()
Removes a tip.
const std::array type_values
const std::array tag_values
void connect_signal_notify_modified(dispatcher &dispatcher, const signal_notification &signal)
Connects a signal handler for getting a notification upon modification.
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal &signal)
Connects a signal handler for a left mouse button click.
std::map< std::string, widget_item > widget_data
std::map< std::string, t_string > widget_item
void show_error_message(const std::string &msg, bool message_use_markup)
Shows an error message to the user.
void show_message(const std::string &title, const std::string &msg, const std::string &button_caption, const bool auto_close, const bool message_use_markup, const bool title_use_markup)
Shows a message to the user.
@ OK
Dialog was closed with the OK button.
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
std::vector< std::string > split(const config_attribute_value &val)
filesystem::scoped_istream preprocess_file(const std::string &fname, preproc_map *defines)
Function to use the WML preprocessor on a file.
One of the realizations of serialization/validator.hpp abstract validator.
void read(config &cfg, std::istream &in, abstract_validator *validator)