15 #define GETTEXT_DOMAIN "wesnoth-lib"
74 , current_addon_(current_addon)
105 ERR_ED <<
"Caught a config error while parsing file " <<
pbl_ <<
"\n" <<
e.message;
109 text_box* name = find_widget<text_box>(&win,
"name",
false,
true);
113 find_widget<scroll_text>(&win,
"description",
false).set_value(pbl[
"description"]);
114 find_widget<text_box>(&win,
"icon",
false).set_value(pbl[
"icon"]);
115 if(!pbl[
"icon"].empty()) {
116 drawing& img = find_widget<drawing>(&win,
"preview",
false);
119 find_widget<text_box>(&win,
"author",
false).set_value(pbl[
"author"]);
120 find_widget<text_box>(&win,
"version",
false).set_value(pbl[
"version"]);
122 multimenu_button& dependencies = find_widget<multimenu_button>(&win,
"dependencies",
false);
129 for(
const std::string& dir :
dirs_) {
130 addons_list.emplace_back(
"label", dir,
"checkbox",
false);
134 std::vector<std::string> existing_dependencies =
utils::split(pbl[
"dependencies"].str(),
',');
135 for(
unsigned i = 0;
i <
dirs_.size();
i++) {
136 if(std::find(existing_dependencies.begin(), existing_dependencies.end(),
dirs_[
i]) != existing_dependencies.end()) {
141 if(pbl[
"forum_auth"].to_bool()) {
142 find_widget<toggle_button>(&win,
"forum_auth",
false).set_value(
true);
150 find_widget<text_box>(&win,
"email",
false).set_value(pbl[
"email"]);
151 find_widget<text_box>(&win,
"password",
false).set_value(pbl[
"passphrase"]);
157 find_widget<text_box>(&win,
"forum_thread",
false).set_value(pbl.
mandatory_child(
"feedback")[
"topic_id"]);
168 menu_button& types = find_widget<menu_button>(&win,
"type",
false);
169 std::vector<config> type_list;
170 type_list.emplace_back(
"label",
"");
171 type_list.emplace_back(
"label",
_(
"Core"));
172 type_list.emplace_back(
"label",
_(
"Campaign"));
173 type_list.emplace_back(
"label",
_(
"Hybrid Campaign"));
174 type_list.emplace_back(
"label",
_(
"Multiplayer Campaign"));
175 type_list.emplace_back(
"label",
_(
"Scenario"));
176 type_list.emplace_back(
"label",
_(
"Multiplayer Scenario"));
177 type_list.emplace_back(
"label",
_(
"Faction"));
178 type_list.emplace_back(
"label",
_(
"Era"));
179 type_list.emplace_back(
"label",
_(
"Map Pack"));
180 type_list.emplace_back(
"label",
_(
"Modification"));
181 type_list.emplace_back(
"label",
_(
"Media"));
182 type_list.emplace_back(
"label",
_(
"Other"));
186 multimenu_button& tags = find_widget<multimenu_button>(&win,
"tags",
false);
187 std::vector<config> tags_list;
188 tags_list.emplace_back(
"label",
_(
"Cooperative"),
"checkbox",
false);
189 tags_list.emplace_back(
"label",
_(
"Cosmetic"),
"checkbox",
false);
190 tags_list.emplace_back(
"label",
_(
"Difficulty"),
"checkbox",
false);
191 tags_list.emplace_back(
"label",
_(
"RNG"),
"checkbox",
false);
192 tags_list.emplace_back(
"label",
_(
"Survival"),
"checkbox",
false);
193 tags_list.emplace_back(
"label",
_(
"Terraforming"),
"checkbox",
false);
196 std::vector<std::string> chosen_tags =
utils::split(pbl[
"tags"].str(),
',');
198 if(std::find(chosen_tags.begin(), chosen_tags.end(),
tag_values[
i]) != chosen_tags.end()) {
203 listbox& translations = find_widget<listbox>(&win,
"translations",
false);
204 button& translations_delete = find_widget<button>(&win,
"translations_delete",
false);
210 {
"translations_description",
widget_item{{
"label",
child[
"description"].str()}}},
226 std::stringstream wml_stream;
236 if(
const std::string& name = find_widget<text_box>(
get_window(),
"name",
false).get_value(); !name.empty()) {
239 if(
const std::string& description = find_widget<scroll_text>(
get_window(),
"description",
false).get_value(); !description.empty()) {
240 cfg[
"description"] = description;
242 if(
const std::string& icon = find_widget<text_box>(
get_window(),
"icon",
false).get_value(); !icon.empty()) {
245 if(
const std::string& author = find_widget<text_box>(
get_window(),
"author",
false).get_value(); !author.empty()) {
246 cfg[
"author"] = author;
248 if(
const std::string& version = find_widget<text_box>(
get_window(),
"version",
false).get_value(); !version.empty()) {
249 cfg[
"version"] = version;
254 std::vector<std::string> chosen_deps;
255 for(
unsigned i = 0;
i < dep_states.size();
i++) {
256 if(dep_states[
i] == 1) {
257 chosen_deps.emplace_back(
dirs_[
i]);
260 if(chosen_deps.size() > 0) {
261 cfg[
"dependencies"] =
utils::join(chosen_deps,
",");
264 if(find_widget<toggle_button>(
get_window(),
"forum_auth",
false).get_value_bool()) {
265 cfg[
"forum_auth"] =
true;
267 if(
const std::string& secondary_authors = find_widget<text_box>(
get_window(),
"secondary_authors",
false).get_value(); !secondary_authors.empty()) {
268 cfg[
"secondary_authors"] = secondary_authors;
271 if(
const std::string& email = find_widget<text_box>(
get_window(),
"email",
false).get_value(); !email.empty()) {
272 cfg[
"email"] = email;
274 if(
const std::string& passphrase = find_widget<text_box>(
get_window(),
"password",
false).get_value(); !passphrase.empty()) {
275 cfg[
"passphrase"] = passphrase;
279 if(
const std::string& topic_id = find_widget<text_box>(
get_window(),
"forum_thread",
false).get_value(); !topic_id.empty()) {
281 feedback[
"topic_id"] = topic_id;
284 if(
unsigned value = find_widget<menu_button>(
get_window(),
"type",
false).get_value(); value != 0) {
290 std::vector<std::string> chosen_tags;
291 for(
unsigned i = 0;
i < tag_states.size();
i++) {
292 if(tag_states[
i] == 1) {
296 if(chosen_tags.size() > 0) {
300 listbox& translations = find_widget<listbox>(
get_window(),
"translations",
false);
335 std::string language;
337 std::string description;
338 editor_edit_pbl_translation::execute(language, title, description);
340 if(!language.empty() && !title.empty()) {
341 listbox& translations = find_widget<listbox>(
get_window(),
"translations",
false);
343 {
"translations_language",
widget_item{{
"label", language}}},
344 {
"translations_title",
widget_item{{
"label", title}}},
345 {
"translations_description",
widget_item{{
"label", description}}},
354 listbox& translations = find_widget<listbox>(
get_window(),
"translations",
false);
357 button& translations_delete = find_widget<button>(
get_window(),
"translations_delete",
false);
365 std::unique_ptr<schema_validation::schema_validator> validator;
367 validator->set_create_exceptions(
false);
370 std::stringstream ss;
372 read(temp, ss.str(), validator.
get());
373 if(!validator->get_errors().empty()) {
376 gui2::show_message(
_(
"Success"),
_(
"No validation errors"), gui2::dialogs::message::button_style::auto_close);
382 std::string icon = find_widget<text_box>(
get_window(),
"icon",
false).get_value();
383 if(icon.find(
".png") != std::string::npos || icon.find(
".jpg") != std::string::npos || icon.find(
".webp") != std::string::npos) {
391 ERR_ED <<
"Failed to find icon file: " <<
path;
398 std::string topic = find_widget<text_box>(
get_window(),
"forum_thread",
false).get_value();
399 find_widget<label>(
get_window(),
"forum_url",
false).set_label(
"https://r.wesnoth.org/t" + topic);
413 find_widget<text_box>(
get_window(),
"icon",
false).set_value(icon);
414 find_widget<drawing>(
get_window(),
"preview",
false).set_label(icon);
419 find_widget<text_box>(
get_window(),
"icon",
false).set_value(uri);
420 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.
void set_active(const bool active)
Activates all children.
widget * find(const std::string &id, const bool must_be_active) override
See widget::find.
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.
A widget that allows the user to input text in single line.
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
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)
utils::optional< std::string > get_wml_location(const std::string &path, const utils::optional< std::string > ¤t_dir)
Returns a translated path to the actual file or directory, if it exists.
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
REGISTER_DIALOG(editor_edit_unit)
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)