1 | /**************************************************************************/ |
2 | /* navigation_region_2d.h */ |
3 | /**************************************************************************/ |
4 | /* This file is part of: */ |
5 | /* GODOT ENGINE */ |
6 | /* https://godotengine.org */ |
7 | /**************************************************************************/ |
8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
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 | |
31 | #ifndef NAVIGATION_REGION_2D_H |
32 | #define NAVIGATION_REGION_2D_H |
33 | |
34 | #include "scene/resources/navigation_polygon.h" |
35 | |
36 | class NavigationRegion2D : public Node2D { |
37 | GDCLASS(NavigationRegion2D, Node2D); |
38 | |
39 | bool enabled = true; |
40 | bool use_edge_connections = true; |
41 | |
42 | RID region; |
43 | RID map_override; |
44 | uint32_t navigation_layers = 1; |
45 | real_t enter_cost = 0.0; |
46 | real_t travel_cost = 1.0; |
47 | Ref<NavigationPolygon> navigation_polygon; |
48 | |
49 | bool constrain_avoidance = false; |
50 | LocalVector<RID> constrain_avoidance_obstacles; |
51 | uint32_t avoidance_layers = 1; |
52 | |
53 | Transform2D current_global_transform; |
54 | |
55 | void _navigation_polygon_changed(); |
56 | |
57 | #ifdef DEBUG_ENABLED |
58 | private: |
59 | void _update_debug_mesh(); |
60 | void _update_debug_edge_connections_mesh(); |
61 | void _navigation_map_changed(RID p_map); |
62 | #endif // DEBUG_ENABLED |
63 | |
64 | protected: |
65 | void _notification(int p_what); |
66 | void _validate_property(PropertyInfo &p_property) const; |
67 | static void _bind_methods(); |
68 | |
69 | #ifndef DISABLE_DEPRECATED |
70 | bool _set(const StringName &p_name, const Variant &p_value); |
71 | bool _get(const StringName &p_name, Variant &r_ret) const; |
72 | #endif // DISABLE_DEPRECATED |
73 | |
74 | public: |
75 | #ifdef TOOLS_ENABLED |
76 | virtual Rect2 _edit_get_rect() const override; |
77 | virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const override; |
78 | #endif |
79 | |
80 | void set_enabled(bool p_enabled); |
81 | bool is_enabled() const; |
82 | |
83 | void set_navigation_map(RID p_navigation_map); |
84 | RID get_navigation_map() const; |
85 | |
86 | void set_use_edge_connections(bool p_enabled); |
87 | bool get_use_edge_connections() const; |
88 | |
89 | void set_navigation_layers(uint32_t p_navigation_layers); |
90 | uint32_t get_navigation_layers() const; |
91 | |
92 | void set_navigation_layer_value(int p_layer_number, bool p_value); |
93 | bool get_navigation_layer_value(int p_layer_number) const; |
94 | |
95 | RID get_region_rid() const; |
96 | |
97 | void set_enter_cost(real_t p_enter_cost); |
98 | real_t get_enter_cost() const; |
99 | |
100 | void set_travel_cost(real_t p_travel_cost); |
101 | real_t get_travel_cost() const; |
102 | |
103 | void set_navigation_polygon(const Ref<NavigationPolygon> &p_navigation_polygon); |
104 | Ref<NavigationPolygon> get_navigation_polygon() const; |
105 | |
106 | void set_constrain_avoidance(bool p_enabled); |
107 | bool get_constrain_avoidance() const; |
108 | |
109 | void set_avoidance_layers(uint32_t p_layers); |
110 | uint32_t get_avoidance_layers() const; |
111 | |
112 | void set_avoidance_layer_value(int p_layer_number, bool p_value); |
113 | bool get_avoidance_layer_value(int p_layer_number) const; |
114 | |
115 | PackedStringArray get_configuration_warnings() const override; |
116 | |
117 | NavigationRegion2D(); |
118 | ~NavigationRegion2D(); |
119 | |
120 | private: |
121 | void _update_avoidance_constrain(); |
122 | void _region_enter_navigation_map(); |
123 | void _region_exit_navigation_map(); |
124 | void _region_update_transform(); |
125 | }; |
126 | |
127 | #endif // NAVIGATION_REGION_2D_H |
128 | |