diff options
Diffstat (limited to 'editor/editor_properties.cpp')
-rw-r--r-- | editor/editor_properties.cpp | 81 |
1 files changed, 72 insertions, 9 deletions
diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index b68ec97406..de948acc71 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -233,7 +233,7 @@ void EditorPropertyPath::_path_pressed() { dialog->set_mode(EditorFileDialog::MODE_OPEN_DIR); dialog->set_current_dir(full_path); } else { - dialog->set_mode(EditorFileDialog::MODE_OPEN_FILE); + dialog->set_mode(save_mode ? EditorFileDialog::MODE_SAVE_FILE : EditorFileDialog::MODE_OPEN_FILE); for (int i = 0; i < extensions.size(); i++) { String e = extensions[i].strip_edges(); if (e != String()) { @@ -260,6 +260,11 @@ void EditorPropertyPath::setup(const Vector<String> &p_extensions, bool p_folder global = p_global; } +void EditorPropertyPath::set_save_mode() { + + save_mode = true; +} + void EditorPropertyPath::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { @@ -296,6 +301,7 @@ EditorPropertyPath::EditorPropertyPath() { path_edit->connect("pressed", this, "_path_pressed"); folder = false; global = false; + save_mode = false; } ///////////////////// CLASS NAME ///////////////////////// @@ -1802,14 +1808,26 @@ void EditorPropertyNodePath::_node_selected(const NodePath &p_path) { NodePath path = p_path; Node *base_node = Object::cast_to<Node>(get_edited_object()); - if (base_node == NULL) { - if (Object::cast_to<Resource>(get_edited_object())) { - Node *to_node = get_node(p_path); - path = get_tree()->get_edited_scene_root()->get_path_to(to_node); - } else if (get_edited_object()->has_method("get_root_path")) { - base_node = get_edited_object()->call("get_root_path"); + if (!base_node) { + //try a base node within history + if (EditorNode::get_singleton()->get_editor_history()->get_path_size() > 0) { + Object *base = ObjectDB::get_instance(EditorNode::get_singleton()->get_editor_history()->get_path_object(0)); + if (base) { + base_node = Object::cast_to<Node>(base); + } } } + + if (!base_node && get_edited_object()->has_method("get_root_path")) { + base_node = get_edited_object()->call("get_root_path"); + } + + if (!base_node && Object::cast_to<Reference>(get_edited_object())) { + Node *to_node = get_node(p_path); + ERR_FAIL_COND(!to_node); + path = get_tree()->get_edited_scene_root()->get_path_to(to_node); + } + if (base_node) { // for AnimationTrackKeyEdit path = base_node->get_path().rel_path_to(p_path); } @@ -2016,6 +2034,13 @@ void EditorPropertyResource::_menu_option(int p_which) { } break; + case OBJ_MENU_SAVE: { + RES res = get_edited_object()->get(get_edited_property()); + if (res.is_null()) + return; + EditorNode::get_singleton()->save_resource(res); + } break; + case OBJ_MENU_COPY: { RES res = get_edited_object()->get(get_edited_property()); @@ -2069,8 +2094,22 @@ void EditorPropertyResource::_menu_option(int p_which) { if (intype == "ViewportTexture") { + Resource *r = Object::cast_to<Resource>(get_edited_object()); + if (r && r->get_path().is_resource_file()) { + EditorNode::get_singleton()->show_warning(TTR("Can't create a ViewportTexture on resources saved as a file.\nResource needs to belong to a scene.")); + return; + } + + if (r && !r->is_local_to_scene()) { + EditorNode::get_singleton()->show_warning(TTR("Can't create a ViewportTexture on this resource because it's not set as local to scene.\nPlease switch on the 'local to scene' property on it (and all resources containing it up to a node).")); + return; + } + if (!scene_tree) { scene_tree = memnew(SceneTreeDialog); + Vector<StringName> valid_types; + valid_types.push_back("Viewport"); + scene_tree->get_scene_tree()->set_valid_types(valid_types); scene_tree->get_scene_tree()->set_show_enabled_subscene(true); add_child(scene_tree); scene_tree->connect("selected", this, "_viewport_selected"); @@ -2131,7 +2170,8 @@ void EditorPropertyResource::_resource_preview(const String &p_path, const Ref<T } } -void EditorPropertyResource::_update_menu() { +void EditorPropertyResource::_update_menu_items() { + //////////////////// UPDATE MENU ////////////////////////// RES res = get_edited_object()->get(get_edited_property()); @@ -2218,6 +2258,7 @@ void EditorPropertyResource::_update_menu() { menu->add_icon_item(get_icon("Edit", "EditorIcons"), TTR("Edit"), OBJ_MENU_EDIT); menu->add_icon_item(get_icon("Clear", "EditorIcons"), TTR("Clear"), OBJ_MENU_CLEAR); menu->add_icon_item(get_icon("Duplicate", "EditorIcons"), TTR("Make Unique"), OBJ_MENU_MAKE_UNIQUE); + menu->add_icon_item(get_icon("Save", "EditorIcons"), TTR("Save"), OBJ_MENU_SAVE); RES r = res; if (r.is_valid() && r->get_path().is_resource_file()) { menu->add_separator(); @@ -2273,6 +2314,11 @@ void EditorPropertyResource::_update_menu() { menu->add_icon_item(icon, vformat(TTR("Convert To %s"), what), CONVERT_BASE_ID + i); } } +} + +void EditorPropertyResource::_update_menu() { + + _update_menu_items(); Rect2 gt = edit->get_global_rect(); menu->set_as_minsize(); @@ -2297,6 +2343,20 @@ void EditorPropertyResource::_sub_inspector_object_id_selected(int p_id) { emit_signal("object_id_selected", get_edited_property(), p_id); } +void EditorPropertyResource::_button_input(const Ref<InputEvent> &p_event) { + Ref<InputEventMouseButton> mb = p_event; + if (mb.is_valid()) { + if (mb->is_pressed() && mb->get_button_index() == BUTTON_RIGHT) { + _update_menu_items(); + Vector2 pos = mb->get_global_position(); + //pos = assign->get_global_transform().xform(pos); + menu->set_as_minsize(); + menu->set_global_position(pos); + menu->popup(); + } + } +} + void EditorPropertyResource::_open_editor_pressed() { RES res = get_edited_object()->get(get_edited_property()); if (res.is_valid()) { @@ -2584,6 +2644,7 @@ void EditorPropertyResource::_bind_methods() { ClassDB::bind_method(D_METHOD("drop_data_fw"), &EditorPropertyResource::drop_data_fw); ClassDB::bind_method(D_METHOD("_button_draw"), &EditorPropertyResource::_button_draw); ClassDB::bind_method(D_METHOD("_open_editor_pressed"), &EditorPropertyResource::_open_editor_pressed); + ClassDB::bind_method(D_METHOD("_button_input"), &EditorPropertyResource::_button_input); } EditorPropertyResource::EditorPropertyResource() { @@ -2610,6 +2671,7 @@ EditorPropertyResource::EditorPropertyResource() { preview->set_margin(MARGIN_BOTTOM, -1); preview->set_margin(MARGIN_RIGHT, -1); assign->add_child(preview); + assign->connect("gui_input", this, "_button_input"); menu = memnew(PopupMenu); add_child(menu); @@ -2618,6 +2680,7 @@ EditorPropertyResource::EditorPropertyResource() { menu->connect("id_pressed", this, "_menu_option"); edit->connect("pressed", this, "_update_menu"); hbc->add_child(edit); + edit->connect("gui_input", this, "_button_input"); file = NULL; scene_tree = NULL; @@ -3039,7 +3102,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ } break; case Variant::ARRAY: { EditorPropertyArray *editor = memnew(EditorPropertyArray); - editor->setup(Variant::ARRAY); + editor->setup(Variant::ARRAY, p_hint_text); add_property_editor(p_path, editor); } break; case Variant::POOL_BYTE_ARRAY: { |