16 #define GETTEXT_DOMAIN "wesnoth-lib"
36 #include <boost/filesystem.hpp>
43 static std::string
type =
"image";
49 static std::string
type =
"mask";
55 static std::string
type =
"sound";
65 , current_tod_(current_time)
66 , color_field_r_(register_integer("tod_red", true))
67 , color_field_g_(register_integer("tod_green", true))
68 , color_field_b_(register_integer("tod_blue", true))
78 static std::map<std::string, tod_attribute_getter> metadata_stuff {
88 for(
const auto&
data : metadata_stuff) {
89 button& copy_w = find_widget<button>(
"copy_" +
data.first);
95 find_widget<button>(
"browse_image"),
96 std::bind(&custom_tod::select_file<tod_getter_image>,
this,
"data/core/images/misc"));
99 find_widget<button>(
"browse_mask"),
100 std::bind(&custom_tod::select_file<tod_getter_mask>,
this,
"data/core/images"));
103 find_widget<button>(
"browse_sound"),
104 std::bind(&custom_tod::select_file<tod_getter_sound>,
this,
"data/core/sounds/ambient"));
107 find_widget<button>(
"preview_image"),
111 find_widget<button>(
"preview_mask"),
115 find_widget<button>(
"preview_sound"),
119 find_widget<button>(
"next_tod"),
123 find_widget<button>(
"previous_tod"),
127 find_widget<button>(
"new"),
131 find_widget<button>(
"delete"),
135 find_widget<button>(
"preview_color"),
139 find_widget<slider>(
"lawful_bonus"),
157 template<custom_tod::
string_pair(*fptr)(const time_of_day&)>
178 =
_(
"This file is outside Wesnoth’s data dirs. Do you wish to copy it into your add-on?");
180 if(
data.first ==
"image") {
187 }
else if(
data.first ==
"mask") {
194 }
else if(
data.first ==
"sound") {
246 }
catch(
const std::out_of_range&) {
247 throw std::string(
"Attempted to fetch a non-existent ToD!");
272 std::string sound_path = find_widget<text_box>(
"path_sound").get_value();
277 std::string img_path = find_widget<text_box>(
"path_"+id_stem).get_value();
278 find_widget<image>(
"current_tod_" + id_stem).set_label(img_path);
286 assert(disp &&
"Display pointer is null!");
303 find_widget<text_box>(
"tod_name").set_value(current_tod.
name);
304 find_widget<text_box>(
"tod_desc").set_value(current_tod.
description);
305 find_widget<text_box>(
"tod_id").set_value(current_tod.
id);
307 find_widget<text_box>(
"path_image").set_value(current_tod.
image);
308 find_widget<text_box>(
"path_mask").set_value(current_tod.
image_mask);
309 find_widget<text_box>(
"path_sound").set_value(current_tod.
sounds);
311 find_widget<image>(
"current_tod_image").set_image(current_tod.
image);
312 find_widget<image>(
"current_tod_mask").set_image(current_tod.
image_mask);
314 find_widget<slider>(
"lawful_bonus").set_value(current_tod.
lawful_bonus);
321 find_widget<label>(
"tod_number").set_label(new_index_str);
329 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
void copy_to_clipboard_callback(std::pair< std::string, tod_attribute_getter > data)
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 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.
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.
bool to_asset_path(std::string &path, std::string addon_id, std::string asset_type)
Helper function to convert absolute path to wesnoth relative path.
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.