diff options
Diffstat (limited to 'scene/2d/navigation_link_2d.cpp')
-rw-r--r-- | scene/2d/navigation_link_2d.cpp | 79 |
1 files changed, 53 insertions, 26 deletions
diff --git a/scene/2d/navigation_link_2d.cpp b/scene/2d/navigation_link_2d.cpp index 9ef0ba617e..26dca40176 100644 --- a/scene/2d/navigation_link_2d.cpp +++ b/scene/2d/navigation_link_2d.cpp @@ -48,11 +48,11 @@ void NavigationLink2D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_navigation_layer_value", "layer_number", "value"), &NavigationLink2D::set_navigation_layer_value); ClassDB::bind_method(D_METHOD("get_navigation_layer_value", "layer_number"), &NavigationLink2D::get_navigation_layer_value); - ClassDB::bind_method(D_METHOD("set_start_location", "location"), &NavigationLink2D::set_start_location); - ClassDB::bind_method(D_METHOD("get_start_location"), &NavigationLink2D::get_start_location); + ClassDB::bind_method(D_METHOD("set_start_position", "position"), &NavigationLink2D::set_start_position); + ClassDB::bind_method(D_METHOD("get_start_position"), &NavigationLink2D::get_start_position); - ClassDB::bind_method(D_METHOD("set_end_location", "location"), &NavigationLink2D::set_end_location); - ClassDB::bind_method(D_METHOD("get_end_location"), &NavigationLink2D::get_end_location); + ClassDB::bind_method(D_METHOD("set_end_position", "position"), &NavigationLink2D::set_end_position); + ClassDB::bind_method(D_METHOD("get_end_position"), &NavigationLink2D::get_end_position); ClassDB::bind_method(D_METHOD("set_enter_cost", "enter_cost"), &NavigationLink2D::set_enter_cost); ClassDB::bind_method(D_METHOD("get_enter_cost"), &NavigationLink2D::get_enter_cost); @@ -63,12 +63,38 @@ void NavigationLink2D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_enabled", "is_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "bidirectional"), "set_bidirectional", "is_bidirectional"); ADD_PROPERTY(PropertyInfo(Variant::INT, "navigation_layers", PROPERTY_HINT_LAYERS_2D_NAVIGATION), "set_navigation_layers", "get_navigation_layers"); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "start_location"), "set_start_location", "get_start_location"); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "end_location"), "set_end_location", "get_end_location"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "start_position"), "set_start_position", "get_start_position"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "end_position"), "set_end_position", "get_end_position"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "enter_cost"), "set_enter_cost", "get_enter_cost"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "travel_cost"), "set_travel_cost", "get_travel_cost"); } +#ifndef DISABLE_DEPRECATED +bool NavigationLink2D::_set(const StringName &p_name, const Variant &p_value) { + if (p_name == "start_location") { + set_start_position(p_value); + return true; + } + if (p_name == "end_location") { + set_end_position(p_value); + return true; + } + return false; +} + +bool NavigationLink2D::_get(const StringName &p_name, Variant &r_ret) const { + if (p_name == "start_location") { + r_ret = get_start_position(); + return true; + } + if (p_name == "end_location") { + r_ret = get_end_position(); + return true; + } + return false; +} +#endif // DISABLE_DEPRECATED + void NavigationLink2D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { @@ -77,15 +103,15 @@ void NavigationLink2D::_notification(int p_what) { // Update global positions for the link. Transform2D gt = get_global_transform(); - NavigationServer2D::get_singleton()->link_set_start_location(link, gt.xform(start_location)); - NavigationServer2D::get_singleton()->link_set_end_location(link, gt.xform(end_location)); + NavigationServer2D::get_singleton()->link_set_start_position(link, gt.xform(start_position)); + NavigationServer2D::get_singleton()->link_set_end_position(link, gt.xform(end_position)); } } break; case NOTIFICATION_TRANSFORM_CHANGED: { // Update global positions for the link. Transform2D gt = get_global_transform(); - NavigationServer2D::get_singleton()->link_set_start_location(link, gt.xform(start_location)); - NavigationServer2D::get_singleton()->link_set_end_location(link, gt.xform(end_location)); + NavigationServer2D::get_singleton()->link_set_start_position(link, gt.xform(start_position)); + NavigationServer2D::get_singleton()->link_set_end_position(link, gt.xform(end_position)); } break; case NOTIFICATION_EXIT_TREE: { NavigationServer2D::get_singleton()->link_set_map(link, RID()); @@ -102,9 +128,9 @@ void NavigationLink2D::_notification(int p_what) { real_t radius = NavigationServer2D::get_singleton()->map_get_link_connection_radius(get_world_2d()->get_navigation_map()); - draw_line(get_start_location(), get_end_location(), color); - draw_arc(get_start_location(), radius, 0, Math_TAU, 10, color); - draw_arc(get_end_location(), radius, 0, Math_TAU, 10, color); + draw_line(get_start_position(), get_end_position(), color); + draw_arc(get_start_position(), radius, 0, Math_TAU, 10, color); + draw_arc(get_end_position(), radius, 0, Math_TAU, 10, color); } #endif // DEBUG_ENABLED } break; @@ -119,14 +145,14 @@ Rect2 NavigationLink2D::_edit_get_rect() const { real_t radius = NavigationServer2D::get_singleton()->map_get_link_connection_radius(get_world_2d()->get_navigation_map()); - Rect2 rect(get_start_location(), Size2()); - rect.expand_to(get_end_location()); + Rect2 rect(get_start_position(), Size2()); + rect.expand_to(get_end_position()); rect.grow_by(radius); return rect; } bool NavigationLink2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { - Point2 segment[2] = { get_start_location(), get_end_location() }; + Point2 segment[2] = { get_start_position(), get_end_position() }; Vector2 closest_point = Geometry2D::get_closest_point_to_segment(p_point, segment); return p_point.distance_to(closest_point) < p_tolerance; @@ -199,19 +225,19 @@ bool NavigationLink2D::get_navigation_layer_value(int p_layer_number) const { return get_navigation_layers() & (1 << (p_layer_number - 1)); } -void NavigationLink2D::set_start_location(Vector2 p_location) { - if (start_location.is_equal_approx(p_location)) { +void NavigationLink2D::set_start_position(Vector2 p_position) { + if (start_position.is_equal_approx(p_position)) { return; } - start_location = p_location; + start_position = p_position; if (!is_inside_tree()) { return; } Transform2D gt = get_global_transform(); - NavigationServer2D::get_singleton()->link_set_start_location(link, gt.xform(start_location)); + NavigationServer2D::get_singleton()->link_set_start_position(link, gt.xform(start_position)); update_configuration_warnings(); @@ -222,19 +248,19 @@ void NavigationLink2D::set_start_location(Vector2 p_location) { #endif // DEBUG_ENABLED } -void NavigationLink2D::set_end_location(Vector2 p_location) { - if (end_location.is_equal_approx(p_location)) { +void NavigationLink2D::set_end_position(Vector2 p_position) { + if (end_position.is_equal_approx(p_position)) { return; } - end_location = p_location; + end_position = p_position; if (!is_inside_tree()) { return; } Transform2D gt = get_global_transform(); - NavigationServer2D::get_singleton()->link_set_end_location(link, gt.xform(end_location)); + NavigationServer2D::get_singleton()->link_set_end_position(link, gt.xform(end_position)); update_configuration_warnings(); @@ -270,8 +296,8 @@ void NavigationLink2D::set_travel_cost(real_t p_travel_cost) { PackedStringArray NavigationLink2D::get_configuration_warnings() const { PackedStringArray warnings = Node::get_configuration_warnings(); - if (start_location.is_equal_approx(end_location)) { - warnings.push_back(RTR("NavigationLink2D start location should be different than the end location to be useful.")); + if (start_position.is_equal_approx(end_position)) { + warnings.push_back(RTR("NavigationLink2D start position should be different than the end position to be useful.")); } return warnings; @@ -282,6 +308,7 @@ NavigationLink2D::NavigationLink2D() { NavigationServer2D::get_singleton()->link_set_owner_id(link, get_instance_id()); set_notify_transform(true); + set_hide_clip_children(true); } NavigationLink2D::~NavigationLink2D() { |