mirror of
https://github.com/godotengine/godot.git
synced 2025-01-30 21:33:18 +08:00
Merge pull request #13166 from Krakean/change_addrootifnone_v2
When drag'n'drop, automatically create dragged resource as a root node if you haven't any yet (v2)
This commit is contained in:
commit
20a566d63a
@ -4486,15 +4486,24 @@ void CanvasItemEditorViewport::_create_nodes(Node *parent, Node *child, String &
|
|||||||
Ref<Texture> texture = Ref<Texture>(Object::cast_to<Texture>(ResourceCache::get(path)));
|
Ref<Texture> texture = Ref<Texture>(Object::cast_to<Texture>(ResourceCache::get(path)));
|
||||||
Size2 texture_size = texture->get_size();
|
Size2 texture_size = texture->get_size();
|
||||||
|
|
||||||
editor_data->get_undo_redo().add_do_method(parent, "add_child", child);
|
if (parent) {
|
||||||
editor_data->get_undo_redo().add_do_method(child, "set_owner", editor->get_edited_scene());
|
editor_data->get_undo_redo().add_do_method(parent, "add_child", child);
|
||||||
editor_data->get_undo_redo().add_do_reference(child);
|
editor_data->get_undo_redo().add_do_method(child, "set_owner", editor->get_edited_scene());
|
||||||
editor_data->get_undo_redo().add_undo_method(parent, "remove_child", child);
|
editor_data->get_undo_redo().add_do_reference(child);
|
||||||
|
editor_data->get_undo_redo().add_undo_method(parent, "remove_child", child);
|
||||||
|
} else { // if we haven't parent, lets try to make a child as a parent.
|
||||||
|
editor_data->get_undo_redo().add_do_method(editor, "set_edited_scene", child);
|
||||||
|
editor_data->get_undo_redo().add_do_method(child, "set_owner", editor->get_edited_scene());
|
||||||
|
editor_data->get_undo_redo().add_do_reference(child);
|
||||||
|
editor_data->get_undo_redo().add_undo_method(editor, "set_edited_scene", (Object *)NULL);
|
||||||
|
}
|
||||||
|
|
||||||
String new_name = parent->validate_child_name(child);
|
if (parent) {
|
||||||
ScriptEditorDebugger *sed = ScriptEditor::get_singleton()->get_debugger();
|
String new_name = parent->validate_child_name(child);
|
||||||
editor_data->get_undo_redo().add_do_method(sed, "live_debug_create_node", editor->get_edited_scene()->get_path_to(parent), child->get_class(), new_name);
|
ScriptEditorDebugger *sed = ScriptEditor::get_singleton()->get_debugger();
|
||||||
editor_data->get_undo_redo().add_undo_method(sed, "live_debug_remove_node", NodePath(String(editor->get_edited_scene()->get_path_to(parent)) + "/" + new_name));
|
editor_data->get_undo_redo().add_do_method(sed, "live_debug_create_node", editor->get_edited_scene()->get_path_to(parent), child->get_class(), new_name);
|
||||||
|
editor_data->get_undo_redo().add_undo_method(sed, "live_debug_remove_node", NodePath(String(editor->get_edited_scene()->get_path_to(parent)) + "/" + new_name));
|
||||||
|
}
|
||||||
|
|
||||||
// handle with different property for texture
|
// handle with different property for texture
|
||||||
String property = "texture";
|
String property = "texture";
|
||||||
@ -4527,8 +4536,8 @@ void CanvasItemEditorViewport::_create_nodes(Node *parent, Node *child, String &
|
|||||||
}
|
}
|
||||||
|
|
||||||
// locate at preview position
|
// locate at preview position
|
||||||
Point2 pos;
|
Point2 pos = Point2(0, 0);
|
||||||
if (parent->has_method("get_global_position")) {
|
if (parent && parent->has_method("get_global_position")) {
|
||||||
pos = parent->call("get_global_position");
|
pos = parent->call("get_global_position");
|
||||||
}
|
}
|
||||||
Transform2D trans = canvas->get_canvas_transform();
|
Transform2D trans = canvas->get_canvas_transform();
|
||||||
@ -4689,6 +4698,18 @@ bool CanvasItemEditorViewport::can_drop_data(const Point2 &p_point, const Varian
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CanvasItemEditorViewport::_show_resource_type_selector() {
|
||||||
|
List<BaseButton *> btn_list;
|
||||||
|
button_group->get_buttons(&btn_list);
|
||||||
|
|
||||||
|
for (int i = 0; i < btn_list.size(); i++) {
|
||||||
|
CheckBox *check = Object::cast_to<CheckBox>(btn_list[i]);
|
||||||
|
check->set_pressed(check->get_text() == default_type);
|
||||||
|
}
|
||||||
|
selector->set_title(vformat(TTR("Add %s"), default_type));
|
||||||
|
selector->popup_centered_minsize();
|
||||||
|
}
|
||||||
|
|
||||||
void CanvasItemEditorViewport::drop_data(const Point2 &p_point, const Variant &p_data) {
|
void CanvasItemEditorViewport::drop_data(const Point2 &p_point, const Variant &p_data) {
|
||||||
bool is_shift = Input::get_singleton()->is_key_pressed(KEY_SHIFT);
|
bool is_shift = Input::get_singleton()->is_key_pressed(KEY_SHIFT);
|
||||||
bool is_alt = Input::get_singleton()->is_key_pressed(KEY_ALT);
|
bool is_alt = Input::get_singleton()->is_key_pressed(KEY_ALT);
|
||||||
@ -4705,10 +4726,8 @@ void CanvasItemEditorViewport::drop_data(const Point2 &p_point, const Variant &p
|
|||||||
if (root_node) {
|
if (root_node) {
|
||||||
list.push_back(root_node);
|
list.push_back(root_node);
|
||||||
} else {
|
} else {
|
||||||
accept->get_ok()->set_text(TTR("OK :("));
|
drop_pos = p_point;
|
||||||
accept->set_text(TTR("No parent to instance a child at."));
|
_show_resource_type_selector();
|
||||||
accept->popup_centered_minsize();
|
|
||||||
_remove_preview();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4727,15 +4746,7 @@ void CanvasItemEditorViewport::drop_data(const Point2 &p_point, const Variant &p
|
|||||||
drop_pos = p_point;
|
drop_pos = p_point;
|
||||||
|
|
||||||
if (is_alt) {
|
if (is_alt) {
|
||||||
List<BaseButton *> btn_list;
|
_show_resource_type_selector();
|
||||||
button_group->get_buttons(&btn_list);
|
|
||||||
|
|
||||||
for (int i = 0; i < btn_list.size(); i++) {
|
|
||||||
CheckBox *check = Object::cast_to<CheckBox>(btn_list[i]);
|
|
||||||
check->set_pressed(check->get_text() == default_type);
|
|
||||||
}
|
|
||||||
selector->set_title(vformat(TTR("Add %s"), default_type));
|
|
||||||
selector->popup_centered_minsize();
|
|
||||||
} else {
|
} else {
|
||||||
_perform_drop_data();
|
_perform_drop_data();
|
||||||
}
|
}
|
||||||
|
@ -578,6 +578,7 @@ class CanvasItemEditorViewport : public Control {
|
|||||||
void _create_nodes(Node *parent, Node *child, String &path, const Point2 &p_point);
|
void _create_nodes(Node *parent, Node *child, String &path, const Point2 &p_point);
|
||||||
bool _create_instance(Node *parent, String &path, const Point2 &p_point);
|
bool _create_instance(Node *parent, String &path, const Point2 &p_point);
|
||||||
void _perform_drop_data();
|
void _perform_drop_data();
|
||||||
|
void _show_resource_type_selector();
|
||||||
|
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user