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 33 #include "scene/2d/node_2d.h" 34 35 class NavigationPolygon : public Resource { 36 37 OBJ_TYPE(NavigationPolygon, Resource); 38 39 DVector<Vector2> vertices; 40 struct Polygon { 41 Vector<int> indices; 42 }; 43 Vector<Polygon> polygons; 44 Vector<DVector<Vector2> > outlines; 45 46 protected: 47 static void _bind_methods(); 48 49 void _set_polygons(const Array &p_array); 50 Array _get_polygons() const; 51 52 void _set_outlines(const Array &p_array); 53 Array _get_outlines() const; 54 55 public: 56 void set_vertices(const DVector<Vector2> &p_vertices); 57 DVector<Vector2> get_vertices() const; 58 59 void add_polygon(const Vector<int> &p_polygon); 60 int get_polygon_count() const; 61 62 void add_outline(const DVector<Vector2> &p_outline); 63 void add_outline_at_index(const DVector<Vector2> &p_outline, int p_index); 64 void set_outline(int p_idx, const DVector<Vector2> &p_outline); 65 DVector<Vector2> get_outline(int p_idx) const; 66 void remove_outline(int p_idx); 67 int get_outline_count() const; 68 69 void clear_outlines(); 70 void make_polygons_from_outlines(); 71 72 Vector<int> get_polygon(int p_idx); 73 void clear_polygons(); 74 75 NavigationPolygon(); 76 }; 77 78 class Navigation2D; 79 80 class NavigationPolygonInstance : public Node2D { 81 82 OBJ_TYPE(NavigationPolygonInstance, Node2D); 83 84 bool enabled; 85 int nav_id; 86 Navigation2D *navigation; 87 Ref<NavigationPolygon> navpoly; 88 89 void _navpoly_changed(); 90 91 protected: 92 void _notification(int p_what); 93 static void _bind_methods(); 94 95 public: 96 void set_enabled(bool p_enabled); 97 bool is_enabled() const; 98 99 void set_navigation_polygon(const Ref<NavigationPolygon> &p_navpoly); 100 Ref<NavigationPolygon> get_navigation_polygon() const; 101 102 String get_configuration_warning() const; 103 104 NavigationPolygonInstance(); 105 }; 106 107 #endif // NAVIGATIONPOLYGON_H 108