supertux
text_array_object.hpp
1 // SuperTux
2 // Copyright (C) 2018 Nir <goproducti@gmail.com>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef HEADER_SUPERTUX_OBJECT_TEXT_ARRAY_OBJECT_HPP
18 #define HEADER_SUPERTUX_OBJECT_TEXT_ARRAY_OBJECT_HPP
19 
20 #include "supertux/game_object.hpp"
21 
22 #include <memory>
23 
24 #include "supertux/timer.hpp"
25 #include "object/text_object.hpp"
26 #include "object/text_array_item.hpp"
27 
28 typedef size_t ta_index;
29 
40 class TextArrayObject final : public GameObject
41 {
42 public:
43  static void register_class(ssq::VM& vm);
44 
45 public:
46  TextArrayObject(const std::string& name = "");
47  ~TextArrayObject() override = default;
48 
49  virtual void draw(DrawingContext& context) override;
50  virtual void update(float dt_sec) override;
51 
52  virtual bool is_saveable() const override { return false; }
53 
54  static std::string class_name() { return "text-array"; }
55  virtual std::string get_class_name() const override { return class_name(); }
56  virtual std::string get_exposed_class_name() const override { return "TextArrayObject"; }
57  static std::string display_name() { return _("Text array"); }
58  virtual std::string get_display_name() const override { return display_name(); }
59  virtual GameObjectClasses get_class_types() const override { return GameObject::get_class_types().add(typeid(TextArrayObject)); }
60 
61  virtual const std::string get_icon_path() const override {
62  return "images/engine/editor/textarray.png";
63  }
64 
69  void clear();
75  void add_text(const std::string& text);
82  void add_text_duration(const std::string& text, float duration);
88  void set_text_index(ta_index index);
95  void set_keep_visible(bool keep_visible);
102  void set_fade_transition(bool fade_transition);
108  void set_fade_time(float fadetime);
115  void set_done(bool done);
121  void set_auto(bool is_auto);
126  void next_text();
131  void prev_text();
132 
133  /*
134  * TextObject API related
135  * @see: text_object.hpp
136  */
137  void set_text(const std::string& text);
138  void set_font(const std::string& fontname);
139  void fade_in(float fadetime);
140  void fade_out(float fadetime);
141  void grow_in(float fadetime);
142  void grow_out(float fadetime);
143  void set_visible(bool visible);
144  void set_centered(bool centered);
145  void set_pos(float x, float y);
146  float get_x() const;
147  float get_y() const;
148  void set_anchor_point(int anchor);
149  int get_anchor_point() const;
150  void set_anchor_offset(float x, float y);
151  float get_wrap_width() const;
152  void set_wrap_width(float width);
153  void set_front_fill_color(float red, float green, float blue, float alpha);
154  void set_back_fill_color(float red, float green, float blue, float alpha);
155  void set_text_color(float red, float green, float blue, float alpha);
156  void set_roundness(float roundness);
157 
161  TextArrayItem* get_text_item(ta_index index) const;
162 
166 
170 
171 private:
173  void override_properties();
174 
176  void reset_automation();
177 
180  void handle_input_requests();
181 
185  bool should_fade() const;
186 
187 private:
192  bool m_finished;
193  bool m_is_auto;
194 
199  bool m_keep_visible;
204  bool m_fade_transition;
205 
206  float m_fadetime;
207 
208  std::vector<std::unique_ptr<TextArrayItem> > m_texts;
209  ta_index m_curTextIndex;
210  ta_index m_lastTextIndex;
211 
212  Timer m_waiting;
213 
214 private:
215  TextArrayObject(const TextArrayObject&) = delete;
216  TextArrayObject& operator=(const TextArrayObject&) = delete;
217 };
218 
219 #endif
220 
221 /* EOF */
void set_auto(bool is_auto)
If set, lets the text array automatically go through all text objects.
Definition: text_array_object.cpp:151
virtual void draw(DrawingContext &context) override
The GameObject should draw itself onto the provided DrawingContext if this function is called...
Definition: text_array_object.cpp:190
An array of text objects, intended for narration.
Definition: text_array_object.hpp:40
void add_text_duration(const std::string &text, float duration)
Adds a text object with a specific text and duration at the end of the stack.
Definition: text_array_object.cpp:53
void set_fade_time(float fadetime)
Sets the fade-in and fade-out time.
Definition: text_array_object.cpp:72
TextArrayItem * get_last_text_item() const
Gets the last text item.
Definition: text_array_object.cpp:139
void set_text_index(ta_index index)
Sets the current text object by its index.
Definition: text_array_object.cpp:65
void clear()
Clears all text objects from the stack.
Definition: text_array_object.cpp:40
TextArrayItem * get_text_item(ta_index index) const
Gets the text item at a certain index.
Definition: text_array_object.cpp:122
This class is responsible for: Updating and drawing the object.
Definition: game_object.hpp:83
void next_text()
If available, goes to the next text object in the stack.
Definition: text_array_object.cpp:78
void set_done(bool done)
Definition: text_array_object.cpp:145
Definition: text_array_item.hpp:17
virtual void update(float dt_sec) override
This function is called once per frame and allows the object to update it&#39;s state.
Definition: text_array_object.cpp:158
virtual GameObjectClasses get_class_types() const
List notable classes in inheritance hierarchy of class.
Definition: game_object.cpp:113
void add_text(const std::string &text)
Adds a text object with a specific text at the end of the stack.
Definition: text_array_object.cpp:47
void set_keep_visible(bool keep_visible)
Definition: text_array_object.cpp:110
TextArrayItem * get_current_text_item() const
Gets the current text item.
Definition: text_array_object.cpp:133
A helper structure to list all the type_indexes of the classes in the type hierarchy of a given class...
Definition: game_object.hpp:57
void prev_text()
If available, goes to the previous text object in the stack.
Definition: text_array_object.cpp:95
Simple timer designed to be used in the update functions of objects.
Definition: timer.hpp:24
void set_fade_transition(bool fade_transition)
Definition: text_array_object.cpp:116
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: text_array_object.hpp:59
virtual std::string get_display_name() const override
Returns the display name of the object, translated to the user&#39;s locale.
Definition: text_array_object.hpp:58
virtual bool is_saveable() const override
Indicates if the object will be saved.
Definition: text_array_object.hpp:52
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42