The Battle for Wesnoth  1.19.0-dev
custom_tod.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2024
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 
24 namespace gui2
25 {
26 
27 namespace dialogs
28 {
29 
30 /**
31  * @ingroup GUIWindowDefinitionWML
32  *
33  * This shows the dialog to modify tod schedules.
34  * Key |Type |Mandatory|Description
35  * ------------------|--------------|---------|-----------
36  * current_tod_name | text_box |yes |The name of the time of day(ToD).
37  * current_tod_id | text_box |yes |The id of the time of day(ToD).
38  * current_tod_image | @ref image |yes |The image for the time of day(ToD).
39  * current_tod_mask | @ref image |yes |The image mask for the time of day(ToD).
40  * current_tod_sound | @ref label |yes |The sound for the time of day(ToD).
41  * next_tod | @ref button |yes |Selects the next ToD.
42  * prev_tod | @ref button |yes |Selects the previous ToD.
43  * lawful_bonus | @ref slider |yes |Sets the Lawful Bonus for the current ToD.
44  * tod_red | @ref slider |yes |Sets the red component of the current ToD.
45  * tod_green | @ref slider |yes |Sets the green component of the current ToD.
46  * tod_blue | @ref slider |yes |Sets the blue component of the current ToD.
47  */
48 class custom_tod : public modal_dialog
49 {
50 public:
51  custom_tod(const std::vector<time_of_day>& times, int current_time);
52 
53  /** The execute function. See @ref modal_dialog for more information. */
55 
56  using string_pair = std::pair<std::string, std::string>;
57  using tod_attribute_getter = std::function<string_pair(const time_of_day&)>;
58 
59  /** Return current schedule */
60  const std::vector<time_of_day> get_schedule();
61 
62  /** Register callback for update */
63  void register_callback(std::function<void(std::vector<time_of_day>)>);
64 
65  /** enum used in identifying sliders */
67 
68 private:
69  virtual const std::string& window_id() const override;
70 
71  virtual void pre_show(window& window) override;
72 
73  virtual void post_show(window& window) override;
74 
75  /** Callback for the next tod button */
76  void do_next_tod();
77  void do_prev_tod();
78 
79  void do_new_tod();
80  void do_delete_tod();
81 
82  /** Callback for preview button */
83  void preview_schedule();
84 
85  template<custom_tod::string_pair(*fptr)(const time_of_day&)>
86  void select_file(const std::string& default_dir);
87 
88  /* Callback for color sliders */
90 
91  /* Update map and schedule in realtime */
92  std::function<void(std::vector<time_of_day>)> update_map_and_schedule_;
93 
94  void update_tod_display();
95 
96  void update_lawful_bonus();
97 
99  const time_of_day& get_selected_tod() const;
100 
102 
104 
105  /** Update current TOD with values from the GUI */
106  void update_schedule();
107 
108  /** Available time_of_days */
109  std::vector<time_of_day> times_;
110 
111  /** Current ToD index */
113 
117 };
118 
119 } // namespace dialogs
120 } // namespace gui2
This shows the dialog to modify tod schedules.
Definition: custom_tod.hpp:49
void update_schedule()
Update current TOD with values from the GUI.
Definition: custom_tod.cpp:301
std::pair< std::string, std::string > string_pair
The execute function.
Definition: custom_tod.hpp:56
field_integer * color_field_g_
Definition: custom_tod.hpp:115
void set_selected_tod(time_of_day tod)
std::function< string_pair(const time_of_day &)> tod_attribute_getter
Definition: custom_tod.hpp:57
void color_slider_callback(COLOR_TYPE type)
Definition: custom_tod.cpp:226
virtual const std::string & window_id() const override
The ID of the window to build.
void select_file(const std::string &default_dir)
Definition: custom_tod.cpp:150
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
Definition: custom_tod.cpp:72
custom_tod(const std::vector< time_of_day > &times, int current_time)
Definition: custom_tod.cpp:58
void preview_schedule()
Callback for preview button.
Definition: custom_tod.cpp:296
std::vector< time_of_day > times_
Available time_of_days.
Definition: custom_tod.hpp:109
COLOR_TYPE
enum used in identifying sliders
Definition: custom_tod.hpp:66
void copy_to_clipboard_callback(tod_attribute_getter getter)
Definition: custom_tod.cpp:290
const time_of_day & get_selected_tod() const
Definition: custom_tod.cpp:217
void do_next_tod()
Callback for the next tod button.
Definition: custom_tod.cpp:182
field_integer * color_field_b_
Definition: custom_tod.hpp:116
field_integer * color_field_r_
Definition: custom_tod.hpp:114
const std::vector< time_of_day > get_schedule()
Return current schedule.
Definition: custom_tod.cpp:319
int current_tod_
Current ToD index.
Definition: custom_tod.hpp:112
void register_callback(std::function< void(std::vector< time_of_day >)>)
Register callback for update.
Definition: custom_tod.cpp:325
std::function< void(std::vector< time_of_day >)> update_map_and_schedule_
Definition: custom_tod.hpp:92
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
Definition: custom_tod.cpp:330
Abstract base class for all modal dialogs.
Template class to implement the generic field implementation.
Definition: field.hpp:246
base class of top level items, the only item which needs to store the final canvases to draw on.
Definition: window.hpp:63
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...
Various uncategorised dialogs.
Generic file dialog.
std::string default_dir()
Definition: editor.cpp:33
Object which defines a time of day with associated bonuses, image, sounds etc.
Definition: time_of_day.hpp:57