The Battle for Wesnoth  1.15.12+dev
custom_tod.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2018 by Mark de Wever <koraq@xs4all.nl>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #pragma once
16 
18 #include "time_of_day.hpp"
19 
20 #include <vector>
21 
22 namespace gui2
23 {
24 class slider;
25 
26 namespace dialogs
27 {
28 
29 /**
30  * @ingroup GUIWindowDefinitionWML
31  *
32  * This shows the dialog to modify tod schedules.
33  * Key |Type |Mandatory|Description
34  * ------------------|--------------|---------|-----------
35  * current_tod_name | text_box |yes |The name of the time of day(ToD).
36  * current_tod_id | text_box |yes |The id of the time of day(ToD).
37  * current_tod_image | @ref image |yes |The image for the time of day(ToD).
38  * current_tod_mask | @ref image |yes |The image mask for the time of day(ToD).
39  * current_tod_sound | @ref label |yes |The sound for the time of day(ToD).
40  * next_tod | @ref button |yes |Selects the next ToD.
41  * prev_tod | @ref button |yes |Selects the previous ToD.
42  * lawful_bonus | @ref slider |yes |Sets the Lawful Bonus for the current ToD.
43  * tod_red | @ref slider |yes |Sets the red component of the current ToD.
44  * tod_green | @ref slider |yes |Sets the green component of the current ToD.
45  * tod_blue | @ref slider |yes |Sets the blue component of the current ToD.
46  */
47 class custom_tod : public modal_dialog
48 {
49 public:
50  custom_tod(const std::vector<time_of_day>& times, int current_time);
51 
52  /** The execute function. See @ref modal_dialog for more information. */
54 
55  using string_pair = std::pair<std::string, std::string>;
56  using tod_attribute_getter = std::function<string_pair(const time_of_day&)>;
57 
58 private:
59  virtual const std::string& window_id() const override;
60 
61  virtual void pre_show(window& window) override;
62 
63  virtual void post_show(window& window) override;
64 
65  /** Callback for the next tod button */
66  void do_next_tod();
67  void do_prev_tod();
68 
69  void do_new_tod();
70  void do_delete_tod();
71 
72  template<custom_tod::string_pair(*fptr)(const time_of_day&)>
73  void select_file(const std::string& default_dir);
74 
75  void color_slider_callback();
76 
77  void update_tod_display();
78 
79  void update_lawful_bonus();
80 
81  void set_selected_tod(time_of_day tod);
82  const time_of_day& get_selected_tod() const;
83 
85 
87 
88  /** Available time_of_days */
89  std::vector<time_of_day> times_;
90 
91  /** Current ToD index */
93 
97 };
98 
99 } // namespace dialogs
100 } // namespace gui2
std::pair< std::string, std::string > string_pair
The execute function.
Definition: custom_tod.hpp:55
int current_tod_
Current ToD index.
Definition: custom_tod.hpp:92
std::vector< time_of_day > times_
Available time_of_days.
Definition: custom_tod.hpp:89
void set_selected_tod(time_of_day tod)
STL namespace.
Generic file dialog.
Definition: field-fwd.hpp:22
std::string default_dir()
Definition: editor.cpp:32
Object which defines a time of day with associated bonuses, image, sounds etc.
Definition: time_of_day.hpp:55
std::function< string_pair(const time_of_day &)> tod_attribute_getter
Definition: custom_tod.hpp:56
const time_of_day & get_selected_tod() const
Definition: custom_tod.cpp:211
field_integer * color_field_g_
Definition: custom_tod.hpp:95
field_integer * color_field_b_
Definition: custom_tod.hpp:96
Various uncategorised dialogs.
field_integer * color_field_r_
Definition: custom_tod.hpp:94
void select_file(const std::string &default_dir)
Definition: custom_tod.cpp:144
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
Definition: custom_tod.cpp:298
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
Definition: custom_tod.cpp:71
void do_next_tod()
Callback for the next tod button.
Definition: custom_tod.cpp:176
This shows the dialog to modify tod schedules.
Definition: custom_tod.hpp:47
Abstract base class for all modal dialogs.
void copy_to_clipboard_callback(tod_attribute_getter getter)
Definition: custom_tod.cpp:293
custom_tod(const std::vector< time_of_day > &times, int current_time)
Definition: custom_tod.cpp:58
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:64
Template class to implement the generic field implementation.
Definition: field-fwd.hpp:35