mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +00:00
Merge pull request #106750 from KoBeWi/path_guesser
Assign base path when creating Resource
This commit is contained in:
commit
591e70ff78
2 changed files with 29 additions and 0 deletions
|
@ -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"
|
||||
|
@ -496,6 +497,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);
|
||||
|
||||
|
@ -589,6 +591,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();
|
||||
|
|
|
@ -101,6 +101,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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue