Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add_to_end in add_property_editor() appears to do nothing #91938

Closed
Arnklit opened this issue May 14, 2024 · 1 comment · Fixed by #92272
Closed

add_to_end in add_property_editor() appears to do nothing #91938

Arnklit opened this issue May 14, 2024 · 1 comment · Fixed by #92272

Comments

@Arnklit
Copy link
Contributor

Arnklit commented May 14, 2024

Tested versions

4.2.2.stable

System information

Godot v4.2.2.stable - Windows 10.0.22631 - Vulkan (Forward+) - dedicated AMD Radeon RX 7800 XT (Advanced Micro Devices, Inc.; 31.0.24019.1006) - AMD Ryzen 9 7900X 12-Core Processor (24 Threads)

Issue description

I assume the add_to_end property is meant to move properties to the end of the inspector? The docs don't say anything about it. But in my testing the argument does nothing, the editor properties just follow the property order.

Here I've made a custom inspector plugin that accepts all ints and puts in my simple editor that is just a label.

@tool
extends EditorInspectorPlugin

var IntEditor = preload("res://addons/exampleplugin/int_editor.gd")

func _can_handle(object) -> bool:
	return true


func _parse_property(object, type, name, hint_type, hint_string, usage_flags, wide) -> bool:
	if type == TYPE_INT:
		add_property_editor(name, IntEditor.new(), true)
		return true
	return false

Here is a script where the int is on top.

extends Node2D

@export var int_test := 0
@export var float_test := 0.0

But it doesn't get moved to the end like I expect.
image

Note: This might just be me misunderstanding what the argument does, but if that's the case, the docs need more info

Steps to reproduce

Try out the MRP project

Minimal reproduction project (MRP)

add_to_end_issue.zip

@kleonc
Copy link
Member

kleonc commented May 14, 2024

That's the relevant source code:

// Search for the inspector plugin that will handle the properties. Then add the correct property editor to it.
for (Ref<EditorInspectorPlugin> &ped : valid_plugins) {
bool exclusive = ped->parse_property(object, p.type, p.name, p.hint, p.hint_string, p.usage, wide_editors);
for (const EditorInspectorPlugin::AddedEditor &F : ped->added_editors) {
if (F.add_to_end) {
late_editors.push_back(F);
} else {
editors.push_back(F);
}
}
ped->added_editors.clear();
if (exclusive) {
break;
}
}
editors.append_array(late_editors);

So basically an EditorProperty added with add_to_end = true is ensured to be added after/below any other EditorProperty handling the same property but added with add_to_end = false.

E.g. after changing your EditorInspectorPlugin to always add the default EditorProperty for int (removed return true from _parse_property):

@tool
extends EditorInspectorPlugin

var IntEditor = preload("res://addons/exampleplugin/int_editor.gd")

func _can_handle(object) -> bool:
	return true


func _parse_property(object, type, name, hint_type, hint_string, usage_flags, wide) -> bool:
	if type == TYPE_INT:
		var add_to_end = ...
		add_property_editor(name, IntEditor.new(), add_to_end)
	return false

Result (v4.2.2.stable.official [15073af]):

add_to_end = false add_to_end = true
Godot_v4 2 2-stable_win64_HzfDH2vkBg nTJ1l9gIVm

In the source it's used (only?) by the EditorInspectorPluginTextureRegion for adding the "Edit Region" button:

bool EditorInspectorPluginTextureRegion::parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const BitField<PropertyUsageFlags> p_usage, const bool p_wide) {
if ((p_type == Variant::RECT2 || p_type == Variant::RECT2I)) {
if (((Object::cast_to<Sprite2D>(p_object) || Object::cast_to<Sprite3D>(p_object) || Object::cast_to<NinePatchRect>(p_object) || Object::cast_to<StyleBoxTexture>(p_object)) && p_path == "region_rect") || (Object::cast_to<AtlasTexture>(p_object) && p_path == "region")) {
Button *button = EditorInspector::create_inspector_action_button(TTR("Edit Region"));
button->set_icon(texture_region_editor->get_editor_theme_icon(SNAME("RegionEdit")));
button->connect("pressed", callable_mp(this, &EditorInspectorPluginTextureRegion::_region_edit).bind(p_object));
add_property_editor(p_path, button, true);
}
}
return false; //not exclusive
}

So seems like it's just a matter of documenting it? 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants