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);
143 find_widget<text_box>(
"primary_authors").set_value(pbl[
"primary_authors"]);
144 find_widget<text_box>(
"secondary_authors").set_value(pbl[
"secondary_authors"]);
154 find_widget<text_box>(
"email").set_value(pbl[
"email"]);
155 find_widget<text_box>(
"password").set_value(pbl[
"passphrase"]);
163 find_widget<text_box>(
"forum_thread").set_value(pbl.
mandatory_child(
"feedback")[
"topic_id"]);
174 menu_button& types = find_widget<menu_button>(
"type");
175 std::vector<config> type_list;
176 type_list.emplace_back(
"label",
"");
177 type_list.emplace_back(
"label",
_(
"Core"));
178 type_list.emplace_back(
"label",
_(
"Campaign"));
179 type_list.emplace_back(
"label",
_(
"Hybrid Campaign"));
180 type_list.emplace_back(
"label",
_(
"Multiplayer Campaign"));
181 type_list.emplace_back(
"label",
_(
"Scenario"));
182 type_list.emplace_back(
"label",
_(
"Multiplayer Scenario"));
183 type_list.emplace_back(
"label",
_(
"Faction"));
184 type_list.emplace_back(
"label",
_(
"Era"));
185 type_list.emplace_back(
"label",
_(
"Map Pack"));
186 type_list.emplace_back(
"label",
_(
"Modification"));
187 type_list.emplace_back(
"label",
_(
"Media"));
188 type_list.emplace_back(
"label",
_(
"Theme"));
189 type_list.emplace_back(
"label",
_(
"Other"));
194 std::vector<config> tags_list;
195 tags_list.emplace_back(
"label",
_(
"Cooperative"),
"checkbox",
false);
196 tags_list.emplace_back(
"label",
_(
"Cosmetic"),
"checkbox",
false);
197 tags_list.emplace_back(
"label",
_(
"Difficulty"),
"checkbox",
false);
198 tags_list.emplace_back(
"label",
_(
"RNG"),
"checkbox",
false);
199 tags_list.emplace_back(
"label",
_(
"Survival"),
"checkbox",
false);
200 tags_list.emplace_back(
"label",
_(
"Terraforming"),
"checkbox",
false);
203 std::vector<std::string> chosen_tags =
utils::split(pbl[
"tags"].str(),
',');
210 listbox& translations = find_widget<listbox>(
"translations");
211 button& translations_delete = find_widget<button>(
"translations_delete");
217 {
"translations_description",
widget_item{{
"label",
child[
"description"].str()}}},
233 std::stringstream wml_stream;
243 if(
const std::string& name = find_widget<text_box>(
"name").get_value(); !name.empty()) {
246 if(
const std::string& description = find_widget<scroll_text>(
"description").get_value(); !description.empty()) {
247 cfg[
"description"] = description;
249 if(
const std::string& icon = find_widget<text_box>(
"icon").get_value(); !icon.empty()) {
252 if(
const std::string& author = find_widget<text_box>(
"author").get_value(); !author.empty()) {
253 cfg[
"author"] = author;
255 if(
const std::string& version = find_widget<text_box>(
"version").get_value(); !version.empty()) {
256 cfg[
"version"] = version;
259 multimenu_button& dependencies = find_widget<multimenu_button>(
"dependencies");
261 std::vector<std::string> chosen_deps;
262 for(
unsigned i = 0;
i < dep_states.size();
i++) {
263 if(dep_states[
i] == 1) {
264 chosen_deps.emplace_back(
dirs_[
i]);
267 if(chosen_deps.size() > 0) {
268 cfg[
"dependencies"] =
utils::join(chosen_deps,
",");
271 if(find_widget<toggle_button>(
"forum_auth").get_value_bool()) {
272 cfg[
"forum_auth"] =
true;
274 if(
const std::string& primary_authors = find_widget<text_box>(
"primary_authors").get_value(); !primary_authors.empty()) {
275 cfg[
"primary_authors"] = primary_authors;
278 if(
const std::string& secondary_authors = find_widget<text_box>(
"secondary_authors").get_value(); !secondary_authors.empty()) {
279 cfg[
"secondary_authors"] = secondary_authors;
282 if(
const std::string& email = find_widget<text_box>(
"email").get_value(); !email.empty()) {
283 cfg[
"email"] = email;
285 if(
const std::string& passphrase = find_widget<text_box>(
"password").get_value(); !passphrase.empty()) {
286 cfg[
"passphrase"] = passphrase;
290 if(
const std::string& topic_id = find_widget<text_box>(
"forum_thread").get_value(); !topic_id.empty()) {
292 feedback[
"topic_id"] = topic_id;
295 if(
unsigned value = find_widget<menu_button>(
"type").get_value(); value != 0) {
301 std::vector<std::string> chosen_tags;
302 for(
unsigned i = 0;
i < tag_states.size();
i++) {
303 if(tag_states[
i] == 1) {
307 if(chosen_tags.size() > 0) {
311 listbox& translations = find_widget<listbox>(
"translations");
326 toggle_button& forum_auth = find_widget<toggle_button>(
"forum_auth");
350 std::string language;
352 std::string description;
353 editor_edit_pbl_translation::execute(language, title, description);
355 if(!language.empty() && !title.empty()) {
356 listbox& translations = find_widget<listbox>(
"translations");
358 {
"translations_language",
widget_item{{
"label", language}}},
359 {
"translations_title",
widget_item{{
"label", title}}},
360 {
"translations_description",
widget_item{{
"label", description}}},
363 find_widget<button>(
"translations_delete").
set_active(
true);
369 listbox& translations = find_widget<listbox>(
"translations");
372 button& translations_delete = find_widget<button>(
"translations_delete");
380 std::unique_ptr<schema_validation::schema_validator>
validator;
385 std::stringstream ss;
391 gui2::show_message(
_(
"Success"),
_(
"No validation errors"), gui2::dialogs::message::button_style::auto_close);
397 std::string icon = find_widget<text_box>(
"icon").get_value();
398 if(icon.find(
".png") != std::string::npos || icon.find(
".jpg") != std::string::npos || icon.find(
".webp") != std::string::npos) {
400 drawing&
img = find_widget<drawing>(
"preview");
406 ERR_ED <<
"Failed to find icon file: " <<
path;
413 std::string topic = find_widget<text_box>(
"forum_thread").get_value();
414 find_widget<label>(
"forum_url").set_label(
"https://r.wesnoth.org/t" + topic);
428 find_widget<text_box>(
"icon").set_value(icon);
429 find_widget<drawing>(
"preview").set_label(icon);
434 find_widget<text_box>(
"icon").set_value(uri);
435 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_view 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)
auto * find(Container &container, const Value &value)
Convenience wrapper for using find on a container without needing to comare to end()
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)