diff options
Diffstat (limited to 'editor/editor_properties.cpp')
-rw-r--r-- | editor/editor_properties.cpp | 145 |
1 files changed, 115 insertions, 30 deletions
diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index c5d0f13c60..45acd1b6d4 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -115,8 +115,8 @@ void EditorPropertyMultilineText::_open_big_text() { add_child(big_text_dialog); } - big_text->set_text(text->get_text()); big_text_dialog->popup_centered_ratio(); + big_text->set_text(text->get_text()); } void EditorPropertyMultilineText::update_property() { @@ -483,16 +483,16 @@ EditorPropertyCheck::EditorPropertyCheck() { void EditorPropertyEnum::_option_selected(int p_which) { - int val = options->get_item_metadata(p_which); + int64_t val = options->get_item_metadata(p_which); emit_changed(get_edited_property(), val); } void EditorPropertyEnum::update_property() { - int which = get_edited_object()->get(get_edited_property()); + int64_t which = get_edited_object()->get(get_edited_property()); for (int i = 0; i < options->get_item_count(); i++) { - if (which == (int)options->get_item_metadata(i)) { + if (which == (int64_t)options->get_item_metadata(i)) { options->select(i); return; } @@ -501,11 +501,11 @@ void EditorPropertyEnum::update_property() { void EditorPropertyEnum::setup(const Vector<String> &p_options) { - int current_val = 0; + int64_t current_val = 0; for (int i = 0; i < p_options.size(); i++) { Vector<String> text_split = p_options[i].split(":"); if (text_split.size() != 1) - current_val = text_split[1].to_int(); + current_val = text_split[1].to_int64(); options->add_item(text_split[0]); options->set_item_metadata(i, current_val); current_val += 1; @@ -665,10 +665,10 @@ public: uint32_t idx = i * 10 + j; bool on = value & (1 << idx); - Rect2 rect = Rect2(o, Size2(bsize, bsize)); + Rect2 rect2 = Rect2(o, Size2(bsize, bsize)); color.a = on ? 0.6 : 0.2; - draw_rect(rect, color); - flag_rects.push_back(rect); + draw_rect(rect2, color); + flag_rects.push_back(rect2); } } } @@ -786,6 +786,7 @@ EditorPropertyLayers::EditorPropertyLayers() { grid->set_h_size_flags(SIZE_EXPAND_FILL); hb->add_child(grid); button = memnew(Button); + button->set_toggle_mode(true); button->set_text(".."); button->connect("pressed", this, "_button_pressed"); hb->add_child(button); @@ -794,6 +795,7 @@ EditorPropertyLayers::EditorPropertyLayers() { add_child(layers); layers->set_hide_on_checkable_item_selection(false); layers->connect("id_pressed", this, "_menu_pressed"); + layers->connect("popup_hide", button, "set_pressed", varray(false)); } ///////////////////// INT ///////////////////////// @@ -801,11 +803,11 @@ EditorPropertyLayers::EditorPropertyLayers() { void EditorPropertyInteger::_value_changed(double val) { if (setting) return; - emit_changed(get_edited_property(), int(val)); + emit_changed(get_edited_property(), (int64_t)val); } void EditorPropertyInteger::update_property() { - int val = get_edited_object()->get(get_edited_property()); + int64_t val = get_edited_object()->get(get_edited_property()); setting = true; spin->set_value(val); setting = false; @@ -1982,6 +1984,8 @@ void EditorPropertyResource::_file_selected(const String &p_path) { RES res = ResourceLoader::load(p_path); + ERR_FAIL_COND(res.is_null()); + List<PropertyInfo> prop_list; get_edited_object()->get_property_list(&prop_list); String property_types; @@ -2187,7 +2191,19 @@ void EditorPropertyResource::_menu_option(int p_which) { return; } - Object *obj = ClassDB::instance(intype); + Object *obj = NULL; + + if (ScriptServer::is_global_class(intype)) { + obj = ClassDB::instance(ScriptServer::get_global_class_native_base(intype)); + if (obj) { + Ref<Script> script = ResourceLoader::load(ScriptServer::get_global_class_path(intype)); + if (script.is_valid()) { + obj->set_script(Variant(script)); + } + } + } else { + obj = ClassDB::instance(intype); + } if (!obj) { obj = EditorNode::get_editor_data().instance_custom_type(intype, "Resource"); @@ -2265,8 +2281,8 @@ void EditorPropertyResource::_update_menu_items() { List<StringName> inheritors; ClassDB::get_inheriters_from_class(base.strip_edges(), &inheritors); - for (int i = 0; i < custom_resources.size(); i++) { - inheritors.push_back(custom_resources[i].name); + for (int j = 0; j < custom_resources.size(); j++) { + inheritors.push_back(custom_resources[j].name); } List<StringName>::Element *E = inheritors.front(); @@ -2275,23 +2291,33 @@ void EditorPropertyResource::_update_menu_items() { E = E->next(); } - for (Set<String>::Element *E = valid_inheritors.front(); E; E = E->next()) { - String t = E->get(); + List<StringName> global_classes; + ScriptServer::get_global_class_list(&global_classes); + E = global_classes.front(); + while (E) { + if (EditorNode::get_editor_data().script_class_is_parent(E->get(), base_type)) { + valid_inheritors.insert(E->get()); + } + E = E->next(); + } + + for (Set<String>::Element *F = valid_inheritors.front(); F; F = F->next()) { + String t = F->get(); bool is_custom_resource = false; Ref<Texture> icon; if (!custom_resources.empty()) { - for (int i = 0; i < custom_resources.size(); i++) { - if (custom_resources[i].name == t) { + for (int j = 0; j < custom_resources.size(); j++) { + if (custom_resources[j].name == t) { is_custom_resource = true; - if (custom_resources[i].icon.is_valid()) - icon = custom_resources[i].icon; + if (custom_resources[j].icon.is_valid()) + icon = custom_resources[j].icon; break; } } } - if (!is_custom_resource && !ClassDB::can_instance(t)) + if (!is_custom_resource && !(ScriptServer::is_global_class(t) || ClassDB::can_instance(t))) continue; inheritors_array.push_back(t); @@ -2427,7 +2453,39 @@ void EditorPropertyResource::_button_input(const Ref<InputEvent> &p_event) { void EditorPropertyResource::_open_editor_pressed() { RES res = get_edited_object()->get(get_edited_property()); if (res.is_valid()) { - EditorNode::get_singleton()->edit_item(res.ptr()); + EditorNode::get_singleton()->call_deferred("edit_item_resource", res); //may clear the editor so do it deferred + } +} + +void EditorPropertyResource::_fold_other_editors(Object *p_self) { + + if (this == p_self) { + return; + } + + RES res = get_edited_object()->get(get_edited_property()); + + if (!res.is_valid()) + return; + bool use_editor = false; + for (int i = 0; i < EditorNode::get_singleton()->get_editor_data().get_editor_plugin_count(); i++) { + EditorPlugin *ep = EditorNode::get_singleton()->get_editor_data().get_editor_plugin(i); + if (ep->handles(res.ptr())) { + use_editor = true; + } + } + + if (!use_editor) + return; + bool unfolded = get_edited_object()->editor_is_section_unfolded(get_edited_property()); + + opened_editor = false; + + if (unfolded) { + //refold + assign->set_pressed(false); + get_edited_object()->editor_set_section_unfold(get_edited_property(), false); + update_property(); } } @@ -2448,7 +2506,7 @@ void EditorPropertyResource::update_property() { sub_inspector->set_enable_v_scroll(false); sub_inspector->set_use_doc_hints(true); - sub_inspector->set_use_sub_inspector_bg(true); + sub_inspector->set_sub_inspector(true); sub_inspector->set_enable_capitalize_paths(true); sub_inspector->connect("property_keyed", this, "_sub_inspector_property_keyed"); @@ -2475,12 +2533,20 @@ void EditorPropertyResource::update_property() { } if (use_editor) { + //open editor directly and hide other open of these + _open_editor_pressed(); + if (is_inside_tree()) { + get_tree()->call_deferred("call_group", "_editor_resource_properties", "_fold_other_editors", this); + } + opened_editor = true; + /* Button *open_in_editor = memnew(Button); open_in_editor->set_text(TTR("Open Editor")); open_in_editor->set_icon(get_icon("Edit", "EditorIcons")); sub_inspector_vbox->add_child(open_in_editor); open_in_editor->connect("pressed", this, "_open_editor_pressed"); open_in_editor->set_h_size_flags(SIZE_SHRINK_CENTER); + */ } } @@ -2488,12 +2554,17 @@ void EditorPropertyResource::update_property() { sub_inspector->edit(res.ptr()); } + sub_inspector->refresh(); } else { if (sub_inspector) { set_bottom_editor(NULL); memdelete(sub_inspector_vbox); sub_inspector = NULL; sub_inspector_vbox = NULL; + if (opened_editor) { + EditorNode::get_singleton()->hide_top_editors(); + opened_editor = false; + } } } #endif @@ -2529,13 +2600,15 @@ void EditorPropertyResource::_resource_selected() { RES res = get_edited_object()->get(get_edited_property()); if (res.is_null()) { + edit->set_pressed(true); _update_menu(); return; } if (use_sub_inspector) { - get_edited_object()->editor_set_section_unfold(get_edited_property(), assign->is_pressed()); + bool unfold = !get_edited_object()->editor_is_section_unfolded(get_edited_property()); + get_edited_object()->editor_set_section_unfold(get_edited_property(), unfold); update_property(); } else { @@ -2714,10 +2787,12 @@ void EditorPropertyResource::_bind_methods() { 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); + ClassDB::bind_method(D_METHOD("_fold_other_editors"), &EditorPropertyResource::_fold_other_editors); } EditorPropertyResource::EditorPropertyResource() { + opened_editor = false; sub_inspector = NULL; sub_inspector_vbox = NULL; use_sub_inspector = bool(EDITOR_GET("interface/inspector/open_resources_in_current_inspector")); @@ -2746,7 +2821,9 @@ EditorPropertyResource::EditorPropertyResource() { add_child(menu); edit = memnew(Button); edit->set_flat(true); + edit->set_toggle_mode(true); menu->connect("id_pressed", this, "_menu_option"); + menu->connect("popup_hide", edit, "set_pressed", varray(false)); edit->connect("pressed", this, "_update_menu"); hbc->add_child(edit); edit->connect("gui_input", this, "_button_input"); @@ -2754,6 +2831,8 @@ EditorPropertyResource::EditorPropertyResource() { file = NULL; scene_tree = NULL; dropping = false; + + add_to_group("_editor_resource_properties"); } ////////////// DEFAULT PLUGIN ////////////////////// @@ -2809,7 +2888,8 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ case PROPERTY_HINT_LAYERS_3D_PHYSICS: lt = EditorPropertyLayers::LAYER_PHYSICS_3D; break; - default: {} //compiler could be smarter here and realize this can't happen + default: { + } //compiler could be smarter here and realize this can't happen } EditorPropertyLayers *editor = memnew(EditorPropertyLayers); editor->setup(lt); @@ -2918,13 +2998,17 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ EditorPropertyClassName *editor = memnew(EditorPropertyClassName); editor->setup("Object", p_hint_text); add_property_editor(p_path, editor); - } else if (p_hint == PROPERTY_HINT_DIR || p_hint == PROPERTY_HINT_FILE || p_hint == PROPERTY_HINT_GLOBAL_DIR || p_hint == PROPERTY_HINT_GLOBAL_FILE) { + } else if (p_hint == PROPERTY_HINT_DIR || p_hint == PROPERTY_HINT_FILE || p_hint == PROPERTY_HINT_SAVE_FILE || p_hint == PROPERTY_HINT_GLOBAL_DIR || p_hint == PROPERTY_HINT_GLOBAL_FILE) { Vector<String> extensions = p_hint_text.split(","); bool global = p_hint == PROPERTY_HINT_GLOBAL_DIR || p_hint == PROPERTY_HINT_GLOBAL_FILE; bool folder = p_hint == PROPERTY_HINT_DIR || p_hint == PROPERTY_HINT_GLOBAL_DIR; + bool save = p_hint == PROPERTY_HINT_SAVE_FILE; EditorPropertyPath *editor = memnew(EditorPropertyPath); editor->setup(extensions, folder, global); + if (save) { + editor->set_save_mode(); + } add_property_editor(p_path, editor); } else if (p_hint == PROPERTY_HINT_METHOD_OF_VARIANT_TYPE || p_hint == PROPERTY_HINT_METHOD_OF_BASE_TYPE || @@ -2946,7 +3030,8 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ case PROPERTY_HINT_PROPERTY_OF_BASE_TYPE: type = EditorPropertyMember::MEMBER_PROPERTY_OF_BASE_TYPE; break; case PROPERTY_HINT_PROPERTY_OF_INSTANCE: type = EditorPropertyMember::MEMBER_PROPERTY_OF_INSTANCE; break; case PROPERTY_HINT_PROPERTY_OF_SCRIPT: type = EditorPropertyMember::MEMBER_PROPERTY_OF_SCRIPT; break; - default: {} + default: { + } } editor->setup(type, p_hint_text); add_property_editor(p_path, editor); @@ -3150,12 +3235,11 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ editor->setup(p_hint == PROPERTY_HINT_RESOURCE_TYPE ? p_hint_text : "Resource"); if (p_hint == PROPERTY_HINT_RESOURCE_TYPE) { - String open_in_new = EDITOR_GET("interface/inspector/resources_types_to_open_in_new_inspector"); + String open_in_new = EDITOR_GET("interface/inspector/resources_to_open_in_new_inspector"); for (int i = 0; i < open_in_new.get_slice_count(","); i++) { String type = open_in_new.get_slicec(',', i).strip_edges(); for (int j = 0; j < p_hint_text.get_slice_count(","); j++) { String inherits = p_hint_text.get_slicec(',', j); - if (ClassDB::is_parent_class(inherits, type)) { editor->set_use_sub_inspector(false); @@ -3211,7 +3295,8 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ editor->setup(Variant::POOL_COLOR_ARRAY); add_property_editor(p_path, editor); } break; - default: {} + default: { + } } return false; //can be overridden, although it will most likely be last anyway |