Skip to content
0.2.0-dev Download ZIP
110 lines ·4.4 KB Raw
1/**************************************************************************/
2/* navigation_link_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#pragma once
32
33#include "scene/2d/node_2d.h"
34
35class NavigationLink2D : public Node2D {
36 GDCLASS(NavigationLink2D, Node2D);
37
38 bool enabled = true;
39 RID link;
40 RID map_override;
41 bool bidirectional = true;
42 uint32_t navigation_layers = 1;
43 Vector2 end_position;
44 Vector2 start_position;
45 real_t enter_cost = 0.0;
46 real_t travel_cost = 1.0;
47
48#ifdef DEBUG_ENABLED
49 void _update_debug_mesh();
50#endif // DEBUG_ENABLED
51
52protected:
53 static void _bind_methods();
54 void _notification(int p_what);
55
56#ifndef DISABLE_DEPRECATED
57 bool _set(const StringName &p_name, const Variant &p_value);
58 bool _get(const StringName &p_name, Variant &r_ret) const;
59#endif // DISABLE_DEPRECATED
60
61public:
62#ifdef DEBUG_ENABLED
63 virtual Rect2 _edit_get_rect() const override;
64 virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const override;
65#endif // DEBUG_ENABLED
66 RID get_rid() const;
67
68 void set_enabled(bool p_enabled);
69 bool is_enabled() const { return enabled; }
70
71 void set_navigation_map(RID p_navigation_map);
72 RID get_navigation_map() const;
73
74 void set_bidirectional(bool p_bidirectional);
75 bool is_bidirectional() const { return bidirectional; }
76
77 void set_navigation_layers(uint32_t p_navigation_layers);
78 uint32_t get_navigation_layers() const { return navigation_layers; }
79
80 void set_navigation_layer_value(int p_layer_number, bool p_value);
81 bool get_navigation_layer_value(int p_layer_number) const;
82
83 void set_start_position(Vector2 p_position);
84 Vector2 get_start_position() const { return start_position; }
85
86 void set_end_position(Vector2 p_position);
87 Vector2 get_end_position() const { return end_position; }
88
89 void set_global_start_position(Vector2 p_position);
90 Vector2 get_global_start_position() const;
91
92 void set_global_end_position(Vector2 p_position);
93 Vector2 get_global_end_position() const;
94
95 void set_enter_cost(real_t p_enter_cost);
96 real_t get_enter_cost() const { return enter_cost; }
97
98 void set_travel_cost(real_t p_travel_cost);
99 real_t get_travel_cost() const { return travel_cost; }
100
101 PackedStringArray get_configuration_warnings() const override;
102
103 NavigationLink2D();
104 ~NavigationLink2D();
105
106private:
107 void _link_enter_navigation_map();
108 void _link_exit_navigation_map();
109 void _link_update_transform();
110};