1
0
Fork 0

Assign base path when creating Resource

This commit is contained in:
kobewi 2025-05-23 16:06:15 +02:00
parent aef0065e09
commit e7d9df33a5
2 changed files with 29 additions and 0 deletions

View File

@ -32,6 +32,7 @@
#include "editor/audio_stream_preview.h"
#include "editor/editor_help.h"
#include "editor/editor_inspector.h"
#include "editor/editor_node.h"
#include "editor/editor_resource_preview.h"
#include "editor/editor_settings.h"
@ -486,6 +487,7 @@ void EditorResourcePicker::_edit_menu_cbk(int p_which) {
Resource *resp = Object::cast_to<Resource>(obj);
ERR_BREAK(!resp);
resp->set_path(_get_owner_path() + "::"); // Assign a base path for built-in Resources.
EditorNode::get_editor_data().instantiate_object_properties(obj);
@ -579,6 +581,32 @@ void EditorResourcePicker::_button_input(const Ref<InputEvent> &p_event) {
}
}
String EditorResourcePicker::_get_owner_path() const {
EditorProperty *property = Object::cast_to<EditorProperty>(get_parent());
if (!property) {
return String();
}
Object *obj = property->get_edited_object();
Node *node = Object::cast_to<Node>(obj);
if (node) {
if (node->get_scene_file_path().is_empty()) {
node = node->get_owner();
}
if (node) {
return node->get_scene_file_path();
}
return String();
}
Resource *res = Object::cast_to<Resource>(obj);
if (res && !res->is_built_in()) {
return res->get_path();
}
// TODO: It would be nice to handle deeper Resource nesting.
return String();
}
String EditorResourcePicker::_get_resource_type(const Ref<Resource> &p_resource) const {
if (p_resource.is_null()) {
return String();

View File

@ -99,6 +99,7 @@ class EditorResourcePicker : public HBoxContainer {
void _button_draw();
void _button_input(const Ref<InputEvent> &p_event);
String _get_owner_path() const;
String _get_resource_type(const Ref<Resource> &p_resource) const;
void _ensure_allowed_types() const;
bool _is_drop_valid(const Dictionary &p_drag_data) const;