The Battle for Wesnoth  1.15.2+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 class custom_tod : public modal_dialog
30 {
31 public:
32  custom_tod(const std::vector<time_of_day>& times, int current_time);
33 
34  /** The execute function. See @ref modal_dialog for more information. */
36 
37  using string_pair = std::pair<std::string, std::string>;
38  using tod_attribute_getter = std::function<string_pair(const time_of_day&)>;
39 
40 private:
41  /** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */
42  virtual const std::string& window_id() const override;
43 
44  /** Inherited from modal_dialog. */
45  virtual void pre_show(window& window) override;
46 
47  /** Inherited from modal_dialog. */
48  virtual void post_show(window& window) override;
49 
50  /** Callback for the next tod button */
51  void do_next_tod(window& window);
52  void do_prev_tod(window& window);
53 
54  void do_new_tod(window& window);
55  void do_delete_tod(window& window);
56 
57  template<custom_tod::string_pair(*fptr)(const time_of_day&)>
58  void select_file(window& window, const std::string& default_dir);
59 
60  void color_slider_callback(window& window);
61 
62  void update_tod_display(window& window);
63 
64  void update_lawful_bonus(window& window);
65 
66  void set_selected_tod(time_of_day tod);
67  const time_of_day& get_selected_tod() const;
68 
69  void update_selected_tod_info(window& window);
70 
72 
73  /** Available time_of_days */
74  std::vector<time_of_day> times_;
75 
76  /** Current ToD index */
78 
82 };
83 
84 } // namespace dialogs
85 } // namespace gui2
std::pair< std::string, std::string > string_pair
The execute function.
Definition: custom_tod.hpp:37
void do_prev_tod(window &window)
Definition: custom_tod.cpp:227
int current_tod_
Current ToD index.
Definition: custom_tod.hpp:77
std::vector< time_of_day > times_
Available time_of_days.
Definition: custom_tod.hpp:74
void set_selected_tod(time_of_day tod)
void update_tod_display(window &window)
Definition: custom_tod.cpp:276
STL namespace.
void do_new_tod(window &window)
Definition: custom_tod.cpp:233
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:57
std::function< string_pair(const time_of_day &)> tod_attribute_getter
Definition: custom_tod.hpp:38
const time_of_day & get_selected_tod() const
Definition: custom_tod.cpp:256
void update_lawful_bonus(window &window)
Definition: custom_tod.cpp:307
field_integer * color_field_g_
Definition: custom_tod.hpp:80
field_integer * color_field_b_
Definition: custom_tod.hpp:81
Various uncategorised dialogs.
field_integer * color_field_r_
Definition: custom_tod.hpp:79
void do_delete_tod(window &window)
Definition: custom_tod.cpp:239
void update_selected_tod_info(window &window)
Definition: custom_tod.cpp:312
virtual void post_show(window &window) override
Inherited from modal_dialog.
Definition: custom_tod.cpp:343
void select_file(window &window, const std::string &default_dir)
Definition: custom_tod.cpp:189
virtual void pre_show(window &window) override
Inherited from modal_dialog.
Definition: custom_tod.cpp:116
Abstract base class for all modal dialogs.
void do_next_tod(window &window)
Callback for the next tod button.
Definition: custom_tod.cpp:221
void copy_to_clipboard_callback(tod_attribute_getter getter)
Definition: custom_tod.cpp:338
custom_tod(const std::vector< time_of_day > &times, int current_time)
Definition: custom_tod.cpp:106
virtual const std::string & window_id() const override
Inherited from modal_dialog, implemented by REGISTER_DIALOG.
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:62
Template class to implement the generic field implementation.
Definition: field-fwd.hpp:35
void color_slider_callback(window &window)
Definition: custom_tod.cpp:265