Mercurial > fife-parpg
comparison engine/core/model/structures/layer.h @ 356:ab41334e8a57
Added or1andov's code with a few adjustments to fix instance transparencies fixed[t:378]
Added layer transparency support
Added layer transparency to map editor
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Thu, 24 Sep 2009 18:24:47 +0000 |
parents | 7e5717105212 |
children | 16c2b3ee59ce |
comparison
equal
deleted
inserted
replaced
355:8b125ec749d7 | 356:ab41334e8a57 |
---|---|
49 | 49 |
50 /** Defines how pathing can be performed on this layer | 50 /** Defines how pathing can be performed on this layer |
51 * | 51 * |
52 * CELL_EDGES_ONLY allows pather to use only cell edges when moving instances from cell to cell on map | 52 * CELL_EDGES_ONLY allows pather to use only cell edges when moving instances from cell to cell on map |
53 * CELL_EDGES_AND_DIAGONALS allows pather to use both cell edges and diagonals when moving instances from cell to cell on map | 53 * CELL_EDGES_AND_DIAGONALS allows pather to use both cell edges and diagonals when moving instances from cell to cell on map |
54 * FREEFORM allows pather to find shortest route regardless of cellgrid used on the layer | 54 * FREEFORM allows pather to find shortest route regardless of cellgrid used on the layer |
55 */ | 55 */ |
56 enum PathingStrategy { | 56 enum PathingStrategy { |
57 CELL_EDGES_ONLY, | 57 CELL_EDGES_ONLY, |
58 CELL_EDGES_AND_DIAGONALS, | 58 CELL_EDGES_AND_DIAGONALS, |
59 FREEFORM | 59 FREEFORM |
60 }; | 60 }; |
61 | 61 |
62 /** Listener interface for changes happening on a layer | 62 /** Listener interface for changes happening on a layer |
63 */ | 63 */ |
64 class LayerChangeListener { | 64 class LayerChangeListener { |
65 public: | 65 public: |
66 virtual ~LayerChangeListener() {}; | 66 virtual ~LayerChangeListener() {}; |
67 | 67 |
68 /** Called when some instance is changed on layer. @see InstanceChangeType | 68 /** Called when some instance is changed on layer. @see InstanceChangeType |
69 * @param layer where change occurred | 69 * @param layer where change occurred |
70 * @param changedInstances list of instances containing some changes | 70 * @param changedInstances list of instances containing some changes |
71 * @note Does not report creations and deletions | 71 * @note Does not report creations and deletions |
72 */ | 72 */ |
73 virtual void onLayerChanged(Layer* layer, std::vector<Instance*>& changedInstances) = 0; | 73 virtual void onLayerChanged(Layer* layer, std::vector<Instance*>& changedInstances) = 0; |
74 | 74 |
75 /** Called when some instance gets created on layer | 75 /** Called when some instance gets created on layer |
76 * @param layer where change occurred | 76 * @param layer where change occurred |
77 * @param instance which got created | 77 * @param instance which got created |
78 */ | 78 */ |
79 virtual void onInstanceCreate(Layer* layer, Instance* instance) = 0; | 79 virtual void onInstanceCreate(Layer* layer, Instance* instance) = 0; |
80 | 80 |
81 /** Called when some instance gets deleted on layer | 81 /** Called when some instance gets deleted on layer |
82 * @param layer where change occurred | 82 * @param layer where change occurred |
83 * @param instance which will be deleted | 83 * @param instance which will be deleted |
84 * @note right after this call, instance actually gets deleted! | 84 * @note right after this call, instance actually gets deleted! |
85 */ | 85 */ |
86 virtual void onInstanceDelete(Layer* layer, Instance* instance) = 0; | 86 virtual void onInstanceDelete(Layer* layer, Instance* instance) = 0; |
87 }; | 87 }; |
88 | 88 |
89 | 89 |
90 /** A basic layer on a map | 90 /** A basic layer on a map |
91 */ | 91 */ |
92 class Layer : public ResourceClass { | 92 class Layer : public ResourceClass { |
93 public: | 93 public: |
94 /** Constructor | 94 /** Constructor |
120 | 120 |
121 /** Set the Cellgrid | 121 /** Set the Cellgrid |
122 */ | 122 */ |
123 void setCellGrid(CellGrid* grid) { m_grid = grid; } | 123 void setCellGrid(CellGrid* grid) { m_grid = grid; } |
124 | 124 |
125 /** Get the instance tree. | 125 /** Get the instance tree. |
126 * @return this layers instance tree. | 126 * @return this layers instance tree. |
127 */ | 127 */ |
128 InstanceTree* getInstanceTree(void) const { return m_instanceTree; } | 128 InstanceTree* getInstanceTree(void) const { return m_instanceTree; } |
129 | 129 |
130 /** Check existance of objects on this layer | 130 /** Check existance of objects on this layer |
137 Instance* createInstance(Object* object, const ModelCoordinate& p, const std::string& id=""); | 137 Instance* createInstance(Object* object, const ModelCoordinate& p, const std::string& id=""); |
138 | 138 |
139 /** Add an instance of an object at a specific position | 139 /** Add an instance of an object at a specific position |
140 */ | 140 */ |
141 Instance* createInstance(Object* object, const ExactModelCoordinate& p, const std::string& id=""); | 141 Instance* createInstance(Object* object, const ExactModelCoordinate& p, const std::string& id=""); |
142 | 142 |
143 /** Add a valid instance at a specific position. This is temporary. It will be moved to a higher level | 143 /** Add a valid instance at a specific position. This is temporary. It will be moved to a higher level |
144 later so that we can ensure that each Instance only lives in one layer. | 144 later so that we can ensure that each Instance only lives in one layer. |
145 */ | 145 */ |
146 bool addInstance(Instance* instance, const ExactModelCoordinate& p); | 146 bool addInstance(Instance* instance, const ExactModelCoordinate& p); |
147 | 147 |
148 /** Remove an instance from the layer | 148 /** Remove an instance from the layer |
149 */ | 149 */ |
150 void deleteInstance(Instance* object); | 150 void deleteInstance(Instance* object); |
151 | 151 |
152 /** Get the list of instances on this layer | 152 /** Get the list of instances on this layer |
168 Instance* getInstance(const std::string& identifier); | 168 Instance* getInstance(const std::string& identifier); |
169 | 169 |
170 /** Set object visibility | 170 /** Set object visibility |
171 */ | 171 */ |
172 void setInstancesVisible(bool vis); | 172 void setInstancesVisible(bool vis); |
173 | |
174 /** Sets the transparency of all instances on the layer. 0=opaque, 255=transparent | |
175 * @parm transparency Transparency value from 0-255. | |
176 */ | |
177 void setLayerTransparency(uint8_t transparency); | |
178 | |
179 /** Returns the layer's transparency value | |
180 */ | |
181 uint8_t getLayerTransparency(); | |
173 | 182 |
174 /** Retrieves the minimum/maximum coordinates of instances on the layer. | 183 /** Retrieves the minimum/maximum coordinates of instances on the layer. |
175 * @param min A reference to a ModelCoordinate that will hold the minimum coordinate. | 184 * @param min A reference to a ModelCoordinate that will hold the minimum coordinate. |
176 * @param max A reference to a ModelCoordinate that will hold the maximum coordinate. | 185 * @param max A reference to a ModelCoordinate that will hold the maximum coordinate. |
177 * @param layer A pointer to another layer that can be used to cast coordinates bettween layers. | 186 * @param layer A pointer to another layer that can be used to cast coordinates bettween layers. |
197 | 206 |
198 /** Called periodically to update events on layer | 207 /** Called periodically to update events on layer |
199 * @returns true if layer was changed since the last update, false otherwise | 208 * @returns true if layer was changed since the last update, false otherwise |
200 */ | 209 */ |
201 bool update(); | 210 bool update(); |
202 | 211 |
203 /** Sets pathing strategy for the layer | 212 /** Sets pathing strategy for the layer |
204 * @see PathingStrategy | 213 * @see PathingStrategy |
205 */ | 214 */ |
206 void setPathingStrategy(PathingStrategy strategy) { m_pathingstrategy = strategy; } | 215 void setPathingStrategy(PathingStrategy strategy) { m_pathingstrategy = strategy; } |
207 | 216 |
208 /** Gets pathing strategy for the layer | 217 /** Gets pathing strategy for the layer |
209 * @see PathingStrategy | 218 * @see PathingStrategy |
210 */ | 219 */ |
211 PathingStrategy getPathingStrategy() const { return m_pathingstrategy; } | 220 PathingStrategy getPathingStrategy() const { return m_pathingstrategy; } |
212 | 221 |
213 /** Adds new change listener | 222 /** Adds new change listener |
214 * @param listener to add | 223 * @param listener to add |
215 */ | 224 */ |
216 void addChangeListener(LayerChangeListener* listener); | 225 void addChangeListener(LayerChangeListener* listener); |
217 | 226 |
218 /** Removes associated change listener | 227 /** Removes associated change listener |
219 * @param listener to remove | 228 * @param listener to remove |
220 */ | 229 */ |
221 void removeChangeListener(LayerChangeListener* listener); | 230 void removeChangeListener(LayerChangeListener* listener); |
222 | 231 |
223 /** Returns true, if layer information was changed during previous update round | 232 /** Returns true, if layer information was changed during previous update round |
224 */ | 233 */ |
225 bool isChanged() { return m_changed; } | 234 bool isChanged() { return m_changed; } |
226 | 235 |
227 /** Returns instances that were changed during previous update round. | 236 /** Returns instances that were changed during previous update round. |
228 * @note does not contain created or deleted instances | 237 * @note does not contain created or deleted instances |
229 */ | 238 */ |
230 std::vector<Instance*>& getChangedInstances() { return m_changedinstances; } | 239 std::vector<Instance*>& getChangedInstances() { return m_changedinstances; } |
231 | 240 |
234 | 243 |
235 Map* m_map; | 244 Map* m_map; |
236 | 245 |
237 bool m_instances_visibility; | 246 bool m_instances_visibility; |
238 | 247 |
248 uint8_t m_transparency; | |
249 | |
239 // all the instances on this layer | 250 // all the instances on this layer |
240 std::vector<Instance*> m_instances; | 251 std::vector<Instance*> m_instances; |
241 | 252 |
242 //The instance tree | 253 //The instance tree |
243 InstanceTree* m_instanceTree; | 254 InstanceTree* m_instanceTree; |
244 | 255 |
245 // layer's cellgrid | 256 // layer's cellgrid |
246 CellGrid* m_grid; | 257 CellGrid* m_grid; |
247 | 258 |
248 // pathing strategy for the layer | 259 // pathing strategy for the layer |
249 PathingStrategy m_pathingstrategy; | 260 PathingStrategy m_pathingstrategy; |
250 | 261 |
251 // listeners for layer changes | 262 // listeners for layer changes |
252 std::vector<LayerChangeListener*> m_changelisteners; | 263 std::vector<LayerChangeListener*> m_changelisteners; |
253 | 264 |
254 // holds changed instances after each update | 265 // holds changed instances after each update |
255 std::vector<Instance*> m_changedinstances; | 266 std::vector<Instance*> m_changedinstances; |
256 | 267 |
257 // true if layer (or it's instance) information was changed during previous update round | 268 // true if layer (or it's instance) information was changed during previous update round |
258 bool m_changed; | 269 bool m_changed; |
259 }; | 270 }; |
260 | 271 |
261 } // FIFE | 272 } // FIFE |