The Battle for Wesnoth  1.19.7+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::dialogs
25 {
26 class custom_tod : public modal_dialog
27 {
28 public:
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 
46 private:
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 
74  void update_lawful_bonus();
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.
Definition: custom_tod.cpp:341
std::pair< std::string, std::string > string_pair
The execute function.
Definition: custom_tod.hpp:34
void update_image(const std::string &id_stem)
Update image when preview is pressed.
Definition: custom_tod.cpp:277
field_integer * color_field_g_
Definition: custom_tod.hpp:102
void set_selected_tod(time_of_day tod)
custom_tod(const std::vector< time_of_day > &times, int current_time, const std::string &addon_id="")
Definition: custom_tod.cpp:62
std::function< string_pair(const time_of_day &)> tod_attribute_getter
Definition: custom_tod.hpp:35
void color_slider_callback(COLOR_TYPE type)
Definition: custom_tod.cpp:252
const std::string addon_id_
ID of the current addon.
Definition: custom_tod.hpp:93
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:159
void preview_schedule()
Callback for preview button.
Definition: custom_tod.cpp:336
std::vector< time_of_day > times_
Available time of days.
Definition: custom_tod.hpp:96
COLOR_TYPE
enum used in identifying sliders
Definition: custom_tod.hpp:44
virtual void post_show() override
Actions to be taken after the window has been shown.
Definition: custom_tod.cpp:370
const time_of_day & get_selected_tod() const
Definition: custom_tod.cpp:243
void do_next_tod()
Callback for the next tod button.
Definition: custom_tod.cpp:208
field_integer * color_field_b_
Definition: custom_tod.hpp:103
field_integer * color_field_r_
Definition: custom_tod.hpp:101
const std::vector< time_of_day > get_schedule()
Return current schedule.
Definition: custom_tod.cpp:359
void copy_to_clipboard_callback(const std::pair< std::string, tod_attribute_getter > &data)
Definition: custom_tod.cpp:327
void play_sound()
Play sound when play is pressed.
Definition: custom_tod.cpp:272
int current_tod_
Current time of day (ToD) index.
Definition: custom_tod.hpp:99
virtual void pre_show() override
Actions to be taken before showing the window.
Definition: custom_tod.cpp:77
void register_callback(std::function< void(std::vector< time_of_day >)>)
Register callback for update.
Definition: custom_tod.cpp:365
std::function< void(std::vector< time_of_day >)> update_map_and_schedule_
Definition: custom_tod.hpp:70
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...
std::string_view data
Definition: picture.cpp:178
Object which defines a time of day with associated bonuses, image, sounds etc.
Definition: time_of_day.hpp:57