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 class custom_tod : public modal_dialog
31 {
32 public:
33  custom_tod(const std::vector<time_of_day>& times, int current_time);
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 
86 
87  /** Update current TOD with values from the GUI */
88  void update_schedule();
89 
90  /** Available time_of_days */
91  std::vector<time_of_day> times_;
92 
93  /** Current ToD index */
95 
99 };
100 
101 } // namespace dialogs
102 } // namespace gui2
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:38
field_integer * color_field_g_
Definition: custom_tod.hpp:97
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: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:91
COLOR_TYPE
enum used in identifying sliders
Definition: custom_tod.hpp:48
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:98
field_integer * color_field_r_
Definition: custom_tod.hpp:96
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:94
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:74
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: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.
Object which defines a time of day with associated bonuses, image, sounds etc.
Definition: time_of_day.hpp:57