The Battle for Wesnoth  1.17.0-dev
custom_tod.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2021
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 
23 namespace gui2
24 {
25 class slider;
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 private:
60  virtual const std::string& window_id() const override;
61 
62  virtual void pre_show(window& window) override;
63 
64  virtual void post_show(window& window) override;
65 
66  /** Callback for the next tod button */
67  void do_next_tod();
68  void do_prev_tod();
69 
70  void do_new_tod();
71  void do_delete_tod();
72 
73  template<custom_tod::string_pair(*fptr)(const time_of_day&)>
74  void select_file(const std::string& default_dir);
75 
76  void color_slider_callback();
77 
78  void update_tod_display();
79 
80  void update_lawful_bonus();
81 
82  void set_selected_tod(time_of_day tod);
83  const time_of_day& get_selected_tod() const;
84 
86 
88 
89  /** Available time_of_days */
90  std::vector<time_of_day> times_;
91 
92  /** Current ToD index */
94 
98 };
99 
100 } // namespace dialogs
101 } // namespace gui2
std::pair< std::string, std::string > string_pair
The execute function.
Definition: custom_tod.hpp:56
int current_tod_
Current ToD index.
Definition: custom_tod.hpp:93
std::vector< time_of_day > times_
Available time_of_days.
Definition: custom_tod.hpp:90
void set_selected_tod(time_of_day tod)
STL namespace.
Generic file dialog.
Definition: field-fwd.hpp:23
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:56
std::function< string_pair(const time_of_day &)> tod_attribute_getter
Definition: custom_tod.hpp:57
const time_of_day & get_selected_tod() const
Definition: custom_tod.cpp:212
field_integer * color_field_g_
Definition: custom_tod.hpp:96
field_integer * color_field_b_
Definition: custom_tod.hpp:97
Various uncategorised dialogs.
field_integer * color_field_r_
Definition: custom_tod.hpp:95
void select_file(const std::string &default_dir)
Definition: custom_tod.cpp:145
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
Definition: custom_tod.cpp:299
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
Definition: custom_tod.cpp:72
void do_next_tod()
Callback for the next tod button.
Definition: custom_tod.cpp:177
This shows the dialog to modify tod schedules.
Definition: custom_tod.hpp:48
Abstract base class for all modal dialogs.
void copy_to_clipboard_callback(tod_attribute_getter getter)
Definition: custom_tod.cpp:294
custom_tod(const std::vector< time_of_day > &times, int current_time)
Definition: custom_tod.cpp:59
virtual const std::string & window_id() const override
The id of the window to build.
base class of top level items, the only item which needs to store the final canvases to draw on...
Definition: window.hpp:65
Template class to implement the generic field implementation.
Definition: field-fwd.hpp:36