diff options
Diffstat (limited to 'editor')
52 files changed, 1461 insertions, 892 deletions
diff --git a/editor/SCsub b/editor/SCsub index d7392f8249..c46e443534 100644 --- a/editor/SCsub +++ b/editor/SCsub @@ -141,6 +141,30 @@ def make_translations_header(target, source, env): g.write("#endif") +def make_authors_header(target, source, env): + + src = source[0].srcnode().abspath + dst = target[0].srcnode().abspath + f = open(src, "rb") + g = open(dst, "wb") + + g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n") + g.write("#ifndef _EDITOR_AUTHORS_H\n") + g.write("#define _EDITOR_AUTHORS_H\n") + g.write("static const char *dev_names[] = {\n") + + name_count = -1 + for line in f: + if name_count >= 0: + if line.startswith(" "): + g.write("\t\"" + line.strip() + "\",\n") + name_count += 1 + elif line.strip() == "## Developers": + name_count = 0 + g.write("\t0\n") + g.write("};\n") + g.write("#define AUTHORS_COUNT " + str(name_count) + "\n") + g.write("#endif\n") if (env["tools"] == "yes"): @@ -188,6 +212,10 @@ if (env["tools"] == "yes"): env.Depends('#editor/builtin_fonts.h', flist) env.Command('#editor/builtin_fonts.h', flist, make_fonts_header) + # Authors + env.Depends('#editor/authors.h', "../AUTHORS.md") + env.Command('#editor/authors.h', "../AUTHORS.md", make_authors_header) + env.add_source_files(env.editor_sources, "*.cpp") diff --git a/editor/animation_editor.cpp b/editor/animation_editor.cpp index a5de4fee88..1798e66e8a 100644 --- a/editor/animation_editor.cpp +++ b/editor/animation_editor.cpp @@ -76,7 +76,7 @@ private: Ref<StyleBox> sb = get_stylebox("normal", "LineEdit"); sb->draw(ci, r); r.size -= sb->get_minimum_size(); - r.pos += sb->get_offset(); + r.position += sb->get_offset(); //VisualServer::get_singleton()->canvas_item_add Ref<Font> f = get_font("font", "Label"); @@ -111,7 +111,7 @@ private: iflp = 1.0 - iflp; } - VisualServer::get_singleton()->canvas_item_add_line(ci, r.pos + Point2(iflp * r.size.width, prev * r.size.height), r.pos + Point2(ifl * r.size.width, h * r.size.height), mcolor); + VisualServer::get_singleton()->canvas_item_add_line(ci, r.position + Point2(iflp * r.size.width, prev * r.size.height), r.position + Point2(ifl * r.size.width, h * r.size.height), mcolor); prev = h; } @@ -138,7 +138,7 @@ private: iflp = 1.0 - iflp; } - VisualServer::get_singleton()->canvas_item_add_line(ci, r.pos + Point2(iflp * r.size.width, prev * r.size.height), r.pos + Point2(ifl * r.size.width, h * r.size.height), color); + VisualServer::get_singleton()->canvas_item_add_line(ci, r.position + Point2(iflp * r.size.width, prev * r.size.height), r.position + Point2(ifl * r.size.width, h * r.size.height), color); prev = h; } } @@ -1900,13 +1900,13 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input) if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed()) { - Point2 mpos = mb->get_pos() - ofs; + Point2 mpos = mb->get_position() - ofs; if (selection.size() == 0) { // Auto-select on right-click if nothing is selected // Note: This code is pretty much duplicated from the left click code, // both codes could be moved into a function to avoid the duplicated code. - Point2 mpos = mb->get_pos() - ofs; + Point2 mpos = mb->get_position() - ofs; if (mpos.y < h) { return; @@ -1951,7 +1951,7 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input) if (key == -1) { click.click = ClickOver::CLICK_SELECT_KEYS; - click.at = mb->get_pos(); + click.at = mb->get_position(); click.to = click.at; click.shift = mb->get_shift(); selected_track = idx; @@ -1974,7 +1974,7 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input) selection.insert(sk, ki); click.click = ClickOver::CLICK_MOVE_KEYS; - click.at = mb->get_pos(); + click.at = mb->get_position(); click.to = click.at; update(); selected_track = idx; @@ -2009,14 +2009,14 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input) if (mb->is_pressed()) { - Point2 mpos = mb->get_pos() - ofs; + Point2 mpos = mb->get_position() - ofs; if (mpos.y < h) { if (mpos.x < name_limit && mpos.x > (name_limit - hsep - hsize_icon->get_width())) { click.click = ClickOver::CLICK_RESIZE_NAMES; - click.at = mb->get_pos(); + click.at = mb->get_position(); click.to = click.at; click.at.y = name_limit; } @@ -2035,7 +2035,7 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input) pos = animation->get_length(); timeline_pos = pos; click.click = ClickOver::CLICK_DRAG_TIMELINE; - click.at = mb->get_pos(); + click.at = mb->get_position(); click.to = click.at; emit_signal("timeline_changed", pos, false); } @@ -2055,7 +2055,7 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input) if (mpos.x >= name_limit && mpos.x < settings_limit) { click.click = ClickOver::CLICK_SELECT_KEYS; - click.at = mb->get_pos(); + click.at = mb->get_position(); click.to = click.at; //drag select region } @@ -2076,7 +2076,7 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input) Rect2 area(ofs.x, ofs.y + ((int(mpos.y) / h) + 1) * h, name_limit, h); track_name->set_text(animation->track_get_path(idx)); - track_name->set_position(te->get_global_position() + area.pos); + track_name->set_position(te->get_global_position() + area.position); track_name->set_size(area.size); track_name->show_modal(); track_name->grab_focus(); @@ -2115,7 +2115,7 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input) if (key == -1) { click.click = ClickOver::CLICK_SELECT_KEYS; - click.at = mb->get_pos(); + click.at = mb->get_position(); click.to = click.at; click.shift = mb->get_shift(); selected_track = idx; @@ -2138,7 +2138,7 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input) selection.insert(sk, ki); click.click = ClickOver::CLICK_MOVE_KEYS; - click.at = mb->get_pos(); + click.at = mb->get_position(); click.to = click.at; update(); selected_track = idx; @@ -2601,7 +2601,7 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input) float clickp = click.at.x - ofs.x; float dif = base - clickp; - float target = mm->get_pos().x + dif - ofs.x; + float target = mm->get_position().x + dif - ofs.x; float ratio = target / settings_limit; @@ -2615,7 +2615,7 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input) } break; case ClickOver::CLICK_DRAG_TIMELINE: { - Point2 mpos = mm->get_pos() - ofs; + Point2 mpos = mm->get_position() - ofs; /* if (mpos.x<name_limit) mpos.x=name_limit; @@ -2646,7 +2646,7 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input) } break; case ClickOver::CLICK_SELECT_KEYS: { - click.to = mm->get_pos(); + click.to = mm->get_position(); if (click.to.y < h && click.at.y > h && mm->get_relative().y < 0) { float prev = v_scroll->get_value(); @@ -2665,7 +2665,7 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input) } break; case ClickOver::CLICK_MOVE_KEYS: { - click.to = mm->get_pos(); + click.to = mm->get_position(); } break; default: {} } @@ -2680,7 +2680,7 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input) if (mm->get_button_mask() == 0) { - Point2 mpos = mm->get_pos() - ofs; + Point2 mpos = mm->get_position() - ofs; if (mpos.y < h) { #if 0 diff --git a/editor/editor_audio_buses.cpp b/editor/editor_audio_buses.cpp index 26029261b2..e3e5793ec8 100644 --- a/editor/editor_audio_buses.cpp +++ b/editor/editor_audio_buses.cpp @@ -342,7 +342,7 @@ void EditorAudioBus::_effect_edited() { if (effect->get_metadata(0) == Variant()) { Rect2 area = effects->get_item_rect(effect); - effect_options->set_position(effects->get_global_position() + area.pos + Vector2(0, area.size.y)); + effect_options->set_position(effects->get_global_position() + area.position + Vector2(0, area.size.y)); effect_options->popup(); //add effect } else { @@ -396,7 +396,7 @@ void EditorAudioBus::_gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventMouseButton> mb = p_event; if (mb.is_valid() && mb->get_button_index() == 2 && mb->is_pressed()) { - Vector2 pos = Vector2(mb->get_pos().x, mb->get_pos().y); + Vector2 pos = Vector2(mb->get_position().x, mb->get_position().y); delete_popup->set_position(get_global_position() + pos); delete_popup->popup(); } @@ -632,21 +632,24 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses) { solo = memnew(ToolButton); solo->set_text("S"); solo->set_toggle_mode(true); - solo->set_modulate(Color(0.8, 1.2, 0.8)); + solo->add_color_override("font_color_pressed", Color(0.2, 0.9, 0.2)); + solo->add_color_override("font_color_hover", Color(0.6, 0.9, 0.6)); solo->set_focus_mode(FOCUS_NONE); solo->connect("pressed", this, "_solo_toggled"); hbc->add_child(solo); mute = memnew(ToolButton); mute->set_text("M"); mute->set_toggle_mode(true); - mute->set_modulate(Color(1.2, 0.8, 0.8)); + mute->add_color_override("font_color_pressed", Color(0.9, 0.2, 0.2)); + mute->add_color_override("font_color_hover", Color(0.9, 0.6, 0.6)); mute->set_focus_mode(FOCUS_NONE); mute->connect("pressed", this, "_mute_toggled"); hbc->add_child(mute); bypass = memnew(ToolButton); bypass->set_text("B"); bypass->set_toggle_mode(true); - bypass->set_modulate(Color(1.1, 1.1, 0.8)); + bypass->add_color_override("font_color_pressed", Color(0.9, 0.9, 0.2)); + bypass->add_color_override("font_color_hover", Color(0.9, 0.9, 0.6)); bypass->set_focus_mode(FOCUS_NONE); bypass->connect("pressed", this, "_bypass_toggled"); hbc->add_child(bypass); diff --git a/editor/editor_fonts.cpp b/editor/editor_fonts.cpp index dc4c2b21bc..0873b90f22 100644 --- a/editor/editor_fonts.cpp +++ b/editor/editor_fonts.cpp @@ -49,8 +49,8 @@ static Ref<BitmapFont> make_font(int p_height, int p_ascent, int p_valign, int p int chr = c[0]; Rect2 frect; - frect.pos.x = c[1]; - frect.pos.y = c[2]; + frect.position.x = c[1]; + frect.position.y = c[2]; frect.size.x = c[3]; frect.size.y = c[4]; Point2 align(c[5], c[6] + p_valign); diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index 8fb307a77d..11cb61370d 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -252,8 +252,8 @@ void EditorHelpSearch::_confirmed() { return; String mdata = ti->get_metadata(0); + EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT); emit_signal("go_to_help", mdata); - editor->call("_editor_select", EditorNode::EDITOR_SCRIPT); // in case EditorHelpSearch beeen invoked on top of other editor window // go to that hide(); } @@ -288,7 +288,6 @@ void EditorHelpSearch::_bind_methods() { EditorHelpSearch::EditorHelpSearch() { - editor = EditorNode::get_singleton(); VBoxContainer *vbc = memnew(VBoxContainer); add_child(vbc); @@ -362,8 +361,8 @@ void EditorHelpIndex::_tree_item_selected() { if (!s) return; + EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT); emit_signal("open_class", s->get_text(0)); - hide(); //_goto_desc(s->get_text(0)); @@ -371,12 +370,10 @@ void EditorHelpIndex::_tree_item_selected() { void EditorHelpIndex::select_class(const String &p_class) { - EditorNode *editor = EditorNode::get_singleton(); if (!tree_item_map.has(p_class)) return; tree_item_map[p_class]->select(0); class_list->ensure_cursor_is_visible(); - editor->call("_editor_select", EditorNode::EDITOR_SCRIPT); // in case EditorHelpIndex beeen invoked on top of other editor window } void EditorHelpIndex::popup() { @@ -1281,7 +1278,7 @@ Error EditorHelp::_goto_desc(const String &p_class, int p_vscr) { void EditorHelp::_request_help(const String &p_string) { Error err = _goto_desc(p_string); if (err == OK) { - editor->call("_editor_select", EditorNode::EDITOR_SCRIPT); + EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT); } //100 palabras } @@ -1691,8 +1688,6 @@ void EditorHelp::_bind_methods() { EditorHelp::EditorHelp() { - editor = EditorNode::get_singleton(); - VBoxContainer *vbc = this; EDITOR_DEF("text_editor/help/sort_functions_alphabetically", true); diff --git a/editor/editor_help.h b/editor/editor_help.h index d6fc0e3bf2..46d83490f4 100644 --- a/editor/editor_help.h +++ b/editor/editor_help.h @@ -49,7 +49,6 @@ class EditorHelpSearch : public ConfirmationDialog { GDCLASS(EditorHelpSearch, ConfirmationDialog) - EditorNode *editor; LineEdit *search_box; Tree *search_options; String base_type; @@ -119,7 +118,6 @@ class EditorHelp : public VBoxContainer { String edited_class; - EditorNode *editor; Map<String, int> method_line; Map<String, int> signal_line; Map<String, int> property_line; diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index c1f422cce3..6587e4fe09 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -30,6 +30,7 @@ #include "editor_node.h" #include "animation_editor.h" +#include "authors.h" #include "bind/core_bind.h" #include "class_db.h" #include "core/io/resource_loader.h" @@ -271,6 +272,8 @@ void EditorNode::_notification(int p_what) { } editor_selection->update(); + scene_root->set_size_override(true, Size2(GlobalConfig::get_singleton()->get("display/window/width"), GlobalConfig::get_singleton()->get("display/window/height"))); + ResourceImporterTexture::get_singleton()->update_imports(); } if (p_what == NOTIFICATION_ENTER_TREE) { @@ -822,56 +825,54 @@ void EditorNode::_save_scene_with_preview(String p_file) { } save.step(TTR("Creating Thumbnail"), 1); //current view? - int screen = -1; - for (int i = 0; i < editor_table.size(); i++) { - if (editor_plugin_screen == editor_table[i]) { - screen = i; - break; - } + + Ref<Image> img; + if (is2d) { + img = scene_root->get_texture()->get_data(); + } else { + img = SpatialEditor::get_singleton()->get_editor_viewport(0)->get_viewport_node()->get_texture()->get_data(); } - _editor_select(is2d ? EDITOR_2D : EDITOR_3D); + if (img.is_valid()) { + save.step(TTR("Creating Thumbnail"), 2); + save.step(TTR("Creating Thumbnail"), 3); - save.step(TTR("Creating Thumbnail"), 2); - save.step(TTR("Creating Thumbnail"), 3); -#if 0 - Image img = VS::get_singleton()->viewport_texture(scree_capture(viewport); - int preview_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); - preview_size*=EDSCALE; - int width,height; - if (img.get_width() > preview_size && img.get_width() >= img.get_height()) { + int preview_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); + preview_size *= EDSCALE; + int width, height; + if (img->get_width() > preview_size && img->get_width() >= img->get_height()) { - width=preview_size; - height = img.get_height() * preview_size / img.get_width(); - } else if (img.get_height() > preview_size && img.get_height() >= img.get_width()) { + width = preview_size; + height = img->get_height() * preview_size / img->get_width(); + } else if (img->get_height() > preview_size && img->get_height() >= img->get_width()) { - height=preview_size; - width = img.get_width() * preview_size / img.get_height(); - } else { + height = preview_size; + width = img->get_width() * preview_size / img->get_height(); + } else { - width=img.get_width(); - height=img.get_height(); - } + width = img->get_width(); + height = img->get_height(); + } - img.convert(Image::FORMAT_RGB8); - img.resize(width,height); + img->convert(Image::FORMAT_RGB8); + img->resize(width, height); + img->flip_y(); - String pfile = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp/last_scene_preview.png"); - img.save_png(pfile); - Vector<uint8_t> imgdata = FileAccess::get_file_as_array(pfile); + //save thumbnail directly, as thumbnailer may not update due to actual scene not changing md5 + String temp_path = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp"); + String cache_base = GlobalConfig::get_singleton()->globalize_path(p_file).md5_text(); + cache_base = temp_path.plus_file("resthumb-" + cache_base); - //print_line("img data is "+itos(imgdata.size())); + //does not have it, try to load a cached thumbnail - if (editor_data.get_edited_scene_import_metadata().is_null()) - editor_data.set_edited_scene_import_metadata(Ref<ResourceImportMetadata>( memnew( ResourceImportMetadata ) ) ); - editor_data.get_edited_scene_import_metadata()->set_option("thumbnail",imgdata); -#endif - //tamanio tel thumbnail - if (screen != -1) { - _editor_select(screen); + String file = cache_base + ".png"; + + img->save_png(file); } + save.step(TTR("Saving Scene"), 4); _save_scene(p_file); + EditorResourcePreview::get_singleton()->check_for_invalidation(p_file); } void EditorNode::_save_scene(String p_file, int idx) { @@ -1084,6 +1085,7 @@ void EditorNode::_dialog_action(String p_file) { GlobalConfig::get_singleton()->set("application/main_scene", p_file); GlobalConfig::get_singleton()->save(); //would be nice to show the project manager opened with the highlighted field.. + _run(false, ""); // automatically run the project } break; case FILE_SAVE_OPTIMIZED: { @@ -1982,7 +1984,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } _menu_option(FILE_SAVE_AS_SCENE); - _menu_option_confirm(FILE_SAVE_AND_RUN, true); + _menu_option_confirm(FILE_SAVE_AND_RUN, false); } break; case FILE_SAVE_OPTIMIZED: { @@ -3736,7 +3738,7 @@ void EditorNode::_dock_select_input(const Ref<InputEvent> &p_input) { if (me.is_valid()) { - Vector2 point = me->get_pos(); + Vector2 point = me->get_position(); int nrect = -1; for (int i = 0; i < DOCK_SLOT_MAX; i++) { @@ -3846,7 +3848,7 @@ void EditorNode::_dock_select_draw() { unusable.a = 0.1; Rect2 unr(s.x * 2, 0, s.x * 2, s.y * 2); - unr.pos += Vector2(2, 5); + unr.position += Vector2(2, 5); unr.size -= Vector2(4, 7); dock_select->draw_rect(unr, unusable); @@ -3899,7 +3901,7 @@ void EditorNode::_dock_select_draw() { Rect2 r(ofs, s); dock_select_rect[i] = r; - r.pos += Vector2(2, 5); + r.position += Vector2(2, 5); r.size -= Vector2(4, 7); if (i == dock_select_rect_over) { @@ -4878,6 +4880,7 @@ EditorNode::EditorNode() { Resource::_get_local_scene_func = _resource_get_edited_scene; VisualServer::get_singleton()->textures_keep_original(true); + VisualServer::get_singleton()->set_debug_generate_wireframes(true); EditorHelp::generate_doc(); //before any editor classes are crated SceneState::set_disable_placeholders(true); @@ -5874,14 +5877,49 @@ EditorNode::EditorNode() { about->get_ok()->set_text(TTR("Thanks!")); about->set_hide_on_ok(true); gui_base->add_child(about); + VBoxContainer *vbc = memnew(VBoxContainer); HBoxContainer *hbc = memnew(HBoxContainer); - about->add_child(hbc); + hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL); + hbc->set_alignment(BoxContainer::ALIGN_CENTER); + about->add_child(vbc); + vbc->add_child(hbc); Label *about_text = memnew(Label); - about_text->set_text(VERSION_FULL_NAME "\n(c) 2008-2017 Juan Linietsky, Ariel Manzur.\n"); + about_text->set_text(VERSION_FULL_NAME + String::utf8("\n\u00A9 2007-2017 Juan Linietsky, Ariel Manzur.\n\u00A9 2014-2017 ") + TTR("Godot Engine contributors") + "\n"); TextureRect *logo = memnew(TextureRect); logo->set_texture(gui_base->get_icon("Logo", "EditorIcons")); hbc->add_child(logo); hbc->add_child(about_text); + TabContainer *tc = memnew(TabContainer); + tc->set_custom_minimum_size(Vector2(740, 300)); + vbc->add_child(tc); + ScrollContainer *dev_base = memnew(ScrollContainer); + dev_base->set_name(TTR("Developers")); + tc->add_child(dev_base); + HBoxContainer *dev_hbc = memnew(HBoxContainer); + dev_hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL); + dev_base->add_child(dev_hbc); + for (int i = 0; i < 3; i++) { + Label *dev_label = memnew(Label); + dev_label->set_h_size_flags(Control::SIZE_EXPAND); + dev_label->set_v_size_flags(Control::SIZE_FILL); + dev_hbc->add_child(dev_label); + } + int dev_name_index = 0; + int dev_name_column = 0; + const int dev_index_max = AUTHORS_COUNT / 3 + (AUTHORS_COUNT % 3 == 0 ? 0 : 1); + String dev_name = ""; + const char **dev_names_ptr = dev_names; + while (*dev_names_ptr) { + dev_name += String::utf8(*dev_names_ptr++); + if (++dev_name_index == dev_index_max || !*dev_names_ptr) { + dev_hbc->get_child(dev_name_column)->cast_to<Label>()->set_text(dev_name); + dev_name_column++; + dev_name = ""; + dev_name_index = 0; + } else { + dev_name += "\n"; + } + } warning = memnew(AcceptDialog); gui_base->add_child(warning); @@ -6020,14 +6058,13 @@ EditorNode::EditorNode() { plugin_init_callbacks[i](); } - /*resource_preview->add_preview_generator( Ref<EditorTexturePreviewPlugin>( memnew(EditorTexturePreviewPlugin ))); - resource_preview->add_preview_generator( Ref<EditorPackedScenePreviewPlugin>( memnew(EditorPackedScenePreviewPlugin ))); - resource_preview->add_preview_generator( Ref<EditorMaterialPreviewPlugin>( memnew(EditorMaterialPreviewPlugin ))); - resource_preview->add_preview_generator( Ref<EditorScriptPreviewPlugin>( memnew(EditorScriptPreviewPlugin ))); - resource_preview->add_preview_generator( Ref<EditorSamplePreviewPlugin>( memnew(EditorSamplePreviewPlugin ))); - resource_preview->add_preview_generator( Ref<EditorMeshPreviewPlugin>( memnew(EditorMeshPreviewPlugin ))); - resource_preview->add_preview_generator( Ref<EditorBitmapPreviewPlugin>( memnew(EditorBitmapPreviewPlugin ))); -*/ + resource_preview->add_preview_generator(Ref<EditorTexturePreviewPlugin>(memnew(EditorTexturePreviewPlugin))); + resource_preview->add_preview_generator(Ref<EditorPackedScenePreviewPlugin>(memnew(EditorPackedScenePreviewPlugin))); + resource_preview->add_preview_generator(Ref<EditorMaterialPreviewPlugin>(memnew(EditorMaterialPreviewPlugin))); + resource_preview->add_preview_generator(Ref<EditorScriptPreviewPlugin>(memnew(EditorScriptPreviewPlugin))); + //resource_preview->add_preview_generator( Ref<EditorSamplePreviewPlugin>( memnew(EditorSamplePreviewPlugin ))); + resource_preview->add_preview_generator(Ref<EditorMeshPreviewPlugin>(memnew(EditorMeshPreviewPlugin))); + resource_preview->add_preview_generator(Ref<EditorBitmapPreviewPlugin>(memnew(EditorBitmapPreviewPlugin))); circle_step_msec = OS::get_singleton()->get_ticks_msec(); circle_step_frame = Engine::get_singleton()->get_frames_drawn(); diff --git a/editor/editor_plugin.cpp b/editor/editor_plugin.cpp index 1b8d1b1677..6fcea98e32 100644 --- a/editor/editor_plugin.cpp +++ b/editor/editor_plugin.cpp @@ -281,6 +281,11 @@ void EditorPlugin::add_import_plugin(const Ref<EditorImportPlugin> &p_importer) EditorFileSystem::get_singleton()->scan_changes(); } +void EditorPlugin::remove_import_plugin(const Ref<EditorImportPlugin> &p_importer) { + ResourceFormatImporter::get_singleton()->remove_importer(p_importer); + EditorFileSystem::get_singleton()->scan_changes(); +} + void EditorPlugin::set_window_layout(Ref<ConfigFile> p_layout) { if (get_script_instance() && get_script_instance()->has_method("set_window_layout")) { @@ -366,6 +371,7 @@ void EditorPlugin::_bind_methods() { ClassDB::bind_method(D_METHOD("queue_save_layout"), &EditorPlugin::queue_save_layout); ClassDB::bind_method(D_METHOD("edit_resource"), &EditorPlugin::edit_resource); ClassDB::bind_method(D_METHOD("add_import_plugin"), &EditorPlugin::add_import_plugin); + ClassDB::bind_method(D_METHOD("remove_import_plugin"), &EditorPlugin::remove_import_plugin); ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "forward_canvas_gui_input", PropertyInfo(Variant::TRANSFORM2D, "canvas_xform"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"))); ClassDB::add_virtual_method(get_class_static(), MethodInfo("forward_draw_over_canvas", PropertyInfo(Variant::TRANSFORM2D, "canvas_xform"), PropertyInfo(Variant::OBJECT, "canvas:Control"))); ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "forward_spatial_gui_input", PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"))); diff --git a/editor/editor_plugin.h b/editor/editor_plugin.h index 1ef447a6b8..c607846ec9 100644 --- a/editor/editor_plugin.h +++ b/editor/editor_plugin.h @@ -148,6 +148,7 @@ public: virtual void save_global_state(); void add_import_plugin(const Ref<EditorImportPlugin> &p_importer); + void remove_import_plugin(const Ref<EditorImportPlugin> &p_importer); EditorPlugin(); virtual ~EditorPlugin(); diff --git a/editor/editor_profiler.cpp b/editor/editor_profiler.cpp index 5aad903485..64cf275c3a 100644 --- a/editor/editor_profiler.cpp +++ b/editor/editor_profiler.cpp @@ -496,7 +496,7 @@ void EditorProfiler::_graph_tex_input(const Ref<InputEvent> &p_ev) { (mb.is_valid() && mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) || (mm.is_valid())) { - int x = me->get_pos().x; + int x = me->get_position().x; x = x * frame_metrics.size() / graph->get_size().width; bool show_hover = x >= 0 && x < frame_metrics.size(); diff --git a/editor/editor_resource_preview.cpp b/editor/editor_resource_preview.cpp index 0b1887e8a2..5d68de3bb6 100644 --- a/editor/editor_resource_preview.cpp +++ b/editor/editor_resource_preview.cpp @@ -190,7 +190,7 @@ void EditorResourcePreview::_thread() { } else { preview_mutex->unlock(); - Ref<Texture> texture; + Ref<ImageTexture> texture; //print_line("pop from queue "+item.path); @@ -229,6 +229,7 @@ void EditorResourcePreview::_thread() { bool cache_valid = true; if (tsize != thumbnail_size) { + cache_valid = false; memdelete(f); } else if (last_modtime != modtime) { @@ -240,6 +241,7 @@ void EditorResourcePreview::_thread() { if (last_md5 != md5) { cache_valid = false; + } else { //update modified time @@ -252,14 +254,20 @@ void EditorResourcePreview::_thread() { memdelete(f); } - cache_valid = false; + //cache_valid = false; if (cache_valid) { - texture = ResourceLoader::load(cache_base + ".png", "ImageTexture", true); - if (!texture.is_valid()) { + Ref<Image> img; + img.instance(); + + if (img->load(cache_base + ".png") != OK) { //well fuck cache_valid = false; + } else { + + texture.instance(); + texture->create_from_image(img, Texture::FLAG_FILTER); } } diff --git a/editor/editor_run.cpp b/editor/editor_run.cpp index e0ebe985cd..c97dc9a88e 100644 --- a/editor/editor_run.cpp +++ b/editor/editor_run.cpp @@ -73,17 +73,17 @@ Error EditorRun::run(const String &p_scene, const String p_custom_args, const Li } Rect2 screen_rect; - screen_rect.pos = OS::get_singleton()->get_screen_position(screen); + screen_rect.position = OS::get_singleton()->get_screen_position(screen); screen_rect.size = OS::get_singleton()->get_screen_size(screen); Size2 desired_size; - desired_size.x = GlobalConfig::get_singleton()->get("display/width"); - desired_size.y = GlobalConfig::get_singleton()->get("display/height"); + desired_size.x = GlobalConfig::get_singleton()->get("display/window/width"); + desired_size.y = GlobalConfig::get_singleton()->get("display/window/height"); Size2 test_size; - test_size.x = GlobalConfig::get_singleton()->get("display/test_width"); - test_size.y = GlobalConfig::get_singleton()->get("display/test_height"); + test_size.x = GlobalConfig::get_singleton()->get("display/window/test_width"); + test_size.y = GlobalConfig::get_singleton()->get("display/window/test_height"); if (test_size.x > 0 && test_size.y > 0) { desired_size = test_size; @@ -95,21 +95,21 @@ Error EditorRun::run(const String &p_scene, const String p_custom_args, const Li case 0: { // default args.push_back("-p"); - args.push_back(itos(screen_rect.pos.x) + "x" + itos(screen_rect.pos.y)); + args.push_back(itos(screen_rect.position.x) + "x" + itos(screen_rect.position.y)); } break; case 1: { // centered - Vector2 pos = screen_rect.pos + ((screen_rect.size - desired_size) / 2).floor(); + Vector2 pos = screen_rect.position + ((screen_rect.size - desired_size) / 2).floor(); args.push_back("-p"); args.push_back(itos(pos.x) + "x" + itos(pos.y)); } break; case 2: { // custom pos Vector2 pos = EditorSettings::get_singleton()->get("run/window_placement/rect_custom_position"); - pos += screen_rect.pos; + pos += screen_rect.position; args.push_back("-p"); args.push_back(itos(pos.x) + "x" + itos(pos.y)); } break; case 3: { // force maximized - Vector2 pos = screen_rect.pos; + Vector2 pos = screen_rect.position; args.push_back("-p"); args.push_back(itos(pos.x) + "x" + itos(pos.y)); args.push_back("-mx"); @@ -117,7 +117,7 @@ Error EditorRun::run(const String &p_scene, const String p_custom_args, const Li } break; case 4: { // force fullscreen - Vector2 pos = screen_rect.pos; + Vector2 pos = screen_rect.position; args.push_back("-p"); args.push_back(itos(pos.x) + "x" + itos(pos.y)); args.push_back("-f"); diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index df12c7c75f..07c7fe97e4 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -556,6 +556,8 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { set("text_editor/line_numbers/line_length_guideline_column", 80); hints["text_editor/line_numbers/line_length_guideline_column"] = PropertyInfo(Variant::INT, "text_editor/line_numbers/line_length_guideline_column", PROPERTY_HINT_RANGE, "20, 160, 10"); + set("text_editor/open_scripts/show_members_overview", true); + set("text_editor/files/trim_trailing_whitespace_on_save", false); set("text_editor/completion/idle_parse_delay", 2); set("text_editor/tools/create_signal_callbacks", true); @@ -612,10 +614,12 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { set("editors/2d/bone_ik_color", Color(0.9, 0.9, 0.45, 0.9)); set("editors/2d/keep_margins_when_changing_anchors", false); set("editors/2d/warped_mouse_panning", true); + set("editors/2d/scroll_to_pan", false); + set("editors/2d/pan_speed", 20); set("editors/poly_editor/point_grab_radius", 8); - set("run/window_placement/rect", 0); + set("run/window_placement/rect", 1); hints["run/window_placement/rect"] = PropertyInfo(Variant::INT, "run/window_placement/rect", PROPERTY_HINT_ENUM, "Default,Centered,Custom Position,Force Maximized,Force Full Screen"); String screen_hints = TTR("Default (Same as Editor)"); for (int i = 0; i < OS::get_singleton()->get_screen_count(); i++) { diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp index bf15f43d32..b6952c3024 100644 --- a/editor/editor_themes.cpp +++ b/editor/editor_themes.cpp @@ -145,8 +145,8 @@ Ref<Theme> create_editor_theme() { theme->set_icon("unchecked", "PopupMenu", theme->get_icon("Unchecked", "EditorIcons")); // Editor background - Ref<StyleBoxFlat> style_background = make_flat_stylebox(dark_color_2, 4, 4, 4, 4); - theme->set_stylebox("Background", "EditorStyles", style_background); + Ref<StyleBoxFlat> style_panel = make_flat_stylebox(dark_color_2, 4, 4, 4, 4); + theme->set_stylebox("Background", "EditorStyles", style_panel); // Focus Ref<StyleBoxFlat> focus_sbt = make_flat_stylebox(light_color_1, 4, 4, 4, 4); @@ -193,9 +193,9 @@ Ref<Theme> create_editor_theme() { theme->set_stylebox("MenuHover", "EditorStyles", style_menu_hover_border); // Content of each tab - Ref<StyleBoxFlat> style_panel = make_flat_stylebox(base_color, 1, 4, 1, 1); - theme->set_stylebox("panel", "TabContainer", style_panel); - theme->set_stylebox("Content", "EditorStyles", style_panel); + Ref<StyleBoxFlat> style_content_panel = make_flat_stylebox(base_color, 1, 4, 1, 1); + theme->set_stylebox("panel", "TabContainer", style_content_panel); + theme->set_stylebox("Content", "EditorStyles", style_content_panel); // Button Ref<StyleBoxFlat> style_button = make_flat_stylebox(dark_color_1, 4, 4, 4, 4); @@ -247,6 +247,10 @@ Ref<Theme> create_editor_theme() { theme->set_icon("arrow_collapsed", "Tree", theme->get_icon("TreeArrowRight", "EditorIcons")); theme->set_icon("select_arrow", "Tree", theme->get_icon("Dropdown", "EditorIcons")); theme->set_stylebox("bg_focus", "Tree", focus_sbt); + theme->set_stylebox("custom_button", "Tree", style_button); + theme->set_stylebox("custom_button_pressed", "Tree", style_button); + theme->set_stylebox("custom_button_hover", "Tree", style_button); + theme->set_color("custom_button_font_highlight", "Tree", HIGHLIGHT_COLOR_LIGHT); Ref<StyleBox> style_tree_btn = make_flat_stylebox(light_color_1, 2, 4, 2, 4); theme->set_stylebox("button_pressed", "Tree", style_tree_btn); @@ -277,7 +281,7 @@ Ref<Theme> create_editor_theme() { theme->set_color("drop_position_color", "Tree", highlight_color); // ItemList - Ref<StyleBoxFlat> style_itemlist_cursor = make_flat_stylebox(highlight_color, 8, 8, 8, 8); + Ref<StyleBoxFlat> style_itemlist_cursor = make_flat_stylebox(highlight_color, 4, 4, 4, 4); style_itemlist_cursor->set_draw_center(false); style_itemlist_cursor->set_border_size(1 * EDSCALE); style_itemlist_cursor->set_light_color(light_color_1); @@ -288,6 +292,7 @@ Ref<Theme> create_editor_theme() { theme->set_stylebox("selected", "ItemList", style_tree_selected); theme->set_stylebox("bg_focus", "ItemList", focus_sbt); theme->set_stylebox("bg", "ItemList", style_bg); + theme->set_constant("vseparation", "ItemList", 5 * EDSCALE); Ref<StyleBoxFlat> style_tab_fg = make_flat_stylebox(base_color, 15, 5, 15, 5); Ref<StyleBoxFlat> style_tab_bg = make_flat_stylebox(base_color, 15, 5, 15, 5); @@ -390,6 +395,9 @@ Ref<Theme> create_editor_theme() { theme->set_icon("grabber", "VSlider", theme->get_icon("SliderGrabber", "EditorIcons")); theme->set_icon("grabber_highlight", "VSlider", theme->get_icon("SliderGrabberHl", "EditorIcons")); + // Panel + theme->set_stylebox("panel", "Panel", style_panel); + // TooltipPanel Ref<StyleBoxFlat> style_tooltip = make_flat_stylebox(Color(1, 1, 1, 0.8), 8, 8, 8, 8); style_tooltip->set_border_size(2 * EDSCALE); diff --git a/editor/import/editor_import_collada.cpp b/editor/import/editor_import_collada.cpp index 907c7b045c..e0a2ea624e 100644 --- a/editor/import/editor_import_collada.cpp +++ b/editor/import/editor_import_collada.cpp @@ -72,7 +72,7 @@ struct ColladaImport { Map<String, NodeMap> node_map; //map from collada node to engine node Map<String, String> node_name_map; //map from collada node to engine node - Map<String, Ref<Mesh> > mesh_cache; + Map<String, Ref<ArrayMesh> > mesh_cache; Map<String, Ref<Curve3D> > curve_cache; Map<String, Ref<Material> > material_cache; Map<Collada::Node *, Skeleton *> skeleton_map; @@ -88,7 +88,7 @@ struct ColladaImport { Error _create_scene(Collada::Node *p_node, Spatial *p_parent); Error _create_resources(Collada::Node *p_node); Error _create_material(const String &p_material); - Error _create_mesh_surfaces(bool p_optimize, Ref<Mesh> &p_mesh, const Map<String, Collada::NodeGeometry::Material> &p_material_map, const Collada::MeshData &meshdata, const Transform &p_local_xform, const Vector<int> &bone_remap, const Collada::SkinControllerData *p_skin_data, const Collada::MorphControllerData *p_morph_data, Vector<Ref<Mesh> > p_morph_meshes = Vector<Ref<Mesh> >(), bool p_for_morph = false, bool p_use_mesh_material = false); + Error _create_mesh_surfaces(bool p_optimize, Ref<ArrayMesh> &p_mesh, const Map<String, Collada::NodeGeometry::Material> &p_material_map, const Collada::MeshData &meshdata, const Transform &p_local_xform, const Vector<int> &bone_remap, const Collada::SkinControllerData *p_skin_data, const Collada::MorphControllerData *p_morph_data, Vector<Ref<ArrayMesh> > p_morph_meshes = Vector<Ref<ArrayMesh> >(), bool p_for_morph = false, bool p_use_mesh_material = false); Error load(const String &p_path, int p_flags, bool p_force_make_tangents = false); void _fix_param_animation_tracks(); void create_animation(int p_clip, bool p_make_tracks_in_all_bones, bool p_import_value_tracks); @@ -591,7 +591,7 @@ static void _generate_tangents_and_binormals(const PoolVector<int> &p_indices, c } } -Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<Mesh> &p_mesh, const Map<String, Collada::NodeGeometry::Material> &p_material_map, const Collada::MeshData &meshdata, const Transform &p_local_xform, const Vector<int> &bone_remap, const Collada::SkinControllerData *skin_controller, const Collada::MorphControllerData *p_morph_data, Vector<Ref<Mesh> > p_morph_meshes, bool p_for_morph, bool p_use_mesh_material) { +Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ArrayMesh> &p_mesh, const Map<String, Collada::NodeGeometry::Material> &p_material_map, const Collada::MeshData &meshdata, const Transform &p_local_xform, const Vector<int> &bone_remap, const Collada::SkinControllerData *skin_controller, const Collada::MorphControllerData *p_morph_data, Vector<Ref<ArrayMesh> > p_morph_meshes, bool p_for_morph, bool p_use_mesh_material) { bool local_xform_mirror = p_local_xform.basis.determinant() < 0; @@ -1530,7 +1530,7 @@ Error ColladaImport::_create_resources(Collada::Node *p_node) { String meshid; Transform apply_xform; Vector<int> bone_remap; - Vector<Ref<Mesh> > morphs; + Vector<Ref<ArrayMesh> > morphs; print_line("mesh: " + String(mi->get_name())); @@ -1621,9 +1621,9 @@ Error ColladaImport::_create_resources(Collada::Node *p_node) { String meshid = names[i]; if (collada.state.mesh_data_map.has(meshid)) { - Ref<Mesh> mesh = Ref<Mesh>(memnew(Mesh)); + Ref<ArrayMesh> mesh = Ref<ArrayMesh>(memnew(ArrayMesh)); const Collada::MeshData &meshdata = collada.state.mesh_data_map[meshid]; - Error err = _create_mesh_surfaces(false, mesh, ng->material_map, meshdata, apply_xform, bone_remap, skin, NULL, Vector<Ref<Mesh> >(), true); + Error err = _create_mesh_surfaces(false, mesh, ng->material_map, meshdata, apply_xform, bone_remap, skin, NULL, Vector<Ref<ArrayMesh> >(), true); ERR_FAIL_COND_V(err, err); morphs.push_back(mesh); @@ -1648,7 +1648,7 @@ Error ColladaImport::_create_resources(Collada::Node *p_node) { meshid = ng->source; } - Ref<Mesh> mesh; + Ref<ArrayMesh> mesh; if (mesh_cache.has(meshid)) { mesh = mesh_cache[meshid]; } else { @@ -1656,7 +1656,7 @@ Error ColladaImport::_create_resources(Collada::Node *p_node) { //bleh, must ignore invalid ERR_FAIL_COND_V(!collada.state.mesh_data_map.has(meshid), ERR_INVALID_DATA); - mesh = Ref<Mesh>(memnew(Mesh)); + mesh = Ref<ArrayMesh>(memnew(ArrayMesh)); const Collada::MeshData &meshdata = collada.state.mesh_data_map[meshid]; mesh->set_name(meshdata.name); Error err = _create_mesh_surfaces(morphs.size() == 0, mesh, ng->material_map, meshdata, apply_xform, bone_remap, skin, morph, morphs, false, use_mesh_builtin_materials); diff --git a/editor/import/resource_importer_obj.cpp b/editor/import/resource_importer_obj.cpp index 21c2ae6eb3..342808f9e1 100644 --- a/editor/import/resource_importer_obj.cpp +++ b/editor/import/resource_importer_obj.cpp @@ -54,7 +54,7 @@ String ResourceImporterOBJ::get_save_extension() const { String ResourceImporterOBJ::get_resource_type() const { - return "Mesh"; + return "ArrayMesh"; } bool ResourceImporterOBJ::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const { @@ -89,7 +89,7 @@ Error ResourceImporterOBJ::import(const String &p_source_file, const String &p_s FileAccessRef f = FileAccess::open(p_source_file, FileAccess::READ); ERR_FAIL_COND_V(!f, ERR_CANT_OPEN); - Ref<Mesh> mesh = Ref<Mesh>(memnew(Mesh)); + Ref<ArrayMesh> mesh = Ref<ArrayMesh>(memnew(ArrayMesh)); Map<String, Ref<Material> > name_map; bool generate_normals = p_options["generate/normals"]; diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index 755f4eb219..d2d2d45a47 100644 --- a/editor/import/resource_importer_scene.cpp +++ b/editor/import/resource_importer_scene.cpp @@ -137,7 +137,7 @@ static String _fixstr(const String &p_what, const String &p_str) { return p_what; } -Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh>, Ref<Shape> > &collision_map) { +Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<ArrayMesh>, Ref<Shape> > &collision_map) { // children first.. for (int i = 0; i < p_node->get_child_count(); i++) { @@ -175,7 +175,7 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> mi->set_flag(GeometryInstance::FLAG_BILLBOARD, true); if (mi->get_mesh().is_valid()) { - Ref<Mesh> m = mi->get_mesh(); + Ref<ArrayMesh> m = mi->get_mesh(); for (int i = 0; i < m->get_surface_count(); i++) { Ref<SpatialMaterial> fm = m->surface_get_material(i); @@ -194,7 +194,7 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> MeshInstance *mi = p_node->cast_to<MeshInstance>(); - Ref<Mesh> m = mi->get_mesh(); + Ref<ArrayMesh> m = mi->get_mesh(); if (m.is_valid()) { @@ -275,7 +275,7 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> if (mi->get_mesh().is_valid()) { - Ref<Mesh> m = mi->get_mesh(); + Ref<ArrayMesh> m = mi->get_mesh(); for (int i = 0; i < m->get_surface_count(); i++) { Ref<SpatialMaterial> fm = m->surface_get_material(i); @@ -325,7 +325,7 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> /*if (mi->get_mesh().is_valid()) { - Ref<Mesh> m = mi->get_mesh(); + Ref<ArrayMesh> m = mi->get_mesh(); for(int i=0;i<m->get_surface_count();i++) { Ref<SpatialMaterial> fm = m->surface_get_material(i); @@ -477,7 +477,7 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> MeshInstance *mi = p_node->cast_to<MeshInstance>(); - Ref<Mesh> mesh = mi->get_mesh(); + Ref<ArrayMesh> mesh = mi->get_mesh(); ERR_FAIL_COND_V(mesh.is_null(), NULL); NavigationMeshInstance *nmi = memnew(NavigationMeshInstance); @@ -655,7 +655,7 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh> MeshInstance *mi = p_node->cast_to<MeshInstance>(); - Ref<Mesh> mesh = mi->get_mesh(); + Ref<ArrayMesh> mesh = mi->get_mesh(); if (!mesh.is_null()) { if (_teststr(mesh->get_name(), "col")) { @@ -972,7 +972,7 @@ static String _make_extname(const String &p_str) { return ext_name; } -void ResourceImporterScene::_make_external_resources(Node *p_node, const String &p_base_path, bool p_make_materials, bool p_make_meshes, Map<Ref<Material>, Ref<Material> > &p_materials, Map<Ref<Mesh>, Ref<Mesh> > &p_meshes) { +void ResourceImporterScene::_make_external_resources(Node *p_node, const String &p_base_path, bool p_make_materials, bool p_make_meshes, Map<Ref<Material>, Ref<Material> > &p_materials, Map<Ref<ArrayMesh>, Ref<ArrayMesh> > &p_meshes) { List<PropertyInfo> pi; @@ -1005,7 +1005,7 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String } } else { - Ref<Mesh> mesh = p_node->get(E->get().name); + Ref<ArrayMesh> mesh = p_node->get(E->get().name); if (mesh.is_valid()) { @@ -1018,7 +1018,7 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String String ext_name = p_base_path + "." + _make_extname(mesh->get_name()) + ".msh"; if (FileAccess::exists(ext_name)) { //if exists, use it - Ref<Mesh> existing = ResourceLoader::load(ext_name); + Ref<ArrayMesh> existing = ResourceLoader::load(ext_name); p_meshes[mesh] = existing; } else { @@ -1059,7 +1059,7 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String } if (!p_make_meshes) { - p_meshes[mesh] = Ref<Mesh>(); //save it anyway, so it won't be checked again + p_meshes[mesh] = Ref<ArrayMesh>(); //save it anyway, so it won't be checked again } } } @@ -1192,7 +1192,7 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p float anim_optimizer_angerr = p_options["animation/optimizer/max_angular_error"]; float anim_optimizer_maxang = p_options["animation/optimizer/max_angle"]; - Map<Ref<Mesh>, Ref<Shape> > collision_map; + Map<Ref<ArrayMesh>, Ref<Shape> > collision_map; scene = _fix_node(scene, scene, collision_map); @@ -1230,7 +1230,7 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p if (external_materials || external_meshes) { Map<Ref<Material>, Ref<Material> > mat_map; - Map<Ref<Mesh>, Ref<Mesh> > mesh_map; + Map<Ref<ArrayMesh>, Ref<ArrayMesh> > mesh_map; _make_external_resources(scene, p_source_file.get_basename(), external_materials, external_meshes, mat_map, mesh_map); } diff --git a/editor/import/resource_importer_scene.h b/editor/import/resource_importer_scene.h index 9f7b1a84e6..ede3028b29 100644 --- a/editor/import/resource_importer_scene.h +++ b/editor/import/resource_importer_scene.h @@ -32,6 +32,7 @@ #include "io/resource_import.h" #include "scene/resources/animation.h" +#include "scene/resources/mesh.h" #include "scene/resources/shape.h" class Material; @@ -100,9 +101,9 @@ public: virtual void get_import_options(List<ImportOption> *r_options, int p_preset = 0) const; virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const; - void _make_external_resources(Node *p_node, const String &p_base_path, bool p_make_materials, bool p_make_meshes, Map<Ref<Material>, Ref<Material> > &p_materials, Map<Ref<Mesh>, Ref<Mesh> > &p_meshes); + void _make_external_resources(Node *p_node, const String &p_base_path, bool p_make_materials, bool p_make_meshes, Map<Ref<Material>, Ref<Material> > &p_materials, Map<Ref<ArrayMesh>, Ref<ArrayMesh> > &p_meshes); - Node *_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh>, Ref<Shape> > &collision_map); + Node *_fix_node(Node *p_node, Node *p_root, Map<Ref<ArrayMesh>, Ref<Shape> > &collision_map); void _create_clips(Node *scene, const Array &p_clips, bool p_bake_all); void _filter_anim_tracks(Ref<Animation> anim, Set<String> &keep); diff --git a/editor/pane_drag.h b/editor/pane_drag.h index 7bd9feb63b..0be017b8f7 100644 --- a/editor/pane_drag.h +++ b/editor/pane_drag.h @@ -34,7 +34,7 @@ class PaneDrag : public Control { - GDCLASS(PaneDrag, Control); + GDCLASS(PaneDrag, Control) bool mouse_over; diff --git a/editor/plugins/animation_tree_editor_plugin.cpp b/editor/plugins/animation_tree_editor_plugin.cpp index fccd527ed6..d67832e10b 100644 --- a/editor/plugins/animation_tree_editor_plugin.cpp +++ b/editor/plugins/animation_tree_editor_plugin.cpp @@ -744,7 +744,7 @@ void AnimationTreeEditor::_gui_input(Ref<InputEvent> p_event) { if (mb->is_pressed()) { if (mb->get_button_index() == 1) { - click_pos = Point2(mb->get_pos().x, mb->get_pos().y); + click_pos = Point2(mb->get_position().x, mb->get_position().y); click_motion = click_pos; click_type = _locate_click(click_pos, &click_node, &click_slot); if (click_type != CLICK_NONE) { @@ -780,7 +780,7 @@ void AnimationTreeEditor::_gui_input(Ref<InputEvent> p_event) { } else { // try to disconnect/remove - Point2 rclick_pos = Point2(mb->get_pos().x, mb->get_pos().y); + Point2 rclick_pos = Point2(mb->get_position().x, mb->get_position().y); rclick_type = _locate_click(rclick_pos, &rclick_node, &rclick_slot); if (rclick_type == CLICK_INPUT_SLOT || rclick_type == CLICK_OUTPUT_SLOT) { @@ -820,7 +820,7 @@ void AnimationTreeEditor::_gui_input(Ref<InputEvent> p_event) { case CLICK_INPUT_SLOT: case CLICK_OUTPUT_SLOT: { - Point2 dst_click_pos = Point2(mb->get_pos().x, mb->get_pos().y); + Point2 dst_click_pos = Point2(mb->get_position().x, mb->get_position().y); StringName id; int slot; ClickType dst_click_type = _locate_click(dst_click_pos, &id, &slot); @@ -859,7 +859,7 @@ void AnimationTreeEditor::_gui_input(Ref<InputEvent> p_event) { if (mm->get_button_mask() & 1 && click_type != CLICK_NONE) { - click_motion = Point2(mm->get_pos().x, mm->get_pos().y); + click_motion = Point2(mm->get_position().x, mm->get_position().y); update(); } if ((mm->get_button_mask() & 4 || Input::get_singleton()->is_key_pressed(KEY_SPACE))) { @@ -876,7 +876,7 @@ void AnimationTreeEditor::_draw_cos_line(const Vector2 &p_from, const Vector2 &p static const int steps = 20; Rect2 r; - r.pos = p_from; + r.position = p_from; r.expand_to(p_to); Vector2 sign = Vector2((p_from.x < p_to.x) ? 1 : -1, (p_from.y < p_to.y) ? 1 : -1); bool flip = sign.x * sign.y < 0; @@ -888,7 +888,7 @@ void AnimationTreeEditor::_draw_cos_line(const Vector2 &p_from, const Vector2 &p float c = -Math::cos(d * Math_PI) * 0.5 + 0.5; if (flip) c = 1.0 - c; - Vector2 p = r.pos + Vector2(d * r.size.width, c * r.size.height); + Vector2 p = r.position + Vector2(d * r.size.width, c * r.size.height); if (i > 0) { diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index a626dffc3c..803e59469c 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -536,10 +536,10 @@ void CanvasItemEditor::_find_canvas_items_at_rect(const Rect2 &p_rect, Node *p_n Rect2 rect = c->get_item_rect(); Transform2D xform = p_parent_xform * p_canvas_xform * c->get_transform(); - if (p_rect.has_point(xform.xform(rect.pos)) && - p_rect.has_point(xform.xform(rect.pos + Vector2(rect.size.x, 0))) && - p_rect.has_point(xform.xform(rect.pos + Vector2(rect.size.x, rect.size.y))) && - p_rect.has_point(xform.xform(rect.pos + Vector2(0, rect.size.y)))) { + if (p_rect.has_point(xform.xform(rect.position)) && + p_rect.has_point(xform.xform(rect.position + Vector2(rect.size.x, 0))) && + p_rect.has_point(xform.xform(rect.position + Vector2(rect.size.x, rect.size.y))) && + p_rect.has_point(xform.xform(rect.position + Vector2(0, rect.size.y)))) { r_items->push_back(c); } @@ -652,7 +652,7 @@ void CanvasItemEditor::_key_move(const Vector2 &p_dir, bool p_snap, KeyMoveMODE // drag = transform.affine_inverse().basis_xform(p_dir); // zoom sensitive drag = canvas_item->get_global_transform_with_canvas().affine_inverse().basis_xform(drag); Rect2 local_rect = canvas_item->get_item_rect(); - local_rect.pos += drag; + local_rect.position += drag; undo_redo->add_do_method(canvas_item, "edit_set_rect", local_rect); } else { // p_move_mode==MOVE_LOCAL_BASE || p_move_mode==MOVE_LOCAL_WITH_ROT @@ -680,7 +680,7 @@ Point2 CanvasItemEditor::_find_topleftmost_point() { Vector2 tl = Point2(1e10, 1e10); Rect2 r2; - r2.pos = tl; + r2.position = tl; List<Node *> &selection = editor_selection->get_selected_node_list(); @@ -695,13 +695,13 @@ Point2 CanvasItemEditor::_find_topleftmost_point() { Rect2 rect = canvas_item->get_item_rect(); Transform2D xform = canvas_item->get_global_transform_with_canvas(); - r2.expand_to(xform.xform(rect.pos)); - r2.expand_to(xform.xform(rect.pos + Vector2(rect.size.x, 0))); - r2.expand_to(xform.xform(rect.pos + rect.size)); - r2.expand_to(xform.xform(rect.pos + Vector2(0, rect.size.y))); + r2.expand_to(xform.xform(rect.position)); + r2.expand_to(xform.xform(rect.position + Vector2(rect.size.x, 0))); + r2.expand_to(xform.xform(rect.position + rect.size)); + r2.expand_to(xform.xform(rect.position + Vector2(0, rect.size.y))); } - return r2.pos; + return r2.position; } int CanvasItemEditor::get_item_count() { @@ -759,18 +759,18 @@ CanvasItemEditor::DragType CanvasItemEditor::_find_drag_type(const Transform2D & Vector2 endpoints[4] = { - xform.xform(rect.pos), - xform.xform(rect.pos + Vector2(rect.size.x, 0)), - xform.xform(rect.pos + rect.size), - xform.xform(rect.pos + Vector2(0, rect.size.y)) + xform.xform(rect.position), + xform.xform(rect.position + Vector2(rect.size.x, 0)), + xform.xform(rect.position + rect.size), + xform.xform(rect.position + Vector2(0, rect.size.y)) }; Vector2 endpointsl[4] = { - xforml.xform(rect.pos), - xforml.xform(rect.pos + Vector2(rect.size.x, 0)), - xforml.xform(rect.pos + rect.size), - xforml.xform(rect.pos + Vector2(0, rect.size.y)) + xforml.xform(rect.position), + xforml.xform(rect.position + Vector2(rect.size.x, 0)), + xforml.xform(rect.position + rect.size), + xforml.xform(rect.position + Vector2(0, rect.size.y)) }; DragType dragger[] = { @@ -962,7 +962,7 @@ bool CanvasItemEditor::get_remove_list(List<Node *> *p_list) { void CanvasItemEditor::_list_select(const Ref<InputEventMouseButton> &b) { - Point2 click = b->get_pos(); + Point2 click = b->get_position(); Node *scene = editor->get_edited_scene(); if (!scene) @@ -1010,13 +1010,12 @@ void CanvasItemEditor::_list_select(const Ref<InputEventMouseButton> &b) { selection_menu->add_item(item->get_name()); selection_menu->set_item_icon(i, icon); selection_menu->set_item_metadata(i, node_path); - selection_menu->set_item_tooltip(i, String(item->get_name()) + - "\nType: " + item->get_class() + "\nPath: " + node_path); + selection_menu->set_item_tooltip(i, String(item->get_name()) + "\nType: " + item->get_class() + "\nPath: " + node_path); } additive_selection = b->get_shift(); - selection_menu->set_global_position(b->get_global_pos()); + selection_menu->set_global_position(b->get_global_position()); selection_menu->popup(); selection_menu->call_deferred("grab_click_focus"); selection_menu->set_invalidate_click_until_motion(); @@ -1047,17 +1046,25 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) { if (b->get_button_index() == BUTTON_WHEEL_DOWN) { - if (zoom < MIN_ZOOM) - return; + if (bool(EditorSettings::get_singleton()->get("editors/2d/scroll_to_pan"))) { + + v_scroll->set_value(v_scroll->get_value() + int(EditorSettings::get_singleton()->get("editors/2d/pan_speed")) / zoom * b->get_factor()); + + } else { + + if (zoom < MIN_ZOOM) + return; - float prev_zoom = zoom; - zoom = zoom * (1 - (0.05 * b->get_factor())); - { - Point2 ofs = b->get_pos(); - ofs = ofs / prev_zoom - ofs / zoom; - h_scroll->set_value(h_scroll->get_value() + ofs.x); - v_scroll->set_value(v_scroll->get_value() + ofs.y); + float prev_zoom = zoom; + zoom = zoom * (1 - (0.05 * b->get_factor())); + { + Point2 ofs = b->get_position(); + ofs = ofs / prev_zoom - ofs / zoom; + h_scroll->set_value(h_scroll->get_value() + ofs.x); + v_scroll->set_value(v_scroll->get_value() + ofs.y); + } } + _update_scroll(0); viewport->update(); return; @@ -1065,16 +1072,21 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) { if (b->get_button_index() == BUTTON_WHEEL_UP) { - if (zoom > MAX_ZOOM) - return; + if (bool(EditorSettings::get_singleton()->get("editors/2d/scroll_to_pan"))) { + + v_scroll->set_value(v_scroll->get_value() - int(EditorSettings::get_singleton()->get("editors/2d/pan_speed")) / zoom * b->get_factor()); - float prev_zoom = zoom; - zoom = zoom * ((0.95 + (0.05 * b->get_factor())) / 0.95); - { - Point2 ofs = b->get_pos(); - ofs = ofs / prev_zoom - ofs / zoom; - h_scroll->set_value(h_scroll->get_value() + ofs.x); - v_scroll->set_value(v_scroll->get_value() + ofs.y); + } else { + if (zoom > MAX_ZOOM) return; + + float prev_zoom = zoom; + zoom = zoom * ((0.95 + (0.05 * b->get_factor())) / 0.95); + { + Point2 ofs = b->get_position(); + ofs = ofs / prev_zoom - ofs / zoom; + h_scroll->set_value(h_scroll->get_value() + ofs.x); + v_scroll->set_value(v_scroll->get_value() + ofs.y); + } } _update_scroll(0); @@ -1082,6 +1094,22 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) { return; } + if (b->get_button_index() == BUTTON_WHEEL_LEFT) { + + if (bool(EditorSettings::get_singleton()->get("editors/2d/scroll_to_pan"))) { + + h_scroll->set_value(h_scroll->get_value() - int(EditorSettings::get_singleton()->get("editors/2d/pan_speed")) / zoom * b->get_factor()); + } + } + + if (b->get_button_index() == BUTTON_WHEEL_RIGHT) { + + if (bool(EditorSettings::get_singleton()->get("editors/2d/scroll_to_pan"))) { + + h_scroll->set_value(h_scroll->get_value() + int(EditorSettings::get_singleton()->get("editors/2d/pan_speed")) / zoom * b->get_factor()); + } + } + if (b->get_button_index() == BUTTON_RIGHT) { if (b->is_pressed() && (tool == TOOL_SELECT && b->get_alt())) { @@ -1156,7 +1184,7 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) { if (b->get_button_index() == BUTTON_LEFT && tool == TOOL_EDIT_PIVOT) { if (b->is_pressed()) { - Point2 mouse_pos = b->get_pos(); + Point2 mouse_pos = b->get_position(); mouse_pos = transform.affine_inverse().xform(mouse_pos); mouse_pos = snap_point(mouse_pos); _edit_set_pivot(mouse_pos); @@ -1274,8 +1302,8 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) { E->get().to }; - Vector2 p = Geometry::get_closest_point_to_segment_2d(b->get_pos(), s); - float d = p.distance_to(b->get_pos()); + Vector2 p = Geometry::get_closest_point_to_segment_2d(b->get_position(), s); + float d = p.distance_to(b->get_position()); if (d < bone_width && d < closest_dist) { Cbone = E; closest_dist = d; @@ -1342,7 +1370,7 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) { CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item); ERR_FAIL_COND(!se); - Point2 click = b->get_pos(); + Point2 click = b->get_position(); if ((b->get_control() && tool == TOOL_SELECT) || tool == TOOL_ROTATE) { @@ -1388,7 +1416,7 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) { //multi canvas_item edit - Point2 click = b->get_pos(); + Point2 click = b->get_position(); if ((b->get_alt() || tool == TOOL_MOVE) && get_item_count()) { _prepare_drag(click); @@ -1451,7 +1479,7 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) { if (box_selecting) { - box_selecting_to = transform.affine_inverse().xform(m->get_pos()); + box_selecting_to = transform.affine_inverse().xform(m->get_position()); viewport->update(); return; } @@ -1497,7 +1525,7 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) { } Vector2 dfrom = drag_from; - Vector2 dto = transform.affine_inverse().xform(m->get_pos()); + Vector2 dto = transform.affine_inverse().xform(m->get_position()); if (canvas_item->has_meta("_edit_lock_")) continue; @@ -1552,8 +1580,8 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) { canvas_item->get_global_transform_with_canvas().affine_inverse().xform(dfrom); Rect2 local_rect = canvas_item->get_item_rect(); - Vector2 begin = local_rect.pos; - Vector2 end = local_rect.pos + local_rect.size; + Vector2 begin = local_rect.position; + Vector2 end = local_rect.position + local_rect.size; Vector2 minsize = canvas_item->edit_get_minimum_size(); if (uniform) { @@ -1645,7 +1673,7 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) { if (!dragging_bone) { - local_rect.pos = begin; + local_rect.position = begin; local_rect.size = end - begin; canvas_item->edit_set_rect(local_rect); @@ -1868,10 +1896,10 @@ void CanvasItemEditor::_viewport_draw() { Vector2 endpoints[4] = { - xform.xform(rect.pos), - xform.xform(rect.pos + Vector2(rect.size.x, 0)), - xform.xform(rect.pos + rect.size), - xform.xform(rect.pos + Vector2(0, rect.size.y)) + xform.xform(rect.position), + xform.xform(rect.position + Vector2(rect.size.x, 0)), + xform.xform(rect.position + rect.size), + xform.xform(rect.position + Vector2(0, rect.size.y)) }; Color c = Color(1, 0.6, 0.4, 0.7); @@ -2212,7 +2240,7 @@ void CanvasItemEditor::_find_canvas_items_span(Node *p_node, Rect2 &r_rect, cons lock.group = c->has_meta("_edit_group_"); if (lock.group || lock.lock) { - lock.pos = xform.xform(rect.pos); + lock.pos = xform.xform(rect.position); lock_list.push_back(lock); } @@ -2228,10 +2256,10 @@ void CanvasItemEditor::_find_canvas_items_span(Node *p_node, Rect2 &r_rect, cons bone_list[id].last_pass = bone_last_frame; } - r_rect.expand_to(xform.xform(rect.pos)); - r_rect.expand_to(xform.xform(rect.pos + Point2(rect.size.x, 0))); - r_rect.expand_to(xform.xform(rect.pos + Point2(0, rect.size.y))); - r_rect.expand_to(xform.xform(rect.pos + rect.size)); + r_rect.expand_to(xform.xform(rect.position)); + r_rect.expand_to(xform.xform(rect.position + Point2(rect.size.x, 0))); + r_rect.expand_to(xform.xform(rect.position + Point2(0, rect.size.y))); + r_rect.expand_to(xform.xform(rect.position + rect.size)); } } @@ -2277,19 +2305,19 @@ void CanvasItemEditor::_update_scrollbars() { //expand area so it's easier to do animations and stuff at 0,0 canvas_item_rect.size += screen_rect * 2; - canvas_item_rect.pos -= screen_rect; + canvas_item_rect.position -= screen_rect; Point2 ofs; if (canvas_item_rect.size.height <= (local_rect.size.y / zoom)) { v_scroll->hide(); - ofs.y = canvas_item_rect.pos.y; + ofs.y = canvas_item_rect.position.y; } else { v_scroll->show(); - v_scroll->set_min(canvas_item_rect.pos.y); - v_scroll->set_max(canvas_item_rect.pos.y + canvas_item_rect.size.y); + v_scroll->set_min(canvas_item_rect.position.y); + v_scroll->set_max(canvas_item_rect.position.y + canvas_item_rect.size.y); v_scroll->set_page(local_rect.size.y / zoom); if (first_update) { //so 0,0 is visible @@ -2304,12 +2332,12 @@ void CanvasItemEditor::_update_scrollbars() { if (canvas_item_rect.size.width <= (local_rect.size.x / zoom)) { h_scroll->hide(); - ofs.x = canvas_item_rect.pos.x; + ofs.x = canvas_item_rect.position.x; } else { h_scroll->show(); - h_scroll->set_min(canvas_item_rect.pos.x); - h_scroll->set_max(canvas_item_rect.pos.x + canvas_item_rect.size.x); + h_scroll->set_min(canvas_item_rect.position.x); + h_scroll->set_max(canvas_item_rect.position.x + canvas_item_rect.size.x); h_scroll->set_page(local_rect.size.x / zoom); ofs.x = h_scroll->get_value(); } @@ -2977,7 +3005,7 @@ void CanvasItemEditor::_focus_selection(int p_op) { Transform2D t(angle, Vector2(0.f, 0.f)); item_rect = t.xform(item_rect); - Rect2 canvas_item_rect(pos + scale * item_rect.pos, scale * item_rect.size); + Rect2 canvas_item_rect(pos + scale * item_rect.position, scale * item_rect.size); if (count == 1) { rect = canvas_item_rect; } else { @@ -2988,7 +3016,7 @@ void CanvasItemEditor::_focus_selection(int p_op) { if (p_op == VIEW_CENTER_TO_SELECTION) { - center = rect.pos + rect.size / 2; + center = rect.position + rect.size / 2; Vector2 offset = viewport->get_size() / 2 - editor->get_scene_root()->get_global_canvas_transform().xform(center); h_scroll->set_value(h_scroll->get_value() - offset.x / zoom); v_scroll->set_value(v_scroll->get_value() - offset.y / zoom); diff --git a/editor/plugins/collision_polygon_2d_editor_plugin.cpp b/editor/plugins/collision_polygon_2d_editor_plugin.cpp index b7cfcaae02..43abea0131 100644 --- a/editor/plugins/collision_polygon_2d_editor_plugin.cpp +++ b/editor/plugins/collision_polygon_2d_editor_plugin.cpp @@ -104,7 +104,7 @@ bool CollisionPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) if (mb.is_valid()) { Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - Vector2 gpoint = mb->get_pos(); + Vector2 gpoint = mb->get_position(); Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); cpoint = canvas_item_editor->snap_point(cpoint); cpoint = node->get_global_transform().affine_inverse().xform(cpoint); @@ -289,7 +289,7 @@ bool CollisionPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) if (edited_point != -1 && (wip_active || mm->get_button_mask() & BUTTON_MASK_LEFT)) { - Vector2 gpoint = mm->get_pos(); + Vector2 gpoint = mm->get_position(); Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); cpoint = canvas_item_editor->snap_point(cpoint); edited_point_pos = node->get_global_transform().affine_inverse().xform(cpoint); diff --git a/editor/plugins/collision_shape_2d_editor_plugin.cpp b/editor/plugins/collision_shape_2d_editor_plugin.cpp index e2184c6158..9a6ee8153e 100644 --- a/editor/plugins/collision_shape_2d_editor_plugin.cpp +++ b/editor/plugins/collision_shape_2d_editor_plugin.cpp @@ -322,7 +322,7 @@ bool CollisionShape2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { Transform2D gt = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - Point2 gpoint(mb->get_pos().x, mb->get_pos().y); + Point2 gpoint(mb->get_position().x, mb->get_position().y); if (mb->get_button_index() == BUTTON_LEFT) { if (mb->is_pressed()) { @@ -368,7 +368,7 @@ bool CollisionShape2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { return false; } - Point2 gpoint = mm->get_pos(); + Point2 gpoint = mm->get_position(); Point2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); cpoint = canvas_item_editor->snap_point(cpoint); cpoint = node->get_global_transform().affine_inverse().xform(cpoint); diff --git a/editor/plugins/curve_editor_plugin.cpp b/editor/plugins/curve_editor_plugin.cpp index 6dd94863a1..d869d703f1 100644 --- a/editor/plugins/curve_editor_plugin.cpp +++ b/editor/plugins/curve_editor_plugin.cpp @@ -57,7 +57,7 @@ void CurveTextureEdit::_gui_input(const Ref<InputEvent> &p_event) { Vector2 size = get_size(); size.y -= font_h; - Point2 p = Vector2(mb->get_pos().x, mb->get_pos().y) / size; + Point2 p = Vector2(mb->get_position().x, mb->get_position().y) / size; p.y = CLAMP(1.0 - p.y, 0, 1) * (max - min) + min; grabbed = -1; grabbing = true; @@ -111,7 +111,7 @@ void CurveTextureEdit::_gui_input(const Ref<InputEvent> &p_event) { Vector2 size = get_size(); size.y -= font_h; - Point2 p = mm->get_pos() / size; + Point2 p = mm->get_position() / size; p.y = CLAMP(1.0 - p.y, 0, 1) * (max - min) + min; p.x = CLAMP(p.x, 0.0, 1.0); diff --git a/editor/plugins/editor_preview_plugins.cpp b/editor/plugins/editor_preview_plugins.cpp index db8060d591..7f8b98e1d3 100644 --- a/editor/plugins/editor_preview_plugins.cpp +++ b/editor/plugins/editor_preview_plugins.cpp @@ -39,239 +39,226 @@ #include "scene/resources/bit_mask.h" #include "scene/resources/mesh.h" -#if 0 -bool EditorTexturePreviewPlugin::handles(const String& p_type) const { +bool EditorTexturePreviewPlugin::handles(const String &p_type) const { - return (ClassDB::is_type(p_type,"ImageTexture") || ClassDB::is_type(p_type, "AtlasTexture")); + return ClassDB::is_parent_class(p_type, "Texture"); } -Ref<Texture> EditorTexturePreviewPlugin::generate(const RES& p_from) { +Ref<Texture> EditorTexturePreviewPlugin::generate(const RES &p_from) { - Image img; + Ref<Image> img; Ref<AtlasTexture> atex = p_from; if (atex.is_valid()) { - Ref<ImageTexture> tex = atex->get_atlas(); + Ref<Texture> tex = atex->get_atlas(); if (!tex.is_valid()) { return Ref<Texture>(); } - Image atlas = tex->get_data(); - img = atlas.get_rect(atex->get_region()); - } - else { - Ref<ImageTexture> tex = p_from; + Ref<Image> atlas = tex->get_data(); + img = atlas->get_rect(atex->get_region()); + } else { + Ref<Texture> tex = p_from; img = tex->get_data(); } - if (img.empty()) + if (img.is_null() || img->empty()) return Ref<Texture>(); - img.clear_mipmaps(); + img->clear_mipmaps(); int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); - thumbnail_size*=EDSCALE; - if (img.is_compressed()) { - if (img.decompress()!=OK) + thumbnail_size *= EDSCALE; + if (img->is_compressed()) { + if (img->decompress() != OK) return Ref<Texture>(); - } else if (img.get_format()!=Image::FORMAT_RGB8 && img.get_format()!=Image::FORMAT_RGBA8) { - img.convert(Image::FORMAT_RGBA8); + } else if (img->get_format() != Image::FORMAT_RGB8 && img->get_format() != Image::FORMAT_RGBA8) { + img->convert(Image::FORMAT_RGBA8); } - int width,height; - if (img.get_width() > thumbnail_size && img.get_width() >= img.get_height()) { + int width, height; + if (img->get_width() > thumbnail_size && img->get_width() >= img->get_height()) { - width=thumbnail_size; - height = img.get_height() * thumbnail_size / img.get_width(); - } else if (img.get_height() > thumbnail_size && img.get_height() >= img.get_width()) { + width = thumbnail_size; + height = img->get_height() * thumbnail_size / img->get_width(); + } else if (img->get_height() > thumbnail_size && img->get_height() >= img->get_width()) { - height=thumbnail_size; - width = img.get_width() * thumbnail_size / img.get_height(); - } else { + height = thumbnail_size; + width = img->get_width() * thumbnail_size / img->get_height(); + } else { - width=img.get_width(); - height=img.get_height(); + width = img->get_width(); + height = img->get_height(); } - img.resize(width,height); + img->resize(width, height); - Ref<ImageTexture> ptex = Ref<ImageTexture>( memnew( ImageTexture )); + Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture)); - ptex->create_from_image(img,0); + ptex->create_from_image(img, 0); return ptex; - } EditorTexturePreviewPlugin::EditorTexturePreviewPlugin() { - - } //////////////////////////////////////////////////////////////////////////// -bool EditorBitmapPreviewPlugin::handles(const String& p_type) const { +bool EditorBitmapPreviewPlugin::handles(const String &p_type) const { - return ClassDB::is_type(p_type,"BitMap"); + return ClassDB::is_parent_class(p_type, "BitMap"); } -Ref<Texture> EditorBitmapPreviewPlugin::generate(const RES& p_from) { +Ref<Texture> EditorBitmapPreviewPlugin::generate(const RES &p_from) { - Ref<BitMap> bm =p_from; + Ref<BitMap> bm = p_from; - if (bm->get_size()==Size2()) { + if (bm->get_size() == Size2()) { return Ref<Texture>(); } PoolVector<uint8_t> data; - data.resize(bm->get_size().width*bm->get_size().height); + data.resize(bm->get_size().width * bm->get_size().height); { - PoolVector<uint8_t>::Write w=data.write(); + PoolVector<uint8_t>::Write w = data.write(); - for(int i=0;i<bm->get_size().width;i++) { - for(int j=0;j<bm->get_size().height;j++) { - if (bm->get_bit(Point2i(i,j))) { - w[j*bm->get_size().width+i]=255; + for (int i = 0; i < bm->get_size().width; i++) { + for (int j = 0; j < bm->get_size().height; j++) { + if (bm->get_bit(Point2i(i, j))) { + w[j * bm->get_size().width + i] = 255; } else { - w[j*bm->get_size().width+i]=0; - + w[j * bm->get_size().width + i] = 0; } } - } } - - Image img(bm->get_size().width,bm->get_size().height,0,Image::FORMAT_L8,data); + Ref<Image> img; + img.instance(); + img->create(bm->get_size().width, bm->get_size().height, 0, Image::FORMAT_L8, data); int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); - thumbnail_size*=EDSCALE; - if (img.is_compressed()) { - if (img.decompress()!=OK) + thumbnail_size *= EDSCALE; + if (img->is_compressed()) { + if (img->decompress() != OK) return Ref<Texture>(); - } else if (img.get_format()!=Image::FORMAT_RGB8 && img.get_format()!=Image::FORMAT_RGBA8) { - img.convert(Image::FORMAT_RGBA8); + } else if (img->get_format() != Image::FORMAT_RGB8 && img->get_format() != Image::FORMAT_RGBA8) { + img->convert(Image::FORMAT_RGBA8); } - int width,height; - if (img.get_width() > thumbnail_size && img.get_width() >= img.get_height()) { + int width, height; + if (img->get_width() > thumbnail_size && img->get_width() >= img->get_height()) { - width=thumbnail_size; - height = img.get_height() * thumbnail_size / img.get_width(); - } else if (img.get_height() > thumbnail_size && img.get_height() >= img.get_width()) { + width = thumbnail_size; + height = img->get_height() * thumbnail_size / img->get_width(); + } else if (img->get_height() > thumbnail_size && img->get_height() >= img->get_width()) { - height=thumbnail_size; - width = img.get_width() * thumbnail_size / img.get_height(); - } else { + height = thumbnail_size; + width = img->get_width() * thumbnail_size / img->get_height(); + } else { - width=img.get_width(); - height=img.get_height(); + width = img->get_width(); + height = img->get_height(); } - img.resize(width,height); + img->resize(width, height); - Ref<ImageTexture> ptex = Ref<ImageTexture>( memnew( ImageTexture )); + Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture)); - ptex->create_from_image(img,0); + ptex->create_from_image(img, 0); return ptex; - } EditorBitmapPreviewPlugin::EditorBitmapPreviewPlugin() { - - } /////////////////////////////////////////////////////////////////////////// +bool EditorPackedScenePreviewPlugin::handles(const String &p_type) const { -Ref<Texture> EditorPackedScenePreviewPlugin::_gen_from_imd(Ref<ResourceImportMetadata> p_imd) { - - if (p_imd.is_null()) { - return Ref<Texture>(); - } + return ClassDB::is_parent_class(p_type, "PackedScene"); +} +Ref<Texture> EditorPackedScenePreviewPlugin::generate(const RES &p_from) { - if (!p_imd->has_option("thumbnail")) - return Ref<Texture>(); + return generate_from_path(p_from->get_path()); +} - Variant tn = p_imd->get_option("thumbnail"); - //print_line(Variant::get_type_name(tn.get_type())); - PoolVector<uint8_t> thumbnail = tn; +Ref<Texture> EditorPackedScenePreviewPlugin::generate_from_path(const String &p_path) { - int len = thumbnail.size(); - if (len==0) - return Ref<Texture>(); + String temp_path = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp"); + String cache_base = GlobalConfig::get_singleton()->globalize_path(p_path).md5_text(); + cache_base = temp_path.plus_file("resthumb-" + cache_base); + //does not have it, try to load a cached thumbnail - PoolVector<uint8_t>::Read r = thumbnail.read(); + String path = cache_base + ".png"; - Image img(r.ptr(),len); - if (img.empty()) + if (!FileAccess::exists(path)) return Ref<Texture>(); - Ref<ImageTexture> ptex = Ref<ImageTexture>( memnew( ImageTexture )); - ptex->create_from_image(img,0); - return ptex; + Ref<Image> img; + img.instance(); + Error err = img->load(path); + if (err == OK) { -} + Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture)); -bool EditorPackedScenePreviewPlugin::handles(const String& p_type) const { + ptex->create_from_image(img, 0); + return ptex; - return ClassDB::is_type(p_type,"PackedScene"); + } else { + return Ref<Texture>(); + } } -Ref<Texture> EditorPackedScenePreviewPlugin::generate(const RES& p_from) { - Ref<ResourceImportMetadata> imd = p_from->get_import_metadata(); - return _gen_from_imd(imd); +EditorPackedScenePreviewPlugin::EditorPackedScenePreviewPlugin() { } -Ref<Texture> EditorPackedScenePreviewPlugin::generate_from_path(const String& p_path) { +////////////////////////////////////////////////////////////////// + +void EditorMaterialPreviewPlugin::_preview_done(const Variant &p_udata) { - Ref<ResourceImportMetadata> imd = ResourceLoader::load_import_metadata(p_path); - return _gen_from_imd(imd); + preview_done = true; } -EditorPackedScenePreviewPlugin::EditorPackedScenePreviewPlugin() { +void EditorMaterialPreviewPlugin::_bind_methods() { + ClassDB::bind_method("_preview_done", &EditorMaterialPreviewPlugin::_preview_done); } -////////////////////////////////////////////////////////////////// +bool EditorMaterialPreviewPlugin::handles(const String &p_type) const { -bool EditorMaterialPreviewPlugin::handles(const String& p_type) const { - - return ClassDB::is_type(p_type,"Material"); //any material + return ClassDB::is_parent_class(p_type, "Material"); //any material } -Ref<Texture> EditorMaterialPreviewPlugin::generate(const RES& p_from) { +Ref<Texture> EditorMaterialPreviewPlugin::generate(const RES &p_from) { Ref<Material> material = p_from; - ERR_FAIL_COND_V(material.is_null(),Ref<Texture>()); + ERR_FAIL_COND_V(material.is_null(), Ref<Texture>()); - VS::get_singleton()->mesh_surface_set_material(sphere,0,material->get_rid()); + VS::get_singleton()->mesh_surface_set_material(sphere, 0, material->get_rid()); - VS::get_singleton()->viewport_queue_screen_capture(viewport); - VS::get_singleton()->viewport_set_render_target_update_mode(viewport,VS::RENDER_TARGET_UPDATE_ONCE); //once used for capture + VS::get_singleton()->viewport_set_update_mode(viewport, VS::VIEWPORT_UPDATE_ONCE); //once used for capture //print_line("queue capture!"); - Image img; - int timeout=1000; - while(timeout) { - //print_line("try capture?"); + preview_done = false; + VS::get_singleton()->request_frame_drawn_callback(this, "_preview_done", Variant()); + + while (!preview_done) { OS::get_singleton()->delay_usec(10); - img = VS::get_singleton()->viewport_get_screen_capture(viewport); - if (!img.empty()) - break; - timeout--; } - //print_line("captured!"); - VS::get_singleton()->mesh_surface_set_material(sphere,0,RID()); + Ref<Image> img = VS::get_singleton()->VS::get_singleton()->texture_get_data(viewport_texture); + VS::get_singleton()->mesh_surface_set_material(sphere, 0, RID()); - int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); - thumbnail_size*=EDSCALE; - img.resize(thumbnail_size,thumbnail_size); + ERR_FAIL_COND_V(!img.is_valid(), Ref<ImageTexture>()); - Ref<ImageTexture> ptex = Ref<ImageTexture>( memnew( ImageTexture )); - ptex->create_from_image(img,0); + int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); + thumbnail_size *= EDSCALE; + img->convert(Image::FORMAT_RGBA8); + img->resize(thumbnail_size, thumbnail_size); + Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture)); + ptex->create_from_image(img, 0); return ptex; } @@ -280,70 +267,68 @@ EditorMaterialPreviewPlugin::EditorMaterialPreviewPlugin() { scenario = VS::get_singleton()->scenario_create(); viewport = VS::get_singleton()->viewport_create(); - VS::get_singleton()->viewport_set_as_render_target(viewport,true); - VS::get_singleton()->viewport_set_render_target_update_mode(viewport,VS::RENDER_TARGET_UPDATE_DISABLED); - VS::get_singleton()->viewport_set_scenario(viewport,scenario); - VS::ViewportRect vr; - vr.x=0; - vr.y=0; - vr.width=128; - vr.height=128; - VS::get_singleton()->viewport_set_rect(viewport,vr); + VS::get_singleton()->viewport_set_update_mode(viewport, VS::VIEWPORT_UPDATE_DISABLED); + VS::get_singleton()->viewport_set_scenario(viewport, scenario); + VS::get_singleton()->viewport_set_size(viewport, 128, 128); + VS::get_singleton()->viewport_set_transparent_background(viewport, true); + VS::get_singleton()->viewport_set_active(viewport, true); + VS::get_singleton()->viewport_set_vflip(viewport, true); + viewport_texture = VS::get_singleton()->viewport_get_texture(viewport); camera = VS::get_singleton()->camera_create(); - VS::get_singleton()->viewport_attach_camera(viewport,camera); - VS::get_singleton()->camera_set_transform(camera,Transform(Matrix3(),Vector3(0,0,3))); - VS::get_singleton()->camera_set_perspective(camera,45,0.1,10); + VS::get_singleton()->viewport_attach_camera(viewport, camera); + VS::get_singleton()->camera_set_transform(camera, Transform(Basis(), Vector3(0, 0, 3))); + VS::get_singleton()->camera_set_perspective(camera, 45, 0.1, 10); light = VS::get_singleton()->light_create(VS::LIGHT_DIRECTIONAL); - light_instance = VS::get_singleton()->instance_create2(light,scenario); - VS::get_singleton()->instance_set_transform(light_instance,Transform().looking_at(Vector3(-1,-1,-1),Vector3(0,1,0))); + light_instance = VS::get_singleton()->instance_create2(light, scenario); + VS::get_singleton()->instance_set_transform(light_instance, Transform().looking_at(Vector3(-1, -1, -1), Vector3(0, 1, 0))); light2 = VS::get_singleton()->light_create(VS::LIGHT_DIRECTIONAL); - VS::get_singleton()->light_set_color(light2,VS::LIGHT_COLOR_DIFFUSE,Color(0.7,0.7,0.7)); - VS::get_singleton()->light_set_color(light2,VS::LIGHT_COLOR_SPECULAR,Color(0.0,0.0,0.0)); - light_instance2 = VS::get_singleton()->instance_create2(light2,scenario); + VS::get_singleton()->light_set_color(light2, Color(0.7, 0.7, 0.7)); + //VS::get_singleton()->light_set_color(light2, Color(0.7, 0.7, 0.7)); + + light_instance2 = VS::get_singleton()->instance_create2(light2, scenario); - VS::get_singleton()->instance_set_transform(light_instance2,Transform().looking_at(Vector3(0,1,0),Vector3(0,0,1))); + VS::get_singleton()->instance_set_transform(light_instance2, Transform().looking_at(Vector3(0, 1, 0), Vector3(0, 0, 1))); sphere = VS::get_singleton()->mesh_create(); - sphere_instance = VS::get_singleton()->instance_create2(sphere,scenario); + sphere_instance = VS::get_singleton()->instance_create2(sphere, scenario); - int lats=32; - int lons=32; - float radius=1.0; + int lats = 32; + int lons = 32; + float radius = 1.0; PoolVector<Vector3> vertices; PoolVector<Vector3> normals; PoolVector<Vector2> uvs; PoolVector<float> tangents; - Matrix3 tt = Matrix3(Vector3(0,1,0),Math_PI*0.5); + Basis tt = Basis(Vector3(0, 1, 0), Math_PI * 0.5); - for(int i = 1; i <= lats; i++) { - double lat0 = Math_PI * (-0.5 + (double) (i - 1) / lats); - double z0 = Math::sin(lat0); - double zr0 = Math::cos(lat0); + for (int i = 1; i <= lats; i++) { + double lat0 = Math_PI * (-0.5 + (double)(i - 1) / lats); + double z0 = Math::sin(lat0); + double zr0 = Math::cos(lat0); - double lat1 = Math_PI * (-0.5 + (double) i / lats); + double lat1 = Math_PI * (-0.5 + (double)i / lats); double z1 = Math::sin(lat1); double zr1 = Math::cos(lat1); - for(int j = lons; j >= 1; j--) { + for (int j = lons; j >= 1; j--) { - double lng0 = 2 * Math_PI * (double) (j - 1) / lons; + double lng0 = 2 * Math_PI * (double)(j - 1) / lons; double x0 = Math::cos(lng0); double y0 = Math::sin(lng0); - double lng1 = 2 * Math_PI * (double) (j) / lons; + double lng1 = 2 * Math_PI * (double)(j) / lons; double x1 = Math::cos(lng1); double y1 = Math::sin(lng1); - - Vector3 v[4]={ - Vector3(x1 * zr0, z0, y1 *zr0), - Vector3(x1 * zr1, z1, y1 *zr1), - Vector3(x0 * zr1, z1, y0 *zr1), - Vector3(x0 * zr0, z0, y0 *zr0) + Vector3 v[4] = { + Vector3(x1 * zr0, z0, y1 * zr0), + Vector3(x1 * zr1, z1, y1 * zr1), + Vector3(x0 * zr1, z1, y0 * zr1), + Vector3(x0 * zr0, z0, y0 * zr0) }; #define ADD_POINT(m_idx) \ @@ -364,8 +349,6 @@ EditorMaterialPreviewPlugin::EditorMaterialPreviewPlugin() { tangents.push_back(1.0); \ } - - ADD_POINT(0); ADD_POINT(1); ADD_POINT(2); @@ -378,12 +361,11 @@ EditorMaterialPreviewPlugin::EditorMaterialPreviewPlugin() { Array arr; arr.resize(VS::ARRAY_MAX); - arr[VS::ARRAY_VERTEX]=vertices; - arr[VS::ARRAY_NORMAL]=normals; - arr[VS::ARRAY_TANGENT]=tangents; - arr[VS::ARRAY_TEX_UV]=uvs; - VS::get_singleton()->mesh_add_surface(sphere,VS::PRIMITIVE_TRIANGLES,arr); - + arr[VS::ARRAY_VERTEX] = vertices; + arr[VS::ARRAY_NORMAL] = normals; + arr[VS::ARRAY_TANGENT] = tangents; + arr[VS::ARRAY_TEX_UV] = uvs; + VS::get_singleton()->mesh_add_surface_from_arrays(sphere, VS::PRIMITIVE_TRIANGLES, arr); } EditorMaterialPreviewPlugin::~EditorMaterialPreviewPlugin() { @@ -397,30 +379,28 @@ EditorMaterialPreviewPlugin::~EditorMaterialPreviewPlugin() { VS::get_singleton()->free(light_instance2); VS::get_singleton()->free(camera); VS::get_singleton()->free(scenario); - } /////////////////////////////////////////////////////////////////////////// static bool _is_text_char(CharType c) { - return (c>='a' && c<='z') || (c>='A' && c<='Z') || (c>='0' && c<='9') || c=='_'; + return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_'; } -bool EditorScriptPreviewPlugin::handles(const String& p_type) const { +bool EditorScriptPreviewPlugin::handles(const String &p_type) const { - return ClassDB::is_type(p_type,"Script"); + return ClassDB::is_parent_class(p_type, "Script"); } -Ref<Texture> EditorScriptPreviewPlugin::generate(const RES& p_from) { - +Ref<Texture> EditorScriptPreviewPlugin::generate(const RES &p_from) { Ref<Script> scr = p_from; if (scr.is_null()) return Ref<Texture>(); String code = scr->get_source_code().strip_edges(); - if (code=="") + if (code == "") return Ref<Texture>(); List<String> kwors; @@ -428,107 +408,103 @@ Ref<Texture> EditorScriptPreviewPlugin::generate(const RES& p_from) { Set<String> keywords; - for(List<String>::Element *E=kwors.front();E;E=E->next()) { + for (List<String>::Element *E = kwors.front(); E; E = E->next()) { keywords.insert(E->get()); - } - int line = 0; - int col=0; + int col = 0; int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); - thumbnail_size*=EDSCALE; - Image img(thumbnail_size,thumbnail_size,0,Image::FORMAT_RGBA8); - - + thumbnail_size *= EDSCALE; + Ref<Image> img; + img.instance(); + img->create(thumbnail_size, thumbnail_size, 0, Image::FORMAT_RGBA8); Color bg_color = EditorSettings::get_singleton()->get("text_editor/highlighting/background_color"); - bg_color.a=1.0; + bg_color.a = 1.0; Color keyword_color = EditorSettings::get_singleton()->get("text_editor/highlighting/keyword_color"); Color text_color = EditorSettings::get_singleton()->get("text_editor/highlighting/text_color"); Color symbol_color = EditorSettings::get_singleton()->get("text_editor/highlighting/symbol_color"); - - for(int i=0;i<thumbnail_size;i++) { - for(int j=0;j<thumbnail_size;j++) { - img.put_pixel(i,j,bg_color); + for (int i = 0; i < thumbnail_size; i++) { + for (int j = 0; j < thumbnail_size; j++) { + img->put_pixel(i, j, bg_color); } - } - bool prev_is_text=false; - bool in_keyword=false; - for(int i=0;i<code.length();i++) { + img->lock(); + bool prev_is_text = false; + bool in_keyword = false; + for (int i = 0; i < code.length(); i++) { CharType c = code[i]; - if (c>32) { - if (col<thumbnail_size) { + if (c > 32) { + if (col < thumbnail_size) { Color color = text_color; - if (c!='_' && ((c>='!' && c<='/') || (c>=':' && c<='@') || (c>='[' && c<='`') || (c>='{' && c<='~') || c=='\t')) { + if (c != '_' && ((c >= '!' && c <= '/') || (c >= ':' && c <= '@') || (c >= '[' && c <= '`') || (c >= '{' && c <= '~') || c == '\t')) { //make symbol a little visible - color=symbol_color; - in_keyword=false; + color = symbol_color; + in_keyword = false; } else if (!prev_is_text && _is_text_char(c)) { int pos = i; - while(_is_text_char(code[pos])) { + while (_is_text_char(code[pos])) { pos++; } ///print_line("from "+itos(i)+" to "+itos(pos)); - String word = code.substr(i,pos-i); + String word = code.substr(i, pos - i); //print_line("found word: "+word); if (keywords.has(word)) - in_keyword=true; + in_keyword = true; } else if (!_is_text_char(c)) { - in_keyword=false; + in_keyword = false; } if (in_keyword) - color=keyword_color; + color = keyword_color; - Color ul=color; - ul.a*=0.5; - img.put_pixel(col,line*2,bg_color.blend(ul)); - img.put_pixel(col,line*2+1,color); + Color ul = color; + ul.a *= 0.5; + img->put_pixel(col, line * 2, bg_color.blend(ul)); + img->put_pixel(col, line * 2 + 1, color); - prev_is_text=_is_text_char(c); + prev_is_text = _is_text_char(c); } } else { - prev_is_text=false; - in_keyword=false; + prev_is_text = false; + in_keyword = false; - if (c=='\n') { - col=0; + if (c == '\n') { + col = 0; line++; - if (line>=thumbnail_size/2) + if (line >= thumbnail_size / 2) break; - } else if (c=='\t') { - col+=3; + } else if (c == '\t') { + col += 3; } } col++; } - Ref<ImageTexture> ptex = Ref<ImageTexture>( memnew( ImageTexture)); + img->unlock(); - ptex->create_from_image(img,0); - return ptex; + Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture)); + ptex->create_from_image(img, 0); + return ptex; } EditorScriptPreviewPlugin::EditorScriptPreviewPlugin() { - - } /////////////////////////////////////////////////////////////////// #if 0 bool EditorSamplePreviewPlugin::handles(const String& p_type) const { - return ClassDB::is_type(p_type,"Sample"); + return ClassDB::is_parent_class(p_type,"Sample"); } Ref<Texture> EditorSamplePreviewPlugin::generate(const RES& p_from) { @@ -795,105 +771,108 @@ EditorSamplePreviewPlugin::EditorSamplePreviewPlugin() { #endif /////////////////////////////////////////////////////////////////////////// -bool EditorMeshPreviewPlugin::handles(const String& p_type) const { +void EditorMeshPreviewPlugin::_preview_done(const Variant &p_udata) { - return ClassDB::is_type(p_type,"Mesh"); //any Mesh + preview_done = true; } -Ref<Texture> EditorMeshPreviewPlugin::generate(const RES& p_from) { +void EditorMeshPreviewPlugin::_bind_methods() { + + ClassDB::bind_method("_preview_done", &EditorMeshPreviewPlugin::_preview_done); +} +bool EditorMeshPreviewPlugin::handles(const String &p_type) const { + + return ClassDB::is_parent_class(p_type, "Mesh"); //any Mesh +} +Ref<Texture> EditorMeshPreviewPlugin::generate(const RES &p_from) { + + print_line("**Generating for mesh finally??"); Ref<Mesh> mesh = p_from; - ERR_FAIL_COND_V(mesh.is_null(),Ref<Texture>()); + ERR_FAIL_COND_V(mesh.is_null(), Ref<Texture>()); - VS::get_singleton()->instance_set_base(mesh_instance,mesh->get_rid()); + VS::get_singleton()->instance_set_base(mesh_instance, mesh->get_rid()); - AABB aabb= mesh->get_aabb(); - Vector3 ofs = aabb.pos + aabb.size*0.5; - aabb.pos-=ofs; + Rect3 aabb = mesh->get_aabb(); + print_line("mesh aabb: " + aabb); + Vector3 ofs = aabb.position + aabb.size * 0.5; + aabb.position -= ofs; Transform xform; - xform.basis=Matrix3().rotated(Vector3(0,1,0),-Math_PI*0.125); - xform.basis = Matrix3().rotated(Vector3(1,0,0),Math_PI*0.125)*xform.basis; - AABB rot_aabb = xform.xform(aabb); - float m = MAX(rot_aabb.size.x,rot_aabb.size.y)*0.5; - if (m==0) + xform.basis = Basis().rotated(Vector3(0, 1, 0), -Math_PI * 0.125); + xform.basis = Basis().rotated(Vector3(1, 0, 0), Math_PI * 0.125) * xform.basis; + Rect3 rot_aabb = xform.xform(aabb); + float m = MAX(rot_aabb.size.x, rot_aabb.size.y) * 0.5; + if (m == 0) return Ref<Texture>(); - m=1.0/m; - m*=0.5; + m = 1.0 / m; + m *= 0.5; //print_line("scale: "+rtos(m)); - xform.basis.scale(Vector3(m,m,m)); - xform.origin=-xform.basis.xform(ofs); //-ofs*m; - xform.origin.z-=rot_aabb.size.z*2; - VS::get_singleton()->instance_set_transform(mesh_instance,xform); - + xform.basis.scale(Vector3(m, m, m)); + xform.origin = -xform.basis.xform(ofs); //-ofs*m; + xform.origin.z -= rot_aabb.size.z * 2; + VS::get_singleton()->instance_set_transform(mesh_instance, xform); - - VS::get_singleton()->viewport_queue_screen_capture(viewport); - VS::get_singleton()->viewport_set_render_target_update_mode(viewport,VS::RENDER_TARGET_UPDATE_ONCE); //once used for capture + VS::get_singleton()->viewport_set_update_mode(viewport, VS::VIEWPORT_UPDATE_ONCE); //once used for capture //print_line("queue capture!"); - Image img; - int timeout=1000; - while(timeout) { - //print_line("try capture?"); + preview_done = false; + VS::get_singleton()->request_frame_drawn_callback(this, "_preview_done", Variant()); + + while (!preview_done) { OS::get_singleton()->delay_usec(10); - img = VS::get_singleton()->viewport_get_screen_capture(viewport); - if (!img.empty()) - break; - timeout--; } - //print_line("captured!"); - VS::get_singleton()->instance_set_base(mesh_instance,RID()); + Ref<Image> img = VS::get_singleton()->VS::get_singleton()->texture_get_data(viewport_texture); + ERR_FAIL_COND_V(img.is_null(), Ref<ImageTexture>()); + + print_line("captured! " + itos(img->get_width()) + "x" + itos(img->get_height())); + VS::get_singleton()->instance_set_base(mesh_instance, RID()); int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); - thumbnail_size*=EDSCALE; - img.resize(thumbnail_size,thumbnail_size); + thumbnail_size *= EDSCALE; + img->convert(Image::FORMAT_RGBA8); + img->resize(thumbnail_size, thumbnail_size); - Ref<ImageTexture> ptex = Ref<ImageTexture>( memnew( ImageTexture )); - ptex->create_from_image(img,0); + Ref<ImageTexture> ptex = Ref<ImageTexture>(memnew(ImageTexture)); + ptex->create_from_image(img, 0); return ptex; } EditorMeshPreviewPlugin::EditorMeshPreviewPlugin() { scenario = VS::get_singleton()->scenario_create(); + viewport = VS::get_singleton()->viewport_create(); - VS::get_singleton()->viewport_set_as_render_target(viewport,true); - VS::get_singleton()->viewport_set_render_target_update_mode(viewport,VS::RENDER_TARGET_UPDATE_DISABLED); - VS::get_singleton()->viewport_set_scenario(viewport,scenario); - VS::ViewportRect vr; - vr.x=0; - vr.y=0; - vr.width=128; - vr.height=128; - VS::get_singleton()->viewport_set_rect(viewport,vr); + VS::get_singleton()->viewport_set_update_mode(viewport, VS::VIEWPORT_UPDATE_DISABLED); + VS::get_singleton()->viewport_set_vflip(viewport, true); + VS::get_singleton()->viewport_set_scenario(viewport, scenario); + VS::get_singleton()->viewport_set_size(viewport, 128, 128); + VS::get_singleton()->viewport_set_transparent_background(viewport, true); + VS::get_singleton()->viewport_set_active(viewport, true); + viewport_texture = VS::get_singleton()->viewport_get_texture(viewport); camera = VS::get_singleton()->camera_create(); - VS::get_singleton()->viewport_attach_camera(viewport,camera); - VS::get_singleton()->camera_set_transform(camera,Transform(Matrix3(),Vector3(0,0,3))); + VS::get_singleton()->viewport_attach_camera(viewport, camera); + VS::get_singleton()->camera_set_transform(camera, Transform(Basis(), Vector3(0, 0, 3))); //VS::get_singleton()->camera_set_perspective(camera,45,0.1,10); - VS::get_singleton()->camera_set_orthogonal(camera,1.0,0.01,1000.0); + VS::get_singleton()->camera_set_orthogonal(camera, 1.0, 0.01, 1000.0); light = VS::get_singleton()->light_create(VS::LIGHT_DIRECTIONAL); - light_instance = VS::get_singleton()->instance_create2(light,scenario); - VS::get_singleton()->instance_set_transform(light_instance,Transform().looking_at(Vector3(-1,-1,-1),Vector3(0,1,0))); + light_instance = VS::get_singleton()->instance_create2(light, scenario); + VS::get_singleton()->instance_set_transform(light_instance, Transform().looking_at(Vector3(-1, -1, -1), Vector3(0, 1, 0))); light2 = VS::get_singleton()->light_create(VS::LIGHT_DIRECTIONAL); - VS::get_singleton()->light_set_color(light2,VS::LIGHT_COLOR_DIFFUSE,Color(0.7,0.7,0.7)); - VS::get_singleton()->light_set_color(light2,VS::LIGHT_COLOR_SPECULAR,Color(0.0,0.0,0.0)); - light_instance2 = VS::get_singleton()->instance_create2(light2,scenario); + VS::get_singleton()->light_set_color(light2, Color(0.7, 0.7, 0.7)); + //VS::get_singleton()->light_set_color(light2, VS::LIGHT_COLOR_SPECULAR, Color(0.0, 0.0, 0.0)); + light_instance2 = VS::get_singleton()->instance_create2(light2, scenario); - VS::get_singleton()->instance_set_transform(light_instance2,Transform().looking_at(Vector3(0,1,0),Vector3(0,0,1))); + VS::get_singleton()->instance_set_transform(light_instance2, Transform().looking_at(Vector3(0, 1, 0), Vector3(0, 0, 1))); //sphere = VS::get_singleton()->mesh_create(); mesh_instance = VS::get_singleton()->instance_create(); - VS::get_singleton()->instance_set_scenario(mesh_instance,scenario); - - - + VS::get_singleton()->instance_set_scenario(mesh_instance, scenario); } - EditorMeshPreviewPlugin::~EditorMeshPreviewPlugin() { //VS::get_singleton()->free(sphere); @@ -905,6 +884,4 @@ EditorMeshPreviewPlugin::~EditorMeshPreviewPlugin() { VS::get_singleton()->free(light_instance2); VS::get_singleton()->free(camera); VS::get_singleton()->free(scenario); - } -#endif diff --git a/editor/plugins/editor_preview_plugins.h b/editor/plugins/editor_preview_plugins.h index 993e36df02..7e7d36eb1e 100644 --- a/editor/plugins/editor_preview_plugins.h +++ b/editor/plugins/editor_preview_plugins.h @@ -32,55 +32,58 @@ #include "editor/editor_resource_preview.h" -#if 0 class EditorTexturePreviewPlugin : public EditorResourcePreviewGenerator { + GDCLASS(EditorTexturePreviewPlugin, EditorResourcePreviewGenerator) public: - - virtual bool handles(const String& p_type) const; - virtual Ref<Texture> generate(const RES& p_from); + virtual bool handles(const String &p_type) const; + virtual Ref<Texture> generate(const RES &p_from); EditorTexturePreviewPlugin(); }; - class EditorBitmapPreviewPlugin : public EditorResourcePreviewGenerator { + GDCLASS(EditorBitmapPreviewPlugin, EditorResourcePreviewGenerator) public: - - virtual bool handles(const String& p_type) const; - virtual Ref<Texture> generate(const RES& p_from); + virtual bool handles(const String &p_type) const; + virtual Ref<Texture> generate(const RES &p_from); EditorBitmapPreviewPlugin(); }; - - class EditorPackedScenePreviewPlugin : public EditorResourcePreviewGenerator { - Ref<Texture> _gen_from_imd(Ref<ResourceImportMetadata> p_imd); public: - - virtual bool handles(const String& p_type) const; - virtual Ref<Texture> generate(const RES& p_from); - virtual Ref<Texture> generate_from_path(const String& p_path); + virtual bool handles(const String &p_type) const; + virtual Ref<Texture> generate(const RES &p_from); + virtual Ref<Texture> generate_from_path(const String &p_path); EditorPackedScenePreviewPlugin(); }; class EditorMaterialPreviewPlugin : public EditorResourcePreviewGenerator { + GDCLASS(EditorMaterialPreviewPlugin, EditorResourcePreviewGenerator) + RID scenario; RID sphere; RID sphere_instance; RID viewport; + RID viewport_texture; RID light; RID light_instance; RID light2; RID light_instance2; RID camera; -public: + volatile bool preview_done; - virtual bool handles(const String& p_type) const; - virtual Ref<Texture> generate(const RES& p_from); + void _preview_done(const Variant &p_udata); + +protected: + static void _bind_methods(); + +public: + virtual bool handles(const String &p_type) const; + virtual Ref<Texture> generate(const RES &p_from); EditorMaterialPreviewPlugin(); ~EditorMaterialPreviewPlugin(); @@ -88,9 +91,8 @@ public: class EditorScriptPreviewPlugin : public EditorResourcePreviewGenerator { public: - - virtual bool handles(const String& p_type) const; - virtual Ref<Texture> generate(const RES& p_from); + virtual bool handles(const String &p_type) const; + virtual Ref<Texture> generate(const RES &p_from); EditorScriptPreviewPlugin(); }; @@ -108,22 +110,30 @@ public: #endif class EditorMeshPreviewPlugin : public EditorResourcePreviewGenerator { + GDCLASS(EditorMeshPreviewPlugin, EditorResourcePreviewGenerator) + RID scenario; RID mesh_instance; RID viewport; + RID viewport_texture; RID light; RID light_instance; RID light2; RID light_instance2; RID camera; -public: + volatile bool preview_done; - virtual bool handles(const String& p_type) const; - virtual Ref<Texture> generate(const RES& p_from); + void _preview_done(const Variant &p_udata); + +protected: + static void _bind_methods(); + +public: + virtual bool handles(const String &p_type) const; + virtual Ref<Texture> generate(const RES &p_from); EditorMeshPreviewPlugin(); ~EditorMeshPreviewPlugin(); }; -#endif #endif // EDITORPREVIEWPLUGINS_H diff --git a/editor/plugins/gradient_texture_editor_plugin.cpp b/editor/plugins/gradient_texture_editor_plugin.cpp index 40f7de478d..bc985dcdf7 100644 --- a/editor/plugins/gradient_texture_editor_plugin.cpp +++ b/editor/plugins/gradient_texture_editor_plugin.cpp @@ -94,14 +94,14 @@ void GradientTextureEdit::_gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventMouseButton> mb = p_event; //Show color picker on double click. if (mb.is_valid() && mb->get_button_index() == 1 && mb->is_doubleclick() && mb->is_pressed()) { - grabbed = _get_point_from_pos(mb->get_pos().x); + grabbed = _get_point_from_pos(mb->get_position().x); _show_color_picker(); accept_event(); } //Delete point on right click if (mb.is_valid() && mb->get_button_index() == 2 && mb->is_pressed()) { - grabbed = _get_point_from_pos(mb->get_pos().x); + grabbed = _get_point_from_pos(mb->get_position().x); if (grabbed != -1) { points.remove(grabbed); grabbed = -1; @@ -115,7 +115,7 @@ void GradientTextureEdit::_gui_input(const Ref<InputEvent> &p_event) { //Hold alt key to duplicate selected color if (mb.is_valid() && mb->get_button_index() == 1 && mb->is_pressed() && mb->get_alt()) { - int x = mb->get_pos().x; + int x = mb->get_position().x; grabbed = _get_point_from_pos(x); if (grabbed != -1) { @@ -140,7 +140,7 @@ void GradientTextureEdit::_gui_input(const Ref<InputEvent> &p_event) { if (mb.is_valid() && mb->get_button_index() == 1 && mb->is_pressed()) { update(); - int x = mb->get_pos().x; + int x = mb->get_position().x; int total_w = get_size().width - get_size().height - 3; //Check if color selector was clicked. @@ -220,7 +220,7 @@ void GradientTextureEdit::_gui_input(const Ref<InputEvent> &p_event) { int total_w = get_size().width - get_size().height - 3; - int x = mm->get_pos().x; + int x = mm->get_position().x; float newofs = CLAMP(x / float(total_w), 0, 1); //Snap to nearest point if holding shift diff --git a/editor/plugins/light_occluder_2d_editor_plugin.cpp b/editor/plugins/light_occluder_2d_editor_plugin.cpp index 9c9e010b47..09021446dc 100644 --- a/editor/plugins/light_occluder_2d_editor_plugin.cpp +++ b/editor/plugins/light_occluder_2d_editor_plugin.cpp @@ -118,7 +118,7 @@ bool LightOccluder2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - Vector2 gpoint = mb->get_pos(); + Vector2 gpoint = mb->get_position(); Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); cpoint = canvas_item_editor->snap_point(cpoint); cpoint = node->get_global_transform().affine_inverse().xform(cpoint); @@ -308,7 +308,7 @@ bool LightOccluder2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { if (edited_point != -1 && (wip_active || mm->get_button_mask() & BUTTON_MASK_LEFT)) { - Vector2 gpoint = mm->get_pos(); + Vector2 gpoint = mm->get_position(); Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); cpoint = canvas_item_editor->snap_point(cpoint); edited_point_pos = node->get_global_transform().affine_inverse().xform(cpoint); diff --git a/editor/plugins/line_2d_editor_plugin.cpp b/editor/plugins/line_2d_editor_plugin.cpp index 3497af3602..76906a5b93 100644 --- a/editor/plugins/line_2d_editor_plugin.cpp +++ b/editor/plugins/line_2d_editor_plugin.cpp @@ -87,7 +87,7 @@ bool Line2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { if (mb.is_valid()) { - Vector2 gpoint = mb->get_pos(); + Vector2 gpoint = mb->get_position(); Vector2 cpoint = mouse_to_local_pos(gpoint, mb->get_alt()); if (mb->is_pressed() && _dragging == false) { @@ -146,7 +146,7 @@ bool Line2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { if (mm.is_valid()) { if (_dragging) { - Vector2 cpoint = mouse_to_local_pos(mm->get_pos(), mm->get_alt()); + Vector2 cpoint = mouse_to_local_pos(mm->get_position(), mm->get_alt()); node->set_point_pos(action_point, cpoint); canvas_item_editor->get_viewport_control()->update(); return true; diff --git a/editor/plugins/navigation_polygon_editor_plugin.cpp b/editor/plugins/navigation_polygon_editor_plugin.cpp index a7fc1d5adb..1457b28ed1 100644 --- a/editor/plugins/navigation_polygon_editor_plugin.cpp +++ b/editor/plugins/navigation_polygon_editor_plugin.cpp @@ -134,7 +134,7 @@ bool NavigationPolygonEditor::forward_gui_input(const Ref<InputEvent> &p_event) Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - Vector2 gpoint = mb->get_pos(); + Vector2 gpoint = mb->get_position(); Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); cpoint = canvas_item_editor->snap_point(cpoint); cpoint = node->get_global_transform().affine_inverse().xform(cpoint); @@ -361,7 +361,7 @@ bool NavigationPolygonEditor::forward_gui_input(const Ref<InputEvent> &p_event) if (edited_point != -1 && (wip_active || mm->get_button_mask() & BUTTON_MASK_LEFT)) { - Vector2 gpoint = mm->get_pos(); + Vector2 gpoint = mm->get_position(); Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); cpoint = canvas_item_editor->snap_point(cpoint); edited_point_pos = node->get_global_transform().affine_inverse().xform(cpoint); diff --git a/editor/plugins/particles_editor_plugin.cpp b/editor/plugins/particles_editor_plugin.cpp index dc2da80b06..d918a3e24e 100644 --- a/editor/plugins/particles_editor_plugin.cpp +++ b/editor/plugins/particles_editor_plugin.cpp @@ -254,7 +254,7 @@ void ParticlesEditor::_generate_emission_points() { for (int j = 0; j < 3; j++) { if (i == 0 && j == 0) - aabb.pos = r[i].vertex[j]; + aabb.position = r[i].vertex[j]; else aabb.expand_to(r[i].vertex[j]); } @@ -272,7 +272,7 @@ void ParticlesEditor::_generate_emission_points() { dir[Math::rand() % 3] = 1.0; Vector3 ofs = Vector3(1, 1, 1) - dir; ofs = (Vector3(1, 1, 1) - dir) * Vector3(Math::randf(), Math::randf(), Math::randf()) * aabb.size; - ofs += aabb.pos; + ofs += aabb.position; Vector3 ofsv = ofs + aabb.size * dir; diff --git a/editor/plugins/path_2d_editor_plugin.cpp b/editor/plugins/path_2d_editor_plugin.cpp index 73d5b28886..f9f16fea16 100644 --- a/editor/plugins/path_2d_editor_plugin.cpp +++ b/editor/plugins/path_2d_editor_plugin.cpp @@ -74,7 +74,7 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - Vector2 gpoint = mb->get_pos(); + Vector2 gpoint = mb->get_position(); Vector2 cpoint = !mb->get_alt() ? canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint)) : @@ -431,7 +431,7 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { if (action != ACTION_NONE) { // Handle point/control movement. Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - Vector2 gpoint = mm->get_pos(); + Vector2 gpoint = mm->get_position(); Vector2 cpoint = !mm->get_alt() ? canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint)) : diff --git a/editor/plugins/path_editor_plugin.cpp b/editor/plugins/path_editor_plugin.cpp index 20535d796e..877707d77b 100644 --- a/editor/plugins/path_editor_plugin.cpp +++ b/editor/plugins/path_editor_plugin.cpp @@ -285,7 +285,7 @@ bool PathEditorPlugin::forward_spatial_gui_input(Camera *p_camera, const Ref<Inp if (mb.is_valid()) { - Point2 mbpos(mb->get_pos().x, mb->get_pos().y); + Point2 mbpos(mb->get_position().x, mb->get_position().y); if (mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT && (curve_create->is_pressed() || (curve_edit->is_pressed() && mb->get_control()))) { //click into curve, break it down diff --git a/editor/plugins/polygon_2d_editor_plugin.cpp b/editor/plugins/polygon_2d_editor_plugin.cpp index c2edc608ab..dd13ca0e63 100644 --- a/editor/plugins/polygon_2d_editor_plugin.cpp +++ b/editor/plugins/polygon_2d_editor_plugin.cpp @@ -212,7 +212,7 @@ bool Polygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - Vector2 gpoint = mb->get_pos(); + Vector2 gpoint = mb->get_position(); Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); cpoint = canvas_item_editor->snap_point(cpoint); cpoint = node->get_global_transform().affine_inverse().xform(cpoint); @@ -397,7 +397,7 @@ bool Polygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { if (edited_point != -1 && (wip_active || mm->get_button_mask() & BUTTON_MASK_LEFT)) { - Vector2 gpoint = mm->get_pos(); + Vector2 gpoint = mm->get_position(); Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); cpoint = canvas_item_editor->snap_point(cpoint); edited_point_pos = node->get_global_transform().affine_inverse().xform(cpoint); @@ -465,7 +465,7 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { if (mb->is_pressed()) { - uv_drag_from = Vector2(mb->get_pos().x, mb->get_pos().y); + uv_drag_from = Vector2(mb->get_position().x, mb->get_position().y); uv_drag = true; uv_prev = node->get_uv(); uv_move_current = uv_mode; @@ -485,7 +485,7 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { for (int i = 0; i < uv_prev.size(); i++) { Vector2 tuv = mtx.xform(uv_prev[i]); - if (tuv.distance_to(Vector2(mb->get_pos().x, mb->get_pos().y)) < 8) { + if (tuv.distance_to(Vector2(mb->get_position().x, mb->get_position().y)) < 8) { uv_drag_from = tuv; uv_drag_index = i; } @@ -537,7 +537,7 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) { } else if (uv_drag) { - Vector2 uv_drag_to = mm->get_pos(); + Vector2 uv_drag_to = mm->get_position(); Vector2 drag = mtx.affine_inverse().xform(uv_drag_to) - mtx.affine_inverse().xform(uv_drag_from); switch (uv_move_current) { @@ -675,14 +675,14 @@ void Polygon2DEditor::_uv_draw() { rect = rect.grow(200); updating_uv_scroll = true; - uv_hscroll->set_min(rect.pos.x); - uv_hscroll->set_max(rect.pos.x + rect.size.x); + uv_hscroll->set_min(rect.position.x); + uv_hscroll->set_max(rect.position.x + rect.size.x); uv_hscroll->set_page(uv_edit_draw->get_size().x); uv_hscroll->set_value(uv_draw_ofs.x); uv_hscroll->set_step(0.001); - uv_vscroll->set_min(rect.pos.y); - uv_vscroll->set_max(rect.pos.y + rect.size.y); + uv_vscroll->set_min(rect.position.y); + uv_vscroll->set_max(rect.position.y + rect.size.y); uv_vscroll->set_page(uv_edit_draw->get_size().y); uv_vscroll->set_value(uv_draw_ofs.y); uv_vscroll->set_step(0.001); diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index fde6d83aa8..f3941d6a16 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -410,7 +410,9 @@ void ScriptEditor::_go_to_tab(int p_idx) { c->set_meta("__editor_pass", ++edit_pass); _update_history_arrows(); _update_script_colors(); + _update_members_overview(); _update_selected_editor_menu(); + _update_members_overview_visibility(); } void ScriptEditor::_add_recent_script(String p_path) { @@ -540,6 +542,7 @@ void ScriptEditor::_close_tab(int p_idx, bool p_save) { _update_history_arrows(); _update_script_names(); + _update_members_overview_visibility(); _save_layout(); } @@ -1025,6 +1028,7 @@ void ScriptEditor::_notification(int p_what) { editor->connect("script_add_function_request", this, "_add_callback"); editor->connect("resource_saved", this, "_res_saved_callback"); script_list->connect("item_selected", this, "_script_selected"); + members_overview->connect("item_selected", this, "_members_overview_selected"); script_split->connect("dragged", this, "_script_split_dragged"); autosave_timer->connect("timeout", this, "_autosave_scripts"); { @@ -1273,6 +1277,16 @@ void ScriptEditor::ensure_focus_current() { se->ensure_focus(); } +void ScriptEditor::_members_overview_selected(int p_idx) { + Node *current = tab_container->get_child(tab_container->get_current_tab()); + ScriptEditorBase *se = current->cast_to<ScriptEditorBase>(); + if (!se) { + return; + } + se->goto_line(members_overview->get_item_metadata(p_idx)); + se->ensure_focus(); +} + void ScriptEditor::_script_selected(int p_idx) { grab_focus_block = !Input::get_singleton()->is_mouse_button_pressed(1); //amazing hack, simply amazing @@ -1342,6 +1356,37 @@ struct _ScriptEditorItemData { } }; +void ScriptEditor::_update_members_overview_visibility() { + Node *current = tab_container->get_child(tab_container->get_current_tab()); + ScriptEditorBase *se = current->cast_to<ScriptEditorBase>(); + if (!se) { + members_overview->set_visible(false); + return; + } + + if (members_overview_enabled && se->show_members_overview()) { + members_overview->set_visible(true); + } else { + members_overview->set_visible(false); + } +} + +void ScriptEditor::_update_members_overview() { + members_overview->clear(); + + Node *current = tab_container->get_child(tab_container->get_current_tab()); + ScriptEditorBase *se = current->cast_to<ScriptEditorBase>(); + if (!se) { + return; + } + + Vector<String> functions = se->get_functions(); + for (int i = 0; i < functions.size(); i++) { + members_overview->add_item(functions[i].get_slice(":", 0)); + members_overview->set_item_metadata(i, functions[i].get_slice(":", 1).to_int() - 1); + } +} + void ScriptEditor::_update_script_colors() { bool script_temperature_enabled = EditorSettings::get_singleton()->get("text_editor/open_scripts/script_temperature_enabled"); @@ -1485,6 +1530,7 @@ void ScriptEditor::_update_script_names() { } } + _update_members_overview(); _update_script_colors(); } @@ -1733,6 +1779,9 @@ void ScriptEditor::_editor_settings_changed() { convert_indent_on_save = EditorSettings::get_singleton()->get("text_editor/indent/convert_indent_on_save"); use_space_indentation = EditorSettings::get_singleton()->get("text_editor/indent/type"); + members_overview_enabled = EditorSettings::get_singleton()->get("text_editor/open_scripts/show_members_overview"); + _update_members_overview_visibility(); + float autosave_time = EditorSettings::get_singleton()->get("text_editor/files/autosave_interval_secs"); if (autosave_time > 0) { autosave_timer->set_wait_time(autosave_time); @@ -2084,6 +2133,7 @@ void ScriptEditor::_bind_methods() { ClassDB::bind_method("_editor_settings_changed", &ScriptEditor::_editor_settings_changed); ClassDB::bind_method("_update_script_names", &ScriptEditor::_update_script_names); ClassDB::bind_method("_tree_changed", &ScriptEditor::_tree_changed); + ClassDB::bind_method("_members_overview_selected", &ScriptEditor::_members_overview_selected); ClassDB::bind_method("_script_selected", &ScriptEditor::_script_selected); ClassDB::bind_method("_script_created", &ScriptEditor::_script_created); ClassDB::bind_method("_script_split_dragged", &ScriptEditor::_script_split_dragged); @@ -2105,6 +2155,7 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { waiting_update_names = false; pending_auto_reload = false; auto_reload_running_scripts = false; + members_overview_enabled = true; editor = p_editor; menu_hb = memnew(HBoxContainer); @@ -2114,10 +2165,19 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { add_child(script_split); script_split->set_v_size_flags(SIZE_EXPAND_FILL); + list_split = memnew(VSplitContainer); + script_split->add_child(list_split); + list_split->set_v_size_flags(SIZE_EXPAND_FILL); + script_list = memnew(ItemList); - script_split->add_child(script_list); + list_split->add_child(script_list); script_list->set_custom_minimum_size(Size2(0, 0)); script_split->set_split_offset(140); + list_split->set_split_offset(500); + + members_overview = memnew(ItemList); + list_split->add_child(members_overview); + members_overview->set_custom_minimum_size(Size2(0, 0)); tab_container = memnew(TabContainer); tab_container->add_style_override("panel", p_editor->get_gui_base()->get_stylebox("ScriptPanel", "EditorStyles")); diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h index 455a888f0e..e036d1ed9c 100644 --- a/editor/plugins/script_editor_plugin.h +++ b/editor/plugins/script_editor_plugin.h @@ -102,6 +102,8 @@ public: virtual void set_debugger_active(bool p_active) = 0; virtual bool can_lose_focus_on_node_selection() { return true; } + virtual bool show_members_overview() = 0; + virtual void set_tooltip_request_func(String p_method, Object *p_obj) = 0; virtual Control *get_edit_menu() = 0; @@ -179,6 +181,9 @@ class ScriptEditor : public VBoxContainer { ItemList *script_list; HSplitContainer *script_split; + ItemList *members_overview; + bool members_overview_enabled; + VSplitContainer *list_split; TabContainer *tab_container; EditorFileDialog *file_dialog; ConfirmationDialog *erase_tab_confirm; @@ -278,8 +283,11 @@ class ScriptEditor : public VBoxContainer { void _editor_settings_changed(); void _autosave_scripts(); + void _update_members_overview_visibility(); + void _update_members_overview(); void _update_script_names(); + void _members_overview_selected(int p_idx); void _script_selected(int p_idx); void _find_scripts(Node *p_base, Node *p_current, Set<Ref<Script> > &used); diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 2d3a14e525..9f76119374 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -218,6 +218,10 @@ void ScriptTextEditor::add_callback(const String &p_function, PoolStringArray p_ code_editor->get_text_edit()->cursor_set_column(1); } +bool ScriptTextEditor::show_members_overview() { + return true; +} + void ScriptTextEditor::update_settings() { code_editor->update_editor_settings(); @@ -1236,8 +1240,8 @@ void ScriptTextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { int col, row; TextEdit *tx = code_editor->get_text_edit(); - tx->_get_mouse_pos(mb->get_global_pos() - tx->get_global_position(), row, col); - Vector2 mpos = mb->get_global_pos() - tx->get_global_position(); + tx->_get_mouse_pos(mb->get_global_position() - tx->get_global_position(), row, col); + Vector2 mpos = mb->get_global_position() - tx->get_global_position(); bool have_selection = (tx->get_selection_text().length() > 0); bool have_color = (tx->get_word_at_pos(mpos) == "Color"); if (have_color) { diff --git a/editor/plugins/script_text_editor.h b/editor/plugins/script_text_editor.h index fdae03949c..ba40645161 100644 --- a/editor/plugins/script_text_editor.h +++ b/editor/plugins/script_text_editor.h @@ -149,6 +149,8 @@ public: virtual void add_callback(const String &p_function, PoolStringArray p_args); virtual void update_settings(); + virtual bool show_members_overview(); + virtual void set_tooltip_request_func(String p_method, Object *p_obj); virtual void set_debugger_active(bool p_active); diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp index 8ae7d55bdd..7c8ee97f22 100644 --- a/editor/plugins/shader_editor_plugin.cpp +++ b/editor/plugins/shader_editor_plugin.cpp @@ -552,7 +552,8 @@ ShaderEditorPlugin::ShaderEditorPlugin(EditorNode *p_node) { shader_editor = memnew(ShaderEditor); shader_editor->set_custom_minimum_size(Size2(0, 300)); - button = editor->add_bottom_panel_item("Shader", shader_editor); + button = editor->add_bottom_panel_item(TTR("Shader"), shader_editor); + button->hide(); } ShaderEditorPlugin::~ShaderEditorPlugin() { diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index ff4b5e430e..a8d875a769 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -636,7 +636,7 @@ void SpatialEditorViewport::_smouseenter() { void SpatialEditorViewport::_list_select(Ref<InputEventMouseButton> b) { - _find_items_at_pos(b->get_pos(), clicked_includes_current, selection_results, b->get_shift()); + _find_items_at_pos(b->get_position(), clicked_includes_current, selection_results, b->get_shift()); Node *scene = editor->get_edited_scene(); @@ -684,7 +684,7 @@ void SpatialEditorViewport::_list_select(Ref<InputEventMouseButton> b) { selection_menu->set_item_tooltip(i, String(spat->get_name()) + "\nType: " + spat->get_class() + "\nPath: " + node_path); } - selection_menu->set_global_position(b->get_global_pos()); + selection_menu->set_global_position(b->get_global_position()); selection_menu->popup(); selection_menu->call_deferred("grab_click_focus"); selection_menu->set_invalidate_click_until_motion(); @@ -818,7 +818,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { break; } - _edit.mouse_pos = b->get_pos(); + _edit.mouse_pos = b->get_position(); _edit.snap = false; _edit.mode = TRANSFORM_NONE; @@ -863,7 +863,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { break; //bye //handle rotate _edit.mode = TRANSFORM_ROTATE; - _compute_edit(b->get_pos()); + _compute_edit(b->get_position()); break; } @@ -873,7 +873,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { break; //bye //handle rotate _edit.mode = TRANSFORM_TRANSLATE; - _compute_edit(b->get_pos()); + _compute_edit(b->get_position()); break; } @@ -883,7 +883,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { break; //bye //handle rotate _edit.mode = TRANSFORM_SCALE; - _compute_edit(b->get_pos()); + _compute_edit(b->get_position()); break; } @@ -891,7 +891,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { int gizmo_handle = -1; - clicked = _select_ray(b->get_pos(), b->get_shift(), clicked_includes_current, &gizmo_handle, b->get_shift()); + clicked = _select_ray(b->get_position(), b->get_shift(), clicked_includes_current, &gizmo_handle, b->get_shift()); //clicking is always deferred to either move or release @@ -904,8 +904,8 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { //default to regionselect cursor.region_select = true; - cursor.region_begin = b->get_pos(); - cursor.region_end = b->get_pos(); + cursor.region_begin = b->get_position(); + cursor.region_end = b->get_position(); } if (clicked && gizmo_handle >= 0) { @@ -989,7 +989,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { if (m.is_valid()) { - _edit.mouse_pos = m->get_pos(); + _edit.mouse_pos = m->get_position(); if (spatial_editor->get_selected()) { @@ -1026,7 +1026,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { if (_edit.gizmo.is_valid()) { - _edit.gizmo->set_handle(_edit.gizmo_handle, camera, m->get_pos()); + _edit.gizmo->set_handle(_edit.gizmo_handle, camera, m->get_position()); Variant v = _edit.gizmo->get_handle_value(_edit.gizmo_handle); String n = _edit.gizmo->get_handle_name(_edit.gizmo_handle); set_message(n + ": " + String(v)); @@ -1058,7 +1058,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { if (cursor.region_select && nav_mode == NAVIGATION_NONE) { - cursor.region_end = m->get_pos(); + cursor.region_end = m->get_position(); surface->update(); return; } @@ -1066,8 +1066,8 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { if (_edit.mode == TRANSFORM_NONE && nav_mode == NAVIGATION_NONE) return; - Vector3 ray_pos = _get_ray_pos(m->get_pos()); - Vector3 ray = _get_ray(m->get_pos()); + Vector3 ray_pos = _get_ray_pos(m->get_position()); + Vector3 ray = _get_ray(m->get_position()); switch (_edit.mode) { @@ -1676,7 +1676,7 @@ void SpatialEditorViewport::_notification(int p_what) { } Transform t = sp->get_global_transform(); - t.translate(se->aabb.pos); + t.translate(se->aabb.position); t.basis.scale(se->aabb.size); exist = true; @@ -1724,6 +1724,33 @@ void SpatialEditorViewport::_notification(int p_what) { bool hdr = GlobalConfig::get_singleton()->get("rendering/quality/hdr"); viewport->set_hdr(hdr); + + bool show_info = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_INFORMATION)); + if (show_info != info->is_visible()) { + if (show_info) + info->show(); + else + info->hide(); + } + + if (show_info) { + + String text; + text += TTR("Objects Drawn") + ": " + itos(viewport->get_render_info(Viewport::RENDER_INFO_OBJECTS_IN_FRAME)) + "\n"; + text += TTR("Material Changes") + ": " + itos(viewport->get_render_info(Viewport::RENDER_INFO_MATERIAL_CHANGES_IN_FRAME)) + "\n"; + text += TTR("Shader Changes") + ": " + itos(viewport->get_render_info(Viewport::RENDER_INFO_SHADER_CHANGES_IN_FRAME)) + "\n"; + text += TTR("Surface Changes") + ": " + itos(viewport->get_render_info(Viewport::RENDER_INFO_SURFACE_CHANGES_IN_FRAME)) + "\n"; + text += TTR("Draw Calls") + ": " + itos(viewport->get_render_info(Viewport::RENDER_INFO_DRAW_CALLS_IN_FRAME)) + "\n"; + text += TTR("Vertices") + ": " + itos(viewport->get_render_info(Viewport::RENDER_INFO_VERTICES_IN_FRAME)); + + if (info_label->get_text() != text || surface->get_size() != prev_size) { + info_label->set_text(text); + Size2 ms = info->get_minimum_size(); + info->set_position(surface->get_size() - ms - Vector2(20, 20) * EDSCALE); + } + } + + prev_size = surface->get_size(); } if (p_what == NOTIFICATION_ENTER_TREE) { @@ -1731,6 +1758,7 @@ void SpatialEditorViewport::_notification(int p_what) { surface->connect("draw", this, "_draw"); surface->connect("gui_input", this, "_sinput"); surface->connect("mouse_entered", this, "_smouseenter"); + info->add_style_override("panel", get_stylebox("panel", "Panel")); preview_camera->set_icon(get_icon("Camera", "EditorIcons")); _init_gizmo_instance(index); } @@ -1752,10 +1780,10 @@ static void stroke_rect(CanvasItem *ci, Rect2 rect, Color color, real_t width = // a---b // | | // c---d - Vector2 a(rect.pos); - Vector2 b(rect.pos.x + rect.size.x, rect.pos.y); - Vector2 c(rect.pos.x, rect.pos.y + rect.size.y); - Vector2 d(rect.pos + rect.size); + Vector2 a(rect.position); + Vector2 b(rect.position.x + rect.size.x, rect.position.y); + Vector2 c(rect.position.x, rect.position.y + rect.size.y); + Vector2 d(rect.position + rect.size); ci->draw_line(a, b, color, width); ci->draw_line(b, d, color, width); @@ -1804,15 +1832,15 @@ void SpatialEditorViewport::_draw() { case Camera::KEEP_WIDTH: { draw_rect.size = Size2(s.width, s.width / aspect); - draw_rect.pos.x = 0; - draw_rect.pos.y = (s.height - draw_rect.size.y) * 0.5; + draw_rect.position.x = 0; + draw_rect.position.y = (s.height - draw_rect.size.y) * 0.5; } break; case Camera::KEEP_HEIGHT: { draw_rect.size = Size2(s.height * aspect, s.height); - draw_rect.pos.y = 0; - draw_rect.pos.x = (s.width - draw_rect.size.x) * 0.5; + draw_rect.position.y = 0; + draw_rect.position.x = (s.width - draw_rect.size.x) * 0.5; } break; } @@ -1846,7 +1874,7 @@ void SpatialEditorViewport::_draw() { real_t sy = r.size.y * logscale_t; surface->draw_rect(r, Color(1, 1, 1, 0.2)); - surface->draw_rect(Rect2(r.pos.x, r.pos.y + r.size.y - sy, r.size.x, sy), Color(1, 1, 1, 0.6)); + surface->draw_rect(Rect2(r.position.x, r.position.y + r.size.y - sy, r.size.x, sy), Color(1, 1, 1, 0.6)); stroke_rect(surface, r.grow(1), Color(0, 0, 0, 0.7)); } } @@ -1997,6 +2025,52 @@ void SpatialEditorViewport::_menu_option(int p_option) { view_menu->get_popup()->set_item_checked(idx, current); } break; + case VIEW_INFORMATION: { + + int idx = view_menu->get_popup()->get_item_index(VIEW_INFORMATION); + bool current = view_menu->get_popup()->is_item_checked(idx); + view_menu->get_popup()->set_item_checked(idx, !current); + + } break; + case VIEW_DISPLAY_NORMAL: { + + viewport->set_debug_draw(Viewport::DEBUG_DRAW_DISABLED); + + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_NORMAL), true); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_WIREFRAME), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_OVERDRAW), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_SHADELESS), false); + + } break; + case VIEW_DISPLAY_WIREFRAME: { + + viewport->set_debug_draw(Viewport::DEBUG_DRAW_WIREFRAME); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_NORMAL), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_WIREFRAME), true); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_OVERDRAW), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_SHADELESS), false); + + } break; + case VIEW_DISPLAY_OVERDRAW: { + + viewport->set_debug_draw(Viewport::DEBUG_DRAW_OVERDRAW); + VisualServer::get_singleton()->scenario_set_debug(get_tree()->get_root()->get_world()->get_scenario(), VisualServer::SCENARIO_DEBUG_OVERDRAW); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_NORMAL), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_WIREFRAME), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_OVERDRAW), true); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_SHADELESS), false); + + } break; + case VIEW_DISPLAY_SHADELESS: { + + viewport->set_debug_draw(Viewport::DEBUG_DRAW_UNSHADED); + VisualServer::get_singleton()->scenario_set_debug(get_tree()->get_root()->get_world()->get_scenario(), VisualServer::SCENARIO_DEBUG_SHADELESS); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_NORMAL), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_WIREFRAME), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_OVERDRAW), false); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_SHADELESS), true); + + } break; } } @@ -2273,6 +2347,7 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed surface = memnew(Control); add_child(surface); surface->set_area_as_parent_rect(); + surface->set_clip_contents(true); camera = memnew(Camera); camera->set_disable_gizmo(true); camera->set_cull_mask(((1 << 20) - 1) | (1 << (GIZMO_BASE_LAYER + p_index)) | (1 << GIZMO_EDIT_LAYER) | (1 << GIZMO_GRID_LAYER)); @@ -2296,12 +2371,18 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed view_menu->get_popup()->add_check_item(TTR("Orthogonal") + " (" + ED_GET_SHORTCUT("spatial_editor/switch_perspective_orthogonal")->get_as_text() + ")", VIEW_ORTHOGONAL); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_PERSPECTIVE), true); view_menu->get_popup()->add_separator(); - view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_environment", TTR("Environment")), VIEW_ENVIRONMENT); + view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_display_normal", TTR("Display Normal")), VIEW_DISPLAY_NORMAL); + view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_display_wireframe", TTR("Display Wireframe")), VIEW_DISPLAY_WIREFRAME); + view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_display_overdraw", TTR("Display Overdraw")), VIEW_DISPLAY_OVERDRAW); + view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_display_unshaded", TTR("Display Unshaded")), VIEW_DISPLAY_SHADELESS); + view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_NORMAL), true); + view_menu->get_popup()->add_separator(); + view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_environment", TTR("View Environment")), VIEW_ENVIRONMENT); + view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_gizmos", TTR("View Gizmos")), VIEW_GIZMOS); + view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_information", TTR("View Information")), VIEW_INFORMATION); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_ENVIRONMENT), true); view_menu->get_popup()->add_separator(); view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_audio_listener", TTR("Audio Listener")), VIEW_AUDIO_LISTENER); - view_menu->get_popup()->add_separator(); - view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_gizmos", TTR("Gizmos")), VIEW_GIZMOS); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_GIZMOS), true); view_menu->get_popup()->add_separator(); @@ -2322,6 +2403,13 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed preview = NULL; gizmo_scale = 1.0; + info = memnew(PanelContainer); + info->set_self_modulate(Color(1, 1, 1, 0.4)); + surface->add_child(info); + info_label = memnew(Label); + info->add_child(info_label); + info->hide(); + freelook_active = false; selection_menu = memnew(PopupMenu); @@ -2341,6 +2429,305 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed EditorSettings::get_singleton()->connect("settings_changed", this, "update_transform_gizmo_view"); } +////////////////////////////////////////////////////////////// + +void SpatialEditorViewportContainer::_gui_input(const Ref<InputEvent> &p_event) { + + Ref<InputEventMouseButton> mb = p_event; + + if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { + + Vector2 size = get_size(); + + int h_sep = get_constant("separation", "HSplitContainer"); + int v_sep = get_constant("separation", "VSplitContainer"); + + int mid_w = size.width * ratio_h; + int mid_h = size.height * ratio_v; + + dragging_h = mb->get_position().x > (mid_w - h_sep / 2) && mb->get_position().x < (mid_w + h_sep / 2); + dragging_v = mb->get_position().y > (mid_h - v_sep / 2) && mb->get_position().y < (mid_h + v_sep / 2); + + drag_begin_pos = mb->get_position(); + drag_begin_ratio.x = ratio_h; + drag_begin_ratio.y = ratio_v; + + switch (view) { + case VIEW_USE_1_VIEWPORT: { + + dragging_h = false; + dragging_v = false; + + } break; + case VIEW_USE_2_VIEWPORTS: { + + dragging_h = false; + + } break; + case VIEW_USE_2_VIEWPORTS_ALT: { + + dragging_v = false; + + } break; + case VIEW_USE_3_VIEWPORTS: { + + if (dragging_v) + dragging_h = false; + else + dragging_v = false; + + } break; + case VIEW_USE_3_VIEWPORTS_ALT: { + + if (dragging_h) + dragging_v = false; + else + dragging_h = false; + } break; + case VIEW_USE_4_VIEWPORTS: { + + } break; + } + } + + if (mb.is_valid() && !mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { + dragging_h = false; + dragging_v = false; + } + + Ref<InputEventMouseMotion> mm = p_event; + + if (mm.is_valid() && (dragging_h || dragging_v)) { + + if (dragging_h) { + float new_ratio = drag_begin_ratio.x + (mm->get_position().x - drag_begin_pos.x) / get_size().width; + new_ratio = CLAMP(new_ratio, 40 / get_size().width, (get_size().width - 40) / get_size().width); + ratio_h = new_ratio; + queue_sort(); + update(); + } + if (dragging_v) { + float new_ratio = drag_begin_ratio.y + (mm->get_position().y - drag_begin_pos.y) / get_size().height; + new_ratio = CLAMP(new_ratio, 40 / get_size().height, (get_size().height - 40) / get_size().height); + ratio_v = new_ratio; + queue_sort(); + update(); + } + } +} + +void SpatialEditorViewportContainer::_notification(int p_what) { + + if (p_what == NOTIFICATION_MOUSE_ENTER || p_what == NOTIFICATION_MOUSE_EXIT) { + + mouseover = (p_what == NOTIFICATION_MOUSE_ENTER); + update(); + } + + if (p_what == NOTIFICATION_DRAW && mouseover) { + + Ref<Texture> h_grabber = get_icon("grabber", "HSplitContainer"); + + Ref<Texture> v_grabber = get_icon("grabber", "VSplitContainer"); + + Vector2 size = get_size(); + + int h_sep = get_constant("separation", "HSplitContainer"); + + int v_sep = get_constant("separation", "VSplitContainer"); + + int mid_w = size.width * ratio_h; + int mid_h = size.height * ratio_v; + + int size_left = mid_w - h_sep / 2; + int size_bottom = size.height - mid_h - v_sep / 2; + + switch (view) { + + case VIEW_USE_1_VIEWPORT: { + + //nothing to show + + } break; + case VIEW_USE_2_VIEWPORTS: { + + draw_texture(v_grabber, Vector2((size.width - v_grabber->get_width()) / 2, mid_h - v_grabber->get_height() / 2)); + + } break; + case VIEW_USE_2_VIEWPORTS_ALT: { + + draw_texture(h_grabber, Vector2(mid_w - h_grabber->get_width() / 2, (size.height - h_grabber->get_height()) / 2)); + + } break; + case VIEW_USE_3_VIEWPORTS: { + + draw_texture(v_grabber, Vector2((size.width - v_grabber->get_width()) / 2, mid_h - v_grabber->get_height() / 2)); + draw_texture(h_grabber, Vector2(mid_w - h_grabber->get_width() / 2, mid_h + v_grabber->get_height() / 2 + (size_bottom - h_grabber->get_height()) / 2)); + + } break; + case VIEW_USE_3_VIEWPORTS_ALT: { + + draw_texture(v_grabber, Vector2((size_left - v_grabber->get_width()) / 2, mid_h - v_grabber->get_height() / 2)); + draw_texture(h_grabber, Vector2(mid_w - h_grabber->get_width() / 2, (size.height - h_grabber->get_height()) / 2)); + } break; + case VIEW_USE_4_VIEWPORTS: { + + Vector2 half(mid_w, mid_h); + draw_texture(v_grabber, half - v_grabber->get_size() / 2.0); + draw_texture(h_grabber, half - h_grabber->get_size() / 2.0); + + } break; + } + } + + if (p_what == NOTIFICATION_SORT_CHILDREN) { + + SpatialEditorViewport *viewports[4]; + int vc = 0; + for (int i = 0; i < get_child_count(); i++) { + viewports[vc] = get_child(i)->cast_to<SpatialEditorViewport>(); + if (viewports[vc]) { + vc++; + } + } + + ERR_FAIL_COND(vc != 4); + + Size2 size = get_size(); + + if (size.x < 10 || size.y < 10) { + for (int i = 0; i < 4; i++) { + viewports[i]->hide(); + } + return; + } + int h_sep = get_constant("separation", "HSplitContainer"); + + int v_sep = get_constant("separation", "VSplitContainer"); + + int mid_w = size.width * ratio_h; + int mid_h = size.height * ratio_v; + + int size_left = mid_w - h_sep / 2; + int size_right = size.width - mid_w - h_sep / 2; + + int size_top = mid_h - v_sep / 2; + int size_bottom = size.height - mid_h - v_sep / 2; + + switch (view) { + + case VIEW_USE_1_VIEWPORT: { + + for (int i = 1; i < 4; i++) { + + viewports[i]->hide(); + } + + fit_child_in_rect(viewports[0], Rect2(Vector2(), size)); + + } break; + case VIEW_USE_2_VIEWPORTS: { + + for (int i = 1; i < 4; i++) { + + if (i == 1 || i == 3) + viewports[i]->hide(); + else + viewports[i]->show(); + } + + fit_child_in_rect(viewports[0], Rect2(Vector2(), Vector2(size.width, size_top))); + fit_child_in_rect(viewports[2], Rect2(Vector2(0, mid_h + v_sep / 2), Vector2(size.width, size_bottom))); + + } break; + case VIEW_USE_2_VIEWPORTS_ALT: { + + for (int i = 1; i < 4; i++) { + + if (i == 1 || i == 3) + viewports[i]->hide(); + else + viewports[i]->show(); + } + fit_child_in_rect(viewports[0], Rect2(Vector2(), Vector2(size_left, size.height))); + fit_child_in_rect(viewports[2], Rect2(Vector2(mid_w + h_sep / 2, 0), Vector2(size_right, size.height))); + + } break; + case VIEW_USE_3_VIEWPORTS: { + + for (int i = 1; i < 4; i++) { + + if (i == 1) + viewports[i]->hide(); + else + viewports[i]->show(); + } + + fit_child_in_rect(viewports[0], Rect2(Vector2(), Vector2(size.width, size_top))); + fit_child_in_rect(viewports[2], Rect2(Vector2(0, mid_h + v_sep / 2), Vector2(size_left, size_bottom))); + fit_child_in_rect(viewports[3], Rect2(Vector2(mid_w + h_sep / 2, mid_h + v_sep / 2), Vector2(size_right, size_bottom))); + + } break; + case VIEW_USE_3_VIEWPORTS_ALT: { + + for (int i = 1; i < 4; i++) { + + if (i == 1) + viewports[i]->hide(); + else + viewports[i]->show(); + } + + fit_child_in_rect(viewports[0], Rect2(Vector2(), Vector2(size_left, size_top))); + fit_child_in_rect(viewports[2], Rect2(Vector2(0, mid_h + v_sep / 2), Vector2(size_left, size_bottom))); + fit_child_in_rect(viewports[3], Rect2(Vector2(mid_w + h_sep / 2, 0), Vector2(size_right, size.height))); + + } break; + case VIEW_USE_4_VIEWPORTS: { + + for (int i = 1; i < 4; i++) { + + viewports[i]->show(); + } + + fit_child_in_rect(viewports[0], Rect2(Vector2(), Vector2(size_left, size_top))); + fit_child_in_rect(viewports[1], Rect2(Vector2(mid_w + h_sep / 2, 0), Vector2(size_right, size_top))); + fit_child_in_rect(viewports[2], Rect2(Vector2(0, mid_h + v_sep / 2), Vector2(size_left, size_bottom))); + fit_child_in_rect(viewports[3], Rect2(Vector2(mid_w + h_sep / 2, mid_h + v_sep / 2), Vector2(size_right, size_bottom))); + + } break; + } + } +} + +void SpatialEditorViewportContainer::set_view(View p_view) { + + view = p_view; + queue_sort(); +} + +SpatialEditorViewportContainer::View SpatialEditorViewportContainer::get_view() { + + return view; +} + +void SpatialEditorViewportContainer::_bind_methods() { + + ClassDB::bind_method("_gui_input", &SpatialEditorViewportContainer::_gui_input); +} + +SpatialEditorViewportContainer::SpatialEditorViewportContainer() { + + view = VIEW_USE_1_VIEWPORT; + mouseover = false; + ratio_h = 0.5; + ratio_v = 0.5; + dragging_v = false; + dragging_h = false; +} + +/////////////////////////////////////////////////////////////////// + SpatialEditor *SpatialEditor::singleton = NULL; SpatialEditorSelectedItem::~SpatialEditorSelectedItem() { @@ -2379,7 +2766,7 @@ void SpatialEditor::update_transform_gizmo() { Transform xf = se->sp->get_global_transform(); if (first) { - center.pos = xf.origin; + center.position = xf.origin; first = false; if (local_gizmo_coords) { gizmo_basis = xf.basis; @@ -2392,7 +2779,7 @@ void SpatialEditor::update_transform_gizmo() { //count++; } - Vector3 pcenter = center.pos + center.size * 0.5; + Vector3 pcenter = center.position + center.size * 0.5; gizmo.visible = !first; gizmo.transform.origin = pcenter; gizmo.transform.basis = gizmo_basis; @@ -2719,12 +3106,7 @@ void SpatialEditor::_menu_item_pressed(int p_option) { } break; case MENU_VIEW_USE_1_VIEWPORT: { - for (int i = 1; i < 4; i++) { - - viewports[i]->hide(); - } - - viewports[0]->set_area_as_parent_rect(); + viewport_base->set_view(SpatialEditorViewportContainer::VIEW_USE_1_VIEWPORT); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), true); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), false); @@ -2736,17 +3118,7 @@ void SpatialEditor::_menu_item_pressed(int p_option) { } break; case MENU_VIEW_USE_2_VIEWPORTS: { - for (int i = 1; i < 4; i++) { - - if (i == 1 || i == 3) - viewports[i]->hide(); - else - viewports[i]->show(); - } - viewports[0]->set_area_as_parent_rect(); - //viewports[0]->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_RATIO,0.5); - viewports[2]->set_area_as_parent_rect(); - //viewports[2]->set_anchor_and_margin(MARGIN_TOP,ANCHOR_RATIO,0.5); + viewport_base->set_view(SpatialEditorViewportContainer::VIEW_USE_2_VIEWPORTS); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), false); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), true); @@ -2758,17 +3130,7 @@ void SpatialEditor::_menu_item_pressed(int p_option) { } break; case MENU_VIEW_USE_2_VIEWPORTS_ALT: { - for (int i = 1; i < 4; i++) { - - if (i == 1 || i == 3) - viewports[i]->hide(); - else - viewports[i]->show(); - } - viewports[0]->set_area_as_parent_rect(); - //viewports[0]->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_RATIO,0.5); - viewports[2]->set_area_as_parent_rect(); - //viewports[2]->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_RATIO,0.5); + viewport_base->set_view(SpatialEditorViewportContainer::VIEW_USE_2_VIEWPORTS_ALT); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), false); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), false); @@ -2780,21 +3142,7 @@ void SpatialEditor::_menu_item_pressed(int p_option) { } break; case MENU_VIEW_USE_3_VIEWPORTS: { - for (int i = 1; i < VIEWPORTS_COUNT; i++) { - - if (i == 1) - viewports[i]->hide(); - else - viewports[i]->show(); - } - viewports[0]->set_area_as_parent_rect(); - //viewports[0]->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_RATIO,0.5); - viewports[2]->set_area_as_parent_rect(); - //viewports[2]->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_RATIO,0.5); - //viewports[2]->set_anchor_and_margin(MARGIN_TOP,ANCHOR_RATIO,0.5); - viewports[3]->set_area_as_parent_rect(); - //viewports[3]->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_RATIO,0.5); - //viewports[3]->set_anchor_and_margin(MARGIN_TOP,ANCHOR_RATIO,0.5); + viewport_base->set_view(SpatialEditorViewportContainer::VIEW_USE_3_VIEWPORTS); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), false); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), false); @@ -2806,21 +3154,7 @@ void SpatialEditor::_menu_item_pressed(int p_option) { } break; case MENU_VIEW_USE_3_VIEWPORTS_ALT: { - for (int i = 1; i < VIEWPORTS_COUNT; i++) { - - if (i == 1) - viewports[i]->hide(); - else - viewports[i]->show(); - } - viewports[0]->set_area_as_parent_rect(); - //viewports[0]->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_RATIO,0.5); - //viewports[0]->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_RATIO,0.5); - viewports[2]->set_area_as_parent_rect(); - //viewports[2]->set_anchor_and_margin(MARGIN_TOP,ANCHOR_RATIO,0.5); - //viewports[2]->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_RATIO,0.5); - viewports[3]->set_area_as_parent_rect(); - //viewports[3]->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_RATIO,0.5); + viewport_base->set_view(SpatialEditorViewportContainer::VIEW_USE_3_VIEWPORTS_ALT); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), false); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), false); @@ -2832,22 +3166,7 @@ void SpatialEditor::_menu_item_pressed(int p_option) { } break; case MENU_VIEW_USE_4_VIEWPORTS: { - for (int i = 1; i < VIEWPORTS_COUNT; i++) { - - viewports[i]->show(); - } - viewports[0]->set_area_as_parent_rect(); - //viewports[0]->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_RATIO,0.5); - //viewports[0]->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_RATIO,0.5); - viewports[1]->set_area_as_parent_rect(); - //viewports[1]->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_RATIO,0.5); - //viewports[1]->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_RATIO,0.5); - viewports[2]->set_area_as_parent_rect(); - //viewports[2]->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_RATIO,0.5); - //viewports[2]->set_anchor_and_margin(MARGIN_TOP,ANCHOR_RATIO,0.5); - viewports[3]->set_area_as_parent_rect(); - //viewports[3]->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_RATIO,0.5); - //viewports[3]->set_anchor_and_margin(MARGIN_TOP,ANCHOR_RATIO,0.5); + viewport_base->set_view(SpatialEditorViewportContainer::VIEW_USE_4_VIEWPORTS); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), false); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), false); @@ -2857,43 +3176,6 @@ void SpatialEditor::_menu_item_pressed(int p_option) { view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT), false); } break; - case MENU_VIEW_DISPLAY_NORMAL: { - - VisualServer::get_singleton()->scenario_set_debug(get_tree()->get_root()->get_world()->get_scenario(), VisualServer::SCENARIO_DEBUG_DISABLED); - - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_NORMAL), true); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_WIREFRAME), false); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_OVERDRAW), false); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_SHADELESS), false); - - } break; - case MENU_VIEW_DISPLAY_WIREFRAME: { - - VisualServer::get_singleton()->scenario_set_debug(get_tree()->get_root()->get_world()->get_scenario(), VisualServer::SCENARIO_DEBUG_WIREFRAME); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_NORMAL), false); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_WIREFRAME), true); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_OVERDRAW), false); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_SHADELESS), false); - - } break; - case MENU_VIEW_DISPLAY_OVERDRAW: { - - VisualServer::get_singleton()->scenario_set_debug(get_tree()->get_root()->get_world()->get_scenario(), VisualServer::SCENARIO_DEBUG_OVERDRAW); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_NORMAL), false); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_WIREFRAME), false); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_OVERDRAW), true); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_SHADELESS), false); - - } break; - case MENU_VIEW_DISPLAY_SHADELESS: { - - VisualServer::get_singleton()->scenario_set_debug(get_tree()->get_root()->get_world()->get_scenario(), VisualServer::SCENARIO_DEBUG_SHADELESS); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_NORMAL), false); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_WIREFRAME), false); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_OVERDRAW), false); - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_SHADELESS), true); - - } break; case MENU_VIEW_ORIGIN: { bool is_checked = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(p_option)); @@ -3055,8 +3337,8 @@ void SpatialEditor::_init_indicators() { for (int i = 0; i < 3; i++) { - move_gizmo[i] = Ref<Mesh>(memnew(Mesh)); - rotate_gizmo[i] = Ref<Mesh>(memnew(Mesh)); + move_gizmo[i] = Ref<ArrayMesh>(memnew(ArrayMesh)); + rotate_gizmo[i] = Ref<ArrayMesh>(memnew(ArrayMesh)); Ref<SpatialMaterial> mat = memnew(SpatialMaterial); mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true); @@ -3242,17 +3524,6 @@ void SpatialEditor::_unhandled_key_input(Ref<InputEvent> p_event) { else if (ED_IS_SHORTCUT("spatial_editor/tool_scale", p_event)) _menu_item_pressed(MENU_TOOL_SCALE); - - else if (ED_IS_SHORTCUT("spatial_editor/display_wireframe", p_event)) { - if (k->get_shift() || k->get_control() || k->get_command()) - return; - - if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_WIREFRAME))) { - _menu_item_pressed(MENU_VIEW_DISPLAY_NORMAL); - } else { - _menu_item_pressed(MENU_VIEW_DISPLAY_WIREFRAME); - } - } } } } @@ -3419,9 +3690,6 @@ void SpatialEditor::clear() { viewports[i]->reset(); } - _menu_item_pressed(MENU_VIEW_USE_1_VIEWPORT); - _menu_item_pressed(MENU_VIEW_DISPLAY_NORMAL); - VisualServer::get_singleton()->instance_set_visible(origin_instance, true); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_ORIGIN), true); for (int i = 0; i < 3; ++i) { @@ -3566,17 +3834,11 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { p->add_check_shortcut(ED_SHORTCUT("spatial_editor/4_viewports", TTR("4 Viewports"), KEY_MASK_CMD + KEY_4), MENU_VIEW_USE_4_VIEWPORTS); p->add_separator(); - p->add_check_shortcut(ED_SHORTCUT("spatial_editor/display_normal", TTR("Display Normal")), MENU_VIEW_DISPLAY_NORMAL); - p->add_check_shortcut(ED_SHORTCUT("spatial_editor/display_wireframe", TTR("Display Wireframe")), MENU_VIEW_DISPLAY_WIREFRAME); - p->add_check_shortcut(ED_SHORTCUT("spatial_editor/display_overdraw", TTR("Display Overdraw")), MENU_VIEW_DISPLAY_OVERDRAW); - p->add_check_shortcut(ED_SHORTCUT("spatial_editor/display_shadeless", TTR("Display Shadeless")), MENU_VIEW_DISPLAY_SHADELESS); - p->add_separator(); p->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_origin", TTR("View Origin")), MENU_VIEW_ORIGIN); p->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_grid", TTR("View Grid")), MENU_VIEW_GRID); p->add_separator(); p->add_shortcut(ED_SHORTCUT("spatial_editor/settings", TTR("Settings")), MENU_VIEW_CAMERA_SETTINGS); - p->set_item_checked(p->get_item_index(MENU_VIEW_DISPLAY_NORMAL), true); p->set_item_checked(p->get_item_index(MENU_VIEW_ORIGIN), true); p->set_item_checked(p->get_item_index(MENU_VIEW_GRID), true); @@ -3591,7 +3853,7 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { shader_split = memnew(VSplitContainer); shader_split->set_h_size_flags(SIZE_EXPAND_FILL); palette_split->add_child(shader_split); - viewport_base = memnew(Control); + viewport_base = memnew(SpatialEditorViewportContainer); shader_split->add_child(viewport_base); viewport_base->set_v_size_flags(SIZE_EXPAND_FILL); for (int i = 0; i < VIEWPORTS_COUNT; i++) { diff --git a/editor/plugins/spatial_editor_plugin.h b/editor/plugins/spatial_editor_plugin.h index 88245ad0dc..6b05a8b370 100644 --- a/editor/plugins/spatial_editor_plugin.h +++ b/editor/plugins/spatial_editor_plugin.h @@ -84,6 +84,11 @@ class SpatialEditorViewport : public Control { VIEW_ORTHOGONAL, VIEW_AUDIO_LISTENER, VIEW_GIZMOS, + VIEW_INFORMATION, + VIEW_DISPLAY_NORMAL, + VIEW_DISPLAY_WIREFRAME, + VIEW_DISPLAY_OVERDRAW, + VIEW_DISPLAY_SHADELESS, }; public: @@ -116,6 +121,9 @@ private: bool freelook_active; + PanelContainer *info; + Label *info_label; + struct _RayResult { Spatial *item; @@ -287,6 +295,43 @@ public: ~SpatialEditorSelectedItem(); }; +class SpatialEditorViewportContainer : public Container { + + GDCLASS(SpatialEditorViewportContainer, Container) +public: + enum View { + VIEW_USE_1_VIEWPORT, + VIEW_USE_2_VIEWPORTS, + VIEW_USE_2_VIEWPORTS_ALT, + VIEW_USE_3_VIEWPORTS, + VIEW_USE_3_VIEWPORTS_ALT, + VIEW_USE_4_VIEWPORTS, + }; + +private: + View view; + bool mouseover; + float ratio_h; + float ratio_v; + + bool dragging_v; + bool dragging_h; + Vector2 drag_begin_pos; + Vector2 drag_begin_ratio; + + void _gui_input(const Ref<InputEvent> &p_event); + +protected: + void _notification(int p_what); + static void _bind_methods(); + +public: + void set_view(View p_view); + View get_view(); + + SpatialEditorViewportContainer(); +}; + class SpatialEditor : public VBoxContainer { GDCLASS(SpatialEditor, VBoxContainer); @@ -309,7 +354,7 @@ private: EditorNode *editor; EditorSelection *editor_selection; - Control *viewport_base; + SpatialEditorViewportContainer *viewport_base; SpatialEditorViewport *viewports[VIEWPORTS_COUNT]; VSplitContainer *shader_split; HSplitContainer *palette_split; @@ -330,13 +375,13 @@ private: bool grid_enable[3]; //should be always visible if true bool grid_enabled; - Ref<Mesh> move_gizmo[3], rotate_gizmo[3]; + Ref<ArrayMesh> move_gizmo[3], rotate_gizmo[3]; Ref<SpatialMaterial> gizmo_color[3]; Ref<SpatialMaterial> gizmo_hl; int over_gizmo_handle; - Ref<Mesh> selection_box; + Ref<ArrayMesh> selection_box; RID indicators; RID indicators_instance; RID cursor_mesh; @@ -379,10 +424,6 @@ private: MENU_VIEW_USE_3_VIEWPORTS, MENU_VIEW_USE_3_VIEWPORTS_ALT, MENU_VIEW_USE_4_VIEWPORTS, - MENU_VIEW_DISPLAY_NORMAL, - MENU_VIEW_DISPLAY_WIREFRAME, - MENU_VIEW_DISPLAY_OVERDRAW, - MENU_VIEW_DISPLAY_SHADELESS, MENU_VIEW_ORIGIN, MENU_VIEW_GRID, MENU_VIEW_CAMERA_SETTINGS, @@ -472,8 +513,8 @@ public: float get_rotate_snap() const { return snap_rotate->get_text().to_double(); } float get_scale_snap() const { return snap_scale->get_text().to_double(); } - Ref<Mesh> get_move_gizmo(int idx) const { return move_gizmo[idx]; } - Ref<Mesh> get_rotate_gizmo(int idx) const { return rotate_gizmo[idx]; } + Ref<ArrayMesh> get_move_gizmo(int idx) const { return move_gizmo[idx]; } + Ref<ArrayMesh> get_rotate_gizmo(int idx) const { return rotate_gizmo[idx]; } void update_transform_gizmo(); diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp index 799bfbf358..976a7b6271 100644 --- a/editor/plugins/texture_region_editor_plugin.cpp +++ b/editor/plugins/texture_region_editor_plugin.cpp @@ -114,10 +114,10 @@ void TextureRegionEditor::_region_draw() { for (List<Rect2>::Element *E = autoslice_cache.front(); E; E = E->next()) { Rect2 r = E->get(); Vector2 endpoints[4] = { - mtx.basis_xform(r.pos), - mtx.basis_xform(r.pos + Vector2(r.size.x, 0)), - mtx.basis_xform(r.pos + r.size), - mtx.basis_xform(r.pos + Vector2(0, r.size.y)) + mtx.basis_xform(r.position), + mtx.basis_xform(r.position + Vector2(r.size.x, 0)), + mtx.basis_xform(r.position + r.size), + mtx.basis_xform(r.position + Vector2(0, r.size.y)) }; for (int i = 0; i < 4; i++) { int next = (i + 1) % 4; @@ -132,10 +132,10 @@ void TextureRegionEditor::_region_draw() { scroll_rect.expand_to(mtx.basis_xform(edit_draw->get_size())); Vector2 endpoints[4] = { - mtx.basis_xform(rect.pos), - mtx.basis_xform(rect.pos + Vector2(rect.size.x, 0)), - mtx.basis_xform(rect.pos + rect.size), - mtx.basis_xform(rect.pos + Vector2(0, rect.size.y)) + mtx.basis_xform(rect.position), + mtx.basis_xform(rect.position + Vector2(rect.size.x, 0)), + mtx.basis_xform(rect.position + rect.size), + mtx.basis_xform(rect.position + Vector2(0, rect.size.y)) }; Color color(0.9, 0.5, 0.5); for (int i = 0; i < 4; i++) { @@ -162,14 +162,14 @@ void TextureRegionEditor::_region_draw() { scroll_rect = scroll_rect.grow(200); updating_scroll = true; - hscroll->set_min(scroll_rect.pos.x); - hscroll->set_max(scroll_rect.pos.x + scroll_rect.size.x); + hscroll->set_min(scroll_rect.position.x); + hscroll->set_max(scroll_rect.position.x + scroll_rect.size.x); hscroll->set_page(edit_draw->get_size().x); hscroll->set_value(draw_ofs.x); hscroll->set_step(0.001); - vscroll->set_min(scroll_rect.pos.y); - vscroll->set_max(scroll_rect.pos.y + scroll_rect.size.y); + vscroll->set_min(scroll_rect.position.y); + vscroll->set_max(scroll_rect.position.y + scroll_rect.size.y); vscroll->set_page(edit_draw->get_size().y); vscroll->set_value(draw_ofs.y); vscroll->set_step(0.001); @@ -208,14 +208,14 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) { mtx.scale_basis(Vector2(draw_zoom, draw_zoom)); Vector2 endpoints[8] = { - mtx.xform(rect.pos) + Vector2(-4, -4), - mtx.xform(rect.pos + Vector2(rect.size.x / 2, 0)) + Vector2(0, -4), - mtx.xform(rect.pos + Vector2(rect.size.x, 0)) + Vector2(4, -4), - mtx.xform(rect.pos + Vector2(rect.size.x, rect.size.y / 2)) + Vector2(4, 0), - mtx.xform(rect.pos + rect.size) + Vector2(4, 4), - mtx.xform(rect.pos + Vector2(rect.size.x / 2, rect.size.y)) + Vector2(0, 4), - mtx.xform(rect.pos + Vector2(0, rect.size.y)) + Vector2(-4, 4), - mtx.xform(rect.pos + Vector2(0, rect.size.y / 2)) + Vector2(-4, 0) + mtx.xform(rect.position) + Vector2(-4, -4), + mtx.xform(rect.position + Vector2(rect.size.x / 2, 0)) + Vector2(0, -4), + mtx.xform(rect.position + Vector2(rect.size.x, 0)) + Vector2(4, -4), + mtx.xform(rect.position + Vector2(rect.size.x, rect.size.y / 2)) + Vector2(4, 0), + mtx.xform(rect.position + rect.size) + Vector2(4, 4), + mtx.xform(rect.position + Vector2(rect.size.x / 2, rect.size.y)) + Vector2(0, 4), + mtx.xform(rect.position + Vector2(0, rect.size.y)) + Vector2(-4, 4), + mtx.xform(rect.position + Vector2(0, rect.size.y / 2)) + Vector2(-4, 0) }; Ref<InputEventMouseButton> mb; @@ -239,31 +239,31 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) { margins[3] = obj_styleBox->get_margin_size(MARGIN_RIGHT); } Vector2 pos[4] = { - mtx.basis_xform(rect.pos + Vector2(0, margins[0])) - draw_ofs, - mtx.basis_xform(rect.pos + rect.size - Vector2(0, margins[1])) - draw_ofs, - mtx.basis_xform(rect.pos + Vector2(margins[2], 0)) - draw_ofs, - mtx.basis_xform(rect.pos + rect.size - Vector2(margins[3], 0)) - draw_ofs + mtx.basis_xform(rect.position + Vector2(0, margins[0])) - draw_ofs, + mtx.basis_xform(rect.position + rect.size - Vector2(0, margins[1])) - draw_ofs, + mtx.basis_xform(rect.position + Vector2(margins[2], 0)) - draw_ofs, + mtx.basis_xform(rect.position + rect.size - Vector2(margins[3], 0)) - draw_ofs }; - if (Math::abs(mb->get_pos().y - pos[0].y) < 8) { + if (Math::abs(mb->get_position().y - pos[0].y) < 8) { edited_margin = 0; prev_margin = margins[0]; - } else if (Math::abs(mb->get_pos().y - pos[1].y) < 8) { + } else if (Math::abs(mb->get_position().y - pos[1].y) < 8) { edited_margin = 1; prev_margin = margins[1]; - } else if (Math::abs(mb->get_pos().x - pos[2].x) < 8) { + } else if (Math::abs(mb->get_position().x - pos[2].x) < 8) { edited_margin = 2; prev_margin = margins[2]; - } else if (Math::abs(mb->get_pos().x - pos[3].x) < 8) { + } else if (Math::abs(mb->get_position().x - pos[3].x) < 8) { edited_margin = 3; prev_margin = margins[3]; } if (edited_margin >= 0) { - drag_from = Vector2(mb->get_pos().x, mb->get_pos().y); + drag_from = Vector2(mb->get_position().x, mb->get_position().y); drag = true; } } if (edited_margin < 0 && snap_mode == SNAP_AUTOSLICE) { - Vector2 point = mtx.affine_inverse().xform(Vector2(mb->get_pos().x, mb->get_pos().y)); + Vector2 point = mtx.affine_inverse().xform(Vector2(mb->get_position().x, mb->get_position().y)); for (List<Rect2>::Element *E = autoslice_cache.front(); E; E = E->next()) { if (E->get().has_point(point)) { rect = E->get(); @@ -277,8 +277,8 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) { r = obj_styleBox->get_region_rect(); else if (atlas_tex.is_valid()) r = atlas_tex->get_region(); - rect.expand_to(r.pos); - rect.expand_to(r.pos + r.size); + rect.expand_to(r.position); + rect.expand_to(r.position + r.size); } undo_redo->create_action("Set Region Rect"); if (node_sprite) { @@ -301,7 +301,7 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) { } } } else if (edited_margin < 0) { - drag_from = mtx.affine_inverse().xform(Vector2(mb->get_pos().x, mb->get_pos().y)); + drag_from = mtx.affine_inverse().xform(Vector2(mb->get_position().x, mb->get_position().y)); if (snap_mode == SNAP_PIXEL) drag_from = drag_from.snapped(Vector2(1, 1)); else if (snap_mode == SNAP_GRID) @@ -318,7 +318,7 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) { for (int i = 0; i < 8; i++) { Vector2 tuv = endpoints[i]; - if (tuv.distance_to(Vector2(mb->get_pos().x, mb->get_pos().y)) < 8) { + if (tuv.distance_to(Vector2(mb->get_position().x, mb->get_position().y)) < 8) { drag_index = i; } } @@ -408,13 +408,13 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) { if (edited_margin >= 0) { float new_margin; if (edited_margin == 0) - new_margin = prev_margin + (mm->get_pos().y - drag_from.y) / draw_zoom; + new_margin = prev_margin + (mm->get_position().y - drag_from.y) / draw_zoom; else if (edited_margin == 1) - new_margin = prev_margin - (mm->get_pos().y - drag_from.y) / draw_zoom; + new_margin = prev_margin - (mm->get_position().y - drag_from.y) / draw_zoom; else if (edited_margin == 2) - new_margin = prev_margin + (mm->get_pos().x - drag_from.x) / draw_zoom; + new_margin = prev_margin + (mm->get_position().x - drag_from.x) / draw_zoom; else if (edited_margin == 3) - new_margin = prev_margin - (mm->get_pos().x - drag_from.x) / draw_zoom; + new_margin = prev_margin - (mm->get_position().x - drag_from.x) / draw_zoom; if (new_margin < 0) new_margin = 0; static Margin m[4] = { MARGIN_TOP, MARGIN_BOTTOM, MARGIN_LEFT, MARGIN_RIGHT }; @@ -423,7 +423,7 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) { if (obj_styleBox.is_valid()) obj_styleBox->set_margin_size(m[edited_margin], new_margin); } else { - Vector2 new_pos = mtx.affine_inverse().xform(mm->get_pos()); + Vector2 new_pos = mtx.affine_inverse().xform(mm->get_position()); if (snap_mode == SNAP_PIXEL) new_pos = new_pos.snapped(Vector2(1, 1)); else if (snap_mode == SNAP_GRID) @@ -439,49 +439,49 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) { switch (drag_index) { case 0: { - Vector2 p = rect_prev.pos + rect_prev.size; + Vector2 p = rect_prev.position + rect_prev.size; rect = Rect2(p, Size2()); rect.expand_to(new_pos); apply_rect(rect); } break; case 1: { - Vector2 p = rect_prev.pos + Vector2(0, rect_prev.size.y); + Vector2 p = rect_prev.position + Vector2(0, rect_prev.size.y); rect = Rect2(p, Size2(rect_prev.size.x, 0)); rect.expand_to(new_pos); apply_rect(rect); } break; case 2: { - Vector2 p = rect_prev.pos + Vector2(0, rect_prev.size.y); + Vector2 p = rect_prev.position + Vector2(0, rect_prev.size.y); rect = Rect2(p, Size2()); rect.expand_to(new_pos); apply_rect(rect); } break; case 3: { - Vector2 p = rect_prev.pos; + Vector2 p = rect_prev.position; rect = Rect2(p, Size2(0, rect_prev.size.y)); rect.expand_to(new_pos); apply_rect(rect); } break; case 4: { - Vector2 p = rect_prev.pos; + Vector2 p = rect_prev.position; rect = Rect2(p, Size2()); rect.expand_to(new_pos); apply_rect(rect); } break; case 5: { - Vector2 p = rect_prev.pos; + Vector2 p = rect_prev.position; rect = Rect2(p, Size2(rect_prev.size.x, 0)); rect.expand_to(new_pos); apply_rect(rect); } break; case 6: { - Vector2 p = rect_prev.pos + Vector2(rect_prev.size.x, 0); + Vector2 p = rect_prev.position + Vector2(rect_prev.size.x, 0); rect = Rect2(p, Size2()); rect.expand_to(new_pos); apply_rect(rect); } break; case 7: { - Vector2 p = rect_prev.pos + Vector2(rect_prev.size.x, 0); + Vector2 p = rect_prev.position + Vector2(rect_prev.size.x, 0); rect = Rect2(p, Size2(0, rect_prev.size.y)); rect.expand_to(new_pos); apply_rect(rect); @@ -693,7 +693,7 @@ void TextureRegionEditor::_edit_region() { if (grown.has_point(Point2(x, y))) { E->get().expand_to(Point2(x, y)); E->get().expand_to(Point2(x + 1, y + 1)); - x = E->get().pos.x + E->get().size.x - 1; + x = E->get().position.x + E->get().size.x - 1; bool merged = true; while (merged) { merged = false; @@ -706,8 +706,8 @@ void TextureRegionEditor::_edit_region() { if (F == E) continue; if (E->get().grow(1).intersects(F->get())) { - E->get().expand_to(F->get().pos); - E->get().expand_to(F->get().pos + F->get().size); + E->get().expand_to(F->get().position); + E->get().expand_to(F->get().position + F->get().size); if (F->prev()) { F = F->prev(); autoslice_cache.erase(F->next()); diff --git a/editor/plugins/tile_map_editor_plugin.cpp b/editor/plugins/tile_map_editor_plugin.cpp index 9f7a41b8b6..d12b979121 100644 --- a/editor/plugins/tile_map_editor_plugin.cpp +++ b/editor/plugins/tile_map_editor_plugin.cpp @@ -98,8 +98,8 @@ void TileMapEditor::_menu_option(int p_option) { return; undo_redo->create_action("Erase Selection"); - for (int i = rectangle.pos.y; i <= rectangle.pos.y + rectangle.size.y; i++) { - for (int j = rectangle.pos.x; j <= rectangle.pos.x + rectangle.size.x; j++) { + for (int i = rectangle.position.y; i <= rectangle.position.y + rectangle.size.y; i++) { + for (int j = rectangle.position.x; j <= rectangle.position.x + rectangle.size.x; j++) { _set_cell(Point2i(j, i), TileMap::INVALID_CELL, false, false, false, true); } @@ -333,7 +333,7 @@ PoolVector<Vector2> TileMapEditor::_bucket_fill(const Point2i &p_start, bool era } Rect2i r = node->get_item_rect(); - r.pos = r.pos / node->get_cell_size(); + r.position = r.position / node->get_cell_size(); r.size = r.size / node->get_cell_size(); int area = r.get_area(); @@ -349,7 +349,7 @@ PoolVector<Vector2> TileMapEditor::_bucket_fill(const Point2i &p_start, bool era invalidate_cache = true; } // Tile ID changed or position wasn't visited by the previous fill - int loc = (p_start.x - r.get_pos().x) + (p_start.y - r.get_pos().y) * r.get_size().x; + int loc = (p_start.x - r.position.x) + (p_start.y - r.position.y) * r.get_size().x; if (prev_id != bucket_cache_tile || !bucket_cache_visited[loc]) { invalidate_cache = true; } @@ -380,7 +380,7 @@ PoolVector<Vector2> TileMapEditor::_bucket_fill(const Point2i &p_start, bool era if (node->get_cell(n.x, n.y) == prev_id) { if (preview) { - int loc = (n.x - r.get_pos().x) + (n.y - r.get_pos().y) * r.get_size().x; + int loc = (n.x - r.position.x) + (n.y - r.position.y) * r.get_size().x; if (bucket_cache_visited[loc]) continue; bucket_cache_visited[loc] = true; @@ -441,7 +441,7 @@ void TileMapEditor::_select(const Point2i &p_from, const Point2i &p_to) { SWAP(begin.y, end.y); } - rectangle.pos = begin; + rectangle.position = begin; rectangle.size = end - begin; canvas_item_editor->update(); @@ -460,7 +460,7 @@ void TileMapEditor::_draw_cell(int p_cell, const Point2i &p_point, bool p_flip_h Size2 sc = p_xform.get_scale(); Rect2 rect = Rect2(); - rect.pos = node->map_to_world(p_point) + node->get_cell_draw_offset(); + rect.position = node->map_to_world(p_point) + node->get_cell_draw_offset(); if (r.has_no_area()) { rect.size = t->get_size(); @@ -490,42 +490,42 @@ void TileMapEditor::_draw_cell(int p_cell, const Point2i &p_point, bool p_flip_h if (node->get_tile_origin() == TileMap::TILE_ORIGIN_TOP_LEFT) { - rect.pos += tile_ofs; + rect.position += tile_ofs; } else if (node->get_tile_origin() == TileMap::TILE_ORIGIN_BOTTOM_LEFT) { Size2 cell_size = node->get_cell_size(); - rect.pos += tile_ofs; + rect.position += tile_ofs; if (p_transpose) { if (p_flip_h) - rect.pos.x -= cell_size.x; + rect.position.x -= cell_size.x; else - rect.pos.x += cell_size.x; + rect.position.x += cell_size.x; } else { if (p_flip_v) - rect.pos.y -= cell_size.y; + rect.position.y -= cell_size.y; else - rect.pos.y += cell_size.y; + rect.position.y += cell_size.y; } } else if (node->get_tile_origin() == TileMap::TILE_ORIGIN_CENTER) { - rect.pos += node->get_cell_size() / 2; + rect.position += node->get_cell_size() / 2; Vector2 s = r.size; Vector2 center = (s / 2) - tile_ofs; if (p_flip_h) - rect.pos.x -= s.x - center.x; + rect.position.x -= s.x - center.x; else - rect.pos.x -= center.x; + rect.position.x -= center.x; if (p_flip_v) - rect.pos.y -= s.y - center.y; + rect.position.y -= s.y - center.y; else - rect.pos.y -= center.y; + rect.position.y -= center.y; } - rect.pos = p_xform.xform(rect.pos); + rect.position = p_xform.xform(rect.position); rect.size *= sc; if (r.has_no_area()) @@ -560,9 +560,9 @@ void TileMapEditor::_update_copydata() { if (!selection_active) return; - for (int i = rectangle.pos.y; i <= rectangle.pos.y + rectangle.size.y; i++) { + for (int i = rectangle.position.y; i <= rectangle.position.y + rectangle.size.y; i++) { - for (int j = rectangle.pos.x; j <= rectangle.pos.x + rectangle.size.x; j++) { + for (int j = rectangle.position.x; j <= rectangle.position.x + rectangle.size.x; j++) { TileData tcd; @@ -737,8 +737,8 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { if (id != TileMap::INVALID_CELL) { undo_redo->create_action("Rectangle Paint"); - for (int i = rectangle.pos.y; i <= rectangle.pos.y + rectangle.size.y; i++) { - for (int j = rectangle.pos.x; j <= rectangle.pos.x + rectangle.size.x; j++) { + for (int i = rectangle.position.y; i <= rectangle.position.y + rectangle.size.y; i++) { + for (int j = rectangle.position.x; j <= rectangle.position.x + rectangle.size.x; j++) { _set_cell(Point2i(j, i), id, flip_h, flip_v, transpose, true); } @@ -749,7 +749,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { } } else if (tool == TOOL_DUPLICATING) { - Point2 ofs = over_tile - rectangle.pos; + Point2 ofs = over_tile - rectangle.position; undo_redo->create_action(TTR("Duplicate")); for (List<TileData>::Element *E = copydata.front(); E; E = E->next()) { @@ -826,7 +826,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { paint_undo.clear(); - Point2 local = node->world_to_map(xform_inv.xform(mb->get_pos())); + Point2 local = node->world_to_map(xform_inv.xform(mb->get_position())); if (mb->get_shift()) { @@ -900,7 +900,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { if (mm.is_valid()) { - Point2i new_over_tile = node->world_to_map(xform_inv.xform(mm->get_pos())); + Point2i new_over_tile = node->world_to_map(xform_inv.xform(mm->get_position())); if (new_over_tile != over_tile) { @@ -985,8 +985,8 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { paint_undo.clear(); - for (int i = rectangle.pos.y; i <= rectangle.pos.y + rectangle.size.y; i++) { - for (int j = rectangle.pos.x; j <= rectangle.pos.x + rectangle.size.x; j++) { + for (int i = rectangle.position.y; i <= rectangle.position.y + rectangle.size.y; i++) { + for (int j = rectangle.position.x; j <= rectangle.position.x + rectangle.size.x; j++) { Point2i tile = Point2i(j, i); paint_undo[tile] = _get_op_from_cell(tile); @@ -1103,7 +1103,7 @@ void TileMapEditor::_canvas_draw() { Size2 screen_size = canvas_item_editor->get_size(); { Rect2 aabb; - aabb.pos = node->world_to_map(xform_inv.xform(Vector2())); + aabb.position = node->world_to_map(xform_inv.xform(Vector2())); aabb.expand_to(node->world_to_map(xform_inv.xform(Vector2(0, screen_size.height)))); aabb.expand_to(node->world_to_map(xform_inv.xform(Vector2(screen_size.width, 0)))); aabb.expand_to(node->world_to_map(xform_inv.xform(screen_size))); @@ -1113,10 +1113,10 @@ void TileMapEditor::_canvas_draw() { int max_lines = 2000; //avoid crash if size too smal - for (int i = (si.pos.x) - 1; i <= (si.pos.x + si.size.x); i++) { + for (int i = (si.position.x) - 1; i <= (si.position.x + si.size.x); i++) { - Vector2 from = xform.xform(node->map_to_world(Vector2(i, si.pos.y))); - Vector2 to = xform.xform(node->map_to_world(Vector2(i, si.pos.y + si.size.y + 1))); + Vector2 from = xform.xform(node->map_to_world(Vector2(i, si.position.y))); + Vector2 to = xform.xform(node->map_to_world(Vector2(i, si.position.y + si.size.y + 1))); Color col = i == 0 ? Color(1, 0.8, 0.2, 0.5) : Color(1, 0.3, 0.1, 0.2); canvas_item_editor->draw_line(from, to, col, 1); @@ -1127,9 +1127,9 @@ void TileMapEditor::_canvas_draw() { int max_lines = 10000; //avoid crash if size too smal - for (int i = (si.pos.x) - 1; i <= (si.pos.x + si.size.x); i++) { + for (int i = (si.position.x) - 1; i <= (si.position.x + si.size.x); i++) { - for (int j = (si.pos.y) - 1; j <= (si.pos.y + si.size.y); j++) { + for (int j = (si.position.y) - 1; j <= (si.position.y + si.size.y); j++) { Vector2 ofs; if (ABS(j) & 1) { @@ -1151,10 +1151,10 @@ void TileMapEditor::_canvas_draw() { if (node->get_half_offset() != TileMap::HALF_OFFSET_Y) { - for (int i = (si.pos.y) - 1; i <= (si.pos.y + si.size.y); i++) { + for (int i = (si.position.y) - 1; i <= (si.position.y + si.size.y); i++) { - Vector2 from = xform.xform(node->map_to_world(Vector2(si.pos.x, i))); - Vector2 to = xform.xform(node->map_to_world(Vector2(si.pos.x + si.size.x + 1, i))); + Vector2 from = xform.xform(node->map_to_world(Vector2(si.position.x, i))); + Vector2 to = xform.xform(node->map_to_world(Vector2(si.position.x + si.size.x + 1, i))); Color col = i == 0 ? Color(1, 0.8, 0.2, 0.5) : Color(1, 0.3, 0.1, 0.2); canvas_item_editor->draw_line(from, to, col, 1); @@ -1164,9 +1164,9 @@ void TileMapEditor::_canvas_draw() { } } else { - for (int i = (si.pos.y) - 1; i <= (si.pos.y + si.size.y); i++) { + for (int i = (si.position.y) - 1; i <= (si.position.y + si.size.y); i++) { - for (int j = (si.pos.x) - 1; j <= (si.pos.x + si.size.x); j++) { + for (int j = (si.position.x) - 1; j <= (si.position.x + si.size.x); j++) { Vector2 ofs; if (ABS(j) & 1) { @@ -1188,10 +1188,10 @@ void TileMapEditor::_canvas_draw() { if (selection_active) { Vector<Vector2> points; - points.push_back(xform.xform(node->map_to_world((rectangle.pos)))); - points.push_back(xform.xform(node->map_to_world((rectangle.pos + Point2(rectangle.size.x + 1, 0))))); - points.push_back(xform.xform(node->map_to_world((rectangle.pos + Point2(rectangle.size.x + 1, rectangle.size.y + 1))))); - points.push_back(xform.xform(node->map_to_world((rectangle.pos + Point2(0, rectangle.size.y + 1))))); + points.push_back(xform.xform(node->map_to_world((rectangle.position)))); + points.push_back(xform.xform(node->map_to_world((rectangle.position + Point2(rectangle.size.x + 1, 0))))); + points.push_back(xform.xform(node->map_to_world((rectangle.position + Point2(rectangle.size.x + 1, rectangle.size.y + 1))))); + points.push_back(xform.xform(node->map_to_world((rectangle.position + Point2(0, rectangle.size.y + 1))))); canvas_item_editor->draw_colored_polygon(points, Color(0.2, 0.8, 1, 0.4)); } @@ -1248,8 +1248,8 @@ void TileMapEditor::_canvas_draw() { if (id == TileMap::INVALID_CELL) return; - for (int i = rectangle.pos.y; i <= rectangle.pos.y + rectangle.size.y; i++) { - for (int j = rectangle.pos.x; j <= rectangle.pos.x + rectangle.size.x; j++) { + for (int i = rectangle.position.y; i <= rectangle.position.y + rectangle.size.y; i++) { + for (int j = rectangle.position.x; j <= rectangle.position.x + rectangle.size.x; j++) { _draw_cell(id, Point2i(j, i), flip_h, flip_v, transpose, xform); } @@ -1264,7 +1264,7 @@ void TileMapEditor::_canvas_draw() { if (ts.is_null()) return; - Point2 ofs = over_tile - rectangle.pos; + Point2 ofs = over_tile - rectangle.position; for (List<TileData>::Element *E = copydata.front(); E; E = E->next()) { @@ -1277,13 +1277,13 @@ void TileMapEditor::_canvas_draw() { } Rect2i duplicate = rectangle; - duplicate.pos = over_tile; + duplicate.position = over_tile; Vector<Vector2> points; - points.push_back(xform.xform(node->map_to_world(duplicate.pos))); - points.push_back(xform.xform(node->map_to_world((duplicate.pos + Point2(duplicate.size.x + 1, 0))))); - points.push_back(xform.xform(node->map_to_world((duplicate.pos + Point2(duplicate.size.x + 1, duplicate.size.y + 1))))); - points.push_back(xform.xform(node->map_to_world((duplicate.pos + Point2(0, duplicate.size.y + 1))))); + points.push_back(xform.xform(node->map_to_world(duplicate.position))); + points.push_back(xform.xform(node->map_to_world((duplicate.position + Point2(duplicate.size.x + 1, 0))))); + points.push_back(xform.xform(node->map_to_world((duplicate.position + Point2(duplicate.size.x + 1, duplicate.size.y + 1))))); + points.push_back(xform.xform(node->map_to_world((duplicate.position + Point2(0, duplicate.size.y + 1))))); canvas_item_editor->draw_colored_polygon(points, Color(0.2, 1.0, 0.8, 0.2)); diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp index a4e8ef70ce..a3d3d42110 100644 --- a/editor/project_manager.cpp +++ b/editor/project_manager.cpp @@ -914,8 +914,9 @@ void ProjectManager::_on_project_created(const String &dir) { _update_scroll_pos(dir); } else { _load_recent_projects(); - scroll->connect("draw", this, "_update_scroll_pos", varray(dir), CONNECT_ONESHOT); + _update_scroll_pos(dir); } + _open_project(); } void ProjectManager::_update_scroll_pos(const String &dir) { @@ -1469,7 +1470,7 @@ ProjectListFilter::ProjectListFilter() { _current_filter = FILTER_NAME; filter_option = memnew(OptionButton); - filter_option->set_custom_minimum_size(Size2(80, 10)); + filter_option->set_custom_minimum_size(Size2(80 * EDSCALE, 10 * EDSCALE)); filter_option->set_clip_text(true); filter_option->connect("item_selected", this, "_filter_option_selected"); add_child(filter_option); diff --git a/editor/project_settings.cpp b/editor/project_settings.cpp index 1c4ca3cb58..8ef7bd427f 100644 --- a/editor/project_settings.cpp +++ b/editor/project_settings.cpp @@ -430,8 +430,8 @@ void ProjectSettings::_action_button_pressed(Object *p_obj, int p_column, int p_ if (p_id == 1) { Point2 ofs = input_editor->get_global_position(); Rect2 ir = input_editor->get_item_rect(ti); - ir.pos.y -= input_editor->get_scroll().y; - ofs += ir.pos + ir.size; + ir.position.y -= input_editor->get_scroll().y; + ofs += ir.position + ir.size; ofs.x -= 100; popup_add->set_position(ofs); popup_add->popup(); diff --git a/editor/property_editor.cpp b/editor/property_editor.cpp index 1c8a1c0ee0..3d3fecc8f9 100644 --- a/editor/property_editor.cpp +++ b/editor/property_editor.cpp @@ -678,8 +678,8 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: field_names.push_back("h"); config_value_editors(4, 4, 10, field_names); Rect2 r = v; - value_editor[0]->set_text(String::num(r.pos.x)); - value_editor[1]->set_text(String::num(r.pos.y)); + value_editor[0]->set_text(String::num(r.position.x)); + value_editor[1]->set_text(String::num(r.position.y)); value_editor[2]->set_text(String::num(r.size.x)); value_editor[3]->set_text(String::num(r.size.y)); } break; @@ -733,9 +733,9 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: config_value_editors(6, 3, 16, field_names); Rect3 aabb = v; - value_editor[0]->set_text(String::num(aabb.pos.x)); - value_editor[1]->set_text(String::num(aabb.pos.y)); - value_editor[2]->set_text(String::num(aabb.pos.z)); + value_editor[0]->set_text(String::num(aabb.position.x)); + value_editor[1]->set_text(String::num(aabb.position.y)); + value_editor[2]->set_text(String::num(aabb.position.z)); value_editor[3]->set_text(String::num(aabb.size.x)); value_editor[4]->set_text(String::num(aabb.size.y)); value_editor[5]->set_text(String::num(aabb.size.z)); @@ -1539,13 +1539,13 @@ void CustomPropertyEditor::_modified(String p_string) { Rect2 r2; if (evaluator) { - r2.pos.x = evaluator->eval(value_editor[0]->get_text()); - r2.pos.y = evaluator->eval(value_editor[1]->get_text()); + r2.position.x = evaluator->eval(value_editor[0]->get_text()); + r2.position.y = evaluator->eval(value_editor[1]->get_text()); r2.size.x = evaluator->eval(value_editor[2]->get_text()); r2.size.y = evaluator->eval(value_editor[3]->get_text()); } else { - r2.pos.x = value_editor[0]->get_text().to_double(); - r2.pos.y = value_editor[1]->get_text().to_double(); + r2.position.x = value_editor[0]->get_text().to_double(); + r2.position.y = value_editor[1]->get_text().to_double(); r2.size.x = value_editor[2]->get_text().to_double(); r2.size.y = value_editor[3]->get_text().to_double(); } @@ -2310,6 +2310,7 @@ void PropertyEditor::set_item_text(TreeItem *p_item, int p_type, const String &p if (obj->get(p_name).get_type() == Variant::NIL || obj->get(p_name).operator RefPtr().is_null()) { p_item->set_text(1, "<null>"); p_item->set_icon(1, Ref<Texture>()); + p_item->set_custom_as_button(1, false); Dictionary d = p_item->get_metadata(0); int hint = d.has("hint") ? d["hint"].operator int() : -1; @@ -2319,6 +2320,7 @@ void PropertyEditor::set_item_text(TreeItem *p_item, int p_type, const String &p } } else { + p_item->set_custom_as_button(1, true); RES res = obj->get(p_name).operator RefPtr(); if (res->is_class("Texture")) { int tw = EditorSettings::get_singleton()->get("docks/property_editor/texture_preview_width"); @@ -3540,17 +3542,21 @@ void PropertyEditor::update_tree() { item->set_cell_mode(1, TreeItem::CELL_MODE_CUSTOM); item->set_editable(1, !read_only); - item->add_button(1, get_icon("EditResource", "EditorIcons")); + //item->add_button(1, get_icon("EditResource", "EditorIcons")); String type; if (p.hint == PROPERTY_HINT_RESOURCE_TYPE) type = p.hint_string; - if (obj->get(p.name).get_type() == Variant::NIL || obj->get(p.name).operator RefPtr().is_null()) { + RES res = obj->get(p.name).operator RefPtr(); + + if (obj->get(p.name).get_type() == Variant::NIL || res.is_null()) { item->set_text(1, "<null>"); item->set_icon(1, Ref<Texture>()); + item->set_custom_as_button(1, false); - } else { - RES res = obj->get(p.name).operator RefPtr(); + } else if (res.is_valid()) { + + item->set_custom_as_button(1, true); if (res->is_class("Texture")) { int tw = EditorSettings::get_singleton()->get("docks/property_editor/texture_preview_width"); @@ -3668,7 +3674,7 @@ void PropertyEditor::_draw_transparency(Object *t, const Rect2 &p_rect) { // make a little space between consecutive color fields Rect2 area = p_rect; - area.pos.y += 1; + area.position.y += 1; area.size.height -= 2; area.size.width -= arrow->get_size().width + 5; tree->draw_texture_rect(get_icon("Transparent", "EditorIcons"), area, true); @@ -3854,6 +3860,16 @@ void PropertyEditor::_item_edited() { _edit_set(name, NodePath(item->get_text(1)), refresh_all); } break; + case Variant::OBJECT: { + if (!item->is_custom_set_as_button(1)) + break; + + RES res = obj->get(name); + if (res.is_valid()) { + emit_signal("resource_selected", res.get_ref_ptr(), name); + } + + } break; case Variant::DICTIONARY: { @@ -3926,7 +3942,7 @@ void PropertyEditor::_custom_editor_request(bool p_arrow) { int hint = d.has("hint") ? d["hint"].operator int() : -1; String hint_text = d.has("hint_text") ? d["hint_text"] : ""; Rect2 where = tree->get_custom_popup_rect(); - custom_editor->set_position(where.pos); + custom_editor->set_position(where.position); if (custom_editor->edit(obj, name, type, v, hint, hint_text)) { custom_editor->popup(); @@ -4033,9 +4049,9 @@ void PropertyEditor::_edit_button(Object *p_item, int p_column, int p_button) { Variant v = obj->get(n); custom_editor->edit(obj, n, (Variant::Type)t, v, h, ht); Rect2 where = tree->get_item_rect(ti, 1); - where.pos -= tree->get_scroll(); - where.pos += tree->get_global_position(); - custom_editor->set_position(where.pos); + where.position -= tree->get_scroll(); + where.position += tree->get_global_position(); + custom_editor->set_position(where.position); custom_editor->popup(); } else if (t == Variant::STRING) { @@ -4046,9 +4062,9 @@ void PropertyEditor::_edit_button(Object *p_item, int p_column, int p_button) { if (h == PROPERTY_HINT_FILE || h == PROPERTY_HINT_DIR || h == PROPERTY_HINT_GLOBAL_DIR || h == PROPERTY_HINT_GLOBAL_FILE) { Rect2 where = tree->get_item_rect(ti, 1); - where.pos -= tree->get_scroll(); - where.pos += tree->get_global_position(); - custom_editor->set_position(where.pos); + where.position -= tree->get_scroll(); + where.position += tree->get_global_position(); + custom_editor->set_position(where.position); custom_editor->popup(); } else { custom_editor->popup_centered_ratio(); @@ -4124,7 +4140,7 @@ void PropertyEditor::_draw_flags(Object *t, const Rect2 &p_rect) { if (i == 1) ofs.y += bsize + 1; - ofs += p_rect.pos; + ofs += p_rect.position; for (int j = 0; j < 10; j++) { Point2 o = ofs + Point2(j * (bsize + 1), 0); diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index 0f05cc79ff..da2d22b900 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -658,6 +658,21 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { } } } break; + + default: { + + if (p_tool >= EDIT_SUBRESOURCE_BASE) { + + int idx = p_tool - EDIT_SUBRESOURCE_BASE; + + ERR_FAIL_INDEX(idx, subresources.size()); + + Object *obj = ObjectDB::get_instance(subresources[idx]); + ERR_FAIL_COND(!obj); + + editor->push_item(obj); + } + } } } @@ -1662,6 +1677,47 @@ void SceneTreeDock::_nodes_dragged(Array p_nodes, NodePath p_to, int p_type) { _do_reparent(to_node, to_pos, nodes, true); } +void SceneTreeDock::_add_children_to_popup(Object *p_obj, int p_depth) { + + if (p_depth > 8) + return; + + List<PropertyInfo> pinfo; + p_obj->get_property_list(&pinfo); + for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { + + if (!(E->get().usage & PROPERTY_USAGE_EDITOR)) + continue; + if (E->get().hint != PROPERTY_HINT_RESOURCE_TYPE) + continue; + + Variant value = p_obj->get(E->get().name); + if (value.get_type() != Variant::OBJECT) + continue; + Object *obj = value; + if (!obj) + continue; + + Ref<Texture> icon; + + if (has_icon(obj->get_class(), "EditorIcons")) + icon = get_icon(obj->get_class(), "EditorIcons"); + else + icon = get_icon("Object", "EditorIcons"); + + if (menu->get_item_count() == 0) { + menu->add_item(TTR("Sub-Resources:")); + menu->set_item_disabled(0, true); + } + int index = menu->get_item_count(); + menu->add_icon_item(icon, E->get().name.capitalize(), EDIT_SUBRESOURCE_BASE + subresources.size()); + menu->set_item_h_offset(index, p_depth * 10 * EDSCALE); + subresources.push_back(obj->get_instance_ID()); + + _add_children_to_popup(obj, p_depth + 1); + } +} + void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) { if (!EditorNode::get_singleton()->get_edited_scene()) { @@ -1683,6 +1739,12 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) { menu->clear(); if (selection.size() == 1) { + + subresources.clear(); + _add_children_to_popup(selection.front()->get(), 0); + if (menu->get_item_count() > 0) + menu->add_separator(); + menu->add_icon_shortcut(get_icon("Add", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/add_child_node"), TOOL_NEW); menu->add_icon_shortcut(get_icon("Instance", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/instance_scene"), TOOL_INSTANCE); menu->add_separator(); diff --git a/editor/scene_tree_dock.h b/editor/scene_tree_dock.h index f190025dd6..79e01e7571 100644 --- a/editor/scene_tree_dock.h +++ b/editor/scene_tree_dock.h @@ -73,6 +73,12 @@ class SceneTreeDock : public VBoxContainer { TOOL_BUTTON_MAX }; + enum { + EDIT_SUBRESOURCE_BASE = 100 + }; + + Vector<ObjectID> subresources; + bool restore_script_editor_on_drag; int current_option; @@ -114,6 +120,8 @@ class SceneTreeDock : public VBoxContainer { Node *edited_scene; EditorNode *editor; + void _add_children_to_popup(Object *p_obj, int p_depth); + Node *_duplicate(Node *p_node, Map<Node *, Node *> &duplimap); void _node_reparent(NodePath p_path, bool p_keep_global_xform); void _do_reparent(Node *p_new_parent, int p_position_in_parent, Vector<Node *> p_nodes, bool p_keep_global_xform); diff --git a/editor/scene_tree_editor.cpp b/editor/scene_tree_editor.cpp index 2945abbd8c..d4e5714c0d 100644 --- a/editor/scene_tree_editor.cpp +++ b/editor/scene_tree_editor.cpp @@ -161,17 +161,17 @@ void SceneTreeEditor::_cell_button_pressed(Object *p_item, int p_column, int p_i if (p_id == BUTTON_SUBSCENE) { //open scene request Rect2 item_rect = tree->get_item_rect(item, 0); - item_rect.pos.y -= tree->get_scroll().y; - item_rect.pos += tree->get_global_position(); + item_rect.position.y -= tree->get_scroll().y; + item_rect.position += tree->get_global_position(); if (n == get_scene_node()) { - inheritance_menu->set_position(item_rect.pos + Vector2(0, item_rect.size.y)); + inheritance_menu->set_position(item_rect.position + Vector2(0, item_rect.size.y)); inheritance_menu->set_size(Vector2(item_rect.size.x, 0)); inheritance_menu->popup(); instance_node = n->get_instance_ID(); } else { - instance_menu->set_position(item_rect.pos + Vector2(0, item_rect.size.y)); + instance_menu->set_position(item_rect.position + Vector2(0, item_rect.size.y)); instance_menu->set_size(Vector2(item_rect.size.x, 0)); if (EditorNode::get_singleton()->get_edited_scene()->is_editable_instance(n)) instance_menu->set_item_checked(0, true); diff --git a/editor/script_editor_debugger.cpp b/editor/script_editor_debugger.cpp index a2bb3a0879..7f1e6023bf 100644 --- a/editor/script_editor_debugger.cpp +++ b/editor/script_editor_debugger.cpp @@ -790,19 +790,19 @@ void ScriptEditorDebugger::_performance_draw() { Point2i p(i % cols, i / cols); Rect2i r(p * s, s); - r.pos += Point2(margin, margin); + r.position += Point2(margin, margin); r.size -= Point2(margin, margin) * 2.0; perf_draw->draw_style_box(graph_sb, r); - r.pos += graph_sb->get_offset(); + r.position += graph_sb->get_offset(); r.size -= graph_sb->get_minimum_size(); int pi = which[i]; Color c = Color(0.7, 0.9, 0.5); c.set_hsv(Math::fmod(c.get_h() + pi * 0.7654, 1), c.get_s(), c.get_v()); c.a = 0.8; - perf_draw->draw_string(graph_font, r.pos + Point2(0, graph_font->get_ascent()), perf_items[pi]->get_text(0), c, r.size.x); + perf_draw->draw_string(graph_font, r.position + Point2(0, graph_font->get_ascent()), perf_items[pi]->get_text(0), c, r.size.x); c.a = 0.6; - perf_draw->draw_string(graph_font, r.pos + Point2(graph_font->get_char_size('X').width, graph_font->get_ascent() + graph_font->get_height()), perf_items[pi]->get_text(1), c, r.size.y); + perf_draw->draw_string(graph_font, r.position + Point2(graph_font->get_char_size('X').width, graph_font->get_ascent() + graph_font->get_height()), perf_items[pi]->get_text(1), c, r.size.y); float spacing = point_sep / float(cols); float from = r.size.width; @@ -819,7 +819,7 @@ void ScriptEditorDebugger::_performance_draw() { c.a = 0.7; if (E != perf_history.front()) - perf_draw->draw_line(r.pos + Point2(from, h), r.pos + Point2(from + spacing, prev), c, 2.0); + perf_draw->draw_line(r.position + Point2(from, h), r.position + Point2(from + spacing, prev), c, 2.0); prev = h; E = E->next(); from -= spacing; diff --git a/editor/spatial_editor_gizmos.cpp b/editor/spatial_editor_gizmos.cpp index 4781bb6a3b..1b7afd3c43 100644 --- a/editor/spatial_editor_gizmos.cpp +++ b/editor/spatial_editor_gizmos.cpp @@ -79,7 +79,7 @@ void EditorSpatialGizmo::Instance::create_instance(Spatial *p_base) { VS::get_singleton()->instance_set_layer_mask(instance, 1 << SpatialEditorViewport::GIZMO_EDIT_LAYER); //gizmos are 26 } -void EditorSpatialGizmo::add_mesh(const Ref<Mesh> &p_mesh, bool p_billboard, const RID &p_skeleton) { +void EditorSpatialGizmo::add_mesh(const Ref<ArrayMesh> &p_mesh, bool p_billboard, const RID &p_skeleton) { ERR_FAIL_COND(!spatial_node); Instance ins; @@ -100,7 +100,7 @@ void EditorSpatialGizmo::add_lines(const Vector<Vector3> &p_lines, const Ref<Mat ERR_FAIL_COND(!spatial_node); Instance ins; - Ref<Mesh> mesh = memnew(Mesh); + Ref<ArrayMesh> mesh = memnew(ArrayMesh); Array a; a.resize(Mesh::ARRAY_MAX); @@ -162,7 +162,7 @@ void EditorSpatialGizmo::add_unscaled_billboard(const Ref<Material> &p_material, uv.push_back(Vector2(0, 1)); uv.push_back(Vector2(1, 1)); - Ref<Mesh> mesh = memnew(Mesh); + Ref<ArrayMesh> mesh = memnew(ArrayMesh); Array a; a.resize(Mesh::ARRAY_MAX); a[Mesh::ARRAY_VERTEX] = vs; @@ -219,7 +219,7 @@ void EditorSpatialGizmo::add_handles(const Vector<Vector3> &p_handles, bool p_bi ERR_FAIL_COND(!spatial_node); Instance ins; - Ref<Mesh> mesh = memnew(Mesh); + Ref<ArrayMesh> mesh = memnew(ArrayMesh); #if 1 Array a; @@ -1029,7 +1029,7 @@ CameraSpatialGizmo::CameraSpatialGizmo(Camera *p_camera) { void MeshInstanceSpatialGizmo::redraw() { - Ref<Mesh> m = mesh->get_mesh(); + Ref<ArrayMesh> m = mesh->get_mesh(); if (!m.is_valid()) return; //none @@ -1248,7 +1248,7 @@ void SkeletonSpatialGizmo::redraw() { */ } - Ref<Mesh> m = surface_tool->commit(); + Ref<ArrayMesh> m = surface_tool->commit(); add_mesh(m, false, skel->get_skeleton()); } @@ -1722,8 +1722,8 @@ void CollisionShapeSpatialGizmo::redraw() { Ref<BoxShape> bs = s; Vector<Vector3> lines; Rect3 aabb; - aabb.pos = -bs->get_extents(); - aabb.size = aabb.pos * -2; + aabb.position = -bs->get_extents(); + aabb.size = aabb.position * -2; for (int i = 0; i < 12; i++) { Vector3 a, b; @@ -1953,7 +1953,7 @@ void VisibilityNotifierGizmo::set_handle(int p_idx, Camera *p_camera, const Poin Vector3 ray_dir = p_camera->project_ray_normal(p_point); Vector3 sg[2] = { gi.xform(ray_from), gi.xform(ray_from + ray_dir * 4096) }; - Vector3 ofs = aabb.pos + aabb.size * 0.5; + Vector3 ofs = aabb.position + aabb.size * 0.5; Vector3 axis; axis[p_idx] = 1.0; @@ -1964,7 +1964,7 @@ void VisibilityNotifierGizmo::set_handle(int p_idx, Camera *p_camera, const Poin if (d < 0.001) d = 0.001; - aabb.pos[p_idx] = (aabb.pos[p_idx] + aabb.size[p_idx] * 0.5) - d; + aabb.position[p_idx] = (aabb.position[p_idx] + aabb.size[p_idx] * 0.5) - d; aabb.size[p_idx] = d * 2; notifier->set_aabb(aabb); } @@ -2002,7 +2002,7 @@ void VisibilityNotifierGizmo::redraw() { for (int i = 0; i < 3; i++) { Vector3 ax; - ax[i] = aabb.pos[i] + aabb.size[i]; + ax[i] = aabb.position[i] + aabb.size[i]; handles.push_back(ax); } @@ -2053,7 +2053,7 @@ void ParticlesGizmo::set_handle(int p_idx, Camera *p_camera, const Point2 &p_poi Vector3 sg[2] = { gi.xform(ray_from), gi.xform(ray_from + ray_dir * 4096) }; - Vector3 ofs = aabb.pos + aabb.size * 0.5; + Vector3 ofs = aabb.position + aabb.size * 0.5; Vector3 axis; axis[p_idx] = 1.0; @@ -2065,7 +2065,7 @@ void ParticlesGizmo::set_handle(int p_idx, Camera *p_camera, const Point2 &p_poi float d = ra[p_idx]; - aabb.pos[p_idx] = d - 1.0 - aabb.size[p_idx] * 0.5; + aabb.position[p_idx] = d - 1.0 - aabb.size[p_idx] * 0.5; particles->set_visibility_aabb(aabb); } else { @@ -2076,7 +2076,7 @@ void ParticlesGizmo::set_handle(int p_idx, Camera *p_camera, const Point2 &p_poi if (d < 0.001) d = 0.001; //resize - aabb.pos[p_idx] = (aabb.pos[p_idx] + aabb.size[p_idx] * 0.5) - d; + aabb.position[p_idx] = (aabb.position[p_idx] + aabb.size[p_idx] * 0.5) - d; aabb.size[p_idx] = d * 2; particles->set_visibility_aabb(aabb); } @@ -2115,13 +2115,13 @@ void ParticlesGizmo::redraw() { for (int i = 0; i < 3; i++) { Vector3 ax; - ax[i] = aabb.pos[i] + aabb.size[i]; - ax[(i + 1) % 3] = aabb.pos[(i + 1) % 3] + aabb.size[(i + 1) % 3] * 0.5; - ax[(i + 2) % 3] = aabb.pos[(i + 2) % 3] + aabb.size[(i + 2) % 3] * 0.5; + ax[i] = aabb.position[i] + aabb.size[i]; + ax[(i + 1) % 3] = aabb.position[(i + 1) % 3] + aabb.size[(i + 1) % 3] * 0.5; + ax[(i + 2) % 3] = aabb.position[(i + 2) % 3] + aabb.size[(i + 2) % 3] * 0.5; handles.push_back(ax); } - Vector3 center = aabb.pos + aabb.size * 0.5; + Vector3 center = aabb.position + aabb.size * 0.5; for (int i = 0; i < 3; i++) { Vector3 ax; @@ -2218,7 +2218,7 @@ void ReflectionProbeGizmo::commit_handle(int p_idx, const Variant &p_restore, bo Rect3 restore = p_restore; if (p_cancel) { - probe->set_extents(restore.pos); + probe->set_extents(restore.position); probe->set_origin_offset(restore.size); return; } @@ -2227,7 +2227,7 @@ void ReflectionProbeGizmo::commit_handle(int p_idx, const Variant &p_restore, bo ur->create_action(TTR("Change Probe Extents")); ur->add_do_method(probe, "set_extents", probe->get_extents()); ur->add_do_method(probe, "set_origin_offset", probe->get_origin_offset()); - ur->add_undo_method(probe, "set_extents", restore.pos); + ur->add_undo_method(probe, "set_extents", restore.position); ur->add_undo_method(probe, "set_origin_offset", restore.size); ur->commit_action(); } @@ -2241,7 +2241,7 @@ void ReflectionProbeGizmo::redraw() { Vector3 extents = probe->get_extents(); Rect3 aabb; - aabb.pos = -extents; + aabb.position = -extents; aabb.size = extents * 2; for (int i = 0; i < 12; i++) { @@ -2262,7 +2262,7 @@ void ReflectionProbeGizmo::redraw() { for (int i = 0; i < 3; i++) { Vector3 ax; - ax[i] = aabb.pos[i] + aabb.size[i]; + ax[i] = aabb.position[i] + aabb.size[i]; handles.push_back(ax); } @@ -2392,7 +2392,7 @@ void GIProbeGizmo::redraw() { for (int k = 0; k < 4; k++) { - Vector3 from = aabb.pos, to = aabb.pos; + Vector3 from = aabb.position, to = aabb.position; from[j] += cell_size * i; to[j] += cell_size * i; @@ -2421,7 +2421,7 @@ void GIProbeGizmo::redraw() { for (int i = 0; i < 3; i++) { Vector3 ax; - ax[i] = aabb.pos[i] + aabb.size[i]; + ax[i] = aabb.position[i] + aabb.size[i]; handles.push_back(ax); } @@ -2511,7 +2511,7 @@ void NavigationMeshSpatialGizmo::redraw() { if (lines.size()) add_lines(lines, navmesh->is_enabled() ? SpatialEditorGizmos::singleton->navmesh_edge_material : SpatialEditorGizmos::singleton->navmesh_edge_material_disabled); add_collision_triangles(tmesh); - Ref<Mesh> m = memnew(Mesh); + Ref<ArrayMesh> m = memnew(ArrayMesh); Array a; a.resize(Mesh::ARRAY_MAX); a[0] = tmeshfaces; @@ -3213,7 +3213,7 @@ SpatialEditorGizmos::SpatialEditorGizmos() { //position 3D Shared mesh - pos3d_mesh = Ref<Mesh>(memnew(Mesh)); + pos3d_mesh = Ref<ArrayMesh>(memnew(ArrayMesh)); { PoolVector<Vector3> cursor_points; @@ -3246,7 +3246,7 @@ SpatialEditorGizmos::SpatialEditorGizmos() { pos3d_mesh->surface_set_material(0, mat); } - listener_line_mesh = Ref<Mesh>(memnew(Mesh)); + listener_line_mesh = Ref<ArrayMesh>(memnew(ArrayMesh)); { PoolVector<Vector3> cursor_points; diff --git a/editor/spatial_editor_gizmos.h b/editor/spatial_editor_gizmos.h index 095586ab91..6a77e91425 100644 --- a/editor/spatial_editor_gizmos.h +++ b/editor/spatial_editor_gizmos.h @@ -59,7 +59,7 @@ class EditorSpatialGizmo : public SpatialEditorGizmo { struct Instance { RID instance; - Ref<Mesh> mesh; + Ref<ArrayMesh> mesh; RID skeleton; bool billboard; bool unscaled; @@ -97,7 +97,7 @@ class EditorSpatialGizmo : public SpatialEditorGizmo { protected: void add_lines(const Vector<Vector3> &p_lines, const Ref<Material> &p_material, bool p_billboard = false); - void add_mesh(const Ref<Mesh> &p_mesh, bool p_billboard = false, const RID &p_skeleton = RID()); + void add_mesh(const Ref<ArrayMesh> &p_mesh, bool p_billboard = false, const RID &p_skeleton = RID()); void add_collision_segments(const Vector<Vector3> &p_lines); void add_collision_triangles(const Ref<TriangleMesh> &p_tmesh); void add_unscaled_billboard(const Ref<Material> &p_material, float p_scale = 1); @@ -454,8 +454,8 @@ public: Ref<SpatialMaterial> shape_material; Ref<Texture> handle_t; - Ref<Mesh> pos3d_mesh; - Ref<Mesh> listener_line_mesh; + Ref<ArrayMesh> pos3d_mesh; + Ref<ArrayMesh> listener_line_mesh; static SpatialEditorGizmos *singleton; Ref<TriangleMesh> test_cube_tm; |