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 <memory>
21 
22 #include "squirrel/exposed_object.hpp"
23 #include "scripting/text_array.hpp"
24 
25 #include "supertux/game_object.hpp"
26 #include "supertux/timer.hpp"
27 
28 #include "object/text_object.hpp"
29 #include "object/text_array_item.hpp"
30 
31 typedef size_t ta_index;
32 
34 class TextArrayObject final : public GameObject,
35  public ExposedObject<TextArrayObject, scripting::TextArray>
36 {
37 public:
38  TextArrayObject(const std::string& name = std::string());
39  TextArrayObject(const ReaderMapping& reader);
40 
41  ~TextArrayObject() = default;
42 
43  virtual void draw(DrawingContext& context) override;
44  virtual void update(float dt_sec) override;
45 
46  virtual bool is_singleton() const override { return true; }
47  virtual bool is_saveable() const override { return false; }
48 
49  virtual std::string get_class() const override { return "text-array"; }
50  virtual std::string get_display_name() const override { return _("Text array"); }
51 
52  virtual const std::string get_icon_path() const override {
53  return "images/engine/editor/textarray.png";
54  }
55 
57 
59  void clear();
60 
64  void add_text(const std::string& text, float duration = 3.0f);
65 
68  void set_text_index(ta_index index);
69 
74  void set_keep_visible(bool keep_visible);
75 
79  void set_fade_transition(bool fade_transition);
80 
84  void set_fade_time(float fadetime);
85 
89  void set_done(bool done);
90 
94  void set_auto(bool is_auto);
95 
99  void next_text();
100 
104  void prev_text();
105 
107 
111  TextArrayItem* get_text_item(ta_index index);
112 
116 
120 
121 private:
123  void override_properties();
124 
126  void reset_automation();
127 
130  void handle_input_requests();
131 
135  bool should_fade();
136 
137 private:
138  bool m_isDone;
139  bool m_isAuto;
140  bool m_keepVisible;
141  bool m_fadeTransition;
142 
143  float m_fadetime;
144 
145  std::vector<std::unique_ptr<TextArrayItem> > m_texts;
146  ta_index m_curTextIndex;
147  ta_index m_lastTextIndex;
148 
149  Timer m_waiting;
150 
151 private:
152  TextArrayObject(const TextArrayObject&) = delete;
153  TextArrayObject& operator=(const TextArrayObject&) = delete;
154 };
155 
156 #endif
157 
158 /* EOF */
virtual bool is_singleton() const override
If true only a single object of this type is allowed in a given GameObjectManager.
Definition: text_array_object.hpp:46
void set_auto(bool is_auto)
Sets the auto flag on & starts the auto narration.
Definition: text_array_object.cpp:155
TextArrayItem * get_current_text_item()
Gets the current text item.
Definition: text_array_object.cpp:137
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:194
A text array object intended for narration.
Definition: text_array_object.hpp:34
This class binds a certain GameObject class to a scripting class.
Definition: exposed_object.hpp:45
void add_text(const std::string &text, float duration=3.0f)
Adds a text with duration.
Definition: text_array_object.cpp:58
void set_fade_time(float fadetime)
Sets fadetime for fade_transition.
Definition: text_array_object.cpp:76
void set_text_index(ta_index index)
Sets the current text index.
Definition: text_array_object.cpp:69
void clear()
Empties the text array.
Definition: text_array_object.cpp:51
TextArrayItem * get_last_text_item()
Gets the last text item.
Definition: text_array_object.cpp:143
Base class for all the things that make up Levels&#39; Sectors.
Definition: game_object.hpp:46
void next_text()
Sets the current text to the next one.
Definition: text_array_object.cpp:82
void set_done(bool done)
Sets the done flag as on.
Definition: text_array_object.cpp:149
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:162
void set_keep_visible(bool keep_visible)
Sets the keep visible flag.
Definition: text_array_object.cpp:114
void prev_text()
Sets the current text to the previous.
Definition: text_array_object.cpp:99
TextArrayItem * get_text_item(ta_index index)
Gets the text item at a certain index.
Definition: text_array_object.cpp:126
Simple timer designed to be used in the update functions of objects.
Definition: timer.hpp:24
void set_fade_transition(bool fade_transition)
Sets the fade transition flag.
Definition: text_array_object.cpp:120
Definition: reader_mapping.hpp:31
virtual bool is_saveable() const override
Indicates if the object will be saved.
Definition: text_array_object.hpp:47
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42