The Battle for Wesnoth  1.19.2+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 class custom_tod : public modal_dialog
31 {
32 public:
33  custom_tod(const std::vector<time_of_day>& times, int current_time, const std::string addon_id = "");
34 
35  /** The execute function. See @ref modal_dialog for more information. */
37 
38  using string_pair = std::pair<std::string, std::string>;
39  using tod_attribute_getter = std::function<string_pair(const time_of_day&)>;
40 
41  /** Return current schedule */
42  const std::vector<time_of_day> get_schedule();
43 
44  /** Register callback for update */
45  void register_callback(std::function<void(std::vector<time_of_day>)>);
46 
47  /** enum used in identifying sliders */
49 
50 private:
51  virtual const std::string& window_id() const override;
52 
53  virtual void pre_show(window& window) override;
54 
55  virtual void post_show(window& window) override;
56 
57  /** Callback for the next tod button */
58  void do_next_tod();
59  void do_prev_tod();
60 
61  void do_new_tod();
62  void do_delete_tod();
63 
64  /** Callback for preview button */
65  void preview_schedule();
66 
67  template<custom_tod::string_pair(*fptr)(const time_of_day&)>
68  void select_file(const std::string& default_dir);
69 
70  /* Callback for color sliders */
72 
73  /* Update map and schedule in realtime */
74  std::function<void(std::vector<time_of_day>)> update_map_and_schedule_;
75 
76  void update_tod_display();
77 
78  void update_lawful_bonus();
79 
81  const time_of_day& get_selected_tod() const;
82 
84 
85  void copy_to_clipboard_callback(std::pair<std::string, tod_attribute_getter> data);
86 
87  /** Update current TOD with values from the GUI */
88  void update_schedule();
89 
90  /** Update image when preview is pressed */
91  void update_image(const std::string& id_stem);
92 
93  /** Play sound when play is pressed */
94  void play_sound();
95 
96  /** ID of the current addon. The schedule file will be saved here. */
97  const std::string addon_id_;
98 
99  /** Available time of days */
100  std::vector<time_of_day> times_;
101 
102  /** Current time of day (ToD) index */
104 
108 };
109 
110 } // namespace dialogs
111 } // namespace gui2
void update_schedule()
Update current TOD with values from the GUI.
Definition: custom_tod.cpp:346
std::pair< std::string, std::string > string_pair
The execute function.
Definition: custom_tod.hpp:38
void update_image(const std::string &id_stem)
Update image when preview is pressed.
Definition: custom_tod.cpp:282
field_integer * color_field_g_
Definition: custom_tod.hpp:106
void set_selected_tod(time_of_day tod)
std::function< string_pair(const time_of_day &)> tod_attribute_getter
Definition: custom_tod.hpp:39
void color_slider_callback(COLOR_TYPE type)
Definition: custom_tod.cpp:257
const std::string addon_id_
ID of the current addon.
Definition: custom_tod.hpp:97
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:164
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
Definition: custom_tod.cpp:76
void preview_schedule()
Callback for preview button.
Definition: custom_tod.cpp:341
std::vector< time_of_day > times_
Available time of days.
Definition: custom_tod.hpp:100
COLOR_TYPE
enum used in identifying sliders
Definition: custom_tod.hpp:48
void copy_to_clipboard_callback(std::pair< std::string, tod_attribute_getter > data)
Definition: custom_tod.cpp:332
const time_of_day & get_selected_tod() const
Definition: custom_tod.cpp:248
void do_next_tod()
Callback for the next tod button.
Definition: custom_tod.cpp:213
field_integer * color_field_b_
Definition: custom_tod.hpp:107
custom_tod(const std::vector< time_of_day > &times, int current_time, const std::string addon_id="")
Definition: custom_tod.cpp:61
field_integer * color_field_r_
Definition: custom_tod.hpp:105
const std::vector< time_of_day > get_schedule()
Return current schedule.
Definition: custom_tod.cpp:364
void play_sound()
Play sound when play is pressed.
Definition: custom_tod.cpp:277
int current_tod_
Current time of day (ToD) index.
Definition: custom_tod.hpp:103
void register_callback(std::function< void(std::vector< time_of_day >)>)
Register callback for update.
Definition: custom_tod.cpp:370
std::function< void(std::vector< time_of_day >)> update_map_and_schedule_
Definition: custom_tod.hpp:74
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
Definition: custom_tod.cpp:375
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:61
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_view data
Definition: picture.cpp:194
Object which defines a time of day with associated bonuses, image, sounds etc.
Definition: time_of_day.hpp:57