diff options
Diffstat (limited to 'editor')
22 files changed, 123 insertions, 72 deletions
diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index bc7f01eb81..0f86a32974 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -1274,12 +1274,7 @@ void AnimationTrackEdit::_notification(int p_what) { } text_color.a *= 0.7; } else if (node) { - Ref<Texture> icon; - if (has_icon(node->get_class(), "EditorIcons")) { - icon = get_icon(node->get_class(), "EditorIcons"); - } else { - icon = get_icon("Node", "EditorIcons"); - } + Ref<Texture> icon = EditorNode::get_singleton()->get_object_icon(node, "Node"); draw_texture(icon, Point2(ofs, int(get_size().height - icon->get_height()) / 2)); icon_cache = icon; @@ -3500,9 +3495,7 @@ void AnimationTrackEditor::_update_tracks() { if (root && root->has_node(base_path)) { Node *n = root->get_node(base_path); if (n) { - if (has_icon(n->get_class(), "EditorIcons")) { - icon = get_icon(n->get_class(), "EditorIcons"); - } + icon = EditorNode::get_singleton()->get_object_icon(n, "Node"); name = n->get_name(); tooltip = root->get_path_to(n); } diff --git a/editor/editor_autoload_settings.h b/editor/editor_autoload_settings.h index 76ce020d8a..1ea2950df4 100644 --- a/editor/editor_autoload_settings.h +++ b/editor/editor_autoload_settings.h @@ -56,7 +56,7 @@ class EditorAutoloadSettings : public VBoxContainer { int order; Node *node; - bool operator==(const AutoLoadInfo &p_info) { + bool operator==(const AutoLoadInfo &p_info) const { return order == p_info.order; } diff --git a/editor/editor_data.cpp b/editor/editor_data.cpp index 38f30df169..f5846c10f6 100644 --- a/editor/editor_data.cpp +++ b/editor/editor_data.cpp @@ -499,7 +499,6 @@ Object *EditorData::instance_custom_type(const String &p_type, const String &p_i for (int i = 0; i < get_custom_types()[p_inherits].size(); i++) { if (get_custom_types()[p_inherits][i].name == p_type) { - Ref<Texture> icon = get_custom_types()[p_inherits][i].icon; Ref<Script> script = get_custom_types()[p_inherits][i].script; Object *ob = ClassDB::instance(p_inherits); @@ -508,8 +507,6 @@ Object *EditorData::instance_custom_type(const String &p_type, const String &p_i ob->call("set_name", p_type); } ob->set_script(script.get_ref_ptr()); - if (icon.is_valid()) - ob->set_meta("_editor_icon", icon); return ob; } } diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 3183f1ae97..b59d42a5f7 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -832,7 +832,7 @@ void EditorNode::_get_scene_metadata(const String &p_file) { for (List<String>::Element *E = esl.front(); E; E = E->next()) { Variant st = cf->get_value("editor_states", E->get()); - if (st.get_type()) { + if (st.get_type() != Variant::NIL) { md[E->get()] = st; } } @@ -2541,8 +2541,6 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { restart_editor(); } break; default: { - if (p_option >= IMPORT_PLUGIN_BASE) { - } } } } @@ -3488,6 +3486,69 @@ void EditorNode::stop_child_process() { _menu_option_confirm(RUN_STOP, false); } +Ref<Script> EditorNode::get_object_custom_type_base(const Object *p_object) const { + ERR_FAIL_COND_V(!p_object, NULL); + + Ref<Script> script = p_object->get_script(); + + if (script.is_valid()) { + // Uncommenting would break things! Consider adding a parameter if you need it. + // StringName name = EditorNode::get_editor_data().script_class_get_name(base_script->get_path()); + // if (name != StringName()) + // return name; + + // should probably be deprecated in 4.x + StringName base = script->get_instance_base_type(); + if (base != StringName() && EditorNode::get_editor_data().get_custom_types().has(base)) { + const Vector<EditorData::CustomType> &types = EditorNode::get_editor_data().get_custom_types()[base]; + + Ref<Script> base_script = script; + while (base_script.is_valid()) { + for (int i = 0; i < types.size(); ++i) { + if (types[i].script == base_script) { + return types[i].script; + } + } + base_script = base_script->get_base_script(); + } + } + } + + return NULL; +} + +StringName EditorNode::get_object_custom_type_name(const Object *p_object) const { + ERR_FAIL_COND_V(!p_object, StringName()); + + Ref<Script> script = p_object->get_script(); + if (script.is_null() && p_object->is_class("Script")) { + script = p_object; + } + + if (script.is_valid()) { + Ref<Script> base_script = script; + while (base_script.is_valid()) { + StringName name = EditorNode::get_editor_data().script_class_get_name(base_script->get_path()); + if (name != StringName()) + return name; + + // should probably be deprecated in 4.x + StringName base = base_script->get_instance_base_type(); + if (base != StringName() && EditorNode::get_editor_data().get_custom_types().has(base)) { + const Vector<EditorData::CustomType> &types = EditorNode::get_editor_data().get_custom_types()[base]; + for (int i = 0; i < types.size(); ++i) { + if (types[i].script == base_script) { + return types[i].name; + } + } + } + base_script = base_script->get_base_script(); + } + } + + return StringName(); +} + Ref<Texture> EditorNode::get_object_icon(const Object *p_object, const String &p_fallback) const { ERR_FAIL_COND_V(!p_object || !gui_base, NULL); @@ -3497,23 +3558,24 @@ Ref<Texture> EditorNode::get_object_icon(const Object *p_object, const String &p } if (script.is_valid()) { - StringName name = EditorNode::get_editor_data().script_class_get_name(script->get_path()); - String icon_path = EditorNode::get_editor_data().script_class_get_icon_path(name); - if (icon_path.length()) - return ResourceLoader::load(icon_path); - - // should probably be deprecated in 4.x - StringName base = script->get_instance_base_type(); - if (base != StringName()) { - const Map<String, Vector<EditorData::CustomType> > &p_map = EditorNode::get_editor_data().get_custom_types(); - for (const Map<String, Vector<EditorData::CustomType> >::Element *E = p_map.front(); E; E = E->next()) { - const Vector<EditorData::CustomType> &ct = E->value(); - for (int i = 0; i < ct.size(); ++i) { - if (ct[i].name == base && ct[i].icon.is_valid()) { - return ct[i].icon; + Ref<Script> base_script = script; + while (base_script.is_valid()) { + StringName name = EditorNode::get_editor_data().script_class_get_name(base_script->get_path()); + String icon_path = EditorNode::get_editor_data().script_class_get_icon_path(name); + if (icon_path.length()) + return ResourceLoader::load(icon_path); + + // should probably be deprecated in 4.x + StringName base = base_script->get_instance_base_type(); + if (base != StringName() && EditorNode::get_editor_data().get_custom_types().has(base)) { + const Vector<EditorData::CustomType> &types = EditorNode::get_editor_data().get_custom_types()[base]; + for (int i = 0; i < types.size(); ++i) { + if (types[i].script == base_script && types[i].icon.is_valid()) { + return types[i].icon; } } } + base_script = base_script->get_base_script(); } } diff --git a/editor/editor_node.h b/editor/editor_node.h index 5dabe529f9..9aee19e6c1 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -776,6 +776,8 @@ public: void stop_child_process(); Ref<Theme> get_editor_theme() const { return theme; } + Ref<Script> get_object_custom_type_base(const Object *p_object) const; + StringName get_object_custom_type_name(const Object *p_object) const; Ref<Texture> get_object_icon(const Object *p_object, const String &p_fallback = "Object") const; Ref<Texture> get_class_icon(const String &p_class, const String &p_fallback = "Object") const; diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index a8ef563368..d54f72382c 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -112,12 +112,13 @@ void EditorPropertyMultilineText::_open_big_text() { big_text->set_wrap_enabled(true); big_text_dialog = memnew(AcceptDialog); big_text_dialog->add_child(big_text); - big_text_dialog->set_title("Edit Text:"); + big_text_dialog->set_title(TTR("Edit Text:")); add_child(big_text_dialog); } big_text_dialog->popup_centered_ratio(); big_text->set_text(text->get_text()); + big_text->grab_focus(); } void EditorPropertyMultilineText::update_property() { @@ -389,7 +390,7 @@ void EditorPropertyMember::_property_select() { type = Variant::Type(i); } } - if (type) + if (type != Variant::NIL) selector->select_method_from_basic_type(type, current); } else if (hint == MEMBER_METHOD_OF_BASE_TYPE) { @@ -2412,7 +2413,6 @@ void EditorPropertyResource::_update_menu_items() { menu->add_separator(); menu->add_item(TTR("Show in FileSystem"), OBJ_MENU_SHOW_IN_FILE_SYSTEM); } - } else { } RES cb = EditorSettings::get_singleton()->get_resource_clipboard(); diff --git a/editor/editor_properties_array_dict.cpp b/editor/editor_properties_array_dict.cpp index 347699c632..203136a3f8 100644 --- a/editor/editor_properties_array_dict.cpp +++ b/editor/editor_properties_array_dict.cpp @@ -414,8 +414,6 @@ void EditorPropertyArray::_remove_pressed(int p_index) { } void EditorPropertyArray::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { - } } void EditorPropertyArray::_edit_pressed() { @@ -968,9 +966,6 @@ void EditorPropertyDictionary::_object_id_selected(const String &p_property, Obj } void EditorPropertyDictionary::_notification(int p_what) { - - if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { - } } void EditorPropertyDictionary::_edit_pressed() { diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index a8197ec2a2..53b67c46b0 100644 --- a/editor/import/resource_importer_scene.cpp +++ b/editor/import/resource_importer_scene.cpp @@ -893,7 +893,6 @@ void ResourceImporterScene::_filter_tracks(Node *scene, const String &p_text) { keep.insert(F->get()); } _filter_anim_tracks(anim->get_animation(name), keep); - } else { } } } diff --git a/editor/import/resource_importer_wav.cpp b/editor/import/resource_importer_wav.cpp index e728dbac31..d267b29224 100644 --- a/editor/import/resource_importer_wav.cpp +++ b/editor/import/resource_importer_wav.cpp @@ -206,6 +206,11 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s frames = chunksize; + if (format_channels == 0) { + file->close(); + memdelete(file); + ERR_FAIL_COND_V(format_channels == 0, ERR_INVALID_DATA); + } frames /= format_channels; frames /= (format_bits >> 3); diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index d4eab888cc..2078a8b053 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -1431,7 +1431,7 @@ bool CanvasItemEditor::_gui_input_anchors(const Ref<InputEvent> &p_event) { for (int i = 0; i < 4; i++) { anchor_pos[i] = (transform * control->get_global_transform_with_canvas()).xform(_anchor_to_position(control, anchor_pos[i])); anchor_rects[i] = Rect2(anchor_pos[i], anchor_handle->get_size()); - anchor_rects[i].position -= anchor_handle->get_size() * Vector2(i == 0 || i == 3, i <= 1); + anchor_rects[i].position -= anchor_handle->get_size() * Vector2(float(i == 0 || i == 3), float(i <= 1)); } DragType dragger[] = { diff --git a/editor/plugins/material_editor_plugin.cpp b/editor/plugins/material_editor_plugin.cpp index ebacccb03c..e125c18ef1 100644 --- a/editor/plugins/material_editor_plugin.cpp +++ b/editor/plugins/material_editor_plugin.cpp @@ -34,9 +34,6 @@ void MaterialEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_PHYSICS_PROCESS) { - } - if (p_what == NOTIFICATION_READY) { //get_scene()->connect("node_removed",this,"_node_removed"); diff --git a/editor/plugins/mesh_editor_plugin.cpp b/editor/plugins/mesh_editor_plugin.cpp index 6203035e25..442110cc84 100644 --- a/editor/plugins/mesh_editor_plugin.cpp +++ b/editor/plugins/mesh_editor_plugin.cpp @@ -48,9 +48,6 @@ void MeshEditor::_gui_input(Ref<InputEvent> p_event) { void MeshEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_PHYSICS_PROCESS) { - } - if (p_what == NOTIFICATION_READY) { //get_scene()->connect("node_removed",this,"_node_removed"); diff --git a/editor/plugins/resource_preloader_editor_plugin.cpp b/editor/plugins/resource_preloader_editor_plugin.cpp index b8d95efd49..620bf28415 100644 --- a/editor/plugins/resource_preloader_editor_plugin.cpp +++ b/editor/plugins/resource_preloader_editor_plugin.cpp @@ -39,9 +39,6 @@ void ResourcePreloaderEditor::_gui_input(Ref<InputEvent> p_event) { void ResourcePreloaderEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_PHYSICS_PROCESS) { - } - if (p_what == NOTIFICATION_ENTER_TREE) { load->set_icon(get_icon("Folder", "EditorIcons")); } diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index a593a92b97..b475eee920 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -514,7 +514,7 @@ void SpatialEditorViewport::_select_region() { for (int i = 0; i < instances.size(); i++) { Spatial *sp = Object::cast_to<Spatial>(ObjectDB::get_instance(instances[i])); - if (!sp && _is_node_locked(sp)) + if (!sp || _is_node_locked(sp)) continue; Node *item = Object::cast_to<Node>(sp); diff --git a/editor/plugins/texture_editor_plugin.cpp b/editor/plugins/texture_editor_plugin.cpp index 0aa4a7662c..6d71c56ead 100644 --- a/editor/plugins/texture_editor_plugin.cpp +++ b/editor/plugins/texture_editor_plugin.cpp @@ -39,9 +39,6 @@ void TextureEditor::_gui_input(Ref<InputEvent> p_event) { void TextureEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_PHYSICS_PROCESS) { - } - if (p_what == NOTIFICATION_READY) { //get_scene()->connect("node_removed",this,"_node_removed"); diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp index cb48b5eaa5..4d349f06b7 100644 --- a/editor/plugins/texture_region_editor_plugin.cpp +++ b/editor/plugins/texture_region_editor_plugin.cpp @@ -193,7 +193,7 @@ void TextureRegionEditor::_region_draw() { updating_scroll = false; if (node_ninepatch || obj_styleBox.is_valid()) { - float margins[4]; + float margins[4] = { 0 }; if (node_ninepatch) { margins[0] = node_ninepatch->get_patch_margin(MARGIN_TOP); margins[1] = node_ninepatch->get_patch_margin(MARGIN_BOTTOM); @@ -204,12 +204,8 @@ void TextureRegionEditor::_region_draw() { margins[1] = obj_styleBox->get_margin_size(MARGIN_BOTTOM); margins[2] = obj_styleBox->get_margin_size(MARGIN_LEFT); margins[3] = obj_styleBox->get_margin_size(MARGIN_RIGHT); - } else { - margins[0] = 0; - margins[1] = 0; - margins[2] = 0; - margins[3] = 0; } + Vector2 pos[4] = { mtx.basis_xform(Vector2(0, margins[0])) + Vector2(0, endpoints[0].y - draw_ofs.y * draw_zoom), -mtx.basis_xform(Vector2(0, margins[1])) + Vector2(0, endpoints[2].y - draw_ofs.y * draw_zoom), @@ -248,7 +244,7 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) { if (mb->is_pressed()) { if (node_ninepatch || obj_styleBox.is_valid()) { edited_margin = -1; - float margins[4]; + float margins[4] = { 0 }; if (node_ninepatch) { margins[0] = node_ninepatch->get_patch_margin(MARGIN_TOP); margins[1] = node_ninepatch->get_patch_margin(MARGIN_BOTTOM); @@ -260,6 +256,7 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) { margins[2] = obj_styleBox->get_margin_size(MARGIN_LEFT); margins[3] = obj_styleBox->get_margin_size(MARGIN_RIGHT); } + Vector2 pos[4] = { mtx.basis_xform(rect.position + Vector2(0, margins[0])) - draw_ofs * draw_zoom, mtx.basis_xform(rect.position + rect.size - Vector2(0, margins[1])) - draw_ofs * draw_zoom, diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index aaa99996e6..28719d9e3e 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -1513,7 +1513,6 @@ void VisualShaderEditor::_notification(int p_what) { if (p_what == NOTIFICATION_THEME_CHANGED && is_visible_in_tree()) _update_graph(); - } else if (p_what == NOTIFICATION_PROCESS) { } } diff --git a/editor/project_settings_editor.cpp b/editor/project_settings_editor.cpp index f05b6b5890..1c588a45f1 100644 --- a/editor/project_settings_editor.cpp +++ b/editor/project_settings_editor.cpp @@ -965,8 +965,6 @@ void ProjectSettingsEditor::_action_add() { while (r->get_next()) r = r->get_next(); - if (!r) - return; r->select(0); input_editor->ensure_cursor_is_visible(); action_add_error->hide(); diff --git a/editor/property_editor.cpp b/editor/property_editor.cpp index 82d974cae3..899343c0f8 100644 --- a/editor/property_editor.cpp +++ b/editor/property_editor.cpp @@ -614,7 +614,7 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: type = Variant::Type(i); } } - if (type) + if (type != Variant::NIL) property_select->select_method_from_basic_type(type, v); updating = false; return false; @@ -971,7 +971,6 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: menu->add_separator(); menu->add_item(TTR("Show in FileSystem"), OBJ_MENU_SHOW_IN_FILE_SYSTEM); } - } else { } RES cb = EditorSettings::get_singleton()->get_resource_clipboard(); diff --git a/editor/property_selector.cpp b/editor/property_selector.cpp index 813e24bd61..3bc93c3900 100644 --- a/editor/property_selector.cpp +++ b/editor/property_selector.cpp @@ -337,7 +337,7 @@ void PropertySelector::_item_selected() { String name = item->get_metadata(0); String class_type; - if (type) { + if (type != Variant::NIL) { class_type = Variant::get_type_name(type); } else { diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index c7fc466cd8..009ac603e2 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -467,8 +467,8 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { Node *n = Object::cast_to<Node>(selection[i]); Ref<Script> existing = n->get_script(); - if (existing.is_valid()) { - const RefPtr empty; + Ref<Script> empty = EditorNode::get_singleton()->get_object_custom_type_base(n); + if (existing != empty) { editor_data->get_undo_redo().add_do_method(n, "set_script", empty); editor_data->get_undo_redo().add_undo_method(n, "set_script", existing); } @@ -2380,6 +2380,7 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) { menu->clear(); Ref<Script> existing_script; + bool exisiting_script_removable = true; if (selection.size() == 1) { Node *selected = selection[0]; @@ -2399,6 +2400,10 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) { menu->add_separator(); existing_script = selected->get_script(); + + if (EditorNode::get_singleton()->get_object_custom_type_base(selected) == existing_script) { + exisiting_script_removable = false; + } } if (profile_allow_script_editing) { @@ -2410,7 +2415,7 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) { menu->add_icon_shortcut(get_icon("ScriptExtend", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/extend_script"), TOOL_ATTACH_SCRIPT); } } - if (selection.size() > 1 || existing_script.is_valid()) { + if (selection.size() > 1 || (existing_script.is_valid() && exisiting_script_removable)) { menu->add_icon_shortcut(get_icon("ScriptRemove", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/clear_script"), TOOL_CLEAR_SCRIPT); } menu->add_separator(); diff --git a/editor/scene_tree_editor.cpp b/editor/scene_tree_editor.cpp index c1a14685b0..2d9accc3d8 100644 --- a/editor/scene_tree_editor.cpp +++ b/editor/scene_tree_editor.cpp @@ -212,13 +212,19 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) { Color accent = get_color("accent_color", "Editor"); Ref<Script> script = p_node->get_script(); - if (!script.is_null()) { + if (!script.is_null() && EditorNode::get_singleton()->get_object_custom_type_base(p_node) != script) { //has script item->add_button(0, get_icon("Script", "EditorIcons"), BUTTON_SCRIPT); } else { - //has no script + //has no script (or script is a custom type) item->set_custom_color(0, get_color("disabled_font_color", "Editor")); item->set_selectable(0, false); + + if (!script.is_null()) { // make sure to mark the script if a custom type + item->add_button(0, get_icon("Script", "EditorIcons"), BUTTON_SCRIPT); + item->set_button_disabled(0, item->get_button_count(0) - 1, true); + } + accent.a *= 0.7; } @@ -284,7 +290,10 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) { item->add_button(0, get_icon("InstanceOptions", "EditorIcons"), BUTTON_SUBSCENE, false, TTR("Open in Editor")); item->set_tooltip(0, TTR("Instance:") + " " + p_node->get_filename() + "\n" + TTR("Type:") + " " + p_node->get_class()); } else { - item->set_tooltip(0, String(p_node->get_name()) + "\n" + TTR("Type:") + " " + p_node->get_class()); + StringName type = EditorNode::get_singleton()->get_object_custom_type_name(p_node); + if (type == StringName()) + type = p_node->get_class(); + item->set_tooltip(0, String(p_node->get_name()) + "\n" + TTR("Type:") + " " + type); } if (can_open_instance && undo_redo) { //Show buttons only when necessary(SceneTreeDock) to avoid crashes @@ -295,6 +304,9 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) { Ref<Script> script = p_node->get_script(); if (!script.is_null()) { item->add_button(0, get_icon("Script", "EditorIcons"), BUTTON_SCRIPT, false, TTR("Open Script:") + " " + script->get_path()); + if (EditorNode::get_singleton()->get_object_custom_type_base(p_node) == script) { + item->set_button_color(0, item->get_button_count(0) - 1, Color(1, 1, 1, 0.5)); + } } if (p_node->is_class("CanvasItem")) { |