TileMapLayer2D.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //
  2. // Copyright (c) 2008-2017 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "../Scene/Component.h"
  24. #include "../Atomic2D/TileMapDefs2D.h"
  25. #ifdef GetObject
  26. #undef GetObject
  27. #endif
  28. namespace Atomic
  29. {
  30. class DebugRenderer;
  31. class Node;
  32. class TileMap2D;
  33. class TmxImageLayer2D;
  34. class TmxLayer2D;
  35. class TmxObjectGroup2D;
  36. class TmxTileLayer2D;
  37. /// Tile map component.
  38. class ATOMIC_API TileMapLayer2D : public Component
  39. {
  40. ATOMIC_OBJECT(TileMapLayer2D, Component);
  41. public:
  42. /// Construct.
  43. TileMapLayer2D(Context* context);
  44. /// Destruct.
  45. ~TileMapLayer2D();
  46. /// Register object factory.
  47. static void RegisterObject(Context* context);
  48. /// Add debug geometry to the debug renderer.
  49. virtual void DrawDebugGeometry(DebugRenderer* debug, bool depthTest);
  50. /// Initialize with tile map and tmx layer.
  51. void Initialize(TileMap2D* tileMap, const TmxLayer2D* tmxLayer);
  52. /// Set draw order
  53. void SetDrawOrder(int drawOrder);
  54. /// Set visible.
  55. void SetVisible(bool visible);
  56. /// Return tile map.
  57. TileMap2D* GetTileMap() const;
  58. /// Return tmx layer.
  59. const TmxLayer2D* GetTmxLayer() const { return tmxLayer_; }
  60. /// Return draw order.
  61. int GetDrawOrder() const { return drawOrder_; }
  62. /// Return visible.
  63. bool IsVisible() const { return visible_; }
  64. /// Return has property
  65. bool HasProperty(const String& name) const;
  66. /// Return property.
  67. const String& GetProperty(const String& name) const;
  68. /// Return layer type.
  69. TileMapLayerType2D GetLayerType() const;
  70. /// Return width (for tile layer only).
  71. int GetWidth() const;
  72. /// Return height (for tile layer only).
  73. int GetHeight() const;
  74. /// Return tile node (for tile layer only).
  75. Node* GetTileNode(int x, int y) const;
  76. /// Return tile (for tile layer only).
  77. Tile2D* GetTile(int x, int y) const;
  78. /// Return number of tile map objects (for object group only).
  79. unsigned GetNumObjects() const;
  80. /// Return tile map object (for object group only).
  81. TileMapObject2D* GetObject(unsigned index) const;
  82. /// Return object node (for object group only).
  83. Node* GetObjectNode(unsigned index) const;
  84. /// Return image node (for image layer only).
  85. Node* GetImageNode() const;
  86. // ATOMIC BEGIN
  87. const String& GetName() const;
  88. // ATOMIC END
  89. private:
  90. /// Set tile layer.
  91. void SetTileLayer(const TmxTileLayer2D* tileLayer);
  92. /// Set object group.
  93. void SetObjectGroup(const TmxObjectGroup2D* objectGroup);
  94. /// Set image layer.
  95. void SetImageLayer(const TmxImageLayer2D* imageLayer);
  96. /// Tile map.
  97. WeakPtr<TileMap2D> tileMap_;
  98. /// Tmx layer.
  99. const TmxLayer2D* tmxLayer_;
  100. /// Tile layer.
  101. const TmxTileLayer2D* tileLayer_;
  102. /// Object group.
  103. const TmxObjectGroup2D* objectGroup_;
  104. /// Image layer.
  105. const TmxImageLayer2D* imageLayer_;
  106. /// Draw order.
  107. int drawOrder_;
  108. /// Visible.
  109. bool visible_;
  110. /// Tile node or image nodes.
  111. Vector<SharedPtr<Node> > nodes_;
  112. };
  113. }