1// SuperTux
2// Copyright (C) 2015 Hume2 <teratux.mail@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_EDITOR_OBJECT_OPTION_HPP
18#define HEADER_SUPERTUX_EDITOR_OBJECT_OPTION_HPP
19
20#include <boost/optional.hpp>
21#include <string>
22#include <vector>
23
24#include <sexp/value.hpp>
25
26#include "video/color.hpp"
27#include "gui/menu_action.hpp"
28
29enum ObjectOptionFlag {
30 /** Set if the value is a hidden implementation detail that
31 shouldn't be exposed to the user */
32 OPTION_HIDDEN = (1 << 0),
33
34 /** Set if the text should be saved as translatable */
35 OPTION_TRANSLATABLE = (1 << 1)
36};
37
38namespace sexp {
39class Value;
40} // namespace sexp
41class Color;
42class Menu;
43class Path;
44class Rectf;
45class TileMap;
46class Writer;
47
48class ObjectOption
49{
50public:
51 ObjectOption(const std::string& text, const std::string& key, unsigned int flags);
52 virtual ~ObjectOption();
53
54 virtual void save(Writer& write) const = 0;
55 virtual std::string to_string() const = 0;
56 virtual void add_to_menu(Menu& menu) const = 0;
57
58 const std::string& get_key() const { return m_key; }
59 const std::string& get_text() const { return m_text; }
60 unsigned int get_flags() const { return m_flags; }
61
62private:
63 const std::string m_text;
64 const std::string m_key;
65 const unsigned int m_flags;
66
67private:
68 ObjectOption(const ObjectOption&) = delete;
69 ObjectOption& operator=(const ObjectOption&) = delete;
70};
71
72class BoolObjectOption : public ObjectOption
73{
74public:
75 BoolObjectOption(const std::string& text, bool* pointer, const std::string& key,
76 boost::optional<bool> default_value,
77 unsigned int flags);
78
79 virtual void save(Writer& write) const override;
80 virtual std::string to_string() const override;
81 virtual void add_to_menu(Menu& menu) const override;
82
83private:
84 bool* const m_pointer;
85 const boost::optional<bool> m_default_value;
86
87private:
88 BoolObjectOption(const BoolObjectOption&) = delete;
89 BoolObjectOption& operator=(const BoolObjectOption&) = delete;
90};
91
92class IntObjectOption : public ObjectOption
93{
94public:
95 IntObjectOption(const std::string& text, int* pointer, const std::string& key,
96 boost::optional<int> default_value,
97 unsigned int flags);
98
99 virtual void save(Writer& write) const override;
100 virtual std::string to_string() const override;
101 virtual void add_to_menu(Menu& menu) const override;
102
103private:
104 int* const m_pointer;
105 const boost::optional<int> m_default_value;
106
107private:
108 IntObjectOption(const IntObjectOption&) = delete;
109 IntObjectOption& operator=(const IntObjectOption&) = delete;
110};
111
112class RectfObjectOption : public ObjectOption
113{
114public:
115 RectfObjectOption(const std::string& text, Rectf* pointer, const std::string& key,
116 unsigned int flags);
117
118 virtual void save(Writer& write) const override;
119 virtual std::string to_string() const override;
120 virtual void add_to_menu(Menu& menu) const override;
121
122private:
123 Rectf* const m_pointer;
124 float m_width;
125 float m_height;
126
127private:
128 RectfObjectOption(const RectfObjectOption&) = delete;
129 RectfObjectOption& operator=(const RectfObjectOption&) = delete;
130};
131
132class FloatObjectOption : public ObjectOption
133{
134public:
135 FloatObjectOption(const std::string& text, float* pointer, const std::string& key,
136 boost::optional<float> default_value,
137 unsigned int flags);
138
139 virtual void save(Writer& write) const override;
140 virtual std::string to_string() const override;
141 virtual void add_to_menu(Menu& menu) const override;
142
143private:
144 float* const m_pointer;
145 const boost::optional<float> m_default_value;
146
147private:
148 FloatObjectOption(const FloatObjectOption&) = delete;
149 FloatObjectOption& operator=(const FloatObjectOption&) = delete;
150};
151
152class StringObjectOption : public ObjectOption
153{
154public:
155 StringObjectOption(const std::string& text, std::string* pointer, const std::string& key,
156 boost::optional<std::string> default_value,
157 unsigned int flags);
158
159 virtual void save(Writer& write) const override;
160 virtual std::string to_string() const override;
161 virtual void add_to_menu(Menu& menu) const override;
162
163private:
164 std::string* const m_pointer;
165 boost::optional<std::string> m_default_value;
166
167private:
168 StringObjectOption(const StringObjectOption&) = delete;
169 StringObjectOption& operator=(const StringObjectOption&) = delete;
170};
171
172class StringSelectObjectOption : public ObjectOption
173{
174public:
175 StringSelectObjectOption(const std::string& text, int* pointer, const std::vector<std::string>& select,
176 boost::optional<int> default_value,
177 const std::string& key, unsigned int flags);
178
179 virtual void save(Writer& write) const override;
180 virtual std::string to_string() const override;
181 virtual void add_to_menu(Menu& menu) const override;
182
183private:
184 int* const m_pointer;
185 const std::vector<std::string> m_select;
186 const boost::optional<int> m_default_value;
187
188private:
189 StringSelectObjectOption(const StringSelectObjectOption&) = delete;
190 StringSelectObjectOption& operator=(const StringSelectObjectOption&) = delete;
191};
192
193class EnumObjectOption : public ObjectOption
194{
195public:
196 EnumObjectOption(const std::string& text, int* pointer,
197 const std::vector<std::string>& labels,
198 const std::vector<std::string>& symbols,
199 boost::optional<int> default_value,
200 const std::string& key, unsigned int flags);
201
202 virtual void save(Writer& write) const override;
203 virtual std::string to_string() const override;
204 virtual void add_to_menu(Menu& menu) const override;
205
206private:
207 int* const m_pointer;
208 const std::vector<std::string> m_labels;
209 const std::vector<std::string> m_symbols;
210 const boost::optional<int> m_default_value;
211
212private:
213 EnumObjectOption(const EnumObjectOption&) = delete;
214 EnumObjectOption& operator=(const EnumObjectOption&) = delete;
215};
216
217class ScriptObjectOption : public ObjectOption
218{
219public:
220 ScriptObjectOption(const std::string& text, std::string* pointer, const std::string& key,
221 unsigned int flags);
222
223 virtual void save(Writer& write) const override;
224 virtual std::string to_string() const override;
225 virtual void add_to_menu(Menu& menu) const override;
226
227private:
228 std::string* const m_pointer;
229
230private:
231 ScriptObjectOption(const ScriptObjectOption&) = delete;
232 ScriptObjectOption& operator=(const ScriptObjectOption&) = delete;
233};
234
235class FileObjectOption : public ObjectOption
236{
237public:
238 FileObjectOption(const std::string& text, std::string* pointer,
239 boost::optional<std::string> default_value,
240 const std::string& key,
241 std::vector<std::string> filter,
242 const std::string& basedir,
243 unsigned int flags);
244
245 virtual void save(Writer& write) const override;
246 virtual std::string to_string() const override;
247 virtual void add_to_menu(Menu& menu) const override;
248
249private:
250 std::string* const m_pointer;
251 boost::optional<std::string> m_default_value;
252 const std::vector<std::string> m_filter;
253 std::string m_basedir;
254
255private:
256 FileObjectOption(const FileObjectOption&) = delete;
257 FileObjectOption& operator=(const FileObjectOption&) = delete;
258};
259
260class ColorObjectOption : public ObjectOption
261{
262public:
263 ColorObjectOption(const std::string& text, Color* pointer, const std::string& key,
264 boost::optional<Color> default_value, bool use_alpha,
265 unsigned int flags);
266
267 virtual void save(Writer& write) const override;
268 virtual std::string to_string() const override;
269 virtual void add_to_menu(Menu& menu) const override;
270
271private:
272 Color* const m_pointer;
273 const boost::optional<Color> m_default_value;
274 bool m_use_alpha;
275
276private:
277 ColorObjectOption(const ColorObjectOption&) = delete;
278 ColorObjectOption& operator=(const ColorObjectOption&) = delete;
279};
280
281class BadGuySelectObjectOption : public ObjectOption
282{
283public:
284 BadGuySelectObjectOption(const std::string& text, std::vector<std::string>* pointer, const std::string& key,
285 unsigned int flags);
286
287 virtual void save(Writer& write) const override;
288 virtual std::string to_string() const override;
289 virtual void add_to_menu(Menu& menu) const override;
290
291private:
292 std::vector<std::string>* const m_pointer;
293
294private:
295 BadGuySelectObjectOption(const BadGuySelectObjectOption&) = delete;
296 BadGuySelectObjectOption& operator=(const BadGuySelectObjectOption&) = delete;
297};
298
299class TilesObjectOption : public ObjectOption
300{
301public:
302 TilesObjectOption(const std::string& text, TileMap* tilemap, const std::string& key,
303 unsigned int flags);
304
305 virtual void save(Writer& write) const override;
306 virtual std::string to_string() const override;
307 virtual void add_to_menu(Menu& menu) const override;
308
309private:
310 TileMap* m_tilemap;
311
312private:
313 TilesObjectOption(const TilesObjectOption&) = delete;
314 TilesObjectOption& operator=(const TilesObjectOption&) = delete;
315};
316
317class PathObjectOption : public ObjectOption
318{
319public:
320 PathObjectOption(const std::string& text, Path* path, const std::string& key,
321 unsigned int flags);
322
323 virtual void save(Writer& write) const override;
324 virtual std::string to_string() const override;
325 virtual void add_to_menu(Menu& menu) const override;
326
327private:
328 Path* m_path;
329
330private:
331 PathObjectOption(const PathObjectOption&) = delete;
332 PathObjectOption& operator=(const PathObjectOption&) = delete;
333};
334
335class PathRefObjectOption : public ObjectOption
336{
337public:
338 PathRefObjectOption(const std::string& text, const std::string& path_ref, const std::string& key,
339 unsigned int flags);
340
341 virtual void save(Writer& write) const override;
342 virtual std::string to_string() const override;
343 virtual void add_to_menu(Menu& menu) const override;
344
345private:
346 std::string m_path_ref;
347
348private:
349 PathRefObjectOption(const PathRefObjectOption&) = delete;
350 PathRefObjectOption& operator=(const PathRefObjectOption&) = delete;
351};
352
353class SExpObjectOption : public ObjectOption
354{
355public:
356 SExpObjectOption(const std::string& text, const std::string& key, sexp::Value& value, unsigned int flags);
357
358 virtual void save(Writer& write) const override;
359 virtual std::string to_string() const override;
360 virtual void add_to_menu(Menu& menu) const override;
361
362private:
363 sexp::Value m_sx;
364
365private:
366 SExpObjectOption(const SExpObjectOption&) = delete;
367 SExpObjectOption& operator=(const SExpObjectOption&) = delete;
368};
369
370class RemoveObjectOption : public ObjectOption
371{
372public:
373 RemoveObjectOption();
374
375 virtual void save(Writer& write) const override {}
376 virtual std::string to_string() const override;
377 virtual void add_to_menu(Menu& menu) const override;
378
379private:
380 RemoveObjectOption(const RemoveObjectOption&) = delete;
381 RemoveObjectOption& operator=(const RemoveObjectOption&) = delete;
382};
383
384#endif
385
386/* EOF */
387