15 #define GETTEXT_DOMAIN "wesnoth-lib"
74 , current_addon_(current_addon)
91 label& url = find_widget<label>(
"forum_url");
105 ERR_ED <<
"Caught a config error while parsing file " <<
pbl_ <<
"\n" <<
e.message;
109 text_box* name = find_widget<text_box>(
"name",
false,
true);
113 find_widget<scroll_text>(
"description").set_value(pbl[
"description"]);
114 find_widget<text_box>(
"icon").set_value(pbl[
"icon"]);
115 if(!pbl[
"icon"].empty()) {
116 drawing&
img = find_widget<drawing>(
"preview");
117 img.set_label(pbl[
"icon"]);
119 find_widget<text_box>(
"author").set_value(pbl[
"author"]);
120 find_widget<text_box>(
"version").set_value(pbl[
"version"]);
122 multimenu_button& dependencies = find_widget<multimenu_button>(
"dependencies");
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>(
"forum_auth").set_value(
true);
150 find_widget<text_box>(
"email").set_value(pbl[
"email"]);
151 find_widget<text_box>(
"password").set_value(pbl[
"passphrase"]);
157 find_widget<text_box>(
"forum_thread").set_value(pbl.
mandatory_child(
"feedback")[
"topic_id"]);
168 menu_button& types = find_widget<menu_button>(
"type");
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",
_(
"Theme"));
183 type_list.emplace_back(
"label",
_(
"Other"));
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>(
"translations");
205 button& translations_delete = find_widget<button>(
"translations_delete");
211 {
"translations_description",
widget_item{{
"label",
child[
"description"].str()}}},
227 std::stringstream wml_stream;
237 if(
const std::string& name = find_widget<text_box>(
"name").get_value(); !name.empty()) {
240 if(
const std::string& description = find_widget<scroll_text>(
"description").get_value(); !description.empty()) {
241 cfg[
"description"] = description;
243 if(
const std::string& icon = find_widget<text_box>(
"icon").get_value(); !icon.empty()) {
246 if(
const std::string& author = find_widget<text_box>(
"author").get_value(); !author.empty()) {
247 cfg[
"author"] = author;
249 if(
const std::string& version = find_widget<text_box>(
"version").get_value(); !version.empty()) {
250 cfg[
"version"] = version;
253 multimenu_button& dependencies = find_widget<multimenu_button>(
"dependencies");
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>(
"forum_auth").get_value_bool()) {
266 cfg[
"forum_auth"] =
true;
268 if(
const std::string& secondary_authors = find_widget<text_box>(
"secondary_authors").get_value(); !secondary_authors.empty()) {
269 cfg[
"secondary_authors"] = secondary_authors;
272 if(
const std::string& email = find_widget<text_box>(
"email").get_value(); !email.empty()) {
273 cfg[
"email"] = email;
275 if(
const std::string& passphrase = find_widget<text_box>(
"password").get_value(); !passphrase.empty()) {
276 cfg[
"passphrase"] = passphrase;
280 if(
const std::string& topic_id = find_widget<text_box>(
"forum_thread").get_value(); !topic_id.empty()) {
282 feedback[
"topic_id"] = topic_id;
285 if(
unsigned value = find_widget<menu_button>(
"type").get_value(); value != 0) {
291 std::vector<std::string> chosen_tags;
292 for(
unsigned i = 0;
i < tag_states.size();
i++) {
293 if(tag_states[
i] == 1) {
297 if(chosen_tags.size() > 0) {
301 listbox& translations = find_widget<listbox>(
"translations");
316 toggle_button& forum_auth = find_widget<toggle_button>(
"forum_auth");
336 std::string language;
338 std::string description;
339 editor_edit_pbl_translation::execute(language, title, description);
341 if(!language.empty() && !title.empty()) {
342 listbox& translations = find_widget<listbox>(
"translations");
344 {
"translations_language",
widget_item{{
"label", language}}},
345 {
"translations_title",
widget_item{{
"label", title}}},
346 {
"translations_description",
widget_item{{
"label", description}}},
349 find_widget<button>(
"translations_delete").
set_active(
true);
355 listbox& translations = find_widget<listbox>(
"translations");
358 button& translations_delete = find_widget<button>(
"translations_delete");
366 std::unique_ptr<schema_validation::schema_validator>
validator;
371 std::stringstream ss;
377 gui2::show_message(
_(
"Success"),
_(
"No validation errors"), gui2::dialogs::message::button_style::auto_close);
383 std::string icon = find_widget<text_box>(
"icon").get_value();
384 if(icon.find(
".png") != std::string::npos || icon.find(
".jpg") != std::string::npos || icon.find(
".webp") != std::string::npos) {
386 drawing&
img = find_widget<drawing>(
"preview");
392 ERR_ED <<
"Failed to find icon file: " <<
path;
399 std::string topic = find_widget<text_box>(
"forum_thread").get_value();
400 find_widget<label>(
"forum_url").set_label(
"https://r.wesnoth.org/t" + topic);
414 find_widget<text_box>(
"icon").set_value(icon);
415 find_widget<drawing>(
"preview").set_label(icon);
420 find_widget<text_box>(
"icon").set_value(uri);
421 find_widget<drawing>(
"preview").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)
config & add_child(config_key_type key)
void delete_translation()
editor_edit_pbl(const std::string &pbl, const std::string ¤t_addon)
virtual void pre_show() override
The execute function.
virtual void post_show() override
Actions to be taken after the window has been shown.
void update_url_preview()
std::string current_addon_
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.
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.
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()
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 img(const std::string &src, const std::string &align, const bool floating)
std::size_t erase(Container &container, const Value &value)
Convenience wrapper for using std::remove on a container.
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)