navigation_polygon.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*************************************************************************/
  2. /* navigation_polygon.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef NAVIGATION_POLYGON_H
  31. #define NAVIGATION_POLYGON_H
  32. #include "scene/2d/node_2d.h"
  33. class NavigationPolygon : public Resource {
  34. GDCLASS(NavigationPolygon, Resource);
  35. PoolVector<Vector2> vertices;
  36. struct Polygon {
  37. Vector<int> indices;
  38. };
  39. Vector<Polygon> polygons;
  40. Vector<PoolVector<Vector2> > outlines;
  41. protected:
  42. static void _bind_methods();
  43. void _set_polygons(const Array &p_array);
  44. Array _get_polygons() const;
  45. void _set_outlines(const Array &p_array);
  46. Array _get_outlines() const;
  47. public:
  48. void set_vertices(const PoolVector<Vector2> &p_vertices);
  49. PoolVector<Vector2> get_vertices() const;
  50. void add_polygon(const Vector<int> &p_polygon);
  51. int get_polygon_count() const;
  52. void add_outline(const PoolVector<Vector2> &p_outline);
  53. void add_outline_at_index(const PoolVector<Vector2> &p_outline, int p_index);
  54. void set_outline(int p_idx, const PoolVector<Vector2> &p_outline);
  55. PoolVector<Vector2> get_outline(int p_idx) const;
  56. void remove_outline(int p_idx);
  57. int get_outline_count() const;
  58. void clear_outlines();
  59. void make_polygons_from_outlines();
  60. Vector<int> get_polygon(int p_idx);
  61. void clear_polygons();
  62. NavigationPolygon();
  63. };
  64. class Navigation2D;
  65. class NavigationPolygonInstance : public Node2D {
  66. GDCLASS(NavigationPolygonInstance, Node2D);
  67. bool enabled;
  68. int nav_id;
  69. Navigation2D *navigation;
  70. Ref<NavigationPolygon> navpoly;
  71. void _navpoly_changed();
  72. protected:
  73. void _notification(int p_what);
  74. static void _bind_methods();
  75. public:
  76. void set_enabled(bool p_enabled);
  77. bool is_enabled() const;
  78. void set_navigation_polygon(const Ref<NavigationPolygon> &p_navpoly);
  79. Ref<NavigationPolygon> get_navigation_polygon() const;
  80. String get_configuration_warning() const;
  81. NavigationPolygonInstance();
  82. };
  83. #endif // NAVIGATIONPOLYGON_H