16 #define GETTEXT_DOMAIN "wesnoth-editor"
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) {
96 copy_w.
set_tooltip(
_(
"Clipboard support not found, contact your packager"));
101 find_widget<button>(&
window,
"browse_image",
false),
102 std::bind(&custom_tod::select_file<tod_getter_image>,
this,
"data/core/images/misc"));
105 find_widget<button>(&
window,
"browse_mask",
false),
106 std::bind(&custom_tod::select_file<tod_getter_mask>,
this,
"data/core/images"));
109 find_widget<button>(&
window,
"browse_sound",
false),
110 std::bind(&custom_tod::select_file<tod_getter_sound>,
this,
"data/core/sounds/ambient"));
113 find_widget<button>(&
window,
"preview_image",
false),
117 find_widget<button>(&
window,
"preview_mask",
false),
121 find_widget<button>(&
window,
"preview_sound",
false),
125 find_widget<button>(&
window,
"next_tod",
false),
129 find_widget<button>(&
window,
"previous_tod",
false),
133 find_widget<button>(&
window,
"new",
false),
137 find_widget<button>(&
window,
"delete",
false),
141 find_widget<button>(&
window,
"preview_color",
false),
145 find_widget<slider>(&
window,
"lawful_bonus",
false),
163 template<custom_tod::
string_pair(*fptr)(const time_of_day&)>
184 =
_(
"This file is outside Wesnoth's data dirs. Do you wish to copy it into your add-on?");
186 if(
data.first ==
"image") {
193 }
else if(
data.first ==
"mask") {
200 }
else if(
data.first ==
"sound") {
252 }
catch(
const std::out_of_range&) {
253 throw std::string(
"Attempted to fetch a non-existant ToD!");
278 std::string sound_path = find_widget<text_box>(
get_window(),
"path_sound",
false).get_value();
283 std::string img_path = find_widget<text_box>(
get_window(),
"path_"+id_stem,
false).get_value();
284 find_widget<image>(
get_window(),
"current_tod_" + id_stem,
false).set_label(img_path);
292 assert(disp &&
"Display pointer is null!");
309 find_widget<text_box>(
get_window(),
"tod_name",
false).set_value(current_tod.
name);
311 find_widget<text_box>(
get_window(),
"tod_id",
false).set_value(current_tod.
id);
313 find_widget<text_box>(
get_window(),
"path_image",
false).set_value(current_tod.
image);
315 find_widget<text_box>(
get_window(),
"path_sound",
false).set_value(current_tod.
sounds);
317 find_widget<image>(
get_window(),
"current_tod_image",
false).set_image(current_tod.
image);
327 find_widget<label>(
get_window(),
"tod_number",
false).set_label(new_index_str);
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)
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
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)
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.
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_
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
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.
window * get_window()
Returns a pointer to the dialog's 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.
base class of top level items, the only item which needs to store the final canvases to draw on.
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, const bool)
Copies text to the clipboard.
bool available()
Whether wesnoth was compiled with support for a 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.