TileMapLayer2D.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //
  2. // Copyright (c) 2008-2014 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 "Component.h"
  24. #include "TileMapDefs2D.h"
  25. namespace Urho3D
  26. {
  27. class DebugRenderer;
  28. class Node;
  29. class TileMap2D;
  30. class TmxImageLayer2D;
  31. class TmxLayer2D;
  32. class TmxObjectGroup2D;
  33. class TmxTileLayer2D;
  34. /// Tile map component.
  35. class URHO3D_API TileMapLayer2D : public Component
  36. {
  37. OBJECT(TileMapLayer2D);
  38. public:
  39. /// Construct.
  40. TileMapLayer2D(Context* context);
  41. /// Destruct.
  42. ~TileMapLayer2D();
  43. /// Register object factory.
  44. static void RegisterObject(Context* context);
  45. /// Add debug geometry to the debug renderer.
  46. virtual void DrawDebugGeometry(DebugRenderer* debug, bool depthTest);
  47. /// Initialize with tile map and tmx layer.
  48. void Initialize(TileMap2D* tileMap, const TmxLayer2D* tmxLayer);
  49. /// Set draw order
  50. void SetDrawOrder(int drawOrder);
  51. /// Set visible.
  52. void SetVisible(bool visible);
  53. /// Return tile map.
  54. TileMap2D* GetTileMap() const;
  55. /// Return tmx layer.
  56. const TmxLayer2D* GetTmxLayer() const { return tmxLayer_; }
  57. /// Return draw order.
  58. int GetDrawOrder() const { return drawOrder_; }
  59. /// Return visible.
  60. bool IsVisible() const { return visible_; }
  61. /// Return has property
  62. bool HasProperty(const String& name) const;
  63. /// Return property.
  64. const String& GetProperty(const String& name) const;
  65. /// Return layer type.
  66. TileMapLayerType2D GetLayerType() const;
  67. /// Return width (for tile layer only).
  68. int GetWidth() const;
  69. /// Return height (for tile layer only).
  70. int GetHeight() const;
  71. /// Return tile node (for tile layer only).
  72. Node* GetTileNode(int x, int y) const;
  73. /// Return tile (for tile layer only).
  74. Tile2D* GetTile(int x, int y) const;
  75. /// Return number of tile map objects (for object group only).
  76. unsigned GetNumObjects() const;
  77. /// Return tile map object (for object group only).
  78. TileMapObject2D* GetObject(unsigned index) const;
  79. /// Return object node (for object group only).
  80. Node* GetObjectNode(unsigned index) const;
  81. /// Return image node (for image layer only).
  82. Node* GetImageNode() const;
  83. private:
  84. /// Set tile layer.
  85. void SetTileLayer(const TmxTileLayer2D* tileLayer);
  86. /// Set object group.
  87. void SetObjectGroup(const TmxObjectGroup2D* objectGroup);
  88. /// Set image layer.
  89. void SetImageLayer(const TmxImageLayer2D* imageLayer);
  90. /// Tile map.
  91. WeakPtr<TileMap2D> tileMap_;
  92. /// Tmx layer.
  93. const TmxLayer2D* tmxLayer_;
  94. /// Tile layer.
  95. const TmxTileLayer2D* tileLayer_;
  96. /// Object group.
  97. const TmxObjectGroup2D* objectGroup_;
  98. /// Image layer.
  99. const TmxImageLayer2D* imageLayer_;
  100. /// Draw order.
  101. int drawOrder_;
  102. /// Visible.
  103. bool visible_;
  104. /// Tile node or image nodes.
  105. Vector<SharedPtr<Node> > nodes_;
  106. };
  107. }