The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
custom_tod.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2008 - 2025
3 by Mark de Wever <koraq@xs4all.nl>
4 Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY.
12
13 See the COPYING file for more details.
14*/
15
16#pragma once
17
19#include "time_of_day.hpp"
20
21#include <vector>
22#include <functional>
23
24namespace gui2::dialogs
25{
27{
28public:
29 custom_tod(const std::vector<time_of_day>& times, int current_time, const std::string& addon_id = "");
30
31 /** The execute function. See @ref modal_dialog for more information. */
33
34 using string_pair = std::pair<std::string, std::string>;
35 using tod_attribute_getter = std::function<string_pair(const time_of_day&)>;
36
37 /** Return current schedule */
38 const std::vector<time_of_day> get_schedule();
39
40 /** Register callback for update */
41 void register_callback(std::function<void(std::vector<time_of_day>)>);
42
43 /** enum used in identifying sliders */
45
46private:
47 virtual const std::string& window_id() const override;
48
49 virtual void pre_show() override;
50
51 virtual void post_show() override;
52
53 /** Callback for the next tod button */
54 void do_next_tod();
55 void do_prev_tod();
56
57 void do_new_tod();
58 void do_delete_tod();
59
60 /** Callback for preview button */
61 void preview_schedule();
62
63 template<custom_tod::string_pair(*fptr)(const time_of_day&)>
64 void select_file(const std::string& default_dir);
65
66 /* Callback for color sliders */
68
69 /* Update map and schedule in realtime */
70 std::function<void(std::vector<time_of_day>)> update_map_and_schedule_;
71
72 void update_tod_display();
73
75
77 const time_of_day& get_selected_tod() const;
78
80
81 void copy_to_clipboard_callback(const std::pair<std::string, tod_attribute_getter>& data);
82
83 /** Update current TOD with values from the GUI */
84 void update_schedule();
85
86 /** Update image when preview is pressed */
87 void update_image(const std::string& id_stem);
88
89 /** Play sound when play is pressed */
90 void play_sound();
91
92 /** ID of the current addon. The schedule file will be saved here. */
93 const std::string addon_id_;
94
95 /** Available time of days */
96 std::vector<time_of_day> times_;
97
98 /** Current time of day (ToD) index */
100
104};
105
106} // namespace gui2::dialogs
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 set_selected_tod(time_of_day tod)
std::function< string_pair(const time_of_day &)> tod_attribute_getter
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 preview_schedule()
Callback for preview button.
std::vector< time_of_day > times_
Available time of days.
virtual const std::string & window_id() const override
The ID of the window to build.
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 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 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_
Abstract base class for all modal dialogs.
Template class to implement the generic field implementation.
Definition field.hpp:245
static const std::string & type()
Static type getter that does not rely on the widget being constructed.
#define DEFINE_SIMPLE_EXECUTE_WRAPPER(dialog)
Adds a bare-bonesstatic execute function to a dialog class that immediately invokes and return the re...
STL namespace.
std::string_view data
Definition picture.cpp:188
Object which defines a time of day with associated bonuses, image, sounds etc.