1 /*
2  * Copyright (C) 2014-2018 Christopho, Solarus - http://www.solarus-games.org
3  *
4  * Solarus Quest Editor 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  * Solarus Quest Editor 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 along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 #include "entities/entity_traits.h"
18 #include <solarus/entities/EntityTypeInfo.h>
19 #include <QApplication>
20 
21 namespace SolarusEditor {
22 
23 /**
24  * @brief Returns all values.
25  * @return The existing values.
26  */
get_values()27 QList<EntityType> EnumTraits<EntityType>::get_values() {
28 
29   return QList<EntityType>::fromStdList(
30       Solarus::EnumInfo<EntityType>::enums()
31   );
32 }
33 
34 /**
35  * @brief Returns a user-friendly name describing a value.
36  * @param value A value.
37  * @return The human-readable name of this value in the current language.
38  */
get_friendly_name(EntityType value)39 QString EnumTraits<EntityType>::get_friendly_name(EntityType value) {
40 
41   // Use a switch to ensure we don't forget a value,
42   // and also to translate names dynamically.
43   switch (value) {
44 
45   case EntityType::ARROW:
46     return QApplication::tr("Arrow");
47 
48   case EntityType::BLOCK:
49     return QApplication::tr("Block");
50 
51   case EntityType::BOMB:
52     return QApplication::tr("Bomb");
53 
54   case EntityType::BOOMERANG:
55     return QApplication::tr("Boomerang");
56 
57   case EntityType::CAMERA:
58     return QApplication::tr("Camera");
59 
60   case EntityType::CARRIED_OBJECT:
61     return QApplication::tr("Carried object");
62 
63   case EntityType::CHEST:
64     return QApplication::tr("Chest");
65 
66   case EntityType::CRYSTAL:
67     return QApplication::tr("Crystal");
68 
69   case EntityType::CRYSTAL_BLOCK:
70     return QApplication::tr("Crystal block");
71 
72   case EntityType::CUSTOM:
73     return QApplication::tr("Custom entity");
74 
75   case EntityType::DESTINATION:
76     return QApplication::tr("Destination");
77 
78   case EntityType::DESTRUCTIBLE:
79     return QApplication::tr("Destructible object");
80 
81   case EntityType::DOOR:
82     return QApplication::tr("Door");
83 
84   case EntityType::DYNAMIC_TILE:
85     return QApplication::tr("Dynamic tile");
86 
87   case EntityType::ENEMY:
88     return QApplication::tr("Enemy");
89 
90   case EntityType::EXPLOSION:
91     return QApplication::tr("Explosion");
92 
93   case EntityType::FIRE:
94     return QApplication::tr("Fire");
95 
96   case EntityType::HERO:
97     return QApplication::tr("Hero");
98 
99   case EntityType::HOOKSHOT:
100     return QApplication::tr("Hookshot");
101 
102   case EntityType::JUMPER:
103     return QApplication::tr("Jumper");
104 
105   case EntityType::NPC:
106     return QApplication::tr("NPC");
107 
108   case EntityType::PICKABLE:
109     return QApplication::tr("Pickable treasure");
110 
111   case EntityType::SENSOR:
112     return QApplication::tr("Sensor");
113 
114   case EntityType::SEPARATOR:
115     return QApplication::tr("Separator");
116 
117   case EntityType::SHOP_TREASURE:
118     return QApplication::tr("Shop treasure");
119 
120   case EntityType::STAIRS:
121     return QApplication::tr("Stairs");
122 
123   case EntityType::STREAM:
124     return QApplication::tr("Stream");
125 
126   case EntityType::SWITCH:
127     return QApplication::tr("Switch");
128 
129   case EntityType::TELETRANSPORTER:
130     return QApplication::tr("Teletransporter");
131 
132   case EntityType::TILE:
133     return QApplication::tr("Tile");
134 
135   case EntityType::WALL:
136     return QApplication::tr("Wall");
137 
138   }
139 
140   return "";
141 }
142 
143 /**
144  * @brief Returns an icon representing a value.
145  * @param value A value.
146  * @return The corresponding icon.
147  */
get_icon(EntityType value)148 QIcon EnumTraits<EntityType>::get_icon(EntityType value) {
149   return QIcon(":/images/entity_" + get_lua_name(value) + ".png");
150 }
151 
152 /**
153  * @brief Returns the Lua name of a value.
154  * @param value A value.
155  * @return The corresponding Lua name.
156  */
get_lua_name(EntityType value)157 QString EnumTraits<EntityType>::get_lua_name(EntityType value) {
158   return QString::fromStdString(Solarus::enum_to_name(value));
159 }
160 
161 /**
162  * @brief Returns whether entities of the specified type can be stored in map files.
163  * @param type A type of entity.
164  * @return @c true if this type can be stored.
165  */
can_be_stored_in_map_file(EntityType type)166 bool EnumTraits<EntityType>::can_be_stored_in_map_file(EntityType type) {
167 
168   return Solarus::EntityTypeInfo::can_be_stored_in_map_file(type);
169 }
170 
171 /**
172  * @brief Returns the keyboard shortcut to show or hide entities to a type.
173  * @param type A type of entity.
174  * @return The keyboard shortcut to use.
175  */
get_show_hide_shortcut(EntityType type)176 QString EnumTraits<EntityType>::get_show_hide_shortcut(EntityType type) {
177 
178   // Use a switch to ensure we don't forget a value,
179   // and also to translate names dynamically.
180   switch (type) {
181 
182   case EntityType::ARROW:
183   case EntityType::BOMB:
184   case EntityType::BOOMERANG:
185   case EntityType::CAMERA:
186   case EntityType::CARRIED_OBJECT:
187   case EntityType::EXPLOSION:
188   case EntityType::HERO:
189   case EntityType::HOOKSHOT:
190   case EntityType::FIRE:
191     return QString();
192 
193   case EntityType::BLOCK:
194     return QApplication::tr("Ctrl+E,Ctrl+B");
195 
196   case EntityType::CHEST:
197     return QApplication::tr("Ctrl+E,Ctrl+C");
198 
199   case EntityType::CRYSTAL:
200     return QApplication::tr("Ctrl+E,Ctrl+L");
201 
202   case EntityType::CRYSTAL_BLOCK:
203     return QApplication::tr("Ctrl+E,Ctrl+K");
204 
205   case EntityType::CUSTOM:
206     return QApplication::tr("Ctrl+E,Ctrl+Y");
207 
208   case EntityType::DESTINATION:
209     return QApplication::tr("Ctrl+E,Ctrl+I");
210 
211   case EntityType::DESTRUCTIBLE:
212     return QApplication::tr("Ctrl+E,Ctrl+D");
213 
214   case EntityType::DOOR:
215     return QApplication::tr("Ctrl+E,Ctrl+O");
216 
217   case EntityType::DYNAMIC_TILE:
218     return QApplication::tr("Ctrl+E,Ctrl+2");
219 
220   case EntityType::ENEMY:
221     return QApplication::tr("Ctrl+E,Ctrl+E");
222 
223   case EntityType::JUMPER:
224     return QApplication::tr("Ctrl+E,Ctrl+J");
225 
226   case EntityType::NPC:
227     return QApplication::tr("Ctrl+E,Ctrl+N");
228 
229   case EntityType::PICKABLE:
230     return QApplication::tr("Ctrl+E,Ctrl+P");
231 
232   case EntityType::SENSOR:
233     return QApplication::tr("Ctrl+E,Ctrl+S");
234 
235   case EntityType::SEPARATOR:
236     return QApplication::tr("Ctrl+E,Ctrl+A");
237 
238   case EntityType::SHOP_TREASURE:
239     return QApplication::tr("Ctrl+E,Ctrl+U");
240 
241   case EntityType::STAIRS:
242     return QApplication::tr("Ctrl+E,Ctrl+R");
243 
244   case EntityType::STREAM:
245     return QApplication::tr("Ctrl+E,Ctrl+M");
246 
247   case EntityType::SWITCH:
248     return QApplication::tr("Ctrl+E,Ctrl+H");
249 
250   case EntityType::TELETRANSPORTER:
251     return QApplication::tr("Ctrl+E,Ctrl+T");
252 
253   case EntityType::TILE:
254     return QApplication::tr("Ctrl+E,Ctrl+1");
255 
256   case EntityType::WALL:
257     return QApplication::tr("Ctrl+E,Ctrl+W");
258 
259   }
260 
261   return "";
262 }
263 
264 }
265