navigation_polygon.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*************************************************************************/
  2. /* navigation_polygon.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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. mutable Rect2 item_rect;
  42. mutable bool rect_cache_dirty;
  43. protected:
  44. static void _bind_methods();
  45. void _set_polygons(const Array &p_array);
  46. Array _get_polygons() const;
  47. void _set_outlines(const Array &p_array);
  48. Array _get_outlines() const;
  49. public:
  50. Rect2 _edit_get_rect() const;
  51. bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const;
  52. void set_vertices(const PoolVector<Vector2> &p_vertices);
  53. PoolVector<Vector2> get_vertices() const;
  54. void add_polygon(const Vector<int> &p_polygon);
  55. int get_polygon_count() const;
  56. void add_outline(const PoolVector<Vector2> &p_outline);
  57. void add_outline_at_index(const PoolVector<Vector2> &p_outline, int p_index);
  58. void set_outline(int p_idx, const PoolVector<Vector2> &p_outline);
  59. PoolVector<Vector2> get_outline(int p_idx) const;
  60. void remove_outline(int p_idx);
  61. int get_outline_count() const;
  62. void clear_outlines();
  63. void make_polygons_from_outlines();
  64. Vector<int> get_polygon(int p_idx);
  65. void clear_polygons();
  66. NavigationPolygon();
  67. };
  68. class Navigation2D;
  69. class NavigationPolygonInstance : public Node2D {
  70. GDCLASS(NavigationPolygonInstance, Node2D);
  71. bool enabled;
  72. int nav_id;
  73. Navigation2D *navigation;
  74. Ref<NavigationPolygon> navpoly;
  75. void _navpoly_changed();
  76. protected:
  77. void _notification(int p_what);
  78. static void _bind_methods();
  79. public:
  80. virtual Rect2 _edit_get_rect() const;
  81. virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const;
  82. void set_enabled(bool p_enabled);
  83. bool is_enabled() const;
  84. void set_navigation_polygon(const Ref<NavigationPolygon> &p_navpoly);
  85. Ref<NavigationPolygon> get_navigation_polygon() const;
  86. String get_configuration_warning() const;
  87. NavigationPolygonInstance();
  88. };
  89. #endif // NAVIGATIONPOLYGON_H