From 9499ebecee827b95eea036e58c9a788e13d0ddb2 Mon Sep 17 00:00:00 2001 From: kobewi Date: Tue, 5 Apr 2022 02:58:21 +0200 Subject: [PATCH 01/10] Add vector value linking Co-authored-by: redlamp <244062+redlamp@users.noreply.github.com> (cherry picked from commit 5553e27fe8346eed22ca4a47728fedcf2a7d7ffd) --- core/global_constants.cpp | 1 + core/object.h | 1 + doc/classes/@GlobalScope.xml | 73 +++++++------- editor/editor_properties.cpp | 171 ++++++++++++++++++++++++++++----- editor/editor_properties.h | 16 ++- editor/icons/icon_unlinked.svg | 1 + scene/2d/node_2d.cpp | 2 +- scene/3d/spatial.cpp | 2 +- scene/gui/control.cpp | 4 + 9 files changed, 208 insertions(+), 63 deletions(-) create mode 100644 editor/icons/icon_unlinked.svg diff --git a/core/global_constants.cpp b/core/global_constants.cpp index f3646bfe12e..ba86205d846 100644 --- a/core/global_constants.cpp +++ b/core/global_constants.cpp @@ -587,6 +587,7 @@ void register_global_constants() { BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_ENUM_SUGGESTION); BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_EXP_EASING); BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_LENGTH); + BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_LINK); BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_KEY_ACCEL); BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_FLAGS); diff --git a/core/object.h b/core/object.h index cf9c8665548..56642b04e89 100644 --- a/core/object.h +++ b/core/object.h @@ -62,6 +62,7 @@ enum PropertyHint { PROPERTY_HINT_ENUM, ///< hint_text= "val1,val2,val3,etc" PROPERTY_HINT_EXP_EASING, /// exponential easing function (Math::ease) use "attenuation" hint string to revert (flip h), "full" to also include in/out. (ie: "attenuation,inout") PROPERTY_HINT_LENGTH, ///< hint_text= "length" (as integer) + PROPERTY_HINT_LINK, PROPERTY_HINT_SPRITE_FRAME, // FIXME: Obsolete: drop whenever we can break compat. Keeping now for GDNative compat. PROPERTY_HINT_KEY_ACCEL, ///< hint_text= "length" (as integer) PROPERTY_HINT_FLAGS, ///< hint_text= "flag1,flag2,etc" (as bit flags) diff --git a/doc/classes/@GlobalScope.xml b/doc/classes/@GlobalScope.xml index 9d7a6a2642b..4c40d59bcda 100644 --- a/doc/classes/@GlobalScope.xml +++ b/doc/classes/@GlobalScope.xml @@ -1421,7 +1421,7 @@ Hints that an integer, float or string property is an enumerated value to pick in a list specified via a hint string. The hint string is a comma separated list of names such as [code]"Hello,Something,Else"[/code]. Whitespaces are [b]not[/b] removed from either end of a name. For integer and float properties, the first name in the list has value 0, the next 1, and so on. Explicit values can also be specified by appending [code]:integer[/code] to the name, e.g. [code]"Zero,One,Three:3,Four,Six:6"[/code]. - + Hints that a string property can be an enumerated value to pick in a list specified via a hint string such as [code]"Hello,Something,Else"[/code]. Unlike [constant PROPERTY_HINT_ENUM] a property with this hint still accepts arbitrary values and can be empty. The list of values serves to suggest possible values. @@ -1431,63 +1431,66 @@ Deprecated hint, unused. - + + Hints that a vector property should allow linking values (e.g. to edit both [code]x[/code] and [code]y[/code] together). + + Deprecated hint, unused. - + Hints that an integer property is a bitmask with named bit flags. For example, to allow toggling bits 0, 1, 2 and 4, the hint could be something like [code]"Bit0,Bit1,Bit2,,Bit4"[/code]. - + Hints that an integer property is a bitmask using the optionally named 2D render layers. - + Hints that an integer property is a bitmask using the optionally named 2D physics layers. - + Hints that an integer property is a bitmask using the optionally named 2D navigation layers. - + Hints that an integer property is a bitmask using the optionally named 3D render layers. - + Hints that an integer property is a bitmask using the optionally named 3D physics layers. - + Hints that an integer property is a bitmask using the optionally named 3D navigation layers. - + Hints that a string property is a path to a file. Editing it will show a file dialog for picking the path. The hint string can be a set of filters with wildcards like [code]"*.png,*.jpg"[/code]. - + Hints that a string property is a path to a directory. Editing it will show a file dialog for picking the path. - + Hints that a string property is an absolute path to a file outside the project folder. Editing it will show a file dialog for picking the path. The hint string can be a set of filters with wildcards like [code]"*.png,*.jpg"[/code]. - + Hints that a string property is an absolute path to a directory outside the project folder. Editing it will show a file dialog for picking the path. - + Hints that a property is an instance of a [Resource]-derived type, optionally specified via the hint string (e.g. [code]"Texture"[/code]). Editing it will show a popup menu of valid resource types to instantiate. - + Hints that a string property is text with line breaks. Editing it will show a text input field where line breaks can be typed. - + Hints that a string property should have a placeholder text visible on its input field, whenever the property is empty. The hint string is the placeholder text to use. - + Hints that a color property should be edited without changing its alpha component, i.e. only R, G and B channels are edited. - + Hints that an image is compressed using lossy compression. - + Hints that an image is compressed using lossless compression. - + - + Hint that a property represents a particular type. If a property is [constant TYPE_STRING], allows to set a type from the create dialog. If you need to create an [Array] to contain elements of a specific type, the [code]hint_string[/code] must encode nested types using [code]":"[/code] and [code]"/"[/code] for specifying [Resource] types. For instance: [codeblock] hint_string = "%s:" % [TYPE_INT] # Array of inteters. @@ -1497,34 +1500,34 @@ [/codeblock] [b]Note:[/b] The final colon is required to specify for properly detecting built-in types. - + - + - + - + - + - + - + - + - + - + - + - + - + Hints that a string property is a locale code. Editing it will show a locale dialog for picking language and country. - + The property is serialized and saved in the scene file (default). diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index 78393afcbcb..35a169f2a01 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -1509,6 +1509,18 @@ void EditorPropertyVector2::_value_changed(double val, const String &p_name) { return; } + if (linked->is_pressed()) { + setting = true; + if (p_name == "x") { + spin[1]->set_value(spin[0]->get_value() * ratio_yx); + } + + if (p_name == "y") { + spin[0]->set_value(spin[1]->get_value() * ratio_xy); + } + setting = false; + } + Vector2 v2; v2.x = spin[0]->get_value(); v2.y = spin[1]->get_value(); @@ -1521,24 +1533,46 @@ void EditorPropertyVector2::update_property() { spin[0]->set_value(val.x); spin[1]->set_value(val.y); setting = false; + _update_ratio(); +} + +void EditorPropertyVector2::_update_ratio() { + linked->set_modulate(Color(1, 1, 1, linked->is_pressed() ? 1.0 : 0.5)); + + if (spin[0]->get_value() != 0 && spin[1]->get_value() != 0) { + ratio_xy = spin[0]->get_value() / spin[1]->get_value(); + ratio_yx = spin[1]->get_value() / spin[0]->get_value(); + } else { + ratio_xy = 1.0; + ratio_yx = 1.0; + } } void EditorPropertyVector2::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { - Color base = get_color("accent_color", "Editor"); - for (int i = 0; i < 2; i++) { - Color c = base; - c.set_hsv(float(i) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v()); - spin[i]->set_custom_label_color(true, c); - } + switch (p_what) { + case NOTIFICATION_ENTER_TREE: + case NOTIFICATION_THEME_CHANGED: { + Ref normal_icon = get_icon("Unlinked", "EditorIcons"); + linked->set_custom_minimum_size(Vector2(normal_icon->get_width(), 0)); + linked->set_normal_texture(normal_icon); + linked->set_pressed_texture(get_icon("Instance", "EditorIcons")); + + Color base = get_color("accent_color", "Editor"); + for (int i = 0; i < 2; i++) { + Color c = base; + c.set_hsv(float(i) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v()); + spin[i]->set_custom_label_color(true, c); + } + } break; } } void EditorPropertyVector2::_bind_methods() { + ClassDB::bind_method(D_METHOD("_update_ratio"), &EditorPropertyVector2::_update_ratio); ClassDB::bind_method(D_METHOD("_value_changed"), &EditorPropertyVector2::_value_changed); } -void EditorPropertyVector2::setup(double p_min, double p_max, double p_step, bool p_no_slider) { +void EditorPropertyVector2::setup(double p_min, double p_max, double p_step, bool p_no_slider, bool p_link) { for (int i = 0; i < 2; i++) { spin[i]->set_min(p_min); spin[i]->set_max(p_max); @@ -1547,21 +1581,31 @@ void EditorPropertyVector2::setup(double p_min, double p_max, double p_step, boo spin[i]->set_allow_greater(true); spin[i]->set_allow_lesser(true); } + + if (!p_link) { + linked->hide(); + } else { + linked->set_pressed(true); + } } EditorPropertyVector2::EditorPropertyVector2() { bool horizontal = EDITOR_GET("interface/inspector/horizontal_vector2_editing"); + HBoxContainer *hb = memnew(HBoxContainer); + hb->set_h_size_flags(SIZE_EXPAND_FILL); + BoxContainer *bc; if (horizontal) { bc = memnew(HBoxContainer); - add_child(bc); - set_bottom_editor(bc); + hb->add_child(bc); + set_bottom_editor(hb); } else { bc = memnew(VBoxContainer); - add_child(bc); + hb->add_child(bc); } + bc->set_h_size_flags(SIZE_EXPAND_FILL); static const char *desc[2] = { "x", "y" }; for (int i = 0; i < 2; i++) { @@ -1576,6 +1620,14 @@ EditorPropertyVector2::EditorPropertyVector2() { } } + linked = memnew(TextureButton); + linked->set_toggle_mode(true); + linked->set_expand(true); + linked->set_stretch_mode(TextureButton::STRETCH_KEEP_CENTERED); + linked->connect("pressed", this, "_update_ratio"); + hb->add_child(linked); + + add_child(hb); if (!horizontal) { set_label_reference(spin[0]); //show text and buttons around this } @@ -1671,6 +1723,25 @@ void EditorPropertyVector3::_value_changed(double val, const String &p_name) { return; } + if (linked->is_pressed()) { + setting = true; + if (p_name == "x") { + spin[1]->set_value(spin[0]->get_value() * ratio_yx); + spin[2]->set_value(spin[0]->get_value() * ratio_zx); + } + + if (p_name == "y") { + spin[0]->set_value(spin[1]->get_value() * ratio_xy); + spin[2]->set_value(spin[1]->get_value() * ratio_zy); + } + + if (p_name == "z") { + spin[0]->set_value(spin[2]->get_value() * ratio_xz); + spin[1]->set_value(spin[2]->get_value() * ratio_yz); + } + setting = false; + } + Vector3 v3; v3.x = spin[0]->get_value(); v3.y = spin[1]->get_value(); @@ -1685,22 +1756,54 @@ void EditorPropertyVector3::update_property() { spin[1]->set_value(val.y); spin[2]->set_value(val.z); setting = false; + + _update_ratio(); } + +void EditorPropertyVector3::_update_ratio() { + linked->set_modulate(Color(1, 1, 1, linked->is_pressed() ? 1.0 : 0.5)); + + if (spin[0]->get_value() != 0 && spin[1]->get_value() != 0) { + ratio_yx = spin[1]->get_value() / spin[0]->get_value(); + ratio_zx = spin[2]->get_value() / spin[0]->get_value(); + ratio_xy = spin[0]->get_value() / spin[1]->get_value(); + ratio_zy = spin[2]->get_value() / spin[1]->get_value(); + ratio_xz = spin[0]->get_value() / spin[2]->get_value(); + ratio_yz = spin[1]->get_value() / spin[2]->get_value(); + } else { + ratio_yx = 1.0; + ratio_zx = 1.0; + ratio_xy = 1.0; + ratio_zy = 1.0; + ratio_xz = 1.0; + ratio_yz = 1.0; + } +} + void EditorPropertyVector3::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { - Color base = get_color("accent_color", "Editor"); - for (int i = 0; i < 3; i++) { - Color c = base; - c.set_hsv(float(i) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v()); - spin[i]->set_custom_label_color(true, c); - } + switch (p_what) { + case NOTIFICATION_ENTER_TREE: + case NOTIFICATION_THEME_CHANGED: { + Ref normal_icon = get_icon("Unlinked", "EditorIcons"); + linked->set_custom_minimum_size(Vector2(normal_icon->get_width(), 0)); + linked->set_normal_texture(normal_icon); + linked->set_pressed_texture(get_icon("Instance", "EditorIcons")); + + Color base = get_color("accent_color", "Editor"); + for (int i = 0; i < 3; i++) { + Color c = base; + c.set_hsv(float(i) / 3.0 + 0.05, c.get_s() * 0.75, c.get_v()); + spin[i]->set_custom_label_color(true, c); + } + } break; } } void EditorPropertyVector3::_bind_methods() { + ClassDB::bind_method(D_METHOD("_update_ratio"), &EditorPropertyVector3::_update_ratio); ClassDB::bind_method(D_METHOD("_value_changed"), &EditorPropertyVector3::_value_changed); } -void EditorPropertyVector3::setup(double p_min, double p_max, double p_step, bool p_no_slider) { +void EditorPropertyVector3::setup(double p_min, double p_max, double p_step, bool p_no_slider, bool p_link) { for (int i = 0; i < 3; i++) { spin[i]->set_min(p_min); spin[i]->set_max(p_max); @@ -1709,21 +1812,31 @@ void EditorPropertyVector3::setup(double p_min, double p_max, double p_step, boo spin[i]->set_allow_greater(true); spin[i]->set_allow_lesser(true); } + + if (!p_link) { + linked->hide(); + } else { + linked->set_pressed(true); + } } EditorPropertyVector3::EditorPropertyVector3() { bool horizontal = EDITOR_GET("interface/inspector/horizontal_vector_types_editing"); + HBoxContainer *hb = memnew(HBoxContainer); + hb->set_h_size_flags(SIZE_EXPAND_FILL); + BoxContainer *bc; if (horizontal) { bc = memnew(HBoxContainer); - add_child(bc); - set_bottom_editor(bc); + hb->add_child(bc); + set_bottom_editor(hb); } else { bc = memnew(VBoxContainer); - add_child(bc); + hb->add_child(bc); } + bc->set_h_size_flags(SIZE_EXPAND_FILL); static const char *desc[3] = { "x", "y", "z" }; for (int i = 0; i < 3; i++) { @@ -1738,11 +1851,21 @@ EditorPropertyVector3::EditorPropertyVector3() { } } + linked = memnew(TextureButton); + linked->set_toggle_mode(true); + linked->set_expand(true); + linked->set_stretch_mode(TextureButton::STRETCH_KEEP_CENTERED); + linked->connect("pressed", this, "_update_ratio"); + hb->add_child(linked); + + add_child(hb); if (!horizontal) { set_label_reference(spin[0]); //show text and buttons around this } setting = false; + _update_ratio(); } + ///////////////////// PLANE ///////////////////////// void EditorPropertyPlane::_value_changed(double val, const String &p_name) { @@ -3035,7 +3158,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ hide_slider = false; } - editor->setup(min, max, step, hide_slider); + editor->setup(min, max, step, hide_slider, p_hint == PROPERTY_HINT_LINK); add_property_editor(p_path, editor); } break; // 5 @@ -3070,7 +3193,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ hide_slider = false; } - editor->setup(min, max, step, hide_slider); + editor->setup(min, max, step, hide_slider, p_hint == PROPERTY_HINT_LINK); add_property_editor(p_path, editor); } break; diff --git a/editor/editor_properties.h b/editor/editor_properties.h index 0866c3bcb40..89fcada02b8 100644 --- a/editor/editor_properties.h +++ b/editor/editor_properties.h @@ -376,6 +376,10 @@ class EditorPropertyVector2 : public EditorProperty { GDCLASS(EditorPropertyVector2, EditorProperty); EditorSpinSlider *spin[2]; bool setting; + double ratio_xy = 1.0; + double ratio_yx = 1.0; + TextureButton *linked = nullptr; + void _update_ratio(); void _value_changed(double p_val, const String &p_name); protected: @@ -384,7 +388,7 @@ protected: public: virtual void update_property(); - void setup(double p_min, double p_max, double p_step, bool p_no_slider); + void setup(double p_min, double p_max, double p_step, bool p_no_slider, bool p_link = false); EditorPropertyVector2(); }; @@ -408,6 +412,14 @@ class EditorPropertyVector3 : public EditorProperty { GDCLASS(EditorPropertyVector3, EditorProperty); EditorSpinSlider *spin[3]; bool setting; + double ratio_yx = 1.0; + double ratio_zx = 1.0; + double ratio_xy = 1.0; + double ratio_zy = 1.0; + double ratio_xz = 1.0; + double ratio_yz = 1.0; + TextureButton *linked = nullptr; + void _update_ratio(); void _value_changed(double p_val, const String &p_name); protected: @@ -416,7 +428,7 @@ protected: public: virtual void update_property(); - void setup(double p_min, double p_max, double p_step, bool p_no_slider); + void setup(double p_min, double p_max, double p_step, bool p_no_slider, bool p_link = false); EditorPropertyVector3(); }; diff --git a/editor/icons/icon_unlinked.svg b/editor/icons/icon_unlinked.svg new file mode 100644 index 00000000000..6c831eacadc --- /dev/null +++ b/editor/icons/icon_unlinked.svg @@ -0,0 +1 @@ + diff --git a/scene/2d/node_2d.cpp b/scene/2d/node_2d.cpp index 04e2e49178b..7e327cdf0a1 100644 --- a/scene/2d/node_2d.cpp +++ b/scene/2d/node_2d.cpp @@ -425,7 +425,7 @@ void Node2D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position"), "set_position", "get_position"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "rotation", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_rotation", "get_rotation"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "rotation_degrees", PROPERTY_HINT_RANGE, "-360,360,0.1,or_lesser,or_greater", PROPERTY_USAGE_EDITOR), "set_rotation_degrees", "get_rotation_degrees"); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scale"), "set_scale", "get_scale"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scale", PROPERTY_HINT_LINK), "set_scale", "get_scale"); ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D, "transform", PROPERTY_HINT_NONE, "", 0), "set_transform", "get_transform"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "global_position", PROPERTY_HINT_NONE, "", 0), "set_global_position", "get_global_position"); diff --git a/scene/3d/spatial.cpp b/scene/3d/spatial.cpp index 47bb5e7b807..5dbe254e8ac 100644 --- a/scene/3d/spatial.cpp +++ b/scene/3d/spatial.cpp @@ -938,7 +938,7 @@ void Spatial::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "translation", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_translation", "get_translation"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "rotation_degrees", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_rotation_degrees", "get_rotation_degrees"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "rotation", PROPERTY_HINT_NONE, "", 0), "set_rotation", "get_rotation"); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "scale", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_scale", "get_scale"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "scale", PROPERTY_HINT_LINK, "", PROPERTY_USAGE_EDITOR), "set_scale", "get_scale"); ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM, "global_transform", PROPERTY_HINT_NONE, "", 0), "set_global_transform", "get_global_transform"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "global_translation", PROPERTY_HINT_NONE, "", 0), "set_global_translation", "get_global_translation"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "global_rotation", PROPERTY_HINT_NONE, "", 0), "set_global_rotation", "get_global_rotation"); diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 029a215588b..fd31e50d6ff 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -432,6 +432,10 @@ void Control::_validate_property(PropertyInfo &property) const { property.hint_string = hint_string; } + + if (property.name == "rect_scale") { + property.hint = PROPERTY_HINT_LINK; + } } Control *Control::get_parent_control() const { From 0d602ce881719f924d22ec5ca44477567ccafd02 Mon Sep 17 00:00:00 2001 From: FireForge <67974470+fire-forge@users.noreply.github.com> Date: Tue, 14 Jun 2022 09:33:44 -0500 Subject: [PATCH 02/10] Add Vector2/3 linking to more properties - Camera2D.zoom - CanvasLayer.scale - ParallaxBackground.scroll_base_scale - ParallaxLayer.motion_scale - Polygon2D.texture_scale - SpatialMaterial.uv1_scale - SpatialMaterial.uv2_scale (cherry picked from commit 92817aa72fe68ebe6f6a0ae74b3d3a7be8cca16c) --- scene/2d/camera_2d.cpp | 2 +- scene/2d/parallax_background.cpp | 2 +- scene/2d/parallax_layer.cpp | 2 +- scene/2d/polygon_2d.cpp | 5 ++++- scene/main/canvas_layer.cpp | 2 +- scene/resources/material.cpp | 4 ++-- 6 files changed, 10 insertions(+), 7 deletions(-) diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp index 9dea44d72f6..6e0671d47ea 100644 --- a/scene/2d/camera_2d.cpp +++ b/scene/2d/camera_2d.cpp @@ -713,7 +713,7 @@ void Camera2D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "anchor_mode", PROPERTY_HINT_ENUM, "Fixed TopLeft,Drag Center"), "set_anchor_mode", "get_anchor_mode"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "rotating"), "set_rotating", "is_rotating"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "current"), "_set_current", "is_current"); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "zoom"), "set_zoom", "get_zoom"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "zoom", PROPERTY_HINT_LINK), "set_zoom", "get_zoom"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "custom_viewport", PROPERTY_HINT_RESOURCE_TYPE, "Viewport", 0), "set_custom_viewport", "get_custom_viewport"); ADD_PROPERTY(PropertyInfo(Variant::INT, "process_mode", PROPERTY_HINT_ENUM, "Physics,Idle"), "set_process_mode", "get_process_mode"); diff --git a/scene/2d/parallax_background.cpp b/scene/2d/parallax_background.cpp index 167ba7716c3..4e872354030 100644 --- a/scene/2d/parallax_background.cpp +++ b/scene/2d/parallax_background.cpp @@ -178,7 +178,7 @@ void ParallaxBackground::_bind_methods() { ADD_GROUP("Scroll", "scroll_"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scroll_offset"), "set_scroll_offset", "get_scroll_offset"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scroll_base_offset"), "set_scroll_base_offset", "get_scroll_base_offset"); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scroll_base_scale"), "set_scroll_base_scale", "get_scroll_base_scale"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scroll_base_scale", PROPERTY_HINT_LINK), "set_scroll_base_scale", "get_scroll_base_scale"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scroll_limit_begin"), "set_limit_begin", "get_limit_begin"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scroll_limit_end"), "set_limit_end", "get_limit_end"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "scroll_ignore_camera_zoom"), "set_ignore_camera_zoom", "is_ignore_camera_zoom"); diff --git a/scene/2d/parallax_layer.cpp b/scene/2d/parallax_layer.cpp index 8e50c73d1b6..0d8a3520133 100644 --- a/scene/2d/parallax_layer.cpp +++ b/scene/2d/parallax_layer.cpp @@ -156,7 +156,7 @@ void ParallaxLayer::_bind_methods() { ClassDB::bind_method(D_METHOD("get_mirroring"), &ParallaxLayer::get_mirroring); ADD_GROUP("Motion", "motion_"); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "motion_scale"), "set_motion_scale", "get_motion_scale"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "motion_scale", PROPERTY_HINT_LINK), "set_motion_scale", "get_motion_scale"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "motion_offset"), "set_motion_offset", "get_motion_offset"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "motion_mirroring"), "set_mirroring", "get_mirroring"); } diff --git a/scene/2d/polygon_2d.cpp b/scene/2d/polygon_2d.cpp index bc7ef2cbc6f..46f764269ba 100644 --- a/scene/2d/polygon_2d.cpp +++ b/scene/2d/polygon_2d.cpp @@ -617,13 +617,16 @@ void Polygon2D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_color", "get_color"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "offset"), "set_offset", "get_offset"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "antialiased"), "set_antialiased", "get_antialiased"); + ADD_GROUP("Texture", ""); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture"); + ADD_GROUP("Texture", "texture_"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "texture_offset"), "set_texture_offset", "get_texture_offset"); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "texture_scale"), "set_texture_scale", "get_texture_scale"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "texture_scale", PROPERTY_HINT_LINK), "set_texture_scale", "get_texture_scale"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "texture_rotation_degrees", PROPERTY_HINT_RANGE, "-360,360,0.1,or_lesser,or_greater"), "set_texture_rotation_degrees", "get_texture_rotation_degrees"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "texture_rotation", PROPERTY_HINT_NONE, "", 0), "set_texture_rotation", "get_texture_rotation"); + ADD_GROUP("Skeleton", ""); ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "skeleton", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Skeleton2D"), "set_skeleton", "get_skeleton"); diff --git a/scene/main/canvas_layer.cpp b/scene/main/canvas_layer.cpp index fd2f0b32fb3..c3025bc18fd 100644 --- a/scene/main/canvas_layer.cpp +++ b/scene/main/canvas_layer.cpp @@ -332,7 +332,7 @@ void CanvasLayer::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "offset"), "set_offset", "get_offset"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "rotation_degrees", PROPERTY_HINT_RANGE, "-1080,1080,0.1,or_lesser,or_greater", PROPERTY_USAGE_EDITOR), "set_rotation_degrees", "get_rotation_degrees"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "rotation", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_rotation", "get_rotation"); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scale"), "set_scale", "get_scale"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scale", PROPERTY_HINT_LINK), "set_scale", "get_scale"); ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D, "transform"), "set_transform", "get_transform"); ADD_GROUP("", ""); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "custom_viewport", PROPERTY_HINT_RESOURCE_TYPE, "Viewport", 0), "set_custom_viewport", "get_custom_viewport"); diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index 85561230ce9..dd248beced8 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -2174,13 +2174,13 @@ void SpatialMaterial::_bind_methods() { ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "detail_normal", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture", TEXTURE_DETAIL_NORMAL); ADD_GROUP("UV1", "uv1_"); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "uv1_scale"), "set_uv1_scale", "get_uv1_scale"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "uv1_scale", PROPERTY_HINT_LINK), "set_uv1_scale", "get_uv1_scale"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "uv1_offset"), "set_uv1_offset", "get_uv1_offset"); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "uv1_triplanar"), "set_flag", "get_flag", FLAG_UV1_USE_TRIPLANAR); ADD_PROPERTY(PropertyInfo(Variant::REAL, "uv1_triplanar_sharpness", PROPERTY_HINT_EXP_EASING), "set_uv1_triplanar_blend_sharpness", "get_uv1_triplanar_blend_sharpness"); ADD_GROUP("UV2", "uv2_"); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "uv2_scale"), "set_uv2_scale", "get_uv2_scale"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "uv2_scale", PROPERTY_HINT_LINK), "set_uv2_scale", "get_uv2_scale"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "uv2_offset"), "set_uv2_offset", "get_uv2_offset"); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "uv2_triplanar"), "set_flag", "get_flag", FLAG_UV2_USE_TRIPLANAR); ADD_PROPERTY(PropertyInfo(Variant::REAL, "uv2_triplanar_sharpness", PROPERTY_HINT_EXP_EASING), "set_uv2_triplanar_blend_sharpness", "get_uv2_triplanar_blend_sharpness"); From 9056cc9c2a5a8c7fb8ae0a14b597c8ee36f14ccb Mon Sep 17 00:00:00 2001 From: Rindbee Date: Mon, 11 Jul 2022 10:13:34 +0800 Subject: [PATCH 03/10] Fix property link not working in MultiNodeEdit This is due to the `p_field` in the `EditorProperty::emit_changed`. `p_field` only works for `MultiNodeEdit`, not for other objects. (cherry picked from commit b6fdd0815c2448b3858746f6655d8a6cd3a763f4) --- editor/editor_properties.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index 35a169f2a01..c34764f12cd 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -1524,7 +1524,7 @@ void EditorPropertyVector2::_value_changed(double val, const String &p_name) { Vector2 v2; v2.x = spin[0]->get_value(); v2.y = spin[1]->get_value(); - emit_changed(get_edited_property(), v2, p_name); + emit_changed(get_edited_property(), v2, linked->is_pressed() ? "" : p_name); } void EditorPropertyVector2::update_property() { @@ -1746,7 +1746,7 @@ void EditorPropertyVector3::_value_changed(double val, const String &p_name) { v3.x = spin[0]->get_value(); v3.y = spin[1]->get_value(); v3.z = spin[2]->get_value(); - emit_changed(get_edited_property(), v3, p_name); + emit_changed(get_edited_property(), v3, linked->is_pressed() ? "" : p_name); } void EditorPropertyVector3::update_property() { From b2e5c8fe10c8b77f7fcecc1a771e5611ca7a0ac9 Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Thu, 15 Dec 2022 19:09:09 +0800 Subject: [PATCH 04/10] Fix possible Tween leak on exit (cherry picked from commit e173710963c3316833ac2e2c26ab3830551fd790) --- scene/main/scene_tree.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index 774ed869e7f..e1103496782 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -777,6 +777,12 @@ void SceneTree::finish() { E->get()->release_connections(); } timers.clear(); + + // Cleanup tweens. + for (List>::Element *E = tweens.front(); E; E = E->next()) { + E->get()->clear(); + } + tweens.clear(); } void SceneTree::quit(int p_exit_code) { From be3017114f30cda349b4417141d958862cc3bc60 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Thu, 15 Dec 2022 19:29:12 +0100 Subject: [PATCH 05/10] Silence `Input.vibrate_handheld()` warning as it's already documented The warning causes messages to be spammed if you are calling this method in a game that runs on both desktop and mobile platforms, unless you guard all calls to `Input.vibrate_handheld()` with `OS.has_feature("mobile") or OS.has_feature("web")`. Since the limitation is already documented (and is obvious enough given the method's name), the warning message is redundant. (cherry picked from commit 4a991887bf3dd5fbb687fb379f06ac85aa4a6245) --- core/os/os.cpp | 4 ---- core/os/os.h | 2 +- doc/classes/Input.xml | 14 +++++++------- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/core/os/os.cpp b/core/os/os.cpp index fcf712d442a..bc221dcb0c2 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -186,10 +186,6 @@ int OS::get_process_id() const { return -1; }; -void OS::vibrate_handheld(int p_duration_ms) { - WARN_PRINT("vibrate_handheld() only works with Android, iOS and HTML5"); -} - bool OS::is_stdout_verbose() const { return _verbose_stdout; } diff --git a/core/os/os.h b/core/os/os.h index 0e59d10ca33..39e3bcb51c5 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -365,7 +365,7 @@ public: virtual Error kill(const ProcessID &p_pid) = 0; virtual int get_process_id() const; virtual bool is_process_running(const ProcessID &p_pid) const = 0; - virtual void vibrate_handheld(int p_duration_ms = 500); + virtual void vibrate_handheld(int p_duration_ms = 500) {} virtual Error shell_open(String p_uri); virtual Error set_cwd(const String &p_cwd); diff --git a/doc/classes/Input.xml b/doc/classes/Input.xml index f30d9c1c633..4f61556e430 100644 --- a/doc/classes/Input.xml +++ b/doc/classes/Input.xml @@ -364,7 +364,7 @@ - Starts to vibrate the joypad. Joypads usually come with two rumble motors, a strong and a weak one. [code]weak_magnitude[/code] is the strength of the weak motor (between 0 and 1) and [code]strong_magnitude[/code] is the strength of the strong motor (between 0 and 1). [code]duration[/code] is the duration of the effect in seconds (a duration of 0 will try to play the vibration indefinitely). + Starts to vibrate the joypad. Joypads usually come with two rumble motors, a strong and a weak one. [code]weak_magnitude[/code] is the strength of the weak motor (between 0 and 1) and [code]strong_magnitude[/code] is the strength of the strong motor (between 0 and 1). [code]duration[/code] is the duration of the effect in seconds (a duration of 0 will try to play the vibration indefinitely). The vibration can be stopped early by calling [method stop_joy_vibration]. [b]Note:[/b] Not every hardware is compatible with long effect durations; it is recommended to restart an effect if it has to be played for more than a few seconds. @@ -372,18 +372,18 @@ - Stops the vibration of the joypad. + Stops the vibration of the joypad started with [method start_joy_vibration]. - Vibrate handheld devices. - [b]Note:[/b] This method is implemented on Android, iOS, and HTML5. - [b]Note:[/b] For Android, it requires enabling the [code]VIBRATE[/code] permission in the export preset. - [b]Note:[/b] For iOS, specifying the duration is supported in iOS 13 and later. - [b]Note:[/b] Some web browsers such as Safari and Firefox for Android do not support this method. + Vibrate the handheld device for the specified duration in milliseconds. + [b]Note:[/b] This method is implemented on Android, iOS, and HTML5. It has no effect on other platforms. + [b]Note:[/b] For Android, [method vibrate_handheld] requires enabling the [code]VIBRATE[/code] permission in the export preset. Otherwise, [method vibrate_handheld] will have no effect. + [b]Note:[/b] For iOS, specifying the duration is only supported in iOS 13 and later. + [b]Note:[/b] Some web browsers such as Safari and Firefox for Android do not support [method vibrate_handheld]. From 17e6d76de62ec5a9a43c327925d18d027aa0eabc Mon Sep 17 00:00:00 2001 From: smix8 <52464204+smix8@users.noreply.github.com> Date: Mon, 5 Dec 2022 23:05:56 +0100 Subject: [PATCH 06/10] Fix Navigation agent callback wild pointer crash Fixes crash in sanitizer builds when callback agent or object are already freed. (cherry picked from commit 194c1c44e0a20faa4463e3a41bb12cf93a71fc03) --- doc/classes/Navigation2DServer.xml | 6 +++--- doc/classes/NavigationServer.xml | 6 +++--- modules/navigation/godot_navigation_server.cpp | 6 +++--- modules/navigation/godot_navigation_server.h | 2 +- scene/2d/navigation_agent_2d.cpp | 6 +++--- scene/3d/navigation_agent.cpp | 6 +++--- servers/navigation_2d_server.cpp | 12 ++++++------ servers/navigation_2d_server.h | 2 +- servers/navigation_server.cpp | 2 +- servers/navigation_server.h | 2 +- 10 files changed, 25 insertions(+), 25 deletions(-) diff --git a/doc/classes/Navigation2DServer.xml b/doc/classes/Navigation2DServer.xml index cbb60ee7a22..2db55faf22d 100644 --- a/doc/classes/Navigation2DServer.xml +++ b/doc/classes/Navigation2DServer.xml @@ -40,12 +40,12 @@ - + - Callback called at the end of the RVO process. If a callback is created manually and the agent is placed on a navigation map it will calculate avoidance for the agent and dispatch the calculated [code]safe_velocity[/code] to the [code]receiver[/code] object with a signal to the chosen [code]method[/code] name. - [b]Note:[/b] Created callbacks are always processed independently of the SceneTree state as long as the agent is on a navigation map and not freed. To disable the dispatch of a callback from an agent use [method agent_set_callback] again with a [code]null[/code] object as the [code]receiver[/code]. + Sets the callback [code]object_id[/code] and [code]method[/code] that gets called after each avoidance processing step for the [code]agent[/code]. The calculated [code]safe_velocity[/code] will be dispatched with a signal to the object just before the physics calculations. + [b]Note:[/b] Created callbacks are always processed independently of the SceneTree state as long as the agent is on a navigation map and not freed. To disable the dispatch of a callback from an agent use [method agent_set_callback] again with a [code]0[/code] ObjectID as the [code]object_id[/code]. diff --git a/doc/classes/NavigationServer.xml b/doc/classes/NavigationServer.xml index 663663898e9..9252e4566b0 100644 --- a/doc/classes/NavigationServer.xml +++ b/doc/classes/NavigationServer.xml @@ -40,12 +40,12 @@ - + - Callback called at the end of the RVO process. If a callback is created manually and the agent is placed on a navigation map it will calculate avoidance for the agent and dispatch the calculated [code]safe_velocity[/code] to the [code]receiver[/code] object with a signal to the chosen [code]method[/code] name. - [b]Note:[/b] Created callbacks are always processed independently of the SceneTree state as long as the agent is on a navigation map and not freed. To disable the dispatch of a callback from an agent use [method agent_set_callback] again with a [code]null[/code] object as the [code]receiver[/code]. + Sets the callback [code]object_id[/code] and [code]method[/code] that gets called after each avoidance processing step for the [code]agent[/code]. The calculated [code]safe_velocity[/code] will be dispatched with a signal to the object just before the physics calculations. + [b]Note:[/b] Created callbacks are always processed independently of the SceneTree state as long as the agent is on a navigation map and not freed. To disable the dispatch of a callback from an agent use [method agent_set_callback] again with a [code]0[/code] ObjectID as the [code]object_id[/code]. diff --git a/modules/navigation/godot_navigation_server.cpp b/modules/navigation/godot_navigation_server.cpp index d835cd13d6d..3267124ace9 100644 --- a/modules/navigation/godot_navigation_server.cpp +++ b/modules/navigation/godot_navigation_server.cpp @@ -537,14 +537,14 @@ bool GodotNavigationServer::agent_is_map_changed(RID p_agent) const { return agent->is_map_changed(); } -COMMAND_4(agent_set_callback, RID, p_agent, Object *, p_receiver, StringName, p_method, Variant, p_udata) { +COMMAND_4(agent_set_callback, RID, p_agent, ObjectID, p_object_id, StringName, p_method, Variant, p_udata) { RvoAgent *agent = agent_owner.getornull(p_agent); ERR_FAIL_COND(agent == nullptr); - agent->set_callback(p_receiver == nullptr ? 0 : p_receiver->get_instance_id(), p_method, p_udata); + agent->set_callback(p_object_id, p_method, p_udata); if (agent->get_map()) { - if (p_receiver == nullptr) { + if (p_object_id == ObjectID()) { agent->get_map()->remove_agent_as_controlled(agent); } else { agent->get_map()->set_agent_as_controlled(agent); diff --git a/modules/navigation/godot_navigation_server.h b/modules/navigation/godot_navigation_server.h index bd20ae863e8..75cb59dcb42 100644 --- a/modules/navigation/godot_navigation_server.h +++ b/modules/navigation/godot_navigation_server.h @@ -147,7 +147,7 @@ public: COMMAND_2(agent_set_position, RID, p_agent, Vector3, p_position); COMMAND_2(agent_set_ignore_y, RID, p_agent, bool, p_ignore); virtual bool agent_is_map_changed(RID p_agent) const; - COMMAND_4_DEF(agent_set_callback, RID, p_agent, Object *, p_receiver, StringName, p_method, Variant, p_udata, Variant()); + COMMAND_4_DEF(agent_set_callback, RID, p_agent, ObjectID, p_object_id, StringName, p_method, Variant, p_udata, Variant()); COMMAND_1(free, RID, p_object); diff --git a/scene/2d/navigation_agent_2d.cpp b/scene/2d/navigation_agent_2d.cpp index 635c8033606..68478ef54c7 100644 --- a/scene/2d/navigation_agent_2d.cpp +++ b/scene/2d/navigation_agent_2d.cpp @@ -211,9 +211,9 @@ NavigationAgent2D::~NavigationAgent2D() { void NavigationAgent2D::set_avoidance_enabled(bool p_enabled) { avoidance_enabled = p_enabled; if (avoidance_enabled) { - Navigation2DServer::get_singleton()->agent_set_callback(agent, this, "_avoidance_done"); + Navigation2DServer::get_singleton()->agent_set_callback(agent, get_instance_id(), "_avoidance_done"); } else { - Navigation2DServer::get_singleton()->agent_set_callback(agent, nullptr, "_avoidance_done"); + Navigation2DServer::get_singleton()->agent_set_callback(agent, ObjectID(), "_avoidance_done"); } } @@ -223,7 +223,7 @@ bool NavigationAgent2D::get_avoidance_enabled() const { void NavigationAgent2D::set_agent_parent(Node *p_agent_parent) { // remove agent from any avoidance map before changing parent or there will be leftovers on the RVO map - Navigation2DServer::get_singleton()->agent_set_callback(agent, nullptr, "_avoidance_done"); + Navigation2DServer::get_singleton()->agent_set_callback(agent, ObjectID(), "_avoidance_done"); if (Object::cast_to(p_agent_parent) != nullptr) { // place agent on navigation map first or else the RVO agent callback creation fails silently later agent_parent = Object::cast_to(p_agent_parent); diff --git a/scene/3d/navigation_agent.cpp b/scene/3d/navigation_agent.cpp index e717f6d1d49..b42dfb62d54 100644 --- a/scene/3d/navigation_agent.cpp +++ b/scene/3d/navigation_agent.cpp @@ -214,9 +214,9 @@ NavigationAgent::~NavigationAgent() { void NavigationAgent::set_avoidance_enabled(bool p_enabled) { avoidance_enabled = p_enabled; if (avoidance_enabled) { - NavigationServer::get_singleton()->agent_set_callback(agent, this, "_avoidance_done"); + NavigationServer::get_singleton()->agent_set_callback(agent, get_instance_id(), "_avoidance_done"); } else { - NavigationServer::get_singleton()->agent_set_callback(agent, nullptr, "_avoidance_done"); + NavigationServer::get_singleton()->agent_set_callback(agent, ObjectID(), "_avoidance_done"); } } @@ -245,7 +245,7 @@ Node *NavigationAgent::get_navigation_node() const { void NavigationAgent::set_agent_parent(Node *p_agent_parent) { // remove agent from any avoidance map before changing parent or there will be leftovers on the RVO map - NavigationServer::get_singleton()->agent_set_callback(agent, nullptr, "_avoidance_done"); + NavigationServer::get_singleton()->agent_set_callback(agent, ObjectID(), "_avoidance_done"); if (Object::cast_to(p_agent_parent) != nullptr) { // place agent on navigation map first or else the RVO agent callback creation fails silently later agent_parent = Object::cast_to(p_agent_parent); diff --git a/servers/navigation_2d_server.cpp b/servers/navigation_2d_server.cpp index 074b92b46f0..728da55ab64 100644 --- a/servers/navigation_2d_server.cpp +++ b/servers/navigation_2d_server.cpp @@ -146,10 +146,6 @@ Transform trf2_to_trf3(const Transform2D &d) { return Transform(b, o); } -Object *obj_to_obj(Object *d) { - return d; -} - StringName sn_to_sn(StringName &d) { return d; } @@ -158,6 +154,10 @@ Variant var_to_var(Variant &d) { return d; } +ObjectID id_to_id(const ObjectID &id) { + return id; +} + Ref poly_to_mesh(Ref d) { if (d.is_valid()) { return d->get_mesh(); @@ -218,7 +218,7 @@ void Navigation2DServer::_bind_methods() { ClassDB::bind_method(D_METHOD("agent_set_target_velocity", "agent", "target_velocity"), &Navigation2DServer::agent_set_target_velocity); ClassDB::bind_method(D_METHOD("agent_set_position", "agent", "position"), &Navigation2DServer::agent_set_position); ClassDB::bind_method(D_METHOD("agent_is_map_changed", "agent"), &Navigation2DServer::agent_is_map_changed); - ClassDB::bind_method(D_METHOD("agent_set_callback", "agent", "receiver", "method", "userdata"), &Navigation2DServer::agent_set_callback, DEFVAL(Variant())); + ClassDB::bind_method(D_METHOD("agent_set_callback", "agent", "object_id", "method", "userdata"), &Navigation2DServer::agent_set_callback, DEFVAL(Variant())); ClassDB::bind_method(D_METHOD("free_rid", "rid"), &Navigation2DServer::free); @@ -319,6 +319,6 @@ void FORWARD_2_C(agent_set_ignore_y, RID, p_agent, bool, p_ignore, rid_to_rid, b bool FORWARD_1_C(agent_is_map_changed, RID, p_agent, rid_to_rid); -void FORWARD_4_C(agent_set_callback, RID, p_agent, Object *, p_receiver, StringName, p_method, Variant, p_udata, rid_to_rid, obj_to_obj, sn_to_sn, var_to_var); +void FORWARD_4_C(agent_set_callback, RID, p_agent, ObjectID, p_object_id, StringName, p_method, Variant, p_udata, rid_to_rid, id_to_id, sn_to_sn, var_to_var); void FORWARD_1_C(free, RID, p_object, rid_to_rid); diff --git a/servers/navigation_2d_server.h b/servers/navigation_2d_server.h index 41d7786be5d..63475a93beb 100644 --- a/servers/navigation_2d_server.h +++ b/servers/navigation_2d_server.h @@ -181,7 +181,7 @@ public: virtual bool agent_is_map_changed(RID p_agent) const; /// Callback called at the end of the RVO process - virtual void agent_set_callback(RID p_agent, Object *p_receiver, StringName p_method, Variant p_udata = Variant()) const; + virtual void agent_set_callback(RID p_agent, ObjectID p_object_id, StringName p_method, Variant p_udata = Variant()) const; /// Destroy the `RID` virtual void free(RID p_object) const; diff --git a/servers/navigation_server.cpp b/servers/navigation_server.cpp index 9a585450089..1ca66755426 100644 --- a/servers/navigation_server.cpp +++ b/servers/navigation_server.cpp @@ -87,7 +87,7 @@ void NavigationServer::_bind_methods() { ClassDB::bind_method(D_METHOD("agent_set_target_velocity", "agent", "target_velocity"), &NavigationServer::agent_set_target_velocity); ClassDB::bind_method(D_METHOD("agent_set_position", "agent", "position"), &NavigationServer::agent_set_position); ClassDB::bind_method(D_METHOD("agent_is_map_changed", "agent"), &NavigationServer::agent_is_map_changed); - ClassDB::bind_method(D_METHOD("agent_set_callback", "agent", "receiver", "method", "userdata"), &NavigationServer::agent_set_callback, DEFVAL(Variant())); + ClassDB::bind_method(D_METHOD("agent_set_callback", "agent", "object_id", "method", "userdata"), &NavigationServer::agent_set_callback, DEFVAL(Variant())); ClassDB::bind_method(D_METHOD("free_rid", "rid"), &NavigationServer::free); diff --git a/servers/navigation_server.h b/servers/navigation_server.h index 5e934352e80..bf40a075888 100644 --- a/servers/navigation_server.h +++ b/servers/navigation_server.h @@ -197,7 +197,7 @@ public: virtual bool agent_is_map_changed(RID p_agent) const = 0; /// Callback called at the end of the RVO process - virtual void agent_set_callback(RID p_agent, Object *p_receiver, StringName p_method, Variant p_udata = Variant()) const = 0; + virtual void agent_set_callback(RID p_agent, ObjectID p_object_id, StringName p_method, Variant p_udata = Variant()) const = 0; /// Destroy the `RID` virtual void free(RID p_object) const = 0; From daa4be06b047227ae7e70fba805507bc7049aaf0 Mon Sep 17 00:00:00 2001 From: Anilforextra Date: Wed, 7 Sep 2022 11:02:57 +0545 Subject: [PATCH 07/10] Enable material editor preview to be rotated. (cherry picked from commit d4ee903004637b6ba12eef004a4d9006462c83b6) --- editor/plugins/material_editor_plugin.cpp | 42 ++++++++++++++++++----- editor/plugins/material_editor_plugin.h | 5 +++ 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/editor/plugins/material_editor_plugin.cpp b/editor/plugins/material_editor_plugin.cpp index 5857e4d057d..045a71f82a6 100644 --- a/editor/plugins/material_editor_plugin.cpp +++ b/editor/plugins/material_editor_plugin.cpp @@ -34,6 +34,19 @@ #include "scene/gui/viewport_container.h" #include "scene/resources/particles_material.h" +void MaterialEditor::_gui_input(const Ref &p_event) { + ERR_FAIL_COND(p_event.is_null()); + + Ref mm = p_event; + if (mm.is_valid() && (mm->get_button_mask() & BUTTON_MASK_LEFT)) { + rot.x -= mm->get_relative().y * 0.01; + rot.y -= mm->get_relative().x * 0.01; + + rot.x = CLAMP(rot.x, -Math_PI / 2, Math_PI / 2); + _update_rotation(); + } +} + void MaterialEditor::_notification(int p_what) { if (p_what == NOTIFICATION_READY) { //get_scene()->connect("node_removed",this,"_node_removed"); @@ -63,6 +76,13 @@ void MaterialEditor::_notification(int p_what) { } } +void MaterialEditor::_update_rotation() { + Transform t; + t.basis.rotate(Vector3(0, 1, 0), -rot.y); + t.basis.rotate(Vector3(1, 0, 0), -rot.x); + rotation->set_transform(t); +} + void MaterialEditor::edit(Ref p_material, const Ref &p_env) { material = p_material; camera->set_environment(p_env); @@ -72,6 +92,10 @@ void MaterialEditor::edit(Ref p_material, const Ref &p_en } else { hide(); } + + rot.x = Math::deg2rad(-15.0); + rot.y = Math::deg2rad(30.0); + _update_rotation(); } void MaterialEditor::_button_pressed(Node *p_button) { @@ -101,6 +125,7 @@ void MaterialEditor::_button_pressed(Node *p_button) { } void MaterialEditor::_bind_methods() { + ClassDB::bind_method(D_METHOD("_gui_input"), &MaterialEditor::_gui_input); ClassDB::bind_method(D_METHOD("_button_pressed"), &MaterialEditor::_button_pressed); } @@ -119,7 +144,7 @@ MaterialEditor::MaterialEditor() { viewport->set_msaa(Viewport::MSAA_4X); camera = memnew(Camera); - camera->set_transform(Transform(Basis(), Vector3(0, 0, 3))); + camera->set_transform(Transform(Basis(), Vector3(0, 0, 1.1))); camera->set_perspective(45, 0.1, 10); camera->make_current(); viewport->add_child(camera); @@ -133,18 +158,17 @@ MaterialEditor::MaterialEditor() { light2->set_color(Color(0.7, 0.7, 0.7)); viewport->add_child(light2); + rotation = memnew(Spatial); + viewport->add_child(rotation); + sphere_instance = memnew(MeshInstance); - viewport->add_child(sphere_instance); + rotation->add_child(sphere_instance); box_instance = memnew(MeshInstance); - viewport->add_child(box_instance); + rotation->add_child(box_instance); - Transform box_xform; - box_xform.basis.rotate(Vector3(1, 0, 0), Math::deg2rad(25.0)); - box_xform.basis = box_xform.basis * Basis().rotated(Vector3(0, 1, 0), Math::deg2rad(-25.0)); - box_xform.basis.scale(Vector3(0.8, 0.8, 0.8)); - box_xform.origin.y = 0.2; - box_instance->set_transform(box_xform); + box_instance->set_transform(Transform(Basis() * 0.25, Vector3() * 0.25)); + sphere_instance->set_transform(Transform(Basis() * 0.375, Vector3() * 0.375)); sphere_mesh.instance(); sphere_instance->set_mesh(sphere_mesh); diff --git a/editor/plugins/material_editor_plugin.h b/editor/plugins/material_editor_plugin.h index a6e4d358650..c3bc1011a4c 100644 --- a/editor/plugins/material_editor_plugin.h +++ b/editor/plugins/material_editor_plugin.h @@ -46,8 +46,11 @@ class ViewportContainer; class MaterialEditor : public Control { GDCLASS(MaterialEditor, Control); + Vector2 rot = Vector2(); + ViewportContainer *vc; Viewport *viewport; + Spatial *rotation; MeshInstance *sphere_instance; MeshInstance *box_instance; DirectionalLight *light1; @@ -70,6 +73,8 @@ class MaterialEditor : public Control { protected: void _notification(int p_what); + void _gui_input(const Ref &p_event); + void _update_rotation(); static void _bind_methods(); From 4951f50b0fa42c26957edd4ccd65a4ce3127da28 Mon Sep 17 00:00:00 2001 From: Tomasz Chabora Date: Sun, 25 Oct 2020 22:32:32 +0100 Subject: [PATCH 08/10] Keep property values when extending script (cherry picked from commit 44cf3c22acb140cc2f19f1062c0a4c0a931fd27b) --- editor/editor_properties.cpp | 8 +++++++ editor/inspector_dock.cpp | 29 +++++++++++++++++++++++++ editor/inspector_dock.h | 4 ++++ editor/scene_tree_dock.cpp | 41 ++++++++++++++++++++++++------------ 4 files changed, 69 insertions(+), 13 deletions(-) diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index c34764f12cd..8e18bb35f1c 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -2608,7 +2608,10 @@ void EditorPropertyResource::_resource_selected(const RES &p_resource, bool p_ed void EditorPropertyResource::_resource_changed(const RES &p_resource) { // Make visual script the correct type. Ref