diff options
Diffstat (limited to 'scene')
-rw-r--r-- | scene/gui/popup_menu.cpp | 6 | ||||
-rw-r--r-- | scene/gui/text_edit.cpp | 6 | ||||
-rw-r--r-- | scene/gui/text_edit.h | 1 | ||||
-rw-r--r-- | scene/resources/capsule_shape_2d.cpp | 22 | ||||
-rw-r--r-- | scene/resources/capsule_shape_2d.h | 2 | ||||
-rw-r--r-- | scene/resources/capsule_shape_3d.cpp | 10 | ||||
-rw-r--r-- | scene/resources/capsule_shape_3d.h | 2 | ||||
-rw-r--r-- | scene/resources/navigation_mesh.cpp | 60 | ||||
-rw-r--r-- | scene/resources/navigation_mesh.h | 16 | ||||
-rw-r--r-- | scene/resources/primitive_meshes.cpp | 28 | ||||
-rw-r--r-- | scene/resources/primitive_meshes.h | 6 |
11 files changed, 96 insertions, 63 deletions
diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index 44f7200cd7..4bd88fde5f 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -1274,13 +1274,13 @@ int PopupMenu::get_item_count() const { } bool PopupMenu::activate_item_by_event(const Ref<InputEvent> &p_event, bool p_for_global_only) { - uint32_t code = 0; + Key code = KEY_NONE; Ref<InputEventKey> k = p_event; if (k.is_valid()) { code = k->get_keycode(); - if (code == 0) { - code = k->get_unicode(); + if (code == KEY_NONE) { + code = (Key)k->get_unicode(); } if (k->is_ctrl_pressed()) { code |= KEY_MASK_CTRL; diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 932846e73e..985abf8e55 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -2258,7 +2258,10 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { selection.selecting_column = col; } - if (!mb->is_double_click() && (OS::get_singleton()->get_ticks_msec() - last_dblclk) < 600 && cursor.line == prev_line) { + const int triple_click_timeout = 600; + const int triple_click_tolerance = 5; + + if (!mb->is_double_click() && (OS::get_singleton()->get_ticks_msec() - last_dblclk) < triple_click_timeout && mb->get_position().distance_to(last_dblclk_pos) < triple_click_tolerance) { // Triple-click select line. selection.selecting_mode = SelectionMode::SELECTION_MODE_LINE; _update_selection_mode_line(); @@ -2268,6 +2271,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { selection.selecting_mode = SelectionMode::SELECTION_MODE_WORD; _update_selection_mode_word(); last_dblclk = OS::get_singleton()->get_ticks_msec(); + last_dblclk_pos = mb->get_position(); } update(); diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index 9e6dedb267..c5853786cf 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -308,6 +308,7 @@ private: String lookup_symbol_word; uint64_t last_dblclk = 0; + Vector2 last_dblclk_pos; Timer *idle_detect; Timer *click_select_held; diff --git a/scene/resources/capsule_shape_2d.cpp b/scene/resources/capsule_shape_2d.cpp index e5edba8a67..596fa70f15 100644 --- a/scene/resources/capsule_shape_2d.cpp +++ b/scene/resources/capsule_shape_2d.cpp @@ -38,11 +38,11 @@ Vector<Vector2> CapsuleShape2D::_get_points() const { Vector<Vector2> points; const real_t turn_step = Math_TAU / 24.0; for (int i = 0; i < 24; i++) { - Vector2 ofs = Vector2(0, (i > 6 && i <= 18) ? -get_height() * 0.5 : get_height() * 0.5); + Vector2 ofs = Vector2(0, (i > 6 && i <= 18) ? -height * 0.5 + radius : height * 0.5 - radius); - points.push_back(Vector2(Math::sin(i * turn_step), Math::cos(i * turn_step)) * get_radius() + ofs); + points.push_back(Vector2(Math::sin(i * turn_step), Math::cos(i * turn_step)) * radius + ofs); if (i == 6 || i == 18) { - points.push_back(Vector2(Math::sin(i * turn_step), Math::cos(i * turn_step)) * get_radius() - ofs); + points.push_back(Vector2(Math::sin(i * turn_step), Math::cos(i * turn_step)) * radius - ofs); } } @@ -59,7 +59,7 @@ void CapsuleShape2D::_update_shape() { } void CapsuleShape2D::set_radius(real_t p_radius) { - radius = p_radius; + radius = MIN(p_radius, height * 0.5); _update_shape(); } @@ -68,11 +68,7 @@ real_t CapsuleShape2D::get_radius() const { } void CapsuleShape2D::set_height(real_t p_height) { - height = p_height; - if (height < 0) { - height = 0; - } - + height = MAX(p_height, radius * 2); _update_shape(); } @@ -93,15 +89,11 @@ void CapsuleShape2D::draw(const RID &p_to_rid, const Color &p_color) { } Rect2 CapsuleShape2D::get_rect() const { - Vector2 he = Point2(get_radius(), get_radius() + get_height() * 0.5); - Rect2 rect; - rect.position = -he; - rect.size = he * 2.0; - return rect; + return Rect2(0, 0, radius, height); } real_t CapsuleShape2D::get_enclosing_radius() const { - return radius + height * 0.5; + return height * 0.5; } void CapsuleShape2D::_bind_methods() { diff --git a/scene/resources/capsule_shape_2d.h b/scene/resources/capsule_shape_2d.h index 439b67e8c3..37b6c52c0e 100644 --- a/scene/resources/capsule_shape_2d.h +++ b/scene/resources/capsule_shape_2d.h @@ -36,7 +36,7 @@ class CapsuleShape2D : public Shape2D { GDCLASS(CapsuleShape2D, Shape2D); - real_t height = 20.0; + real_t height = 30.0; real_t radius = 10.0; void _update_shape(); diff --git a/scene/resources/capsule_shape_3d.cpp b/scene/resources/capsule_shape_3d.cpp index 226fe1ecd2..e267941d6a 100644 --- a/scene/resources/capsule_shape_3d.cpp +++ b/scene/resources/capsule_shape_3d.cpp @@ -37,7 +37,7 @@ Vector<Vector3> CapsuleShape3D::get_debug_mesh_lines() const { Vector<Vector3> points; - Vector3 d(0, height * 0.5, 0); + Vector3 d(0, height * 0.5 - radius, 0); for (int i = 0; i < 360; i++) { float ra = Math::deg2rad((float)i); float rb = Math::deg2rad((float)i + 1); @@ -67,7 +67,7 @@ Vector<Vector3> CapsuleShape3D::get_debug_mesh_lines() const { } real_t CapsuleShape3D::get_enclosing_radius() const { - return radius + height * 0.5; + return height * 0.5; } void CapsuleShape3D::_update_shape() { @@ -80,6 +80,9 @@ void CapsuleShape3D::_update_shape() { void CapsuleShape3D::set_radius(float p_radius) { radius = p_radius; + if (radius > height * 0.5) { + radius = height * 0.5; + } _update_shape(); notify_change_to_owners(); } @@ -90,6 +93,9 @@ float CapsuleShape3D::get_radius() const { void CapsuleShape3D::set_height(float p_height) { height = p_height; + if (radius > height * 0.5) { + height = radius * 2; + } _update_shape(); notify_change_to_owners(); } diff --git a/scene/resources/capsule_shape_3d.h b/scene/resources/capsule_shape_3d.h index 25645ecf9d..f09b4fb77d 100644 --- a/scene/resources/capsule_shape_3d.h +++ b/scene/resources/capsule_shape_3d.h @@ -36,7 +36,7 @@ class CapsuleShape3D : public Shape3D { GDCLASS(CapsuleShape3D, Shape3D); float radius = 1.0; - float height = 1.0; + float height = 3.0; protected: static void _bind_methods(); diff --git a/scene/resources/navigation_mesh.cpp b/scene/resources/navigation_mesh.cpp index ddc50c0490..3c3c643367 100644 --- a/scene/resources/navigation_mesh.cpp +++ b/scene/resources/navigation_mesh.cpp @@ -64,22 +64,22 @@ void NavigationMesh::create_from_mesh(const Ref<Mesh> &p_mesh) { } } -void NavigationMesh::set_sample_partition_type(int p_value) { - ERR_FAIL_COND(p_value >= SAMPLE_PARTITION_MAX); - partition_type = static_cast<SamplePartitionType>(p_value); +void NavigationMesh::set_sample_partition_type(SamplePartitionType p_value) { + ERR_FAIL_INDEX(p_value, SAMPLE_PARTITION_MAX); + partition_type = p_value; } -int NavigationMesh::get_sample_partition_type() const { - return static_cast<int>(partition_type); +NavigationMesh::SamplePartitionType NavigationMesh::get_sample_partition_type() const { + return partition_type; } -void NavigationMesh::set_parsed_geometry_type(int p_value) { - ERR_FAIL_COND(p_value >= PARSED_GEOMETRY_MAX); - parsed_geometry_type = static_cast<ParsedGeometryType>(p_value); +void NavigationMesh::set_parsed_geometry_type(ParsedGeometryType p_value) { + ERR_FAIL_INDEX(p_value, PARSED_GEOMETRY_MAX); + parsed_geometry_type = p_value; notify_property_list_changed(); } -int NavigationMesh::get_parsed_geometry_type() const { +NavigationMesh::ParsedGeometryType NavigationMesh::get_parsed_geometry_type() const { return parsed_geometry_type; } @@ -107,13 +107,13 @@ bool NavigationMesh::get_collision_mask_bit(int p_bit) const { return get_collision_mask() & (1 << p_bit); } -void NavigationMesh::set_source_geometry_mode(int p_geometry_mode) { +void NavigationMesh::set_source_geometry_mode(SourceGeometryMode p_geometry_mode) { ERR_FAIL_INDEX(p_geometry_mode, SOURCE_GEOMETRY_MAX); - source_geometry_mode = static_cast<SourceGeometryMode>(p_geometry_mode); + source_geometry_mode = p_geometry_mode; notify_property_list_changed(); } -int NavigationMesh::get_source_geometry_mode() const { +NavigationMesh::SourceGeometryMode NavigationMesh::get_source_geometry_mode() const { return source_geometry_mode; } @@ -126,6 +126,7 @@ StringName NavigationMesh::get_source_group_name() const { } void NavigationMesh::set_cell_size(float p_value) { + ERR_FAIL_COND(p_value <= 0); cell_size = p_value; } @@ -134,6 +135,7 @@ float NavigationMesh::get_cell_size() const { } void NavigationMesh::set_cell_height(float p_value) { + ERR_FAIL_COND(p_value <= 0); cell_height = p_value; } @@ -142,6 +144,7 @@ float NavigationMesh::get_cell_height() const { } void NavigationMesh::set_agent_height(float p_value) { + ERR_FAIL_COND(p_value < 0); agent_height = p_value; } @@ -150,6 +153,7 @@ float NavigationMesh::get_agent_height() const { } void NavigationMesh::set_agent_radius(float p_value) { + ERR_FAIL_COND(p_value < 0); agent_radius = p_value; } @@ -158,6 +162,7 @@ float NavigationMesh::get_agent_radius() { } void NavigationMesh::set_agent_max_climb(float p_value) { + ERR_FAIL_COND(p_value < 0); agent_max_climb = p_value; } @@ -166,6 +171,7 @@ float NavigationMesh::get_agent_max_climb() const { } void NavigationMesh::set_agent_max_slope(float p_value) { + ERR_FAIL_COND(p_value < 0 || p_value > 90); agent_max_slope = p_value; } @@ -174,6 +180,7 @@ float NavigationMesh::get_agent_max_slope() const { } void NavigationMesh::set_region_min_size(float p_value) { + ERR_FAIL_COND(p_value < 0); region_min_size = p_value; } @@ -182,6 +189,7 @@ float NavigationMesh::get_region_min_size() const { } void NavigationMesh::set_region_merge_size(float p_value) { + ERR_FAIL_COND(p_value < 0); region_merge_size = p_value; } @@ -190,6 +198,7 @@ float NavigationMesh::get_region_merge_size() const { } void NavigationMesh::set_edge_max_length(float p_value) { + ERR_FAIL_COND(p_value < 0); edge_max_length = p_value; } @@ -198,6 +207,7 @@ float NavigationMesh::get_edge_max_length() const { } void NavigationMesh::set_edge_max_error(float p_value) { + ERR_FAIL_COND(p_value < 0); edge_max_error = p_value; } @@ -206,6 +216,7 @@ float NavigationMesh::get_edge_max_error() const { } void NavigationMesh::set_verts_per_poly(float p_value) { + ERR_FAIL_COND(p_value < 3); verts_per_poly = p_value; } @@ -214,6 +225,7 @@ float NavigationMesh::get_verts_per_poly() const { } void NavigationMesh::set_detail_sample_distance(float p_value) { + ERR_FAIL_COND(p_value < 0); detail_sample_distance = p_value; } @@ -222,6 +234,7 @@ float NavigationMesh::get_detail_sample_distance() const { } void NavigationMesh::set_detail_sample_max_error(float p_value) { + ERR_FAIL_COND(p_value < 0); detail_sample_max_error = p_value; } @@ -460,14 +473,6 @@ void NavigationMesh::_bind_methods() { ClassDB::bind_method(D_METHOD("_set_polygons", "polygons"), &NavigationMesh::_set_polygons); ClassDB::bind_method(D_METHOD("_get_polygons"), &NavigationMesh::_get_polygons); - BIND_CONSTANT(SAMPLE_PARTITION_WATERSHED); - BIND_CONSTANT(SAMPLE_PARTITION_MONOTONE); - BIND_CONSTANT(SAMPLE_PARTITION_LAYERS); - - BIND_CONSTANT(PARSED_GEOMETRY_MESH_INSTANCES); - BIND_CONSTANT(PARSED_GEOMETRY_STATIC_COLLIDERS); - BIND_CONSTANT(PARSED_GEOMETRY_BOTH); - ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR3_ARRAY, "vertices", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "set_vertices", "get_vertices"); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "polygons", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_polygons", "_get_polygons"); @@ -494,6 +499,21 @@ void NavigationMesh::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "filter/low_hanging_obstacles"), "set_filter_low_hanging_obstacles", "get_filter_low_hanging_obstacles"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "filter/ledge_spans"), "set_filter_ledge_spans", "get_filter_ledge_spans"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "filter/filter_walkable_low_height_spans"), "set_filter_walkable_low_height_spans", "get_filter_walkable_low_height_spans"); + + BIND_ENUM_CONSTANT(SAMPLE_PARTITION_WATERSHED); + BIND_ENUM_CONSTANT(SAMPLE_PARTITION_MONOTONE); + BIND_ENUM_CONSTANT(SAMPLE_PARTITION_LAYERS); + BIND_ENUM_CONSTANT(SAMPLE_PARTITION_MAX); + + BIND_ENUM_CONSTANT(PARSED_GEOMETRY_MESH_INSTANCES); + BIND_ENUM_CONSTANT(PARSED_GEOMETRY_STATIC_COLLIDERS); + BIND_ENUM_CONSTANT(PARSED_GEOMETRY_BOTH); + BIND_ENUM_CONSTANT(PARSED_GEOMETRY_MAX); + + BIND_ENUM_CONSTANT(SOURCE_GEOMETRY_NAVMESH_CHILDREN); + BIND_ENUM_CONSTANT(SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN); + BIND_ENUM_CONSTANT(SOURCE_GEOMETRY_GROUPS_EXPLICIT); + BIND_ENUM_CONSTANT(SOURCE_GEOMETRY_MAX); } void NavigationMesh::_validate_property(PropertyInfo &property) const { diff --git a/scene/resources/navigation_mesh.h b/scene/resources/navigation_mesh.h index 966221c7c6..99b2b6ff58 100644 --- a/scene/resources/navigation_mesh.h +++ b/scene/resources/navigation_mesh.h @@ -109,11 +109,11 @@ protected: public: // Recast settings - void set_sample_partition_type(int p_value); - int get_sample_partition_type() const; + void set_sample_partition_type(SamplePartitionType p_value); + SamplePartitionType get_sample_partition_type() const; - void set_parsed_geometry_type(int p_value); - int get_parsed_geometry_type() const; + void set_parsed_geometry_type(ParsedGeometryType p_value); + ParsedGeometryType get_parsed_geometry_type() const; void set_collision_mask(uint32_t p_mask); uint32_t get_collision_mask() const; @@ -121,8 +121,8 @@ public: void set_collision_mask_bit(int p_bit, bool p_value); bool get_collision_mask_bit(int p_bit) const; - void set_source_geometry_mode(int p_geometry_mode); - int get_source_geometry_mode() const; + void set_source_geometry_mode(SourceGeometryMode p_geometry_mode); + SourceGeometryMode get_source_geometry_mode() const; void set_source_group_name(StringName p_group_name); StringName get_source_group_name() const; @@ -190,4 +190,8 @@ public: NavigationMesh(); }; +VARIANT_ENUM_CAST(NavigationMesh::SamplePartitionType); +VARIANT_ENUM_CAST(NavigationMesh::ParsedGeometryType); +VARIANT_ENUM_CAST(NavigationMesh::SourceGeometryMode); + #endif // NAVIGATION_MESH_H diff --git a/scene/resources/primitive_meshes.cpp b/scene/resources/primitive_meshes.cpp index dfa45cc810..ba85ea4a6c 100644 --- a/scene/resources/primitive_meshes.cpp +++ b/scene/resources/primitive_meshes.cpp @@ -300,7 +300,7 @@ void CapsuleMesh::_create_mesh_array(Array &p_arr) const { z = cos(u * Math_TAU); Vector3 p = Vector3(x * radius * w, y, -z * radius * w); - points.push_back(p + Vector3(0.0, 0.5 * mid_height, 0.0)); + points.push_back(p + Vector3(0.0, 0.5 * height - radius, 0.0)); normals.push_back(p.normalized()); ADD_TANGENT(z, 0.0, x, 1.0) uvs.push_back(Vector2(u, v * onethird)); @@ -328,8 +328,8 @@ void CapsuleMesh::_create_mesh_array(Array &p_arr) const { v = j; v /= (rings + 1); - y = mid_height * v; - y = (mid_height * 0.5) - y; + y = (height - 2.0 * radius) * v; + y = (0.5 * height - radius) - y; for (i = 0; i <= radial_segments; i++) { u = i; @@ -379,7 +379,7 @@ void CapsuleMesh::_create_mesh_array(Array &p_arr) const { z = cos(u2 * Math_TAU); Vector3 p = Vector3(x * radius * w, y, -z * radius * w); - points.push_back(p + Vector3(0.0, -0.5 * mid_height, 0.0)); + points.push_back(p + Vector3(0.0, -0.5 * height + radius, 0.0)); normals.push_back(p.normalized()); ADD_TANGENT(z, 0.0, x, 1.0) uvs.push_back(Vector2(u2, twothirds + ((v - 1.0) * onethird))); @@ -410,8 +410,8 @@ void CapsuleMesh::_create_mesh_array(Array &p_arr) const { void CapsuleMesh::_bind_methods() { ClassDB::bind_method(D_METHOD("set_radius", "radius"), &CapsuleMesh::set_radius); ClassDB::bind_method(D_METHOD("get_radius"), &CapsuleMesh::get_radius); - ClassDB::bind_method(D_METHOD("set_mid_height", "mid_height"), &CapsuleMesh::set_mid_height); - ClassDB::bind_method(D_METHOD("get_mid_height"), &CapsuleMesh::get_mid_height); + ClassDB::bind_method(D_METHOD("set_height", "height"), &CapsuleMesh::set_height); + ClassDB::bind_method(D_METHOD("get_height"), &CapsuleMesh::get_height); ClassDB::bind_method(D_METHOD("set_radial_segments", "segments"), &CapsuleMesh::set_radial_segments); ClassDB::bind_method(D_METHOD("get_radial_segments"), &CapsuleMesh::get_radial_segments); @@ -419,13 +419,16 @@ void CapsuleMesh::_bind_methods() { ClassDB::bind_method(D_METHOD("get_rings"), &CapsuleMesh::get_rings); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "radius", PROPERTY_HINT_RANGE, "0.001,100.0,0.001,or_greater"), "set_radius", "get_radius"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "mid_height", PROPERTY_HINT_RANGE, "0.001,100.0,0.001,or_greater"), "set_mid_height", "get_mid_height"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "height", PROPERTY_HINT_RANGE, "0.001,100.0,0.001,or_greater"), "set_height", "get_height"); ADD_PROPERTY(PropertyInfo(Variant::INT, "radial_segments", PROPERTY_HINT_RANGE, "1,100,1,or_greater"), "set_radial_segments", "get_radial_segments"); ADD_PROPERTY(PropertyInfo(Variant::INT, "rings", PROPERTY_HINT_RANGE, "1,100,1,or_greater"), "set_rings", "get_rings"); } void CapsuleMesh::set_radius(const float p_radius) { radius = p_radius; + if (radius > height * 0.5) { + radius = height * 0.5; + } _request_update(); } @@ -433,13 +436,16 @@ float CapsuleMesh::get_radius() const { return radius; } -void CapsuleMesh::set_mid_height(const float p_mid_height) { - mid_height = p_mid_height; +void CapsuleMesh::set_height(const float p_height) { + height = p_height; + if (radius > height * 0.5) { + height = radius * 2; + } _request_update(); } -float CapsuleMesh::get_mid_height() const { - return mid_height; +float CapsuleMesh::get_height() const { + return height; } void CapsuleMesh::set_radial_segments(const int p_segments) { diff --git a/scene/resources/primitive_meshes.h b/scene/resources/primitive_meshes.h index a3de34d3e3..7915cb0028 100644 --- a/scene/resources/primitive_meshes.h +++ b/scene/resources/primitive_meshes.h @@ -108,7 +108,7 @@ class CapsuleMesh : public PrimitiveMesh { private: float radius = 1.0; - float mid_height = 1.0; + float height = 3.0; int radial_segments = 64; int rings = 8; @@ -120,8 +120,8 @@ public: void set_radius(const float p_radius); float get_radius() const; - void set_mid_height(const float p_mid_height); - float get_mid_height() const; + void set_height(const float p_height); + float get_height() const; void set_radial_segments(const int p_segments); int get_radial_segments() const; |