16 #define GETTEXT_DOMAIN "wesnoth-lib"
35 #include <boost/filesystem.hpp>
44 static std::string
type =
"image";
50 static std::string
type =
"mask";
56 static std::string
type =
"sound";
66 , current_tod_(current_time)
67 , color_field_r_(register_integer("tod_red", true))
68 , color_field_g_(register_integer("tod_green", true))
69 , color_field_b_(register_integer("tod_blue", true))
79 static std::map<std::string, tod_attribute_getter> metadata_stuff {
89 for(
const auto&
data : metadata_stuff) {
90 button& copy_w = find_widget<button>(
"copy_" +
data.first);
96 find_widget<button>(
"browse_image"),
97 std::bind(&custom_tod::select_file<tod_getter_image>,
this,
"data/core/images/misc"));
100 find_widget<button>(
"browse_mask"),
101 std::bind(&custom_tod::select_file<tod_getter_mask>,
this,
"data/core/images"));
104 find_widget<button>(
"browse_sound"),
105 std::bind(&custom_tod::select_file<tod_getter_sound>,
this,
"data/core/sounds/ambient"));
108 find_widget<button>(
"preview_image"),
112 find_widget<button>(
"preview_mask"),
116 find_widget<button>(
"preview_sound"),
120 find_widget<button>(
"next_tod"),
124 find_widget<button>(
"previous_tod"),
128 find_widget<button>(
"new"),
132 find_widget<button>(
"delete"),
136 find_widget<button>(
"preview_color"),
140 find_widget<slider>(
"lawful_bonus"),
158 template<custom_tod::
string_pair(*fptr)(const time_of_day&)>
179 =
_(
"This file is outside Wesnoth’s data dirs. Do you wish to copy it into your add-on?");
181 if(
data.first ==
"image") {
188 }
else if(
data.first ==
"mask") {
195 }
else if(
data.first ==
"sound") {
247 }
catch(
const std::out_of_range&) {
248 throw std::string(
"Attempted to fetch a non-existent ToD!");
273 std::string sound_path = find_widget<text_box>(
"path_sound").get_value();
278 std::string img_path = find_widget<text_box>(
"path_"+id_stem).get_value();
279 find_widget<image>(
"current_tod_" + id_stem).set_label(img_path);
287 assert(disp &&
"Display pointer is null!");
304 find_widget<text_box>(
"tod_name").set_value(current_tod.
name);
305 find_widget<text_box>(
"tod_desc").set_value(current_tod.
description);
306 find_widget<text_box>(
"tod_id").set_value(current_tod.
id);
308 find_widget<text_box>(
"path_image").set_value(current_tod.
image);
309 find_widget<text_box>(
"path_mask").set_value(current_tod.
image_mask);
310 find_widget<text_box>(
"path_sound").set_value(current_tod.
sounds);
312 find_widget<image>(
"current_tod_image").set_image(current_tod.
image);
313 find_widget<image>(
"current_tod_mask").set_image(current_tod.
image_mask);
315 find_widget<slider>(
"lawful_bonus").set_value(current_tod.
lawful_bonus);
322 find_widget<label>(
"tod_number").set_label(new_index_str);
330 button& copy_w = find_widget<button>(
"copy_" +
type);
Sort-of-Singleton that many classes, both GUI and non-GUI, use to access the game data.
void update_tod(const time_of_day *tod_override=nullptr)
Applies r,g,b coloring to the map.
static display * get_singleton()
Returns the display object if a display object exists.
void update_schedule()
Update current TOD with values from the GUI.
std::pair< std::string, std::string > string_pair
The execute function.
void update_image(const std::string &id_stem)
Update image when preview is pressed.
field_integer * color_field_g_
void color_slider_callback(COLOR_TYPE type)
const std::string addon_id_
ID of the current addon.
void select_file(const std::string &default_dir)
void update_lawful_bonus()
void preview_schedule()
Callback for preview button.
std::vector< time_of_day > times_
Available time of days.
COLOR_TYPE
enum used in identifying sliders
virtual void post_show() override
Actions to be taken after the window has been shown.
const time_of_day & get_selected_tod() const
void update_selected_tod_info()
void do_next_tod()
Callback for the next tod button.
field_integer * color_field_b_
field_integer * color_field_r_
const std::vector< time_of_day > get_schedule()
Return current schedule.
void copy_to_clipboard_callback(const std::pair< std::string, tod_attribute_getter > &data)
void play_sound()
Play sound when play is pressed.
int current_tod_
Current time of day (ToD) index.
virtual void pre_show() override
Actions to be taken before showing the window.
void update_tod_display()
void register_callback(std::function< void(std::vector< time_of_day >)>)
Register callback for update.
std::function< void(std::vector< time_of_day >)> update_map_and_schedule_
file_dialog & set_ok_label(const std::string &value)
Sets the OK button label.
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.
file_dialog & set_read_only(bool value)
Whether to provide user interface elements for manipulating existing objects.
std::string path() const
Gets the current file selection.
Main class to show messages to the user.
@ yes_no_buttons
Shows a yes and no button.
Abstract base class for all modal dialogs.
bool show(const unsigned auto_close_time=0)
Shows the window.
styled_widget * get_widget()
void set_widget_value(CT value)
Sets the value of the field.
T get_widget_value()
Gets the value of the field.
void invalidate_layout()
Updates the size of the window.
static const std::string & type()
Static type getter that does not rely on the widget being constructed.
void add_to_tab_order(widget *widget, int at=-1)
Add the widget to the tabbing order.
map_display and display: classes which take care of displaying the map and game-data on the screen.
Implements some helper classes to ease adding fields to a dialog and hide the synchronization needed.
Declarations for File-IO.
static std::string _(const char *str)
void copy_to_clipboard(const std::string &text)
Copies text to the clipboard.
bool to_asset_path(std::string &path, const std::string &addon_id, const std::string &asset_type)
Helper function to convert absolute path to wesnoth relative path.
std::string base_name(const std::string &file, const bool remove_extension)
Returns the base filename of a file, with directory name stripped.
void copy_file(const std::string &src, const std::string &dest)
Read a file and then writes it back out.
std::string directory_name(const std::string &file)
Returns the directory name of a file, with filename stripped.
static custom_tod::string_pair tod_getter_mask(const time_of_day &tod)
REGISTER_DIALOG(editor_edit_unit)
static custom_tod::string_pair tod_getter_image(const time_of_day &tod)
static custom_tod::string_pair tod_getter_sound(const time_of_day &tod)
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.
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.
void play_sound(const std::string &files, channel_group group, unsigned int repeats)
Object which defines a time of day with associated bonuses, image, sounds etc.
tod_color color
The color modifications that should be made to the game board to reflect the time of day.
int lawful_bonus
The % bonus lawful units receive.
std::string image
The image to be displayed in the game status.
std::string sounds
List of "ambient" sounds associated with this time_of_day, Played at the beginning of turn.
std::string image_mask
The image that is to be laid over all images while this time of day lasts.