ScummVM API documentation
item.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef STARK_RESOURCES_ITEM_H
23 #define STARK_RESOURCES_ITEM_H
24 
25 #include "engines/stark/resources/object.h"
26 #include "engines/stark/resourcereference.h"
27 
28 #include "common/rect.h"
29 #include "common/str.h"
30 
31 #include "math/vector3d.h"
32 
33 namespace Stark {
34 
35 class AnimHandler;
36 class Movement;
37 class Visual;
38 
39 namespace Gfx {
40 class RenderEntry;
41 }
42 
43 namespace Formats {
44 class XRCReadStream;
45 }
46 
47 namespace Resources {
48 
49 class Anim;
50 class AnimHierarchy;
51 class BonesMesh;
52 class Bookmark;
53 class ItemVisual;
54 class Script;
55 class TextureSet;
56 
62 class Item : public Object {
63 public:
64  static const Type::ResourceType TYPE = Type::kItem;
65 
66  enum SubType {
67  kItemGlobalTemplate = 1,
68  kItemInventory = 2,
69  kItemLevelTemplate = 3,
70  kItemStaticProp = 5,
71  kItemAnimatedProp = 6,
72  kItemBackgroundElement = 7,
73  kItemBackground = 8,
74  kItemModel = 10
75  };
76 
78  static Object *construct(Object *parent, byte subType, uint16 index, const Common::String &name);
79 
80  Item(Object *parent, byte subType, uint16 index, const Common::String &name);
81  virtual ~Item();
82 
83  // Resource API
84  void readData(Formats::XRCReadStream *stream) override;
85  void onGameLoop() override;
86  void saveLoad(ResourceSerializer *serializer) override;
87  void saveLoadCurrent(ResourceSerializer *serializer) override;
88 
90  bool isEnabled() const;
91 
93  virtual void setEnabled(bool enabled);
94 
96  int32 getCharacterIndex() const;
97 
99  virtual Gfx::RenderEntry *getRenderEntry(const Common::Point &positionOffset);
100 
102  virtual ItemVisual *getSceneInstance() = 0;
103 
105  void setMovement(Movement *movement);
106 
108  Movement *getMovement() const;
109 
116  void setMovementSuspendedScript(Script *script);
117 
119  virtual void setAnimHierarchy(AnimHierarchy *animHierarchy) = 0;
120 
122  virtual Common::Array<Common::Point> listExitPositions();
123 
124 protected:
125  void printData() override;
126 
127  bool _enabled;
128  int32 _characterIndex;
129 
130  Movement *_movement;
131  Script *_movementSuspendedScript;
132 };
133 
139 class ItemVisual : public Item {
140 public:
141  ItemVisual(Object *parent, byte subType, uint16 index, const Common::String &name);
142  virtual ~ItemVisual();
143 
144  // Resource API
145  void readData(Formats::XRCReadStream *stream) override;
146  void onAllLoaded() override;
147  void saveLoad(ResourceSerializer *serializer) override;
148  void saveLoadCurrent(ResourceSerializer *serializer) override;
149 
150  // Item API
151  void setEnabled(bool enabled) override;
152  ItemVisual *getSceneInstance() override;
153  void setAnimHierarchy(AnimHierarchy *animHierarchy) override;
154 
160  virtual void setPosition2D(const Common::Point &position);
161 
163  int getHotspotIndexForPoint(const Common::Point &point);
164 
166  Common::String getHotspotTitle(uint32 hotspotIndex);
167 
169  bool canPerformAction(uint32 action, uint32 hotspotIndex);
170 
172  bool doAction(uint32 action, uint32 hotspotIndex);
173 
175  void setAnimActivity(int32 activity);
176 
178  int32 getAnimActivity() const;
179 
181  Anim *getAnim() const;
182 
184  Anim *getActionAnim() const;
185 
187  void playActionAnim(Anim *anim);
188 
190  void resetActionAnim();
191 
192 protected:
193  // Resource API
194  void printData() override;
195 
197  Common::Array<Common::Point> listExitPositionsImpl();
198 
199  Visual *getVisual();
200 
201  Gfx::RenderEntry *_renderEntry;
202 
203  Anim *_actionAnim;
204  AnimHierarchy *_animHierarchy;
205  int32 _currentAnimActivity;
206  bool _clickable;
207 };
208 
214 class ItemTemplate : public Item {
215 public:
216  ItemTemplate(Object *parent, byte subType, uint16 index, const Common::String &name);
217  virtual ~ItemTemplate();
218 
219  // Resource API
220  void onAllLoaded() override;
221  void onEnterLocation() override;
222  void saveLoadCurrent(ResourceSerializer *serializer) override;
223 
224  // Item API
225  ItemVisual *getSceneInstance() override;
226  void setAnimHierarchy(AnimHierarchy *animHierarchy) override;
227 
229  virtual BonesMesh *findBonesMesh() = 0;
230 
232  virtual TextureSet *findTextureSet(uint32 textureType) = 0;
233 
235  virtual AnimHierarchy *findStockAnimHierarchy() = 0;
236 
238  void setStockAnimHierachy(AnimHierarchy *animHierarchy);
239 
241  void setBonesMesh(int32 index);
242 
244  void setTexture(int32 index, uint32 textureType);
245 
247  void setInstanciatedItem(Item *instance);
248 
249 protected:
250  int32 _meshIndex;
251  int32 _textureNormalIndex;
252  int32 _textureFaceIndex;
253  int32 _animHierarchyIndex;
254 
255  Item *_instanciatedItem;
256  ItemTemplate *_referencedItem;
257 };
258 
265 public:
266  GlobalItemTemplate(Object *parent, byte subType, uint16 index, const Common::String &name);
267  virtual ~GlobalItemTemplate();
268 
269  // ItemTemplate API
270  BonesMesh *findBonesMesh() override;
271  TextureSet *findTextureSet(uint32 textureType) override;
272  AnimHierarchy *findStockAnimHierarchy() override;
273 
274 protected:
275 };
276 
280 class InventoryItem : public ItemVisual {
281 public:
282  InventoryItem(Object *parent, byte subType, uint16 index, const Common::String &name);
283  virtual ~InventoryItem();
284 
285  // Item API
286  Gfx::RenderEntry *getRenderEntry(const Common::Point &positionOffset) override;
287  void setEnabled(bool enabled) override;
288 
290  Visual *getActionVisual(bool active) const;
291 
293  Visual *getCursorVisual() const;
294 
295 protected:
296 };
297 
305 public:
306  LevelItemTemplate(Object *parent, byte subType, uint16 index, const Common::String &name);
307  virtual ~LevelItemTemplate();
308 
309  // Resource API
310  void readData(Formats::XRCReadStream *stream) override;
311  void onAllLoaded() override;
312 
313  // ItemTemplate API
314  BonesMesh *findBonesMesh() override;
315  TextureSet *findTextureSet(uint32 textureType) override;
316  AnimHierarchy *findStockAnimHierarchy() override;
317 
319  ItemTemplate *getItemTemplate() const;
320 
321 protected:
322  void printData() override;
323 
324  ResourceReference _reference;
325 };
326 
334 public:
335  FloorPositionedItem(Object *parent, byte subType, uint16 index, const Common::String &name);
336  virtual ~FloorPositionedItem();
337 
338  // Object API
339  void saveLoad(ResourceSerializer *serializer) override;
340 
342  void placeOnBookmark(Bookmark *target);
343 
345  void placeDefaultPosition();
346 
348  Math::Vector3d getPosition3D() const;
350  void setPosition3D(const Math::Vector3d &position);
351 
353  int32 getFloorFaceIndex() const;
355  void setFloorFaceIndex(int32 faceIndex);
356 
358  Math::Vector3d getDirectionVector() const;
359 
361  void setDirection(const Math::Angle &direction);
362 
364  float getSortKey() const;
365 
371  void overrideSortKey(float sortKey);
372 
373 protected:
374  int32 _floorFaceIndex;
375  Math::Vector3d _position3D;
376  float _direction3D;
377 
378  bool _sortKeyOverride;
379  float _sortKeyOverridenValue;
380 };
381 
388 public:
389  FloorPositionedImageItem(Object *parent, byte subType, uint16 index, const Common::String &name);
390  virtual ~FloorPositionedImageItem();
391 
392  // Resource API
393  void readData(Formats::XRCReadStream *stream) override;
394 
395  // Item API
396  Gfx::RenderEntry *getRenderEntry(const Common::Point &positionOffset) override;
397  Common::Array<Common::Point> listExitPositions() override;
398 
399  // ItemVisual API
400  void setPosition2D(const Common::Point &position) override;
401 
402 protected:
403  void printData() override;
404 
405  Common::Point _position;
406 };
407 
414 public:
415  ModelItem(Object *parent, byte subType, uint16 index, const Common::String &name);
416  virtual ~ModelItem();
417 
418  // Resource API
419  void readData(Formats::XRCReadStream *stream) override;
420  void onAllLoaded() override;
421  void onEnterLocation() override;
422  void onExitLocation() override;
423  void saveLoadCurrent(ResourceSerializer *serializer) override;
424 
425  // Item API
426  Gfx::RenderEntry *getRenderEntry(const Common::Point &positionOffset) override;
427 
429  void setTexture(int32 index, uint32 textureType);
430 
432  void setBonesMesh(int32 index);
433 
435  BonesMesh *findBonesMesh();
436 
438  TextureSet *findTextureSet(uint32 textureType);
439 
441  ItemTemplate *getItemTemplate() const;
442 
444  void updateAnim();
445 
447  void resetAnimationBlending();
448 
450  Anim *getIdleActionAnim() const;
451 
452  AnimHandler *getAnimHandler() const;
453 
454 protected:
455  void printData() override;
456 
457  int32 _meshIndex;
458  int32 _textureNormalIndex;
459  int32 _textureFaceIndex;
460 
461  ResourceReference _reference;
462  ItemTemplate *_referencedItem;
463 
464  AnimHandler *_animHandler;
465 };
466 
472 class ImageItem : public ItemVisual {
473 public:
474  ImageItem(Object *parent, byte subType, uint16 index, const Common::String &name);
475  virtual ~ImageItem();
476 
477  // Resource API
478  void readData(Formats::XRCReadStream *stream) override;
479 
480  // Item API
481  Gfx::RenderEntry *getRenderEntry(const Common::Point &positionOffset) override;
482  Common::Array<Common::Point> listExitPositions() override;
483 
484  // ItemVisual API
485  void setPosition2D(const Common::Point &position) override;
486 
487 protected:
488  void printData() override;
489 
490  ResourceReference _reference;
491  Common::Point _position;
492 };
493 
494 } // End of namespace Resources
495 } // End of namespace Stark
496 
497 #endif // STARK_RESOURCES_ITEM_H
Definition: str.h:59
Definition: visual.h:29
Definition: animhandler.h:36
Definition: animhierarchy.h:51
Definition: item.h:413
Definition: item.h:280
Definition: item.h:62
Definition: anim.h:58
Definition: item.h:139
Definition: item.h:472
Definition: resourcereference.h:39
Definition: console.h:27
Definition: object.h:143
Definition: textureset.h:47
Definition: rect.h:45
Definition: movement.h:38
Definition: bonesmesh.h:43
Movement
Definition: walking.h:85
Definition: item.h:214
Definition: bookmark.h:44
Definition: xrc.h:45
Definition: renderentry.h:67
Definition: stateprovider.h:51
Definition: script.h:45