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 |
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 | |
29 | enum 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 | |
38 | namespace sexp { |
39 | class Value; |
40 | } // namespace sexp |
41 | class Color; |
42 | class ; |
43 | class Path; |
44 | class Rectf; |
45 | class TileMap; |
46 | class Writer; |
47 | |
48 | class ObjectOption |
49 | { |
50 | public: |
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 (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 | |
62 | private: |
63 | const std::string m_text; |
64 | const std::string m_key; |
65 | const unsigned int m_flags; |
66 | |
67 | private: |
68 | ObjectOption(const ObjectOption&) = delete; |
69 | ObjectOption& operator=(const ObjectOption&) = delete; |
70 | }; |
71 | |
72 | class BoolObjectOption : public ObjectOption |
73 | { |
74 | public: |
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 (Menu& ) const override; |
82 | |
83 | private: |
84 | bool* const m_pointer; |
85 | const boost::optional<bool> m_default_value; |
86 | |
87 | private: |
88 | BoolObjectOption(const BoolObjectOption&) = delete; |
89 | BoolObjectOption& operator=(const BoolObjectOption&) = delete; |
90 | }; |
91 | |
92 | class IntObjectOption : public ObjectOption |
93 | { |
94 | public: |
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 (Menu& ) const override; |
102 | |
103 | private: |
104 | int* const m_pointer; |
105 | const boost::optional<int> m_default_value; |
106 | |
107 | private: |
108 | IntObjectOption(const IntObjectOption&) = delete; |
109 | IntObjectOption& operator=(const IntObjectOption&) = delete; |
110 | }; |
111 | |
112 | class RectfObjectOption : public ObjectOption |
113 | { |
114 | public: |
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 (Menu& ) const override; |
121 | |
122 | private: |
123 | Rectf* const m_pointer; |
124 | float m_width; |
125 | float m_height; |
126 | |
127 | private: |
128 | RectfObjectOption(const RectfObjectOption&) = delete; |
129 | RectfObjectOption& operator=(const RectfObjectOption&) = delete; |
130 | }; |
131 | |
132 | class FloatObjectOption : public ObjectOption |
133 | { |
134 | public: |
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 (Menu& ) const override; |
142 | |
143 | private: |
144 | float* const m_pointer; |
145 | const boost::optional<float> m_default_value; |
146 | |
147 | private: |
148 | FloatObjectOption(const FloatObjectOption&) = delete; |
149 | FloatObjectOption& operator=(const FloatObjectOption&) = delete; |
150 | }; |
151 | |
152 | class StringObjectOption : public ObjectOption |
153 | { |
154 | public: |
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 (Menu& ) const override; |
162 | |
163 | private: |
164 | std::string* const m_pointer; |
165 | boost::optional<std::string> m_default_value; |
166 | |
167 | private: |
168 | StringObjectOption(const StringObjectOption&) = delete; |
169 | StringObjectOption& operator=(const StringObjectOption&) = delete; |
170 | }; |
171 | |
172 | class StringSelectObjectOption : public ObjectOption |
173 | { |
174 | public: |
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 (Menu& ) const override; |
182 | |
183 | private: |
184 | int* const m_pointer; |
185 | const std::vector<std::string> m_select; |
186 | const boost::optional<int> m_default_value; |
187 | |
188 | private: |
189 | StringSelectObjectOption(const StringSelectObjectOption&) = delete; |
190 | StringSelectObjectOption& operator=(const StringSelectObjectOption&) = delete; |
191 | }; |
192 | |
193 | class EnumObjectOption : public ObjectOption |
194 | { |
195 | public: |
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 (Menu& ) const override; |
205 | |
206 | private: |
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 | |
212 | private: |
213 | EnumObjectOption(const EnumObjectOption&) = delete; |
214 | EnumObjectOption& operator=(const EnumObjectOption&) = delete; |
215 | }; |
216 | |
217 | class ScriptObjectOption : public ObjectOption |
218 | { |
219 | public: |
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 (Menu& ) const override; |
226 | |
227 | private: |
228 | std::string* const m_pointer; |
229 | |
230 | private: |
231 | ScriptObjectOption(const ScriptObjectOption&) = delete; |
232 | ScriptObjectOption& operator=(const ScriptObjectOption&) = delete; |
233 | }; |
234 | |
235 | class FileObjectOption : public ObjectOption |
236 | { |
237 | public: |
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 (Menu& ) const override; |
248 | |
249 | private: |
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 | |
255 | private: |
256 | FileObjectOption(const FileObjectOption&) = delete; |
257 | FileObjectOption& operator=(const FileObjectOption&) = delete; |
258 | }; |
259 | |
260 | class ColorObjectOption : public ObjectOption |
261 | { |
262 | public: |
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 (Menu& ) const override; |
270 | |
271 | private: |
272 | Color* const m_pointer; |
273 | const boost::optional<Color> m_default_value; |
274 | bool m_use_alpha; |
275 | |
276 | private: |
277 | ColorObjectOption(const ColorObjectOption&) = delete; |
278 | ColorObjectOption& operator=(const ColorObjectOption&) = delete; |
279 | }; |
280 | |
281 | class BadGuySelectObjectOption : public ObjectOption |
282 | { |
283 | public: |
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 (Menu& ) const override; |
290 | |
291 | private: |
292 | std::vector<std::string>* const m_pointer; |
293 | |
294 | private: |
295 | BadGuySelectObjectOption(const BadGuySelectObjectOption&) = delete; |
296 | BadGuySelectObjectOption& operator=(const BadGuySelectObjectOption&) = delete; |
297 | }; |
298 | |
299 | class TilesObjectOption : public ObjectOption |
300 | { |
301 | public: |
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 (Menu& ) const override; |
308 | |
309 | private: |
310 | TileMap* m_tilemap; |
311 | |
312 | private: |
313 | TilesObjectOption(const TilesObjectOption&) = delete; |
314 | TilesObjectOption& operator=(const TilesObjectOption&) = delete; |
315 | }; |
316 | |
317 | class PathObjectOption : public ObjectOption |
318 | { |
319 | public: |
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 (Menu& ) const override; |
326 | |
327 | private: |
328 | Path* m_path; |
329 | |
330 | private: |
331 | PathObjectOption(const PathObjectOption&) = delete; |
332 | PathObjectOption& operator=(const PathObjectOption&) = delete; |
333 | }; |
334 | |
335 | class PathRefObjectOption : public ObjectOption |
336 | { |
337 | public: |
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 (Menu& ) const override; |
344 | |
345 | private: |
346 | std::string m_path_ref; |
347 | |
348 | private: |
349 | PathRefObjectOption(const PathRefObjectOption&) = delete; |
350 | PathRefObjectOption& operator=(const PathRefObjectOption&) = delete; |
351 | }; |
352 | |
353 | class SExpObjectOption : public ObjectOption |
354 | { |
355 | public: |
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 (Menu& ) const override; |
361 | |
362 | private: |
363 | sexp::Value m_sx; |
364 | |
365 | private: |
366 | SExpObjectOption(const SExpObjectOption&) = delete; |
367 | SExpObjectOption& operator=(const SExpObjectOption&) = delete; |
368 | }; |
369 | |
370 | class RemoveObjectOption : public ObjectOption |
371 | { |
372 | public: |
373 | RemoveObjectOption(); |
374 | |
375 | virtual void save(Writer& write) const override {} |
376 | virtual std::string to_string() const override; |
377 | virtual void (Menu& ) const override; |
378 | |
379 | private: |
380 | RemoveObjectOption(const RemoveObjectOption&) = delete; |
381 | RemoveObjectOption& operator=(const RemoveObjectOption&) = delete; |
382 | }; |
383 | |
384 | #endif |
385 | |
386 | /* EOF */ |
387 | |