diff options
Diffstat (limited to 'editor')
79 files changed, 2325 insertions, 1645 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 7c29162e67..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 = mb->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 = mb->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 = mb->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,22 +2665,22 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input) } break; case ClickOver::CLICK_MOVE_KEYS: { - click.to = mb->get_pos(); + click.to = mm->get_position(); } break; default: {} } return; - } else if (mb->get_button_mask() & BUTTON_MASK_MIDDLE) { + } else if (mm->get_button_mask() & BUTTON_MASK_MIDDLE) { int rel = mm->get_relative().x; float relf = rel / _get_zoom_scale(); h_scroll->set_value(h_scroll->get_value() - relf); } - if (mb->get_button_mask() == 0) { + if (mm->get_button_mask() == 0) { - Point2 mpos = mb->get_pos() - ofs; + Point2 mpos = mm->get_position() - ofs; if (mpos.y < h) { #if 0 diff --git a/editor/create_dialog.cpp b/editor/create_dialog.cpp index c5cfea0b95..1089068344 100644 --- a/editor/create_dialog.cpp +++ b/editor/create_dialog.cpp @@ -203,7 +203,7 @@ void CreateDialog::_update_search() { } List<StringName>::Element *I = type_list.front(); - TreeItem *to_select = NULL; + TreeItem *to_select = search_box->get_text() == base_type ? root : NULL; for (; I; I = I->next()) { @@ -489,11 +489,13 @@ void CreateDialog::_favorite_selected() { void CreateDialog::_history_activated() { + _history_selected(); _confirmed(); } void CreateDialog::_favorite_activated() { + _favorite_selected(); _confirmed(); } diff --git a/editor/editor_asset_installer.cpp b/editor/editor_asset_installer.cpp index e3ed9fe1af..96bfb295ea 100644 --- a/editor/editor_asset_installer.cpp +++ b/editor/editor_asset_installer.cpp @@ -113,13 +113,13 @@ void EditorAssetInstaller::open(const String &p_path, int p_depth) { extension_guess["png"] = get_icon("Texture", "EditorIcons"); extension_guess["jpg"] = get_icon("Texture", "EditorIcons"); extension_guess["tex"] = get_icon("Texture", "EditorIcons"); - extension_guess["atex"] = get_icon("Texture", "EditorIcons"); + extension_guess["atlastex"] = get_icon("Texture", "EditorIcons"); extension_guess["dds"] = get_icon("Texture", "EditorIcons"); extension_guess["scn"] = get_icon("PackedScene", "EditorIcons"); extension_guess["tscn"] = get_icon("PackedScene", "EditorIcons"); extension_guess["xml"] = get_icon("PackedScene", "EditorIcons"); extension_guess["xscn"] = get_icon("PackedScene", "EditorIcons"); - extension_guess["mtl"] = get_icon("Material", "EditorIcons"); + extension_guess["material"] = get_icon("Material", "EditorIcons"); extension_guess["shd"] = get_icon("Shader", "EditorIcons"); extension_guess["gd"] = get_icon("GDScript", "EditorIcons"); } diff --git a/editor/editor_audio_buses.cpp b/editor/editor_audio_buses.cpp index f60186e3b4..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); @@ -1108,9 +1111,9 @@ EditorAudioBuses::EditorAudioBuses() { file_dialog = memnew(EditorFileDialog); List<String> ext; - ResourceLoader::get_recognized_extensions_for_type("AudioServerState", &ext); + ResourceLoader::get_recognized_extensions_for_type("AudioBusLayout", &ext); for (List<String>::Element *E = ext.front(); E; E = E->next()) { - file_dialog->add_filter("*." + E->get() + "; Audio Bus State"); + file_dialog->add_filter("*." + E->get() + "; Audio Bus Layout"); } add_child(file_dialog); file_dialog->connect("file_selected", this, "_file_dialog_callback"); diff --git a/editor/editor_data.cpp b/editor/editor_data.cpp index 31c1402c8f..58ffa223fb 100644 --- a/editor/editor_data.cpp +++ b/editor/editor_data.cpp @@ -675,7 +675,12 @@ String EditorData::get_scene_title(int p_idx) const { return "[empty]"; if (edited_scene[p_idx].root->get_filename() == "") return "[unsaved]"; - return edited_scene[p_idx].root->get_filename().get_file(); + bool show_ext = EDITOR_DEF("interface/scene_tabs/show_extension", false); + String name = edited_scene[p_idx].root->get_filename().get_file(); + if (!show_ext) { + name = name.get_basename(); + } + return name; } String EditorData::get_scene_path(int p_idx) const { diff --git a/editor/editor_export.cpp b/editor/editor_export.cpp index cb1b958cca..5cd00738a2 100644 --- a/editor/editor_export.cpp +++ b/editor/editor_export.cpp @@ -211,6 +211,7 @@ EditorExportPreset::EditorExportPreset() { void EditorExportPlatform::gen_debug_flags(Vector<String> &r_flags, int p_flags) { String host = EditorSettings::get_singleton()->get("network/debug/remote_host"); + int remote_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port"); if (p_flags & DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST) host = "localhost"; @@ -230,7 +231,7 @@ void EditorExportPlatform::gen_debug_flags(Vector<String> &r_flags, int p_flags) r_flags.push_back("-rdebug"); - r_flags.push_back(host + ":" + String::num(GLOBAL_DEF("network/debug/remote_port", 6007))); + r_flags.push_back(host + ":" + String::num(remote_port)); List<String> breakpoints; ScriptEditor::get_singleton()->get_breakpoints(&breakpoints); @@ -621,6 +622,7 @@ Error EditorExportPlatform::save_zip(const Ref<EditorExportPreset> &p_preset, co void EditorExportPlatform::gen_export_flags(Vector<String> &r_flags, int p_flags) { String host = EditorSettings::get_singleton()->get("network/debug/remote_host"); + int remote_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port"); if (p_flags & DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST) host = "localhost"; @@ -640,7 +642,7 @@ void EditorExportPlatform::gen_export_flags(Vector<String> &r_flags, int p_flags r_flags.push_back("-rdebug"); - r_flags.push_back(host + ":" + String::num(GLOBAL_DEF("network/debug/remote_port", 6007))); + r_flags.push_back(host + ":" + String::num(remote_port)); List<String> breakpoints; ScriptEditor::get_singleton()->get_breakpoints(&breakpoints); @@ -1941,14 +1943,14 @@ Error EditorExportPlatform::export_project_files(EditorExportSaveFunction p_func atex->set_region(region); atex->set_margin(margin); - String path = EditorSettings::get_singleton()->get_settings_path()+"/tmp/tmpatlas.atex"; + String path = EditorSettings::get_singleton()->get_settings_path()+"/tmp/tmpatlas.atlastex"; Error err = ResourceSaver::save(path,atex); if (err!=OK) { EditorNode::add_io_error(TTR("Could not save atlas subtexture:")+" "+path); return ERR_CANT_CREATE; } Vector<uint8_t> data = FileAccess::get_file_as_array(path); - String dst_path = F->get().operator String().get_basename()+".atex"; + String dst_path = F->get().operator String().get_basename()+".atlastex"; err = p_func(p_udata,dst_path,data,counter++,files.size()); saved.insert(dst_path); if (err) @@ -2109,6 +2111,7 @@ static int _get_pad(int p_alignment, int p_n) { void EditorExportPlatform::gen_export_flags(Vector<String> &r_flags, int p_flags) { String host = EditorSettings::get_singleton()->get("network/debug/remote_host"); + int remote_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port"); if (p_flags&EXPORT_REMOTE_DEBUG_LOCALHOST) host="localhost"; @@ -2128,7 +2131,7 @@ void EditorExportPlatform::gen_export_flags(Vector<String> &r_flags, int p_flags r_flags.push_back("-rdebug"); - r_flags.push_back(host+":"+String::num(GLOBAL_DEF("network/debug/remote_port", 6007))); + r_flags.push_back(host+":"+String::num(remote_port)); List<String> breakpoints; ScriptEditor::get_singleton()->get_breakpoints(&breakpoints); diff --git a/editor/editor_file_dialog.cpp b/editor/editor_file_dialog.cpp index 25fade46d6..c2a408e8ab 100644 --- a/editor/editor_file_dialog.cpp +++ b/editor/editor_file_dialog.cpp @@ -1300,16 +1300,21 @@ EditorFileDialog::EditorFileDialog() { favorite->connect("toggled", this, "_favorite_toggled"); pathhb->add_child(favorite); + Ref<ButtonGroup> view_mode_group; + view_mode_group.instance(); + mode_thumbnails = memnew(ToolButton); mode_thumbnails->connect("pressed", this, "set_display_mode", varray(DISPLAY_THUMBNAILS)); mode_thumbnails->set_toggle_mode(true); mode_thumbnails->set_pressed(display_mode == DISPLAY_THUMBNAILS); + mode_thumbnails->set_button_group(view_mode_group); pathhb->add_child(mode_thumbnails); mode_list = memnew(ToolButton); mode_list->connect("pressed", this, "set_display_mode", varray(DISPLAY_LIST)); mode_list->set_toggle_mode(true); mode_list->set_pressed(display_mode == DISPLAY_LIST); + mode_list->set_button_group(view_mode_group); pathhb->add_child(mode_list); drives = memnew(OptionButton); diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp index 64a9d5df82..f314f772d1 100644 --- a/editor/editor_file_system.cpp +++ b/editor/editor_file_system.cpp @@ -153,6 +153,7 @@ EditorFileSystemDirectory::EditorFileSystemDirectory() { modified_time = 0; parent = NULL; + verified = false; } EditorFileSystemDirectory::~EditorFileSystemDirectory() { @@ -1040,7 +1041,10 @@ bool EditorFileSystem::_find_file(const String &p_file, EditorFileSystemDirector if (idx == -1) { //does not exist, create i guess? EditorFileSystemDirectory *efsd = memnew(EditorFileSystemDirectory); + efsd->name = path[i]; + efsd->parent = fs; + int idx2 = 0; for (int j = 0; j < fs->get_subdir_count(); j++) { @@ -1421,6 +1425,7 @@ EditorFileSystem::EditorFileSystem() { singleton = this; filesystem = memnew(EditorFileSystemDirectory); //like, empty + filesystem->parent = NULL; thread = NULL; scanning = false; @@ -1429,7 +1434,9 @@ EditorFileSystem::EditorFileSystem() { thread_sources = NULL; new_filesystem = NULL; + abort_scan = false; scanning_changes = false; + scanning_changes_done = false; ResourceSaver::set_save_callback(_resource_saved); DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES); diff --git a/editor/editor_file_system.h b/editor/editor_file_system.h index b5d61d47d3..3522a1ab1d 100644 --- a/editor/editor_file_system.h +++ b/editor/editor_file_system.h @@ -168,8 +168,6 @@ class EditorFileSystem : public Node { void _scan_fs_changes(EditorFileSystemDirectory *p_dir, const ScanProgress &p_progress); - int md_count; - Set<String> valid_extensions; Set<String> import_extensions; 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 5c5fc7c3d4..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)); @@ -1279,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 } @@ -1689,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 4ecb292027..56b62cdf6e 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" @@ -72,10 +73,10 @@ #include "plugins/collision_polygon_2d_editor_plugin.h" #include "plugins/collision_polygon_editor_plugin.h" #include "plugins/collision_shape_2d_editor_plugin.h" -#include "plugins/color_ramp_editor_plugin.h" #include "plugins/cube_grid_theme_editor_plugin.h" #include "plugins/curve_editor_plugin.h" #include "plugins/gi_probe_editor_plugin.h" +#include "plugins/gradient_editor_plugin.h" #include "plugins/gradient_texture_editor_plugin.h" #include "plugins/item_list_editor_plugin.h" #include "plugins/light_occluder_2d_editor_plugin.h" @@ -269,28 +270,9 @@ void EditorNode::_notification(int p_what) { update_menu->set_icon(gui_base->get_icon("Progress" + itos(circle_step + 1), "EditorIcons")); } } - editor_selection->update(); - { - uint32_t p32 = 0; //AudioServer::get_singleton()->read_output_peak()>>8; - - float peak = p32 == 0 ? -80 : Math::linear2db(p32 / 65535.0); - - if (peak < -80) - peak = -80; - float vu = audio_vu->get_value(); - - if (peak > vu) { - audio_vu->set_value(peak); - } else { - float new_vu = vu - get_process_delta_time() * 70.0; - if (new_vu < -80) - new_vu = -80; - if (new_vu != -80 && vu != -80) - audio_vu->set_value(new_vu); - } - } + 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(); } @@ -360,6 +342,14 @@ void EditorNode::_notification(int p_what) { play_button_panel->add_style_override("panel", gui_base->get_stylebox("PlayButtonPanel", "EditorStyles")); scene_root_parent->add_style_override("panel", gui_base->get_stylebox("Content", "EditorStyles")); bottom_panel->add_style_override("panel", gui_base->get_stylebox("Content", "EditorStyles")); + scene_tabs->add_style_override("tab_fg", gui_base->get_stylebox("SceneTabFG", "EditorStyles")); + scene_tabs->add_style_override("tab_bg", gui_base->get_stylebox("SceneTabBG", "EditorStyles")); + if (bool(EDITOR_DEF("interface/scene_tabs/resize_if_many_tabs", true))) { + scene_tabs->set_min_width(int(EDITOR_DEF("interface/scene_tabs/minimum_width", 50)) * EDSCALE); + } else { + scene_tabs->set_min_width(0); + } + _update_scene_tabs(); } } @@ -843,56 +833,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) { @@ -910,6 +898,7 @@ void EditorNode::_save_scene(String p_file, int idx) { } editor_data.apply_changes_in_editors(); + _save_default_environment(); _set_scene_metadata(p_file, idx); @@ -971,7 +960,7 @@ void EditorNode::_save_scene(String p_file, int idx) { _dialog_display_file_error(p_file, err); } -}; +} void EditorNode::_import_action(const String &p_action) { #if 0 @@ -1104,6 +1093,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: { @@ -1134,6 +1124,7 @@ void EditorNode::_dialog_action(String p_file) { if (file->get_mode() == EditorFileDialog::MODE_SAVE_FILE) { //_save_scene(p_file); + _save_default_environment(); _save_scene_with_preview(p_file); } @@ -1143,6 +1134,7 @@ void EditorNode::_dialog_action(String p_file) { if (file->get_mode() == EditorFileDialog::MODE_SAVE_FILE) { //_save_scene(p_file); + _save_default_environment(); _save_scene_with_preview(p_file); _call_build(); _run(true); @@ -1396,6 +1388,17 @@ void EditorNode::_property_editor_back() { _edit_current(); } +void EditorNode::_save_default_environment() { + + Ref<Environment> fallback = get_tree()->get_root()->get_world()->get_fallback_environment(); + + if (fallback.is_valid() && fallback->get_path().is_resource_file()) { + Map<RES, bool> processed; + _find_and_save_edited_subresources(fallback.ptr(), processed, 0); + save_resource_in_path(fallback, fallback->get_path()); + } +} + void EditorNode::_imported(Node *p_node) { /* @@ -1474,11 +1477,16 @@ void EditorNode::_edit_current() { Node *current_node = current_obj->cast_to<Node>(); ERR_FAIL_COND(!current_node); - ERR_FAIL_COND(!current_node->is_inside_tree()); + // ERR_FAIL_COND(!current_node->is_inside_tree()); property_editor->edit(current_node); - node_dock->set_node(current_node); - scene_tree_dock->set_selected(current_node); + if (current_node->is_inside_tree()) { + node_dock->set_node(current_node); + scene_tree_dock->set_selected(current_node); + } else { + node_dock->set_node(NULL); + scene_tree_dock->set_selected(NULL); + } object_menu->get_popup()->clear(); //top_pallete->set_current_tab(0); @@ -1972,17 +1980,20 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } } // else: ignore new scenes } + + _save_default_environment(); } break; case FILE_SAVE_BEFORE_RUN: { if (!p_confirmed) { - accept->get_ok()->set_text(TTR("Yes")); - accept->set_text(TTR("This scene has never been saved. Save before running?")); - accept->popup_centered_minsize(); + confirmation->get_cancel()->set_text(TTR("No")); + confirmation->get_ok()->set_text(TTR("Yes")); + confirmation->set_text(TTR("This scene has never been saved. Save before running?")); + confirmation->popup_centered_minsize(); break; } _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: { @@ -2405,6 +2416,8 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } break; case RUN_PLAY_SCENE: { + + _save_default_environment(); _menu_option_confirm(RUN_STOP, true); _call_build(); _run(true); @@ -2457,28 +2470,28 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { case RUN_FILE_SERVER: { //file_server - bool ischecked = debug_button->get_popup()->is_item_checked(debug_button->get_popup()->get_item_index(RUN_FILE_SERVER)); + bool ischecked = debug_menu->get_popup()->is_item_checked(debug_menu->get_popup()->get_item_index(RUN_FILE_SERVER)); if (ischecked) { file_server->stop(); run_native->set_deploy_dumb(false); - //debug_button->set_icon(gui_base->get_icon("FileServer","EditorIcons")); - //debug_button->get_popup()->set_item_text( debug_button->get_popup()->get_item_index(RUN_FILE_SERVER),"Enable File Server"); + //debug_menu->set_icon(gui_base->get_icon("FileServer","EditorIcons")); + //debug_menu->get_popup()->set_item_text( debug_menu->get_popup()->get_item_index(RUN_FILE_SERVER),"Enable File Server"); } else { file_server->start(); run_native->set_deploy_dumb(true); - //debug_button->set_icon(gui_base->get_icon("FileServerActive","EditorIcons")); - //debug_button->get_popup()->set_item_text( debug_button->get_popup()->get_item_index(RUN_FILE_SERVER),"Disable File Server"); + //debug_menu->set_icon(gui_base->get_icon("FileServerActive","EditorIcons")); + //debug_menu->get_popup()->set_item_text( debug_menu->get_popup()->get_item_index(RUN_FILE_SERVER),"Disable File Server"); } - debug_button->get_popup()->set_item_checked(debug_button->get_popup()->get_item_index(RUN_FILE_SERVER), !ischecked); + debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(RUN_FILE_SERVER), !ischecked); EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_file_server", !ischecked); } break; case RUN_LIVE_DEBUG: { - bool ischecked = debug_button->get_popup()->is_item_checked(debug_button->get_popup()->get_item_index(RUN_LIVE_DEBUG)); + bool ischecked = debug_menu->get_popup()->is_item_checked(debug_menu->get_popup()->get_item_index(RUN_LIVE_DEBUG)); - debug_button->get_popup()->set_item_checked(debug_button->get_popup()->get_item_index(RUN_LIVE_DEBUG), !ischecked); + debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(RUN_LIVE_DEBUG), !ischecked); ScriptEditor::get_singleton()->get_debugger()->set_live_debugging(!ischecked); EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_live_debug", !ischecked); @@ -2486,23 +2499,23 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { /*case RUN_DEPLOY_DUMB_CLIENTS: { - bool ischecked = debug_button->get_popup()->is_item_checked( debug_button->get_popup()->get_item_index(RUN_DEPLOY_DUMB_CLIENTS)); - debug_button->get_popup()->set_item_checked( debug_button->get_popup()->get_item_index(RUN_DEPLOY_DUMB_CLIENTS),!ischecked); + bool ischecked = debug_menu->get_popup()->is_item_checked( debug_menu->get_popup()->get_item_index(RUN_DEPLOY_DUMB_CLIENTS)); + debug_menu->get_popup()->set_item_checked( debug_menu->get_popup()->get_item_index(RUN_DEPLOY_DUMB_CLIENTS),!ischecked); run_native->set_deploy_dumb(!ischecked); } break;*/ case RUN_DEPLOY_REMOTE_DEBUG: { - bool ischecked = debug_button->get_popup()->is_item_checked(debug_button->get_popup()->get_item_index(RUN_DEPLOY_REMOTE_DEBUG)); - debug_button->get_popup()->set_item_checked(debug_button->get_popup()->get_item_index(RUN_DEPLOY_REMOTE_DEBUG), !ischecked); + bool ischecked = debug_menu->get_popup()->is_item_checked(debug_menu->get_popup()->get_item_index(RUN_DEPLOY_REMOTE_DEBUG)); + debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(RUN_DEPLOY_REMOTE_DEBUG), !ischecked); run_native->set_deploy_debug_remote(!ischecked); EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_deploy_remote_debug", !ischecked); } break; case RUN_DEBUG_COLLISONS: { - bool ischecked = debug_button->get_popup()->is_item_checked(debug_button->get_popup()->get_item_index(RUN_DEBUG_COLLISONS)); - debug_button->get_popup()->set_item_checked(debug_button->get_popup()->get_item_index(RUN_DEBUG_COLLISONS), !ischecked); + bool ischecked = debug_menu->get_popup()->is_item_checked(debug_menu->get_popup()->get_item_index(RUN_DEBUG_COLLISONS)); + debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(RUN_DEBUG_COLLISONS), !ischecked); run_native->set_debug_collisions(!ischecked); editor_run.set_debug_collisions(!ischecked); EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_debug_collisons", !ischecked); @@ -2510,8 +2523,8 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } break; case RUN_DEBUG_NAVIGATION: { - bool ischecked = debug_button->get_popup()->is_item_checked(debug_button->get_popup()->get_item_index(RUN_DEBUG_NAVIGATION)); - debug_button->get_popup()->set_item_checked(debug_button->get_popup()->get_item_index(RUN_DEBUG_NAVIGATION), !ischecked); + bool ischecked = debug_menu->get_popup()->is_item_checked(debug_menu->get_popup()->get_item_index(RUN_DEBUG_NAVIGATION)); + debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(RUN_DEBUG_NAVIGATION), !ischecked); run_native->set_debug_navigation(!ischecked); editor_run.set_debug_navigation(!ischecked); EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_debug_navigation", !ischecked); @@ -2519,8 +2532,8 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } break; case RUN_RELOAD_SCRIPTS: { - bool ischecked = debug_button->get_popup()->is_item_checked(debug_button->get_popup()->get_item_index(RUN_RELOAD_SCRIPTS)); - debug_button->get_popup()->set_item_checked(debug_button->get_popup()->get_item_index(RUN_RELOAD_SCRIPTS), !ischecked); + bool ischecked = debug_menu->get_popup()->is_item_checked(debug_menu->get_popup()->get_item_index(RUN_RELOAD_SCRIPTS)); + debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(RUN_RELOAD_SCRIPTS), !ischecked); ScriptEditor::get_singleton()->set_live_auto_reload_running_scripts(!ischecked); EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_reload_scripts", !ischecked); @@ -2582,8 +2595,25 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { file->popup_centered_ratio(); } break; - case SETTINGS_ABOUT: { - + case HELP_CLASSES: { + emit_signal("request_help_index", ""); + } break; + case HELP_SEARCH: { + emit_signal("request_help_search", ""); + } break; + case HELP_DOCS: { + OS::get_singleton()->shell_open("http://docs.godotengine.org/"); + } break; + case HELP_QA: { + OS::get_singleton()->shell_open("https://godotengine.org/qa/"); + } break; + case HELP_ISSUES: { + OS::get_singleton()->shell_open("https://github.com/godotengine/godot/issues"); + } break; + case HELP_COMMUNITY: { + OS::get_singleton()->shell_open("https://godotengine.org/community"); + } break; + case HELP_ABOUT: { about->popup_centered_minsize(Size2(500, 130) * EDSCALE); } break; case SOURCES_REIMPORT: { @@ -3717,7 +3747,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++) { @@ -3827,7 +3857,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); @@ -3880,7 +3910,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) { @@ -4248,7 +4278,47 @@ void EditorNode::_scene_tab_closed(int p_tab) { } } +void EditorNode::_scene_tab_hover(int p_tab) { + if (bool(EDITOR_DEF("interface/scene_tabs/show_thumbnail_on_hover", true)) == false) { + return; + } + int current_tab = scene_tabs->get_current_tab(); + + if (p_tab == current_tab || p_tab < 0) { + tab_preview_panel->hide(); + } else { + String path = editor_data.get_scene_path(p_tab); + EditorResourcePreview::get_singleton()->queue_resource_preview(path, this, "_thumbnail_done", p_tab); + } +} + +void EditorNode::_scene_tab_exit() { + tab_preview_panel->hide(); +} + +void EditorNode::_scene_tab_input(const Ref<InputEvent> &p_input) { + Ref<InputEventMouseButton> mb = p_input; + + if (mb.is_valid()) { + if (mb->get_button_index() == BUTTON_MIDDLE && mb->is_pressed() && scene_tabs->get_hovered_tab() >= 0) { + _scene_tab_closed(scene_tabs->get_hovered_tab()); + } + } +} + +void EditorNode::_thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Variant &p_udata) { + int p_tab = p_udata.operator signed int(); + if (p_preview.is_valid()) { + Rect2 rect = scene_tabs->get_tab_rect(p_tab); + rect.position += scene_tabs->get_global_position(); + tab_preview->set_texture(p_preview); + tab_preview_panel->set_position(rect.position + Vector2(0, rect.size.height)); + tab_preview_panel->show(); + } +} + void EditorNode::_scene_tab_changed(int p_tab) { + tab_preview_panel->hide(); //print_line("set current 1 "); bool unsaved = (saved_version != editor_data.get_undo_redo().get_version()); @@ -4739,7 +4809,6 @@ void EditorNode::_dim_timeout() { } void EditorNode::_check_gui_base_size() { - print_line(itos(int(gui_base->get_size().width))); if (gui_base->get_size().width > 1200 * EDSCALE) { for (int i = 0; i < singleton->main_editor_button_vb->get_child_count(); i++) { ToolButton *btn = singleton->main_editor_button_vb->get_child(i)->cast_to<ToolButton>(); @@ -4816,6 +4885,10 @@ void EditorNode::_bind_methods() { ClassDB::bind_method("set_current_version", &EditorNode::set_current_version); ClassDB::bind_method("_scene_tab_changed", &EditorNode::_scene_tab_changed); ClassDB::bind_method("_scene_tab_closed", &EditorNode::_scene_tab_closed); + ClassDB::bind_method("_scene_tab_hover", &EditorNode::_scene_tab_hover); + ClassDB::bind_method("_scene_tab_exit", &EditorNode::_scene_tab_exit); + ClassDB::bind_method("_scene_tab_input", &EditorNode::_scene_tab_input); + ClassDB::bind_method("_thumbnail_done", &EditorNode::_thumbnail_done); ClassDB::bind_method("_scene_tab_script_edited", &EditorNode::_scene_tab_script_edited); ClassDB::bind_method("_set_main_scene_state", &EditorNode::_set_main_scene_state); ClassDB::bind_method("_update_scene_tabs", &EditorNode::_update_scene_tabs); @@ -4844,6 +4917,7 @@ void EditorNode::_bind_methods() { ADD_SIGNAL(MethodInfo("stop_pressed")); ADD_SIGNAL(MethodInfo("request_help")); ADD_SIGNAL(MethodInfo("request_help_search")); + ADD_SIGNAL(MethodInfo("request_help_index")); ADD_SIGNAL(MethodInfo("script_add_function_request", PropertyInfo(Variant::OBJECT, "obj"), PropertyInfo(Variant::STRING, "function"), PropertyInfo(Variant::POOL_STRING_ARRAY, "args"))); ADD_SIGNAL(MethodInfo("resource_saved", PropertyInfo(Variant::OBJECT, "obj"))); } @@ -4858,6 +4932,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); @@ -5158,15 +5233,43 @@ EditorNode::EditorNode() { main_editor_tabs->connect("tab_changed",this,"_editor_select"); main_editor_tabs->set_tab_close_display_policy(Tabs::SHOW_NEVER); */ + tab_preview_panel = memnew(Panel); + tab_preview_panel->set_size(Size2(100, 100) * EDSCALE); + tab_preview_panel->hide(); + tab_preview_panel->set_self_modulate(Color(1, 1, 1, 0.7)); + gui_base->add_child(tab_preview_panel); + + tab_preview = memnew(TextureRect); + tab_preview->set_stretch_mode(TextureRect::STRETCH_KEEP_ASPECT_CENTERED); + tab_preview->set_size(Size2(96, 96) * EDSCALE); + tab_preview->set_position(Point2(2, 2) * EDSCALE); + tab_preview_panel->add_child(tab_preview); + scene_tabs = memnew(Tabs); + scene_tabs->add_style_override("tab_fg", gui_base->get_stylebox("SceneTabFG", "EditorStyles")); + scene_tabs->add_style_override("tab_bg", gui_base->get_stylebox("SceneTabBG", "EditorStyles")); scene_tabs->add_tab("unsaved"); scene_tabs->set_tab_align(Tabs::ALIGN_LEFT); scene_tabs->set_tab_close_display_policy((bool(EDITOR_DEF("interface/always_show_close_button_in_scene_tabs", false)) ? Tabs::CLOSE_BUTTON_SHOW_ALWAYS : Tabs::CLOSE_BUTTON_SHOW_ACTIVE_ONLY)); + scene_tabs->set_min_width(int(EDITOR_DEF("interface/scene_tabs/minimum_width", 50)) * EDSCALE); scene_tabs->connect("tab_changed", this, "_scene_tab_changed"); scene_tabs->connect("right_button_pressed", this, "_scene_tab_script_edited"); scene_tabs->connect("tab_close", this, "_scene_tab_closed"); + scene_tabs->connect("tab_hover", this, "_scene_tab_hover"); + scene_tabs->connect("mouse_exited", this, "_scene_tab_exit"); + scene_tabs->connect("gui_input", this, "_scene_tab_input"); - srt->add_child(scene_tabs); + HBoxContainer *tabbar_container = memnew(HBoxContainer); + scene_tabs->set_h_size_flags(Control::SIZE_EXPAND_FILL); + + srt->add_child(tabbar_container); + tabbar_container->add_child(scene_tabs); + distraction_free = memnew(ToolButton); + tabbar_container->add_child(distraction_free); + distraction_free->set_shortcut(ED_SHORTCUT("editor/distraction_free_mode", TTR("Distraction Free Mode"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_F11)); + distraction_free->connect("pressed", this, "_toggle_distraction_free_mode"); + distraction_free->set_icon(gui_base->get_icon("DistractionFree", "EditorIcons")); + distraction_free->set_toggle_mode(true); scene_root_parent = memnew(PanelContainer); scene_root_parent->set_custom_minimum_size(Size2(0, 80) * EDSCALE); @@ -5210,6 +5313,34 @@ EditorNode::EditorNode() { PopupMenu *p; + project_menu = memnew(MenuButton); + project_menu->set_tooltip(TTR("Miscellaneous project or scene-wide tools.")); + project_menu->set_text(TTR("Project")); + project_menu->add_style_override("hover", gui_base->get_stylebox("MenuHover", "EditorStyles")); + left_menu_hb->add_child(project_menu); + + p = project_menu->get_popup(); + p->connect("id_pressed", this, "_menu_option"); + p->add_item(TTR("Run Script"), FILE_RUN_SCRIPT, KEY_MASK_SHIFT + KEY_MASK_CMD + KEY_R); + p->add_item(TTR("Export"), FILE_EXPORT_PROJECT); + + PopupMenu *tool_menu = memnew(PopupMenu); + tool_menu->set_name("Tools"); + tool_menu->connect("id_pressed", this, "_menu_option"); + p->add_child(tool_menu); + p->add_submenu_item(TTR("Tools"), "Tools"); + tool_menu->add_item(TTR("Orphan Resource Explorer"), TOOLS_ORPHAN_RESOURCES); + p->add_separator(); + p->add_item(TTR("Project Settings"), RUN_SETTINGS); + p->add_separator(); + +#ifdef OSX_ENABLED + p->add_item(TTR("Quit to Project List"), RUN_PROJECT_MANAGER, KEY_MASK_SHIFT + KEY_MASK_ALT + KEY_Q); +#else + p->add_item(TTR("Quit to Project List"), RUN_PROJECT_MANAGER, KEY_MASK_SHIFT + KEY_MASK_CTRL + KEY_Q); +#endif + p->add_item(TTR("Quit"), FILE_QUIT, KEY_MASK_CMD + KEY_Q); + file_menu = memnew(MenuButton); file_menu->set_text(TTR("Scene")); //file_menu->set_icon(gui_base->get_icon("Save","EditorIcons")); @@ -5262,18 +5393,7 @@ EditorNode::EditorNode() { p->add_shortcut(ED_SHORTCUT("editor/undo", TTR("Undo"), KEY_MASK_CMD + KEY_Z), EDIT_UNDO, true); p->add_shortcut(ED_SHORTCUT("editor/redo", TTR("Redo"), KEY_MASK_SHIFT + KEY_MASK_CMD + KEY_Z), EDIT_REDO, true); p->add_separator(); - p->add_item(TTR("Run Script"), FILE_RUN_SCRIPT, KEY_MASK_SHIFT + KEY_MASK_CMD + KEY_R); - p->add_separator(); - p->add_item(TTR("Project Settings"), RUN_SETTINGS); - p->add_separator(); p->add_item(TTR("Revert Scene"), EDIT_REVERT); - p->add_separator(); -#ifdef OSX_ENABLED - p->add_item(TTR("Quit to Project List"), RUN_PROJECT_MANAGER, KEY_MASK_SHIFT + KEY_MASK_ALT + KEY_Q); -#else - p->add_item(TTR("Quit to Project List"), RUN_PROJECT_MANAGER, KEY_MASK_SHIFT + KEY_MASK_CTRL + KEY_Q); -#endif - p->add_item(TTR("Quit"), FILE_QUIT, KEY_MASK_CMD + KEY_Q); recent_scenes = memnew(PopupMenu); recent_scenes->set_name("RecentScenes"); @@ -5289,14 +5409,9 @@ EditorNode::EditorNode() { PanelContainer *editor_region = memnew(PanelContainer); main_editor_button_vb = memnew(HBoxContainer); editor_region->add_child(main_editor_button_vb); - menu_hb->add_child(editor_region); - distraction_free = memnew(ToolButton); - main_editor_button_vb->add_child(distraction_free); - distraction_free->set_shortcut(ED_SHORTCUT("editor/distraction_free_mode", TTR("Distraction Free Mode"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_F11)); - distraction_free->connect("pressed", this, "_toggle_distraction_free_mode"); - distraction_free->set_icon(gui_base->get_icon("DistractionFree", "EditorIcons")); - distraction_free->set_toggle_mode(true); + menu_hb->add_spacer(); + menu_hb->add_child(editor_region); //menu_hb->add_spacer(); #if 0 @@ -5327,27 +5442,66 @@ EditorNode::EditorNode() { menu_panel->add_child( resource_menu ); #endif - tool_menu = memnew(MenuButton); - tool_menu->set_tooltip(TTR("Miscellaneous project or scene-wide tools.")); - tool_menu->set_text(TTR("Tools")); - tool_menu->add_style_override("hover", gui_base->get_stylebox("MenuHover", "EditorStyles")); + debug_menu = memnew(MenuButton); + debug_menu->set_text(TTR("Debug")); + debug_menu->add_style_override("hover", gui_base->get_stylebox("MenuHover", "EditorStyles")); + left_menu_hb->add_child(debug_menu); + p = debug_menu->get_popup(); + p->set_hide_on_item_selection(false); + p->add_check_item(TTR("Deploy with Remote Debug"), RUN_DEPLOY_REMOTE_DEBUG); + p->set_item_tooltip(p->get_item_count() - 1, TTR("When exporting or deploying, the resulting executable will attempt to connect to the IP of this computer in order to be debugged.")); + p->add_check_item(TTR("Small Deploy with Network FS"), RUN_FILE_SERVER); + p->set_item_tooltip(p->get_item_count() - 1, TTR("When this option is enabled, export or deploy will produce a minimal executable.\nThe filesystem will be provided from the project by the editor over the network.\nOn Android, deploy will use the USB cable for faster performance. This option speeds up testing for games with a large footprint.")); + p->add_separator(); + p->add_check_item(TTR("Visible Collision Shapes"), RUN_DEBUG_COLLISONS); + p->set_item_tooltip(p->get_item_count() - 1, TTR("Collision shapes and raycast nodes (for 2D and 3D) will be visible on the running game if this option is turned on.")); + p->add_check_item(TTR("Visible Navigation"), RUN_DEBUG_NAVIGATION); + p->set_item_tooltip(p->get_item_count() - 1, TTR("Navigation meshes and polygons will be visible on the running game if this option is turned on.")); + p->add_separator(); + p->add_check_item(TTR("Sync Scene Changes"), RUN_LIVE_DEBUG); + p->set_item_tooltip(p->get_item_count() - 1, TTR("When this option is turned on, any changes made to the scene in the editor will be replicated in the running game.\nWhen used remotely on a device, this is more efficient with network filesystem.")); + p->add_check_item(TTR("Sync Script Changes"), RUN_RELOAD_SCRIPTS); + p->set_item_tooltip(p->get_item_count() - 1, TTR("When this option is turned on, any script that is saved will be reloaded on the running game.\nWhen used remotely on a device, this is more efficient with network filesystem.")); + p->connect("id_pressed", this, "_menu_option"); - //tool_menu->set_icon(gui_base->get_icon("Save","EditorIcons")); - left_menu_hb->add_child(tool_menu); + menu_hb->add_spacer(); - p = tool_menu->get_popup(); - p->connect("id_pressed", this, "_menu_option"); - p->add_item(TTR("Orphan Resource Explorer"), TOOLS_ORPHAN_RESOURCES); + settings_menu = memnew(MenuButton); + left_menu_hb->add_child(settings_menu); + settings_menu->set_text(TTR("Editor")); + settings_menu->add_style_override("hover", gui_base->get_stylebox("MenuHover", "EditorStyles")); + //settings_menu->set_anchor(MARGIN_RIGHT,ANCHOR_END); + p = settings_menu->get_popup(); - export_button = memnew(ToolButton); - export_button->set_tooltip(TTR("Export the project to many platforms.")); - export_button->set_text(TTR("Export")); - export_button->connect("pressed", this, "_menu_option", varray(FILE_EXPORT_PROJECT)); - export_button->set_focus_mode(Control::FOCUS_NONE); - export_button->add_style_override("hover", gui_base->get_stylebox("MenuHover", "EditorStyles")); - left_menu_hb->add_child(export_button); + //p->add_item("Export Settings",SETTINGS_EXPORT_PREFERENCES); + p->add_item(TTR("Editor Settings"), SETTINGS_PREFERENCES); + //p->add_item("Optimization Presets",SETTINGS_OPTIMIZED_PRESETS); + p->add_separator(); + editor_layouts = memnew(PopupMenu); + editor_layouts->set_name("Layouts"); + p->add_child(editor_layouts); + editor_layouts->connect("id_pressed", this, "_layout_menu_option"); + p->add_submenu_item(TTR("Editor Layout"), "Layouts"); + p->add_shortcut(ED_SHORTCUT("editor/fullscreen_mode", TTR("Toggle Fullscreen"), KEY_MASK_SHIFT | KEY_F11), SETTINGS_TOGGLE_FULLSCREN); + p->add_separator(); + p->add_item(TTR("Manage Export Templates"), SETTINGS_MANAGE_EXPORT_TEMPLATES); - menu_hb->add_spacer(); + // Help Menu + MenuButton *help_menu = memnew(MenuButton); + left_menu_hb->add_child(help_menu); + help_menu->set_text(TTR("Help")); + help_menu->add_style_override("hover", gui_base->get_stylebox("MenuHover", "EditorStyles")); + p = help_menu->get_popup(); + p->connect("id_pressed", this, "_menu_option"); + p->add_icon_item(gui_base->get_icon("ClassList", "EditorIcons"), TTR("Classes"), HELP_CLASSES); + p->add_icon_item(gui_base->get_icon("Help", "EditorIcons"), TTR("Search"), HELP_SEARCH); + p->add_separator(); + p->add_icon_item(gui_base->get_icon("Instance", "EditorIcons"), TTR("Online Docs"), HELP_DOCS); + p->add_icon_item(gui_base->get_icon("Instance", "EditorIcons"), TTR("Q&A"), HELP_QA); + p->add_icon_item(gui_base->get_icon("Instance", "EditorIcons"), TTR("Issue Tracker"), HELP_ISSUES); + p->add_icon_item(gui_base->get_icon("Instance", "EditorIcons"), TTR("Community"), HELP_COMMUNITY); + p->add_separator(); + p->add_icon_item(gui_base->get_icon("GodotDocs", "EditorIcons"), TTR("About"), HELP_ABOUT); //Separator *s1 = memnew( VSeparator ); //menu_panel->add_child(s1); @@ -5356,7 +5510,7 @@ EditorNode::EditorNode() { play_cc = memnew(CenterContainer); play_cc->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); - gui_base->add_child(play_cc); + menu_hb->add_child(play_cc); play_cc->set_area_as_parent_rect(); play_cc->set_anchor_and_margin(MARGIN_BOTTOM, Control::ANCHOR_BEGIN, 10); play_cc->set_margin(MARGIN_TOP, 5); @@ -5427,33 +5581,6 @@ EditorNode::EditorNode() { play_custom_scene_button->set_tooltip(TTR("Play custom scene")); play_custom_scene_button->set_shortcut(ED_SHORTCUT("editor/play_custom_scene", TTR("Play Custom Scene"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_F5)); - debug_button = memnew(MenuButton); - debug_button->set_flat(true); - play_hb->add_child(debug_button); - //debug_button->set_toggle_mode(true); - debug_button->set_focus_mode(Control::FOCUS_NONE); - debug_button->set_icon(gui_base->get_icon("Remote", "EditorIcons")); - //debug_button->connect("pressed", this,"_menu_option",make_binds(RUN_LIVE_DEBUG)); - debug_button->set_tooltip(TTR("Debug options")); - - p = debug_button->get_popup(); - p->set_hide_on_item_selection(false); - p->add_check_item(TTR("Deploy with Remote Debug"), RUN_DEPLOY_REMOTE_DEBUG); - p->set_item_tooltip(p->get_item_count() - 1, TTR("When exporting or deploying, the resulting executable will attempt to connect to the IP of this computer in order to be debugged.")); - p->add_check_item(TTR("Small Deploy with Network FS"), RUN_FILE_SERVER); - p->set_item_tooltip(p->get_item_count() - 1, TTR("When this option is enabled, export or deploy will produce a minimal executable.\nThe filesystem will be provided from the project by the editor over the network.\nOn Android, deploy will use the USB cable for faster performance. This option speeds up testing for games with a large footprint.")); - p->add_separator(); - p->add_check_item(TTR("Visible Collision Shapes"), RUN_DEBUG_COLLISONS); - p->set_item_tooltip(p->get_item_count() - 1, TTR("Collision shapes and raycast nodes (for 2D and 3D) will be visible on the running game if this option is turned on.")); - p->add_check_item(TTR("Visible Navigation"), RUN_DEBUG_NAVIGATION); - p->set_item_tooltip(p->get_item_count() - 1, TTR("Navigation meshes and polygons will be visible on the running game if this option is turned on.")); - p->add_separator(); - p->add_check_item(TTR("Sync Scene Changes"), RUN_LIVE_DEBUG); - p->set_item_tooltip(p->get_item_count() - 1, TTR("When this option is turned on, any changes made to the scene in the editor will be replicated in the running game.\nWhen used remotely on a device, this is more efficient with network filesystem.")); - p->add_check_item(TTR("Sync Script Changes"), RUN_RELOAD_SCRIPTS); - p->set_item_tooltip(p->get_item_count() - 1, TTR("When this option is turned on, any script that is saved will be reloaded on the running game.\nWhen used remotely on a device, this is more efficient with network filesystem.")); - p->connect("id_pressed", this, "_menu_option"); - /* run_settings_button = memnew( ToolButton ); //menu_hb->add_child(run_settings_button); @@ -5473,62 +5600,24 @@ EditorNode::EditorNode() { */ progress_hb = memnew(BackgroundProgress); - menu_hb->add_child(progress_hb); + //menu_hb->add_child(progress_hb); { Control *sp = memnew(Control); sp->set_custom_minimum_size(Size2(30, 0) * EDSCALE); - menu_hb->add_child(sp); + //menu_hb->add_child(sp); } - PanelContainer *vu_cont = memnew(PanelContainer); - menu_hb->add_child(vu_cont); - - audio_vu = memnew(TextureProgress); - CenterContainer *vu_cc = memnew(CenterContainer); - vu_cc->add_child(audio_vu); - vu_cont->add_child(vu_cc); - audio_vu->set_under_texture(gui_base->get_icon("VuEmpty", "EditorIcons")); - audio_vu->set_progress_texture(gui_base->get_icon("VuFull", "EditorIcons")); - audio_vu->set_max(24); - audio_vu->set_min(-80); - audio_vu->set_step(0.01); - audio_vu->set_value(0); - { Control *sp = memnew(Control); sp->set_custom_minimum_size(Size2(30, 0) * EDSCALE); - menu_hb->add_child(sp); + //menu_hb->add_child(sp); } top_region = memnew(PanelContainer); HBoxContainer *right_menu_hb = memnew(HBoxContainer); - top_region->add_child(right_menu_hb); - menu_hb->add_child(top_region); - - settings_menu = memnew(MenuButton); - settings_menu->set_text(TTR("Settings")); - settings_menu->add_style_override("hover", gui_base->get_stylebox("MenuHover", "EditorStyles")); - //settings_menu->set_anchor(MARGIN_RIGHT,ANCHOR_END); - right_menu_hb->add_child(settings_menu); - p = settings_menu->get_popup(); - - //p->add_item("Export Settings",SETTINGS_EXPORT_PREFERENCES); - p->add_item(TTR("Editor Settings"), SETTINGS_PREFERENCES); - //p->add_item("Optimization Presets",SETTINGS_OPTIMIZED_PRESETS); - p->add_separator(); - editor_layouts = memnew(PopupMenu); - editor_layouts->set_name("Layouts"); - p->add_child(editor_layouts); - editor_layouts->connect("id_pressed", this, "_layout_menu_option"); - p->add_submenu_item(TTR("Editor Layout"), "Layouts"); - - p->add_shortcut(ED_SHORTCUT("editor/fullscreen_mode", TTR("Toggle Fullscreen"), KEY_MASK_SHIFT | KEY_F11), SETTINGS_TOGGLE_FULLSCREN); - - p->add_separator(); - p->add_item(TTR("Manage Export Templates"), SETTINGS_MANAGE_EXPORT_TEMPLATES); - p->add_separator(); - p->add_item(TTR("About"), SETTINGS_ABOUT); + //top_region->add_child(right_menu_hb); + menu_hb->add_child(right_menu_hb); layout_dialog = memnew(EditorNameDialog); gui_base->add_child(layout_dialog); @@ -5536,16 +5625,11 @@ EditorNode::EditorNode() { layout_dialog->set_size(Size2(175, 70) * EDSCALE); layout_dialog->connect("name_confirmed", this, "_dialog_action"); - sources_button = memnew(ToolButton); - right_menu_hb->add_child(sources_button); - sources_button->set_icon(gui_base->get_icon("DependencyOk", "EditorIcons")); - sources_button->connect("pressed", this, "_menu_option", varray(SOURCES_REIMPORT)); - sources_button->set_tooltip(TTR("Alerts when an external resource has changed.")); - update_menu = memnew(MenuButton); update_menu->set_tooltip(TTR("Spins when the editor window repaints!")); right_menu_hb->add_child(update_menu); update_menu->set_icon(gui_base->get_icon("Progress1", "EditorIcons")); + update_menu->get_popup()->connect("id_pressed", this, "_menu_option"); p = update_menu->get_popup(); p->add_check_item(TTR("Update Always"), SETTINGS_UPDATE_ALWAYS); p->add_check_item(TTR("Update Changes"), SETTINGS_UPDATE_CHANGES); @@ -5863,14 +5947,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); @@ -5930,7 +6049,6 @@ EditorNode::EditorNode() { file_menu->get_popup()->connect("id_pressed", this, "_menu_option"); object_menu->get_popup()->connect("id_pressed", this, "_menu_option"); - update_menu->get_popup()->connect("id_pressed", this, "_menu_option"); settings_menu->get_popup()->connect("id_pressed", this, "_menu_option"); file->connect("file_selected", this, "_dialog_action"); @@ -5988,13 +6106,13 @@ EditorNode::EditorNode() { add_editor_plugin(memnew(Particles2DEditorPlugin(this))); add_editor_plugin(memnew(GIProbeEditorPlugin(this))); add_editor_plugin(memnew(Path2DEditorPlugin(this))); - //add_editor_plugin( memnew( PathEditorPlugin(this) ) ); + add_editor_plugin(memnew(PathEditorPlugin(this))); //add_editor_plugin( memnew( BakedLightEditorPlugin(this) ) ); add_editor_plugin(memnew(Line2DEditorPlugin(this))); add_editor_plugin(memnew(Polygon2DEditorPlugin(this))); add_editor_plugin(memnew(LightOccluder2DEditorPlugin(this))); add_editor_plugin(memnew(NavigationPolygonEditorPlugin(this))); - add_editor_plugin(memnew(ColorRampEditorPlugin(this))); + add_editor_plugin(memnew(GradientEditorPlugin(this))); add_editor_plugin(memnew(GradientTextureEditorPlugin(this))); add_editor_plugin(memnew(CollisionShape2DEditorPlugin(this))); add_editor_plugin(memnew(CurveTextureEditorPlugin(this))); @@ -6010,14 +6128,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(); @@ -6025,6 +6142,7 @@ EditorNode::EditorNode() { editor_plugin_screen = NULL; editor_plugins_over = memnew(EditorPluginList); + editor_plugins_force_input_forwarding = memnew(EditorPluginList); //force_top_viewport(true); _edit_current(); @@ -6173,6 +6291,7 @@ EditorNode::~EditorNode() { memdelete(EditorHelp::get_doc_data()); memdelete(editor_selection); memdelete(editor_plugins_over); + memdelete(editor_plugins_force_input_forwarding); memdelete(file_server); EditorSettings::destroy(); } @@ -6208,10 +6327,14 @@ bool EditorPluginList::forward_gui_input(const Transform2D &p_canvas_xform, cons return discard; } -bool EditorPluginList::forward_spatial_gui_input(Camera *p_camera, const Ref<InputEvent> &p_event) { +bool EditorPluginList::forward_spatial_gui_input(Camera *p_camera, const Ref<InputEvent> &p_event, bool serve_when_force_input_enabled) { bool discard = false; for (int i = 0; i < plugins_list.size(); i++) { + if ((!serve_when_force_input_enabled) && plugins_list[i]->is_input_event_forwarding_always_enabled()) { + continue; + } + if (plugins_list[i]->forward_spatial_gui_input(p_camera, p_event)) { discard = true; } @@ -6227,6 +6350,10 @@ void EditorPluginList::forward_draw_over_canvas(const Transform2D &p_canvas_xfor } } +void EditorPluginList::add_plugin(EditorPlugin *p_plugin) { + plugins_list.push_back(p_plugin); +} + bool EditorPluginList::empty() { return plugins_list.empty(); } diff --git a/editor/editor_node.h b/editor/editor_node.h index 667f58e6da..3870edb7c6 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -186,12 +186,19 @@ private: SETTINGS_PICK_MAIN_SCENE, SETTINGS_TOGGLE_FULLSCREN, SETTINGS_HELP, - SETTINGS_ABOUT, SOURCES_REIMPORT, DEPENDENCY_LOAD_CHANGED_IMAGES, DEPENDENCY_UPDATE_IMPORTED, SCENE_TAB_CLOSE, + HELP_CLASSES, + HELP_SEARCH, + HELP_DOCS, + HELP_QA, + HELP_ISSUES, + HELP_COMMUNITY, + HELP_ABOUT, + IMPORT_PLUGIN_BASE = 100, OBJECT_METHOD_BASE = 500, @@ -226,6 +233,8 @@ private: //main tabs Tabs *scene_tabs; + Panel *tab_preview_panel; + TextureRect *tab_preview; int tab_closing; bool exiting; @@ -244,7 +253,9 @@ private: HBoxContainer *menu_hb; Control *viewport; MenuButton *file_menu; - MenuButton *tool_menu; + MenuButton *project_menu; + MenuButton *debug_menu; + PopupMenu *tool_menu; ToolButton *export_button; ToolButton *prev_scene; MenuButton *object_menu; @@ -256,7 +267,6 @@ private: ToolButton *run_settings_button; ToolButton *play_scene_button; ToolButton *play_custom_scene_button; - MenuButton *debug_button; ToolButton *search_button; TextureProgress *audio_vu; //MenuButton *fileserver_menu; @@ -312,7 +322,7 @@ private: LineEdit *file_export_password; String current_path; MenuButton *update_menu; - ToolButton *sources_button; + //TabContainer *prop_pallete; //TabContainer *top_pallete; String defer_load_scene; @@ -388,6 +398,7 @@ private: Vector<EditorPlugin *> editor_plugins; EditorPlugin *editor_plugin_screen; EditorPluginList *editor_plugins_over; + EditorPluginList *editor_plugins_force_input_forwarding; EditorHistory editor_history; EditorData editor_data; @@ -548,6 +559,10 @@ private: void _dock_popup_exit(); void _scene_tab_changed(int p_tab); void _scene_tab_closed(int p_tab); + void _scene_tab_hover(int p_tab); + void _scene_tab_exit(); + void _scene_tab_input(const Ref<InputEvent> &p_input); + void _thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Variant &p_udata); void _scene_tab_script_edited(int p_tab); Dictionary _get_main_scene_state(); @@ -585,6 +600,7 @@ private: static int plugin_init_callback_count; static EditorPluginInitializeCallback plugin_init_callbacks[MAX_INIT_CALLBACKS]; + void _save_default_environment(); void _call_build(); static int build_callback_count; @@ -632,6 +648,7 @@ public: EditorPlugin *get_editor_plugin_screen() { return editor_plugin_screen; } EditorPluginList *get_editor_plugins_over() { return editor_plugins_over; } + EditorPluginList *get_editor_plugins_force_input_forwarding() { return editor_plugins_force_input_forwarding; } PropertyEditor *get_property_editor() { return property_editor; } VBoxContainer *get_property_editor_vb() { return prop_editor_vb; } @@ -808,8 +825,9 @@ public: void make_visible(bool p_visible); void edit(Object *p_object); bool forward_gui_input(const Transform2D &p_canvas_xform, const Ref<InputEvent> &p_event); - bool forward_spatial_gui_input(Camera *p_camera, const Ref<InputEvent> &p_event); + bool forward_spatial_gui_input(Camera *p_camera, const Ref<InputEvent> &p_event, bool serve_when_force_input_enabled); void forward_draw_over_canvas(const Transform2D &p_canvas_xform, Control *p_canvas); + void add_plugin(EditorPlugin *p_plugin); void clear(); bool empty(); diff --git a/editor/editor_plugin.cpp b/editor/editor_plugin.cpp index 1b8d1b1677..75ab1e8a44 100644 --- a/editor/editor_plugin.cpp +++ b/editor/editor_plugin.cpp @@ -147,6 +147,12 @@ void EditorPlugin::remove_tool_menu_item(const String &p_name) { //EditorNode::get_singleton()->remove_tool_menu_item(p_name); } +void EditorPlugin::set_input_event_forwarding_always_enabled() { + input_event_forwarding_always_enabled = true; + EditorPluginList *always_input_forwarding_list = EditorNode::get_singleton()->get_editor_plugins_force_input_forwarding(); + always_input_forwarding_list->add_plugin(this); +} + Ref<SpatialEditorGizmo> EditorPlugin::create_spatial_gizmo(Spatial *p_spatial) { //?? if (get_script_instance() && get_script_instance()->has_method("create_spatial_gizmo")) { @@ -281,6 +287,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 +377,8 @@ 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::bind_method(D_METHOD("set_input_event_forwarding_always_enabled"), &EditorPlugin::set_input_event_forwarding_always_enabled); 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"))); @@ -408,6 +421,7 @@ void EditorPlugin::_bind_methods() { EditorPlugin::EditorPlugin() { undo_redo = NULL; + input_event_forwarding_always_enabled = false; } EditorPlugin::~EditorPlugin() { diff --git a/editor/editor_plugin.h b/editor/editor_plugin.h index 1ef447a6b8..57a22a8b2f 100644 --- a/editor/editor_plugin.h +++ b/editor/editor_plugin.h @@ -61,6 +61,8 @@ class EditorPlugin : public Node { UndoRedo *_get_undo_redo() { return undo_redo; } + bool input_event_forwarding_always_enabled; + protected: static void _bind_methods(); UndoRedo &get_undo_redo() { return *undo_redo; } @@ -106,6 +108,9 @@ public: void add_tool_submenu_item(const String &p_name, Object *p_submenu); void remove_tool_menu_item(const String &p_name); + void set_input_event_forwarding_always_enabled(); + bool is_input_event_forwarding_always_enabled() { return input_event_forwarding_always_enabled; } + virtual Ref<SpatialEditorGizmo> create_spatial_gizmo(Spatial *p_spatial); virtual bool forward_canvas_gui_input(const Transform2D &p_canvas_xform, const Ref<InputEvent> &p_event); virtual void forward_draw_over_canvas(const Transform2D &p_canvas_xform, Control *p_canvas); @@ -148,6 +153,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 d427126734..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(); @@ -523,7 +523,7 @@ void EditorProfiler::_graph_tex_input(const Ref<InputEvent> &p_ev) { hover_metric = -1; } - if (mb.is_valid() || mb->get_button_mask() & BUTTON_MASK_LEFT) { + if (mb.is_valid() || mm->get_button_mask() & BUTTON_MASK_LEFT) { //cursor_metric=x; updating_frame = true; 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..a8106b4eec 100644 --- a/editor/editor_run.cpp +++ b/editor/editor_run.cpp @@ -42,6 +42,7 @@ Error EditorRun::run(const String &p_scene, const String p_custom_args, const Li String resource_path = GlobalConfig::get_singleton()->get_resource_path(); String remote_host = EditorSettings::get_singleton()->get("network/debug/remote_host"); + int remote_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port"); if (resource_path != "") { args.push_back("-path"); @@ -50,7 +51,7 @@ Error EditorRun::run(const String &p_scene, const String p_custom_args, const Li if (true) { args.push_back("-rdebug"); - args.push_back(remote_host + ":" + String::num(GLOBAL_GET("network/debug/remote_port"))); + args.push_back(remote_host + ":" + String::num(remote_port)); } args.push_back("-epid"); @@ -73,17 +74,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 +96,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 +118,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 ebd4643537..485f8236de 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -292,6 +292,12 @@ void EditorSettings::create() { dir->change_dir(".."); } + if (dir->change_dir("script_templates") != OK) { + dir->make_dir("script_templates"); + } else { + dir->change_dir(".."); + } + if (dir->change_dir("tmp") != OK) { dir->make_dir("tmp"); } else { @@ -502,9 +508,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { set("interface/source_font_size", 14); hints["interface/source_font_size"] = PropertyInfo(Variant::INT, "interface/source_font_size", PROPERTY_HINT_RANGE, "8,96,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); set("interface/custom_font", ""); - hints["interface/custom_font"] = PropertyInfo(Variant::STRING, "interface/custom_font", PROPERTY_HINT_GLOBAL_FILE, "*.fnt", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); - set("interface/custom_theme", ""); - hints["interface/custom_theme"] = PropertyInfo(Variant::STRING, "interface/custom_theme", PROPERTY_HINT_GLOBAL_FILE, "*.res,*.tres,*.theme", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); + hints["interface/custom_font"] = PropertyInfo(Variant::STRING, "interface/custom_font", PROPERTY_HINT_GLOBAL_FILE, "*.font", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); set("interface/dim_editor_on_dialog_popup", true); set("interface/dim_amount", 0.6f); hints["interface/dim_amount"] = PropertyInfo(Variant::REAL, "interface/dim_amount", PROPERTY_HINT_RANGE, "0,1,0.01", PROPERTY_USAGE_DEFAULT); @@ -513,6 +517,23 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { set("interface/separate_distraction_mode", false); + set("interface/theme/preset", 0); + hints["interface/theme/preset"] = PropertyInfo(Variant::INT, "interface/theme/preset", PROPERTY_HINT_ENUM, "Default,Grey,Godot 2,Arc,Custom", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); + set("interface/theme/base_color", Color::html("#273241")); + hints["interface/theme/highlight_color"] = PropertyInfo(Variant::COLOR, "interface/theme/highlight_color", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); + set("interface/theme/highlight_color", Color::html("#b79047")); + hints["interface/theme/base_color"] = PropertyInfo(Variant::COLOR, "interface/theme/base_color", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); + set("interface/theme/contrast", 0.2); + hints["interface/theme/contrast"] = PropertyInfo(Variant::REAL, "interface/theme/contrast", PROPERTY_HINT_RANGE, "0.01, 1, 0.01"); + set("interface/theme/custom_theme", ""); + hints["interface/theme/custom_theme"] = PropertyInfo(Variant::STRING, "interface/theme/custom_theme", PROPERTY_HINT_GLOBAL_FILE, "*.res,*.tres,*.theme", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); + + set("interface/scene_tabs/show_extension", false); + set("interface/scene_tabs/show_thumbnail_on_hover", true); + set("interface/scene_tabs/resize_if_many_tabs", true); + set("interface/scene_tabs/minimum_width", 50); + hints["interface/scene_tabs/minimum_width"] = PropertyInfo(Variant::INT, "interface/scene_tabs/minimum_width", PROPERTY_HINT_RANGE, "50,500,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); + set("filesystem/directories/autoscan_project_path", ""); hints["filesystem/directories/autoscan_project_path"] = PropertyInfo(Variant::STRING, "filesystem/directories/autoscan_project_path", PROPERTY_HINT_GLOBAL_DIR); set("filesystem/directories/default_project_path", ""); @@ -547,6 +568,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); @@ -558,7 +581,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { hints["text_editor/cursor/caret_blink_speed"] = PropertyInfo(Variant::REAL, "text_editor/cursor/caret_blink_speed", PROPERTY_HINT_RANGE, "0.1, 10, 0.1"); set("text_editor/theme/font", ""); - hints["text_editor/theme/font"] = PropertyInfo(Variant::STRING, "text_editor/theme/font", PROPERTY_HINT_GLOBAL_FILE, "*.fnt"); + hints["text_editor/theme/font"] = PropertyInfo(Variant::STRING, "text_editor/theme/font", PROPERTY_HINT_GLOBAL_FILE, "*.font"); set("text_editor/completion/auto_brace_complete", false); set("text_editor/files/restore_scripts_on_load", true); set("text_editor/completion/complete_file_paths", true); @@ -575,7 +598,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { set("editors/3d/grid_color", Color(0, 1, 0, 0.2)); hints["editors/3d/grid_color"] = PropertyInfo(Variant::COLOR, "editors/3d/grid_color", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); - set("editors/3d/default_fov", 45.0); + set("editors/3d/default_fov", 55.0); set("editors/3d/default_z_near", 0.1); set("editors/3d/default_z_far", 500.0); @@ -603,15 +626,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("editors/theme/base_color", Color(0.3, 0.3, 0.3, 1)); - hints["editors/theme/base_color"] = PropertyInfo(Variant::COLOR, "editors/theme/base_color", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); - set("editors/theme/contrast", 0.2); - hints["editors/theme/contrast"] = PropertyInfo(Variant::REAL, "editors/theme/contrast", PROPERTY_HINT_RANGE, "0.01, 1, 0.01"); - - 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++) { @@ -938,6 +958,25 @@ bool EditorSettings::save_text_editor_theme_as(String p_file) { return false; } +Vector<String> EditorSettings::get_script_templates(const String &p_extension) { + + Vector<String> templates; + DirAccess *d = DirAccess::open(settings_path + "/script_templates"); + if (d) { + d->list_dir_begin(); + String file = d->get_next(); + while (file != String()) { + if (file.get_extension() == p_extension) { + templates.push_back(file.get_basename()); + } + file = d->get_next(); + } + d->list_dir_end(); + memdelete(d); + } + return templates; +} + bool EditorSettings::_save_text_editor_theme(String p_file) { String theme_section = "color_theme"; Ref<ConfigFile> cf = memnew(ConfigFile); // hex is better? diff --git a/editor/editor_settings.h b/editor/editor_settings.h index 7b45e28350..d5adb84b63 100644 --- a/editor/editor_settings.h +++ b/editor/editor_settings.h @@ -159,6 +159,8 @@ public: bool save_text_editor_theme(); bool save_text_editor_theme_as(String p_file); + Vector<String> get_script_templates(const String &p_extension); + void add_shortcut(const String &p_name, Ref<ShortCut> &p_shortcut); bool is_shortcut(const String &p_name, const Ref<InputEvent> &p_event) const; Ref<ShortCut> get_shortcut(const String &p_name) const; diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp index 1d73192f76..e6df58bc60 100644 --- a/editor/editor_themes.cpp +++ b/editor/editor_themes.cpp @@ -95,16 +95,40 @@ Ref<Theme> create_editor_theme() { editor_register_icons(theme); // Define colors - Color highlight_color = EDITOR_DEF("editors/theme/highlight_color", Color::html("#6ca9f3")); - Color base_color = EDITOR_DEF("editors/theme/base_color", Color::html("#2e3742")); - float contrast = EDITOR_DEF("editors/theme/contrast", 0.2); + Color highlight_color = EDITOR_DEF("interface/theme/highlight_color", Color::html("#b79047")); + Color base_color = EDITOR_DEF("interface/theme/base_color", Color::html("#273241")); + float contrast = EDITOR_DEF("interface/theme/contrast", 0.25); + int preset = EDITOR_DEF("interface/theme/preset", 0); + + switch (preset) { + case 0: { // Default + highlight_color = Color::html("#b79047"); + base_color = Color::html("#273241"); + contrast = 0.25; + } break; + case 1: { // Grey + highlight_color = Color::html("#3e3e3e"); + base_color = Color::html("#3d3d3d"); + contrast = 0.2; + } break; + case 2: { // Godot 2 + highlight_color = Color::html("#86ace2"); + base_color = Color::html("#3C3A44"); + contrast = 0.25; + } break; + case 3: { // Arc + highlight_color = Color::html("#68a7f2"); + base_color = Color::html("#434a59"); + contrast = 0.2; + } break; + } Color dark_color_1 = base_color.linear_interpolate(Color(0, 0, 0, 1), contrast); - Color dark_color_2 = base_color.linear_interpolate(Color(0, 0, 0, 1), contrast * 2); - Color dark_color_3 = base_color.linear_interpolate(Color(0, 0, 0, 1), contrast * 3); + Color dark_color_2 = base_color.linear_interpolate(Color(0, 0, 0, 1), contrast * 1.5); + Color dark_color_3 = base_color.linear_interpolate(Color(0, 0, 0, 1), contrast * 2); Color light_color_1 = base_color.linear_interpolate(Color(1, 1, 1, 1), contrast); - Color light_color_2 = base_color.linear_interpolate(Color(1, 1, 1, 1), contrast * 2); + Color light_color_2 = base_color.linear_interpolate(Color(1, 1, 1, 1), contrast * 1.5); theme->set_color("highlight_color", "Editor", highlight_color); theme->set_color("base_color", "Editor", base_color); @@ -121,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); @@ -169,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); @@ -223,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); @@ -253,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); @@ -264,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); @@ -278,6 +307,8 @@ Ref<Theme> create_editor_theme() { theme->set_color("font_color_bg", "TabContainer", light_color_2); theme->set_icon("menu", "TabContainer", theme->get_icon("TabMenu", "EditorIcons")); theme->set_icon("menu_hl", "TabContainer", theme->get_icon("TabMenu", "EditorIcons")); + theme->set_stylebox("SceneTabFG", "EditorStyles", make_flat_stylebox(base_color, 10, 5, 10, 5)); + theme->set_stylebox("SceneTabBG", "EditorStyles", make_empty_stylebox(6, 5, 6, 5)); // Debugger Ref<StyleBoxFlat> style_panel_debugger = make_flat_stylebox(dark_color_2, 0, 4, 0, 0); @@ -366,6 +397,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); @@ -425,7 +459,7 @@ Ref<Theme> create_editor_theme() { Ref<Theme> create_custom_theme() { Ref<Theme> theme; - String custom_theme = EditorSettings::get_singleton()->get("interface/custom_theme"); + String custom_theme = EditorSettings::get_singleton()->get("interface/theme/custom_theme"); if (custom_theme != "") { theme = ResourceLoader::load(custom_theme); } diff --git a/editor/icons/icon_h_button_array.png b/editor/icons/icon_h_button_array.png Binary files differdeleted file mode 100644 index baf3386801..0000000000 --- a/editor/icons/icon_h_button_array.png +++ /dev/null diff --git a/editor/icons/icon_v_button_array.png b/editor/icons/icon_v_button_array.png Binary files differdeleted file mode 100644 index d7ea9cc375..0000000000 --- a/editor/icons/icon_v_button_array.png +++ /dev/null diff --git a/editor/import/editor_import_collada.cpp b/editor/import/editor_import_collada.cpp index 2cefcdbc4a..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); @@ -402,8 +402,8 @@ Error ColladaImport::_create_material(const String &p_target) { Ref<Texture> texture = ResourceLoader::load(texfile, "Texture"); if (texture.is_valid()) { - material->set_texture(SpatialMaterial::TEXTURE_SPECULAR, texture); - material->set_specular(Color(1, 1, 1, 1)); + material->set_texture(SpatialMaterial::TEXTURE_METALLIC, texture); + material->set_specular(1.0); //material->set_texture(SpatialMaterial::PARAM_SPECULAR,texture); //material->set_parameter(SpatialMaterial::PARAM_SPECULAR,Color(1,1,1,1)); @@ -411,8 +411,9 @@ Error ColladaImport::_create_material(const String &p_target) { missing_textures.push_back(texfile.get_file()); } } + } else { - material->set_metalness(effect.specular.color.get_v()); + material->set_metallic(effect.specular.color.get_v()); } // EMISSION @@ -553,10 +554,10 @@ static void _generate_tangents_and_binormals(const PoolVector<int> &p_indices, c tangent = Vector3(); } else { tangent = Vector3((t2 * x1 - t1 * x2) * r, (t2 * y1 - t1 * y2) * r, - (t2 * z1 - t1 * z2) * r) + (t2 * z1 - t1 * z2) * r) .normalized(); binormal = Vector3((s1 * x2 - s2 * x1) * r, (s1 * y2 - s2 * y1) * r, - (s1 * z2 - s2 * z1) * r) + (s1 * z2 - s2 * z1) * r) .normalized(); } @@ -590,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; @@ -1529,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())); @@ -1620,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); @@ -1647,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 { @@ -1655,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_csv_translation.cpp b/editor/import/resource_importer_csv_translation.cpp index ea43477dc3..9214b8f45e 100644 --- a/editor/import/resource_importer_csv_translation.cpp +++ b/editor/import/resource_importer_csv_translation.cpp @@ -54,7 +54,7 @@ String ResourceImporterCSVTranslation::get_save_extension() const { String ResourceImporterCSVTranslation::get_resource_type() const { - return "StreamCSVTranslation"; + return "Translation"; } bool ResourceImporterCSVTranslation::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const { @@ -128,7 +128,7 @@ Error ResourceImporterCSVTranslation::import(const String &p_source_file, const xlt = cxl; } - String save_path = p_source_file.get_basename() + "." + translations[i]->get_locale() + ".xl"; + String save_path = p_source_file.get_basename() + "." + translations[i]->get_locale() + ".translation"; ResourceSaver::save(save_path, xlt); if (r_gen_files) { diff --git a/editor/import/resource_importer_obj.cpp b/editor/import/resource_importer_obj.cpp index 21c2ae6eb3..1c5aa95ff1 100644 --- a/editor/import/resource_importer_obj.cpp +++ b/editor/import/resource_importer_obj.cpp @@ -33,7 +33,6 @@ #include "os/file_access.h" #include "scene/resources/mesh.h" #include "scene/resources/surface_tool.h" -#include "scene/resources/surface_tool.h" String ResourceImporterOBJ::get_importer_name() const { @@ -49,12 +48,12 @@ void ResourceImporterOBJ::get_recognized_extensions(List<String> *p_extensions) p_extensions->push_back("obj"); } String ResourceImporterOBJ::get_save_extension() const { - return "msh"; + return "mesh"; } 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 +88,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"]; @@ -244,7 +243,7 @@ Error ResourceImporterOBJ::import(const String &p_source_file, const String &p_s } */ - Error err = ResourceSaver::save(p_save_path + ".msh", mesh); + Error err = ResourceSaver::save(p_save_path + ".mesh", mesh); return err; } diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index 755f4eb219..2409f6707d 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; @@ -987,7 +987,7 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String if (!p_materials.has(mat)) { - String ext_name = p_base_path + "." + _make_extname(mat->get_name()) + ".mtl"; + String ext_name = p_base_path + "." + _make_extname(mat->get_name()) + ".material"; if (FileAccess::exists(ext_name)) { //if exists, use it Ref<Material> existing = ResourceLoader::load(ext_name); @@ -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()) { @@ -1015,10 +1015,10 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String if (!p_meshes.has(mesh)) { - String ext_name = p_base_path + "." + _make_extname(mesh->get_name()) + ".msh"; + String ext_name = p_base_path + "." + _make_extname(mesh->get_name()) + ".mesh"; 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 { @@ -1040,7 +1040,7 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String if (!p_materials.has(mat)) { - String ext_name = p_base_path + "." + _make_extname(mat->get_name()) + ".mtl"; + String ext_name = p_base_path + "." + _make_extname(mat->get_name()) + ".material"; if (FileAccess::exists(ext_name)) { //if exists, use it Ref<Material> existing = ResourceLoader::load(ext_name); @@ -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/import/resource_importer_texture.cpp b/editor/import/resource_importer_texture.cpp index c115f0014a..41b2353ed3 100644 --- a/editor/import/resource_importer_texture.cpp +++ b/editor/import/resource_importer_texture.cpp @@ -66,6 +66,22 @@ void ResourceImporterTexture::_texture_reimport_3d(const Ref<StreamTexture> &p_t singleton->mutex->unlock(); } +void ResourceImporterTexture::_texture_reimport_normal(const Ref<StreamTexture> &p_tex) { + + singleton->mutex->lock(); + StringName path = p_tex->get_path(); + + if (!singleton->make_flags.has(path)) { + singleton->make_flags[path] = 0; + } + + singleton->make_flags[path] |= MAKE_NORMAL_FLAG; + + print_line("requesting normalfor " + String(path)); + + singleton->mutex->unlock(); +} + void ResourceImporterTexture::update_imports() { if (EditorFileSystem::get_singleton()->is_scanning() || EditorFileSystem::get_singleton()->is_importing()) { @@ -96,6 +112,11 @@ void ResourceImporterTexture::update_imports() { changed = true; } + if (E->get() & MAKE_NORMAL_FLAG && int(cf->get_value("params", "compress/normal_map")) == 0) { + cf->set_value("params", "compress/normal_map", 1); + changed = true; + } + if (E->get() & MAKE_3D_FLAG && bool(cf->get_value("params", "detect_3d"))) { cf->set_value("params", "detect_3d", false); cf->set_value("params", "compress/mode", 2); @@ -144,8 +165,12 @@ String ResourceImporterTexture::get_resource_type() const { bool ResourceImporterTexture::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const { - if (p_option == "compress/lossy_quality" && int(p_options["compress/mode"]) != COMPRESS_LOSSY) - return false; + if (p_option == "compress/lossy_quality") { + int compress_mode = int(p_options["compress/mode"]); + if (compress_mode != COMPRESS_LOSSY && compress_mode != COMPRESS_VIDEO_RAM) { + return false; + } + } return true; } @@ -169,6 +194,8 @@ void ResourceImporterTexture::get_import_options(List<ImportOption> *r_options, r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "compress/mode", PROPERTY_HINT_ENUM, "Lossless,Lossy,Video RAM,Uncompressed", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), p_preset == PRESET_3D ? 2 : 0)); r_options->push_back(ImportOption(PropertyInfo(Variant::REAL, "compress/lossy_quality", PROPERTY_HINT_RANGE, "0,1,0.01"), 0.7)); + r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "compress/hdr_mode", PROPERTY_HINT_ENUM, "Compress,Force RGBE"), 0)); + r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "compress/normal_map", PROPERTY_HINT_ENUM, "Detect,Enable,Disabled"), 0)); r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "flags/repeat", PROPERTY_HINT_ENUM, "Disabled,Enabled,Mirrored"), p_preset == PRESET_3D ? 1 : 0)); r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "flags/filter"), p_preset == PRESET_2D_PIXEL ? false : true)); r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "flags/mipmaps"), p_preset == PRESET_3D ? true : false)); @@ -176,13 +203,15 @@ void ResourceImporterTexture::get_import_options(List<ImportOption> *r_options, r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "flags/srgb", PROPERTY_HINT_ENUM, "Disable,Enable,Detect"), 2)); r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "process/fix_alpha_border"), p_preset != PRESET_3D ? true : false)); r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "process/premult_alpha"), true)); + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "process/HDR_as_SRGB"), false)); r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "stream"), false)); r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "size_limit", PROPERTY_HINT_RANGE, "0,4096,1"), 0)); r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "detect_3d"), p_preset == PRESET_DETECT)); } -void ResourceImporterTexture::_save_stex(const Ref<Image> &p_image, const String &p_to_path, int p_compress_mode, float p_lossy_quality, Image::CompressMode p_vram_compression, bool p_mipmaps, int p_texture_flags, bool p_streamable, bool p_detect_3d, bool p_detect_srgb) { +void ResourceImporterTexture::_save_stex(const Ref<Image> &p_image, const String &p_to_path, int p_compress_mode, float p_lossy_quality, Image::CompressMode p_vram_compression, bool p_mipmaps, int p_texture_flags, bool p_streamable, bool p_detect_3d, bool p_detect_srgb, bool p_force_rgbe, bool p_detect_normal, bool p_force_normal) { + print_line("saving: " + p_to_path); FileAccess *f = FileAccess::open(p_to_path, FileAccess::WRITE); f->store_8('G'); f->store_8('D'); @@ -203,6 +232,12 @@ void ResourceImporterTexture::_save_stex(const Ref<Image> &p_image, const String format |= StreamTexture::FORMAT_BIT_DETECT_3D; if (p_detect_srgb) format |= StreamTexture::FORMAT_BIT_DETECT_SRGB; + if (p_detect_normal) + format |= StreamTexture::FORMAT_BIT_DETECT_NORMAL; + + if ((p_compress_mode == COMPRESS_LOSSLESS || p_compress_mode == COMPRESS_LOSSY) && p_image->get_format() > Image::FORMAT_RGBA8) { + p_compress_mode == COMPRESS_UNCOMPRESSED; //these can't go as lossy + } switch (p_compress_mode) { case COMPRESS_LOSSLESS: { @@ -267,7 +302,19 @@ void ResourceImporterTexture::_save_stex(const Ref<Image> &p_image, const String Ref<Image> image = p_image->duplicate(); image->generate_mipmaps(); - image->compress(p_vram_compression); + + if (p_force_rgbe && image->get_format() >= Image::FORMAT_R8 && image->get_format() <= Image::FORMAT_RGBE9995) { + image->convert(Image::FORMAT_RGBE9995); + } else { + Image::CompressSource csource = Image::COMPRESS_SOURCE_GENERIC; + if (p_force_normal) { + csource = Image::COMPRESS_SOURCE_NORMAL; + } else if (p_texture_flags & VS::TEXTURE_FLAG_CONVERT_TO_LINEAR) { + csource = Image::COMPRESS_SOURCE_SRGB; + } + + image->compress(p_vram_compression, csource, p_lossy_quality); + } format |= image->get_format(); @@ -277,7 +324,6 @@ void ResourceImporterTexture::_save_stex(const Ref<Image> &p_image, const String int dl = data.size(); PoolVector<uint8_t>::Read r = data.read(); f->store_buffer(r.ptr(), dl); - } break; case COMPRESS_UNCOMPRESSED: { @@ -316,10 +362,13 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String bool premult_alpha = p_options["process/premult_alpha"]; bool stream = p_options["stream"]; int size_limit = p_options["size_limit"]; + bool force_rgbe = int(p_options["compress/hdr_mode"]) == 1; + bool hdr_as_srgb = p_options["process/HDR_as_SRGB"]; + int normal = p_options["compress/normal_map"]; Ref<Image> image; image.instance(); - Error err = ImageLoader::load_image(p_source_file, image); + Error err = ImageLoader::load_image(p_source_file, image, NULL, hdr_as_srgb); if (err != OK) return err; @@ -363,20 +412,38 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String bool detect_3d = p_options["detect_3d"]; bool detect_srgb = srgb == 2; + bool detect_normal = normal == 0; + bool force_normal = normal == 1; if (compress_mode == COMPRESS_VIDEO_RAM) { //must import in all formats //Android, GLES 2.x - _save_stex(image, p_save_path + ".etc.stex", compress_mode, lossy, Image::COMPRESS_ETC, mipmaps, tex_flags, stream, detect_3d, detect_srgb); - r_platform_variants->push_back("etc"); - //_save_stex(image,p_save_path+".etc2.stex",compress_mode,lossy,Image::COMPRESS_ETC2,mipmaps,tex_flags,stream); - //r_platform_variants->push_back("etc2"); - _save_stex(image, p_save_path + ".s3tc.stex", compress_mode, lossy, Image::COMPRESS_S3TC, mipmaps, tex_flags, stream, detect_3d, detect_srgb); - r_platform_variants->push_back("s3tc"); + if (GlobalConfig::get_singleton()->get("rendering/vram_formats/use_s3tc")) { + + _save_stex(image, p_save_path + ".s3tc.stex", compress_mode, lossy, Image::COMPRESS_S3TC, mipmaps, tex_flags, stream, detect_3d, detect_srgb, force_rgbe, detect_normal, force_normal); + r_platform_variants->push_back("s3tc"); + } + + if (GlobalConfig::get_singleton()->get("rendering/vram_formats/use_etc")) { + _save_stex(image, p_save_path + ".etc.stex", compress_mode, lossy, Image::COMPRESS_ETC, mipmaps, tex_flags, stream, detect_3d, detect_srgb, force_rgbe, detect_normal, force_normal); + r_platform_variants->push_back("etc"); + } + + if (GlobalConfig::get_singleton()->get("rendering/vram_formats/use_etc2")) { + + _save_stex(image, p_save_path + ".etc2.stex", compress_mode, lossy, Image::COMPRESS_ETC2, mipmaps, tex_flags, stream, detect_3d, detect_srgb, force_rgbe, detect_normal, force_normal); + r_platform_variants->push_back("etc2"); + } + + if (GlobalConfig::get_singleton()->get("rendering/vram_formats/use_pvrtc")) { + + _save_stex(image, p_save_path + ".pvrtc.stex", compress_mode, lossy, Image::COMPRESS_PVRTC4, mipmaps, tex_flags, stream, detect_3d, detect_srgb, force_rgbe, detect_normal, force_normal); + r_platform_variants->push_back("pvrtc"); + } } else { //import normally - _save_stex(image, p_save_path + ".stex", compress_mode, lossy, Image::COMPRESS_16BIT /*this is ignored */, mipmaps, tex_flags, stream, detect_3d, detect_srgb); + _save_stex(image, p_save_path + ".stex", compress_mode, lossy, Image::COMPRESS_S3TC /*this is ignored */, mipmaps, tex_flags, stream, detect_3d, detect_srgb, force_rgbe, detect_normal, force_normal); } return OK; @@ -389,6 +456,7 @@ ResourceImporterTexture::ResourceImporterTexture() { singleton = this; StreamTexture::request_3d_callback = _texture_reimport_3d; StreamTexture::request_srgb_callback = _texture_reimport_srgb; + StreamTexture::request_normal_callback = _texture_reimport_normal; mutex = Mutex::create(); } diff --git a/editor/import/resource_importer_texture.h b/editor/import/resource_importer_texture.h index e782fc2978..31bd0f29b0 100644 --- a/editor/import/resource_importer_texture.h +++ b/editor/import/resource_importer_texture.h @@ -41,7 +41,8 @@ class ResourceImporterTexture : public ResourceImporter { protected: enum { MAKE_3D_FLAG = 1, - MAKE_SRGB_FLAG = 2 + MAKE_SRGB_FLAG = 2, + MAKE_NORMAL_FLAG = 4 }; Mutex *mutex; @@ -49,6 +50,7 @@ protected: static void _texture_reimport_srgb(const Ref<StreamTexture> &p_tex); static void _texture_reimport_3d(const Ref<StreamTexture> &p_tex); + static void _texture_reimport_normal(const Ref<StreamTexture> &p_tex); static ResourceImporterTexture *singleton; @@ -80,7 +82,7 @@ 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 _save_stex(const Ref<Image> &p_image, const String &p_to_path, int p_compress_mode, float p_lossy_quality, Image::CompressMode p_vram_compression, bool p_mipmaps, int p_texture_flags, bool p_streamable, bool p_detect_3d, bool p_detect_srgb); + void _save_stex(const Ref<Image> &p_image, const String &p_to_path, int p_compress_mode, float p_lossy_quality, Image::CompressMode p_vram_compression, bool p_mipmaps, int p_texture_flags, bool p_streamable, bool p_detect_3d, bool p_detect_srgb, bool p_force_rgbe, bool p_detect_normal, bool p_force_normal); virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = NULL); diff --git a/editor/import/resource_importer_wav.cpp b/editor/import/resource_importer_wav.cpp index 92c1aa47db..7841baa02e 100644 --- a/editor/import/resource_importer_wav.cpp +++ b/editor/import/resource_importer_wav.cpp @@ -48,7 +48,7 @@ void ResourceImporterWAV::get_recognized_extensions(List<String> *p_extensions) p_extensions->push_back("wav"); } String ResourceImporterWAV::get_save_extension() const { - return "smp"; + return "sample"; } String ResourceImporterWAV::get_resource_type() const { @@ -485,7 +485,7 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s sample->set_loop_end(loop_end); sample->set_stereo(format_channels == 2); - ResourceSaver::save(p_save_path + ".smp", sample); + ResourceSaver::save(p_save_path + ".sample", sample); return OK; } diff --git a/editor/io_plugins/editor_font_import_plugin.cpp b/editor/io_plugins/editor_font_import_plugin.cpp index fa66328887..9831e08cf1 100644 --- a/editor/io_plugins/editor_font_import_plugin.cpp +++ b/editor/io_plugins/editor_font_import_plugin.cpp @@ -533,16 +533,16 @@ class EditorFontImportDialog : public ConfirmationDialog { return; } - if (dest->get_line_edit()->get_text().get_file()==".fnt") { - dest->get_line_edit()->set_text(dest->get_line_edit()->get_text().get_base_dir() + "/" + source->get_line_edit()->get_text().get_file().get_basename() + ".fnt" ); + if (dest->get_line_edit()->get_text().get_file()==".font") { + dest->get_line_edit()->set_text(dest->get_line_edit()->get_text().get_base_dir() + "/" + source->get_line_edit()->get_text().get_file().get_basename() + ".font" ); } if (dest->get_line_edit()->get_text().get_extension() == dest->get_line_edit()->get_text()) { - dest->get_line_edit()->set_text(dest->get_line_edit()->get_text() + ".fnt"); + dest->get_line_edit()->set_text(dest->get_line_edit()->get_text() + ".font"); } - if (dest->get_line_edit()->get_text().get_extension().to_lower() != "fnt") { - error_dialog->set_text(TTR("Invalid file extension.\nPlease use .fnt.")); + if (dest->get_line_edit()->get_text().get_extension().to_lower() != "font") { + error_dialog->set_text(TTR("Invalid file extension.\nPlease use .font.")); error_dialog->popup_centered(Size2(200,100)); return; } @@ -665,7 +665,7 @@ public: // List<String> fl; Ref<BitmapFont> font= memnew(BitmapFont); - dest->get_file_dialog()->add_filter("*.fnt ; Font" ); + dest->get_file_dialog()->add_filter("*.font ; Font" ); /* ResourceSaver::get_recognized_extensions(font,&fl); for(List<String>::Element *E=fl.front();E;E=E->next()) { @@ -1690,7 +1690,7 @@ void EditorFontImportPlugin::import_from_drop(const Vector<String>& p_drop, cons if (ext=="ttf" || ext=="otf" || ext=="fnt") { import_dialog(); - dialog->set_source_and_dest(p_drop[i],p_dest_path.plus_file(file.get_basename()+".fnt")); + dialog->set_source_and_dest(p_drop[i],p_dest_path.plus_file(file.get_basename()+".font")); break; } } diff --git a/editor/io_plugins/editor_mesh_import_plugin.cpp b/editor/io_plugins/editor_mesh_import_plugin.cpp index a8ecc2f10e..0c9f3a3f37 100644 --- a/editor/io_plugins/editor_mesh_import_plugin.cpp +++ b/editor/io_plugins/editor_mesh_import_plugin.cpp @@ -262,7 +262,7 @@ public: imd->add_source(EditorImportPlugin::validate_source_path(meshes[i])); - String file_path = dst.plus_file(meshes[i].get_file().get_basename()+".msh"); + String file_path = dst.plus_file(meshes[i].get_file().get_basename()+".mesh"); plugin->import(file_path,imd); } diff --git a/editor/io_plugins/editor_sample_import_plugin.cpp b/editor/io_plugins/editor_sample_import_plugin.cpp index 7836b60fde..0909b96cdc 100644 --- a/editor/io_plugins/editor_sample_import_plugin.cpp +++ b/editor/io_plugins/editor_sample_import_plugin.cpp @@ -299,7 +299,7 @@ public: error_dialog->popup_centered(Size2(200,100)*EDSCALE); } - dst = dst.plus_file(samples[i].get_file().get_basename()+".smp"); + dst = dst.plus_file(samples[i].get_file().get_basename()+".sample"); plugin->import(dst,imd); } @@ -910,13 +910,13 @@ Vector<uint8_t> EditorSampleExportPlugin::custom_export(String& p_path,const Ref imd->set_option("edit/loop",false); imd->set_option("compress/mode",1); - String savepath = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp/smpconv.smp"); + String savepath = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp/smpconv.sample"); Error err = EditorSampleImportPlugin::singleton->import(savepath,imd); ERR_FAIL_COND_V(err!=OK,Vector<uint8_t>()); - p_path=p_path.get_basename()+".converted.smp"; + p_path=p_path.get_basename()+".converted.sample"; return FileAccess::get_file_as_array(savepath); } diff --git a/editor/io_plugins/editor_texture_import_plugin.cpp b/editor/io_plugins/editor_texture_import_plugin.cpp index e860866d24..d48675fa30 100644 --- a/editor/io_plugins/editor_texture_import_plugin.cpp +++ b/editor/io_plugins/editor_texture_import_plugin.cpp @@ -596,7 +596,7 @@ void EditorTextureImportDialog::_mode_changed(int p_mode) { size->show(); file_select->set_mode(EditorFileDialog::MODE_OPEN_FILE); - save_file_select->add_filter("*.ltex;"+TTR("Large Texture")); + save_file_select->add_filter("*.largetex;"+TTR("Large Texture")); texture_options->set_flags(EditorTextureImportPlugin::IMAGE_FLAG_FIX_BORDER_ALPHA|EditorTextureImportPlugin::IMAGE_FLAG_NO_MIPMAPS|EditorTextureImportPlugin::IMAGE_FLAG_FILTER); texture_options->set_quality(0.7); @@ -1097,7 +1097,7 @@ Error EditorTextureImportPlugin::import2(const String& p_path, const Ref<Resourc int cell_size=from->get_option("large_cell_size"); ERR_FAIL_COND_V(cell_size<128 || cell_size>16384,ERR_CANT_OPEN); - EditorProgress pg("ltex",TTR("Import Large Texture"),3); + EditorProgress pg("largetex",TTR("Import Large Texture"),3); pg.step(TTR("Load Source Image"),0); Image img; @@ -1317,9 +1317,9 @@ Error EditorTextureImportPlugin::import2(const String& p_path, const Ref<Resourc String spath = from->get_source_path(E->get()).get_file(); if (p_external) { - apath = p_path.get_base_dir().plus_file(spath.get_basename()+"."+from->get_source_path(E->get()).md5_text()+".atex"); + apath = p_path.get_base_dir().plus_file(spath.get_basename()+"."+from->get_source_path(E->get()).md5_text()+".atlastex"); } else { - apath = p_path.get_base_dir().plus_file(spath.get_basename()+".atex"); + apath = p_path.get_base_dir().plus_file(spath.get_basename()+".atlastex"); } Ref<AtlasTexture> at; diff --git a/editor/io_plugins/editor_translation_import_plugin.cpp b/editor/io_plugins/editor_translation_import_plugin.cpp index caa0659046..5b15b94006 100644 --- a/editor/io_plugins/editor_translation_import_plugin.cpp +++ b/editor/io_plugins/editor_translation_import_plugin.cpp @@ -258,7 +258,7 @@ public: imd->set_option("skip_first",ignore_first->is_pressed()); imd->set_option("compress",compress->is_pressed()); - String savefile = save_path->get_text().plus_file(import_path->get_text().get_file().get_basename()+"."+locale+".xl"); + String savefile = save_path->get_text().plus_file(import_path->get_text().get_file().get_basename()+"."+locale+".translation"); Error err = plugin->import(savefile,imd); if (err!=OK) { error_dialog->set_text(TTR("Couldn't import!")); 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_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp index 17fb953f3f..28c5b89741 100644 --- a/editor/plugins/animation_player_editor_plugin.cpp +++ b/editor/plugins/animation_player_editor_plugin.cpp @@ -1377,19 +1377,18 @@ AnimationPlayerEditor::AnimationPlayerEditor(EditorNode *p_editor) { name_dialog->set_title(TTR("Create New Animation")); name_dialog->set_hide_on_ok(false); add_child(name_dialog); - name = memnew(LineEdit); - name_dialog->add_child(name); - name->set_position(Point2(18, 30)); - name->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 10); - name_dialog->register_text_enter(name); + VBoxContainer *vb = memnew(VBoxContainer); + name_dialog->add_child(vb); l = memnew(Label); l->set_text(TTR("Animation Name:")); - l->set_position(Point2(10, 10)); - - name_dialog->add_child(l); + vb->add_child(l); name_title = l; + name = memnew(LineEdit); + vb->add_child(name); + name_dialog->register_text_enter(name); + error_dialog = memnew(ConfirmationDialog); error_dialog->get_ok()->set_text(TTR("Close")); //error_dialog->get_cancel()->set_text("Close"); 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..11d804422a 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,104 @@ 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"); + img->lock(); - 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++) { + 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 +772,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 +885,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/color_ramp_editor_plugin.cpp b/editor/plugins/gradient_editor_plugin.cpp index 63369e5475..9884db934b 100644 --- a/editor/plugins/color_ramp_editor_plugin.cpp +++ b/editor/plugins/gradient_editor_plugin.cpp @@ -27,15 +27,15 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "color_ramp_editor_plugin.h" +#include "gradient_editor_plugin.h" #include "canvas_item_editor_plugin.h" #include "spatial_editor_plugin.h" -ColorRampEditorPlugin::ColorRampEditorPlugin(EditorNode *p_node) { +GradientEditorPlugin::GradientEditorPlugin(EditorNode *p_node) { editor = p_node; - ramp_editor = memnew(ColorRampEdit); + ramp_editor = memnew(GradientEdit); add_control_to_container(CONTAINER_PROPERTY_EDITOR_BOTTOM, ramp_editor); @@ -44,21 +44,21 @@ ColorRampEditorPlugin::ColorRampEditorPlugin(EditorNode *p_node) { ramp_editor->connect("ramp_changed", this, "ramp_changed"); } -void ColorRampEditorPlugin::edit(Object *p_object) { +void GradientEditorPlugin::edit(Object *p_object) { - ColorRamp *color_ramp = p_object->cast_to<ColorRamp>(); - if (!color_ramp) + Gradient *gradient = p_object->cast_to<Gradient>(); + if (!gradient) return; - color_ramp_ref = Ref<ColorRamp>(color_ramp); - ramp_editor->set_points(color_ramp_ref->get_points()); + gradient_ref = Ref<Gradient>(gradient); + ramp_editor->set_points(gradient_ref->get_points()); } -bool ColorRampEditorPlugin::handles(Object *p_object) const { +bool GradientEditorPlugin::handles(Object *p_object) const { - return p_object->is_class("ColorRamp"); + return p_object->is_class("Gradient"); } -void ColorRampEditorPlugin::make_visible(bool p_visible) { +void GradientEditorPlugin::make_visible(bool p_visible) { if (p_visible) { ramp_editor->show(); @@ -67,43 +67,43 @@ void ColorRampEditorPlugin::make_visible(bool p_visible) { } } -void ColorRampEditorPlugin::_ramp_changed() { +void GradientEditorPlugin::_ramp_changed() { - if (color_ramp_ref.is_valid()) { + if (gradient_ref.is_valid()) { UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); //Not sure if I should convert this data to PoolVector Vector<float> new_offsets = ramp_editor->get_offsets(); Vector<Color> new_colors = ramp_editor->get_colors(); - Vector<float> old_offsets = color_ramp_ref->get_offsets(); - Vector<Color> old_colors = color_ramp_ref->get_colors(); + Vector<float> old_offsets = gradient_ref->get_offsets(); + Vector<Color> old_colors = gradient_ref->get_colors(); if (old_offsets.size() != new_offsets.size()) ur->create_action(TTR("Add/Remove Color Ramp Point")); else ur->create_action(TTR("Modify Color Ramp"), UndoRedo::MERGE_ENDS); - ur->add_do_method(this, "undo_redo_color_ramp", new_offsets, new_colors); - ur->add_undo_method(this, "undo_redo_color_ramp", old_offsets, old_colors); + ur->add_do_method(this, "undo_redo_gradient", new_offsets, new_colors); + ur->add_undo_method(this, "undo_redo_gradient", old_offsets, old_colors); ur->commit_action(); //color_ramp_ref->set_points(ramp_editor->get_points()); } } -void ColorRampEditorPlugin::_undo_redo_color_ramp(const Vector<float> &offsets, +void GradientEditorPlugin::_undo_redo_gradient(const Vector<float> &offsets, const Vector<Color> &colors) { - color_ramp_ref->set_offsets(offsets); - color_ramp_ref->set_colors(colors); - ramp_editor->set_points(color_ramp_ref->get_points()); + gradient_ref->set_offsets(offsets); + gradient_ref->set_colors(colors); + ramp_editor->set_points(gradient_ref->get_points()); ramp_editor->update(); } -ColorRampEditorPlugin::~ColorRampEditorPlugin() { +GradientEditorPlugin::~GradientEditorPlugin() { } -void ColorRampEditorPlugin::_bind_methods() { - ClassDB::bind_method(D_METHOD("ramp_changed"), &ColorRampEditorPlugin::_ramp_changed); - ClassDB::bind_method(D_METHOD("undo_redo_color_ramp", "offsets", "colors"), &ColorRampEditorPlugin::_undo_redo_color_ramp); +void GradientEditorPlugin::_bind_methods() { + ClassDB::bind_method(D_METHOD("ramp_changed"), &GradientEditorPlugin::_ramp_changed); + ClassDB::bind_method(D_METHOD("undo_redo_gradient", "offsets", "colors"), &GradientEditorPlugin::_undo_redo_gradient); } diff --git a/editor/plugins/color_ramp_editor_plugin.h b/editor/plugins/gradient_editor_plugin.h index 73b15b85a1..843e98a917 100644 --- a/editor/plugins/color_ramp_editor_plugin.h +++ b/editor/plugins/gradient_editor_plugin.h @@ -32,21 +32,21 @@ #include "editor/editor_node.h" #include "editor/editor_plugin.h" -#include "scene/gui/color_ramp_edit.h" +#include "scene/gui/gradient_edit.h" -class ColorRampEditorPlugin : public EditorPlugin { +class GradientEditorPlugin : public EditorPlugin { - GDCLASS(ColorRampEditorPlugin, EditorPlugin); + GDCLASS(GradientEditorPlugin, EditorPlugin); bool _2d; - Ref<ColorRamp> color_ramp_ref; - ColorRampEdit *ramp_editor; + Ref<Gradient> gradient_ref; + GradientEdit *ramp_editor; EditorNode *editor; protected: static void _bind_methods(); void _ramp_changed(); - void _undo_redo_color_ramp(const Vector<float> &offsets, const Vector<Color> &colors); + void _undo_redo_gradient(const Vector<float> &offsets, const Vector<Color> &colors); public: virtual String get_name() const { return "ColorRamp"; } @@ -55,8 +55,8 @@ public: virtual bool handles(Object *p_node) const; virtual void make_visible(bool p_visible); - ColorRampEditorPlugin(EditorNode *p_node); - ~ColorRampEditorPlugin(); + GradientEditorPlugin(EditorNode *p_node); + ~GradientEditorPlugin(); }; #endif /* TOOLS_EDITOR_PLUGINS_COLOR_RAMP_EDITOR_PLUGIN_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 f8d250334c..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)) : @@ -94,16 +94,14 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { // Check for point movement start (for point + in/out controls). if (mb->get_button_index() == BUTTON_LEFT) { - if (!mb->get_shift() && mode == MODE_EDIT) { - // Point can only be moved in edit mode. - if (dist_to_p < grab_threshold) { + if (mode == MODE_EDIT && !mb->get_shift() && dist_to_p < grab_threshold) { + // Points can only be moved in edit mode. - action = ACTION_MOVING_POINT; - action_point = i; - moving_from = curve->get_point_pos(i); - moving_screen_from = gpoint; - return true; - } + action = ACTION_MOVING_POINT; + action_point = i; + moving_from = curve->get_point_pos(i); + moving_screen_from = gpoint; + return true; } else if (mode == MODE_EDIT || mode == MODE_EDIT_CURVE) { // In/out controls can be moved in multiple modes. if (dist_to_p_out < grab_threshold && i < (curve->get_point_count() - 1)) { @@ -433,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 12b6dce798..877707d77b 100644 --- a/editor/plugins/path_editor_plugin.cpp +++ b/editor/plugins/path_editor_plugin.cpp @@ -33,61 +33,57 @@ #include "scene/resources/curve.h" #include "spatial_editor_plugin.h" -#if 0 String PathSpatialGizmo::get_handle_name(int p_idx) const { Ref<Curve3D> c = path->get_curve(); if (c.is_null()) return ""; - if (p_idx<c->get_point_count()) { + if (p_idx < c->get_point_count()) { - return TTR("Curve Point #")+itos(p_idx); + return TTR("Curve Point #") + itos(p_idx); } - p_idx=p_idx-c->get_point_count()+1; + p_idx = p_idx - c->get_point_count() + 1; - int idx=p_idx/2; - int t=p_idx%2; - String n = TTR("Curve Point #")+itos(idx); - if (t==0) - n+=" In"; + int idx = p_idx / 2; + int t = p_idx % 2; + String n = TTR("Curve Point #") + itos(idx); + if (t == 0) + n += " In"; else - n+=" Out"; + n += " Out"; return n; - - } -Variant PathSpatialGizmo::get_handle_value(int p_idx) const{ +Variant PathSpatialGizmo::get_handle_value(int p_idx) const { Ref<Curve3D> c = path->get_curve(); if (c.is_null()) return Variant(); - if (p_idx<c->get_point_count()) { + if (p_idx < c->get_point_count()) { - original=c->get_point_pos(p_idx); + original = c->get_point_pos(p_idx); return original; } - p_idx=p_idx-c->get_point_count()+1; + p_idx = p_idx - c->get_point_count() + 1; - int idx=p_idx/2; - int t=p_idx%2; + int idx = p_idx / 2; + int t = p_idx % 2; Vector3 ofs; - if (t==0) - ofs=c->get_point_in(idx); + if (t == 0) + ofs = c->get_point_in(idx); else - ofs= c->get_point_out(idx); + ofs = c->get_point_out(idx); - original=ofs+c->get_point_pos(idx); + original = ofs + c->get_point_pos(idx); return ofs; - } -void PathSpatialGizmo::set_handle(int p_idx,Camera *p_camera, const Point2& p_point){ +void PathSpatialGizmo::set_handle(int p_idx, Camera *p_camera, const Point2 &p_point) { Ref<Curve3D> c = path->get_curve(); if (c.is_null()) @@ -98,51 +94,49 @@ void PathSpatialGizmo::set_handle(int p_idx,Camera *p_camera, const Point2& p_po Vector3 ray_from = p_camera->project_ray_origin(p_point); Vector3 ray_dir = p_camera->project_ray_normal(p_point); - if (p_idx<c->get_point_count()) { + if (p_idx < c->get_point_count()) { - Plane p(gt.xform(original),p_camera->get_transform().basis.get_axis(2)); + Plane p(gt.xform(original), p_camera->get_transform().basis.get_axis(2)); Vector3 inters; - if (p.intersects_ray(ray_from,ray_dir,&inters)) { + if (p.intersects_ray(ray_from, ray_dir, &inters)) { - if(SpatialEditor::get_singleton()->is_snap_enabled()) - { + if (SpatialEditor::get_singleton()->is_snap_enabled()) { float snap = SpatialEditor::get_singleton()->get_translate_snap(); inters.snap(snap); } - + Vector3 local = gi.xform(inters); - c->set_point_pos(p_idx,local); + c->set_point_pos(p_idx, local); } return; } - p_idx=p_idx-c->get_point_count()+1; + p_idx = p_idx - c->get_point_count() + 1; - int idx=p_idx/2; - int t=p_idx%2; + int idx = p_idx / 2; + int t = p_idx % 2; Vector3 base = c->get_point_pos(idx); - Plane p(gt.xform(original),p_camera->get_transform().basis.get_axis(2)); + Plane p(gt.xform(original), p_camera->get_transform().basis.get_axis(2)); Vector3 inters; - if (p.intersects_ray(ray_from,ray_dir,&inters)) { + if (p.intersects_ray(ray_from, ray_dir, &inters)) { - Vector3 local = gi.xform(inters)-base; - if (t==0) { - c->set_point_in(idx,local); + Vector3 local = gi.xform(inters) - base; + if (t == 0) { + c->set_point_in(idx, local); } else { - c->set_point_out(idx,local); + c->set_point_out(idx, local); } } - } -void PathSpatialGizmo::commit_handle(int p_idx,const Variant& p_restore,bool p_cancel){ +void PathSpatialGizmo::commit_handle(int p_idx, const Variant &p_restore, bool p_cancel) { Ref<Curve3D> c = path->get_curve(); if (c.is_null()) @@ -150,67 +144,59 @@ void PathSpatialGizmo::commit_handle(int p_idx,const Variant& p_restore,bool p_c UndoRedo *ur = SpatialEditor::get_singleton()->get_undo_redo(); - if (p_idx<c->get_point_count()) { + if (p_idx < c->get_point_count()) { if (p_cancel) { - c->set_point_pos(p_idx,p_restore); + c->set_point_pos(p_idx, p_restore); return; } ur->create_action(TTR("Set Curve Point Pos")); - ur->add_do_method(c.ptr(),"set_point_pos",p_idx,c->get_point_pos(p_idx)); - ur->add_undo_method(c.ptr(),"set_point_pos",p_idx,p_restore); + ur->add_do_method(c.ptr(), "set_point_pos", p_idx, c->get_point_pos(p_idx)); + ur->add_undo_method(c.ptr(), "set_point_pos", p_idx, p_restore); ur->commit_action(); return; } - p_idx=p_idx-c->get_point_count()+1; + p_idx = p_idx - c->get_point_count() + 1; - int idx=p_idx/2; - int t=p_idx%2; + int idx = p_idx / 2; + int t = p_idx % 2; Vector3 ofs; if (p_cancel) { - - return; } - - - if (t==0) { + if (t == 0) { if (p_cancel) { - c->set_point_in(p_idx,p_restore); + c->set_point_in(p_idx, p_restore); return; } ur->create_action(TTR("Set Curve In Pos")); - ur->add_do_method(c.ptr(),"set_point_in",idx,c->get_point_in(idx)); - ur->add_undo_method(c.ptr(),"set_point_in",idx,p_restore); + ur->add_do_method(c.ptr(), "set_point_in", idx, c->get_point_in(idx)); + ur->add_undo_method(c.ptr(), "set_point_in", idx, p_restore); ur->commit_action(); - } else { if (p_cancel) { - c->set_point_out(idx,p_restore); + c->set_point_out(idx, p_restore); return; } ur->create_action(TTR("Set Curve Out Pos")); - ur->add_do_method(c.ptr(),"set_point_out",idx,c->get_point_out(idx)); - ur->add_undo_method(c.ptr(),"set_point_out",idx,p_restore); + ur->add_do_method(c.ptr(), "set_point_out", idx, c->get_point_out(idx)); + ur->add_undo_method(c.ptr(), "set_point_out", idx, p_restore); ur->commit_action(); - } - } - -void PathSpatialGizmo::redraw(){ +void PathSpatialGizmo::redraw() { clear(); @@ -218,80 +204,76 @@ void PathSpatialGizmo::redraw(){ if (c.is_null()) return; - Vector3Array v3a=c->tesselate(); - //Vector3Array v3a=c->get_baked_points(); + PoolVector<Vector3> v3a = c->tesselate(); + //PoolVector<Vector3> v3a=c->get_baked_points(); int v3s = v3a.size(); - if (v3s==0) + if (v3s == 0) return; Vector<Vector3> v3p; - Vector3Array::Read r = v3a.read(); + PoolVector<Vector3>::Read r = v3a.read(); - for(int i=0;i<v3s-1;i++) { + // BUG: the following won't work when v3s, avoid drawing as a temporary workaround. + for (int i = 0; i < v3s - 1; i++) { v3p.push_back(r[i]); - v3p.push_back(r[i+1]); + v3p.push_back(r[i + 1]); //v3p.push_back(r[i]); //v3p.push_back(r[i]+Vector3(0,0.2,0)); } - add_lines(v3p,PathEditorPlugin::singleton->path_material); + add_lines(v3p, PathEditorPlugin::singleton->path_material); add_collision_segments(v3p); - if (PathEditorPlugin::singleton->get_edited_path()==path) { + if (PathEditorPlugin::singleton->get_edited_path() == path) { v3p.clear(); Vector<Vector3> handles; Vector<Vector3> sec_handles; - for(int i=0;i<c->get_point_count();i++) { + for (int i = 0; i < c->get_point_count(); i++) { Vector3 p = c->get_point_pos(i); handles.push_back(p); - if (i>0) { + if (i > 0) { v3p.push_back(p); - v3p.push_back(p+c->get_point_in(i)); - sec_handles.push_back(p+c->get_point_in(i)); + v3p.push_back(p + c->get_point_in(i)); + sec_handles.push_back(p + c->get_point_in(i)); } - if (i<c->get_point_count()-1) { + if (i < c->get_point_count() - 1) { v3p.push_back(p); - v3p.push_back(p+c->get_point_out(i)); - sec_handles.push_back(p+c->get_point_out(i)); + v3p.push_back(p + c->get_point_out(i)); + sec_handles.push_back(p + c->get_point_out(i)); } } - add_lines(v3p,PathEditorPlugin::singleton->path_thin_material); + add_lines(v3p, PathEditorPlugin::singleton->path_thin_material); add_handles(handles); - add_handles(sec_handles,false,true); + add_handles(sec_handles, false, true); } - } -PathSpatialGizmo::PathSpatialGizmo(Path* p_path){ +PathSpatialGizmo::PathSpatialGizmo(Path *p_path) { - path=p_path; + path = p_path; set_spatial_node(p_path); - - - } -Ref<SpatialEditorGizmo> PathEditorPlugin::create_spatial_gizmo(Spatial* p_spatial) { - +Ref<SpatialEditorGizmo> PathEditorPlugin::create_spatial_gizmo(Spatial *p_spatial) { if (p_spatial->cast_to<Path>()) { - return memnew( PathSpatialGizmo(p_spatial->cast_to<Path>())); + return memnew(PathSpatialGizmo(p_spatial->cast_to<Path>())); } return Ref<SpatialEditorGizmo>(); } -bool PathEditorPlugin::forward_spatial_gui_input(Camera* p_camera,const InputEvent& p_event) { +bool PathEditorPlugin::forward_spatial_gui_input(Camera *p_camera, const Ref<InputEvent> &p_event) { if (!path) return false; - Ref<Curve3D> c=path->get_curve(); + Ref<Curve3D> c = path->get_curve(); if (c.is_null()) return false; Transform gt = path->get_global_transform(); @@ -299,105 +281,99 @@ bool PathEditorPlugin::forward_spatial_gui_input(Camera* p_camera,const InputEve static const int click_dist = 10; //should make global + Ref<InputEventMouseButton> mb = p_event; - if (p_event.type==InputEvent::MOUSE_BUTTON) { + if (mb.is_valid()) { - const InputEventMouseButton &mb=p_event.mouse_button; - 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()))) { + 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 - Vector3Array v3a = c->tesselate(); - int idx=0; - int rc=v3a.size(); - int closest_seg=-1; + PoolVector<Vector3> v3a = c->tesselate(); + int idx = 0; + int rc = v3a.size(); + int closest_seg = -1; Vector3 closest_seg_point; - float closest_d=1e20; + float closest_d = 1e20; - if (rc>=2) { - Vector3Array::Read r = v3a.read(); + if (rc >= 2) { + PoolVector<Vector3>::Read r = v3a.read(); - if (p_camera->unproject_position(gt.xform(c->get_point_pos(0))).distance_to(mbpos)<click_dist) + if (p_camera->unproject_position(gt.xform(c->get_point_pos(0))).distance_to(mbpos) < click_dist) return false; //nope, existing - - for(int i=0;i<c->get_point_count()-1;i++) { + for (int i = 0; i < c->get_point_count() - 1; i++) { //find the offset and point index of the place to break up - int j=idx; - if (p_camera->unproject_position(gt.xform(c->get_point_pos(i+1))).distance_to(mbpos)<click_dist) + int j = idx; + if (p_camera->unproject_position(gt.xform(c->get_point_pos(i + 1))).distance_to(mbpos) < click_dist) return false; //nope, existing + while (j < rc && c->get_point_pos(i + 1) != r[j]) { - while(j<rc && c->get_point_pos(i+1)!=r[j]) { - - Vector3 from =r[j]; - Vector3 to =r[j+1]; + Vector3 from = r[j]; + Vector3 to = r[j + 1]; real_t cdist = from.distance_to(to); - from=gt.xform(from); - to=gt.xform(to); - if (cdist>0) { + from = gt.xform(from); + to = gt.xform(to); + if (cdist > 0) { Vector2 s[2]; s[0] = p_camera->unproject_position(from); s[1] = p_camera->unproject_position(to); - Vector2 inters = Geometry::get_closest_point_to_segment_2d(mbpos,s); + Vector2 inters = Geometry::get_closest_point_to_segment_2d(mbpos, s); float d = inters.distance_to(mbpos); - if (d<10 && d<closest_d) { + if (d < 10 && d < closest_d) { + closest_d = d; + closest_seg = i; + Vector3 ray_from = p_camera->project_ray_origin(mbpos); + Vector3 ray_dir = p_camera->project_ray_normal(mbpos); - closest_d=d; - closest_seg=i; - Vector3 ray_from=p_camera->project_ray_origin(mbpos); - Vector3 ray_dir=p_camera->project_ray_normal(mbpos); + Vector3 ra, rb; + Geometry::get_closest_points_between_segments(ray_from, ray_from + ray_dir * 4096, from, to, ra, rb); - Vector3 ra,rb; - Geometry::get_closest_points_between_segments(ray_from,ray_from+ray_dir*4096,from,to,ra,rb); - - closest_seg_point=it.xform(rb); + closest_seg_point = it.xform(rb); } - } j++; - } - if (idx==j) + if (idx == j) idx++; //force next else - idx=j; //swap + idx = j; //swap - - if (j==rc) + if (j == rc) break; } } UndoRedo *ur = editor->get_undo_redo(); - if (closest_seg!=-1) { + if (closest_seg != -1) { //subdivide ur->create_action(TTR("Split Path")); - ur->add_do_method(c.ptr(),"add_point",closest_seg_point,Vector3(),Vector3(),closest_seg+1); - ur->add_undo_method(c.ptr(),"remove_point",closest_seg+1); + ur->add_do_method(c.ptr(), "add_point", closest_seg_point, Vector3(), Vector3(), closest_seg + 1); + ur->add_undo_method(c.ptr(), "remove_point", closest_seg + 1); ur->commit_action(); return true; } else { Vector3 org; - if (c->get_point_count()==0) - org=path->get_transform().get_origin(); + if (c->get_point_count() == 0) + org = path->get_transform().get_origin(); else - org=gt.xform(c->get_point_pos(c->get_point_count())); - Plane p(org,p_camera->get_transform().basis.get_axis(2)); - Vector3 ray_from=p_camera->project_ray_origin(mbpos); - Vector3 ray_dir=p_camera->project_ray_normal(mbpos); + org = gt.xform(c->get_point_pos(c->get_point_count() - 1)); + Plane p(org, p_camera->get_transform().basis.get_axis(2)); + Vector3 ray_from = p_camera->project_ray_origin(mbpos); + Vector3 ray_dir = p_camera->project_ray_normal(mbpos); Vector3 inters; - if (p.intersects_ray(ray_from,ray_dir,&inters)) { + if (p.intersects_ray(ray_from, ray_dir, &inters)) { ur->create_action(TTR("Add Point to Curve")); - ur->add_do_method(c.ptr(),"add_point",it.xform(inters),Vector3(),Vector3(),-1); - ur->add_undo_method(c.ptr(),"remove_point",c->get_point_count()); + ur->add_do_method(c.ptr(), "add_point", it.xform(inters), Vector3(), Vector3(), -1); + ur->add_undo_method(c.ptr(), "remove_point", c->get_point_count()); ur->commit_action(); return true; } @@ -405,9 +381,9 @@ bool PathEditorPlugin::forward_spatial_gui_input(Camera* p_camera,const InputEve //add new at pos } - } else if (mb->is_pressed() && ((mb->get_button_index()==BUTTON_LEFT && curve_del->is_pressed()) || (mb->get_button_index()==BUTTON_RIGHT && curve_edit->is_pressed()))) { + } else if (mb->is_pressed() && ((mb->get_button_index() == BUTTON_LEFT && curve_del->is_pressed()) || (mb->get_button_index() == BUTTON_RIGHT && curve_edit->is_pressed()))) { - for(int i=0;i<c->get_point_count();i++) { + for (int i = 0; i < c->get_point_count(); i++) { real_t dist_to_p = p_camera->unproject_position(gt.xform(c->get_point_pos(i))).distance_to(mbpos); real_t dist_to_p_out = p_camera->unproject_position(gt.xform(c->get_point_pos(i) + c->get_point_out(i))).distance_to(mbpos); real_t dist_to_p_in = p_camera->unproject_position(gt.xform(c->get_point_pos(i) + c->get_point_in(i))).distance_to(mbpos); @@ -418,40 +394,38 @@ bool PathEditorPlugin::forward_spatial_gui_input(Camera* p_camera,const InputEve UndoRedo *ur = editor->get_undo_redo(); ur->create_action(TTR("Remove Path Point")); - ur->add_do_method(c.ptr(),"remove_point",i); - ur->add_undo_method(c.ptr(),"add_point",c->get_point_pos(i),c->get_point_in(i),c->get_point_out(i),i); + ur->add_do_method(c.ptr(), "remove_point", i); + ur->add_undo_method(c.ptr(), "add_point", c->get_point_pos(i), c->get_point_in(i), c->get_point_out(i), i); ur->commit_action(); return true; } else if (dist_to_p_out < click_dist) { UndoRedo *ur = editor->get_undo_redo(); ur->create_action(TTR("Remove Out-Control Point")); - ur->add_do_method(c.ptr(),"set_point_out",i,Vector3()); - ur->add_undo_method(c.ptr(),"set_point_out",i,c->get_point_out(i)); + ur->add_do_method(c.ptr(), "set_point_out", i, Vector3()); + ur->add_undo_method(c.ptr(), "set_point_out", i, c->get_point_out(i)); ur->commit_action(); return true; } else if (dist_to_p_in < click_dist) { UndoRedo *ur = editor->get_undo_redo(); ur->create_action(TTR("Remove In-Control Point")); - ur->add_do_method(c.ptr(),"set_point_in",i,Vector3()); - ur->add_undo_method(c.ptr(),"set_point_in",i,c->get_point_in(i)); + ur->add_do_method(c.ptr(), "set_point_in", i, Vector3()); + ur->add_undo_method(c.ptr(), "set_point_in", i, c->get_point_in(i)); ur->commit_action(); return true; } } } - } return false; } - void PathEditorPlugin::edit(Object *p_object) { if (p_object) { - path=p_object->cast_to<Path>(); + path = p_object->cast_to<Path>(); if (path) { if (path->get_curve().is_valid()) { @@ -459,8 +433,8 @@ void PathEditorPlugin::edit(Object *p_object) { } } } else { - Path *pre=path; - path=NULL; + Path *pre = path; + path = NULL; if (pre) { pre->get_curve()->emit_signal("changed"); } @@ -470,7 +444,7 @@ void PathEditorPlugin::edit(Object *p_object) { bool PathEditorPlugin::handles(Object *p_object) const { - return p_object->is_type("Path"); + return p_object->is_class("Path"); } void PathEditorPlugin::make_visible(bool p_visible) { @@ -480,120 +454,115 @@ void PathEditorPlugin::make_visible(bool p_visible) { curve_create->show(); curve_edit->show(); curve_del->show(); - curve_close->show(); - sep->show(); + curve_close->show(); + sep->show(); } else { curve_create->hide(); curve_edit->hide(); curve_del->hide(); - curve_close->hide(); - sep->hide(); + curve_close->hide(); + sep->hide(); { - Path *pre=path; - path=NULL; + Path *pre = path; + path = NULL; if (pre && pre->get_curve().is_valid()) { pre->get_curve()->emit_signal("changed"); } } } - } void PathEditorPlugin::_mode_changed(int p_idx) { - curve_create->set_pressed(p_idx==0); - curve_edit->set_pressed(p_idx==1); - curve_del->set_pressed(p_idx==2); + curve_create->set_pressed(p_idx == 0); + curve_edit->set_pressed(p_idx == 1); + curve_del->set_pressed(p_idx == 2); } void PathEditorPlugin::_close_curve() { - Ref<Curve3D> c = path->get_curve(); - if (c.is_null()) - return ; - if (c->get_point_count()<2) - return; - c->add_point(c->get_point_pos(0),c->get_point_in(0),c->get_point_out(0)); - + Ref<Curve3D> c = path->get_curve(); + if (c.is_null()) + return; + if (c->get_point_count() < 2) + return; + c->add_point(c->get_point_pos(0), c->get_point_in(0), c->get_point_out(0)); } void PathEditorPlugin::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_TREE) { + if (p_what == NOTIFICATION_ENTER_TREE) { - curve_create->connect("pressed",this,"_mode_changed",make_binds(0)); - curve_edit->connect("pressed",this,"_mode_changed",make_binds(1)); - curve_del->connect("pressed",this,"_mode_changed",make_binds(2)); - curve_close->connect("pressed",this,"_close_curve"); - } + curve_create->connect("pressed", this, "_mode_changed", make_binds(0)); + curve_edit->connect("pressed", this, "_mode_changed", make_binds(1)); + curve_del->connect("pressed", this, "_mode_changed", make_binds(2)); + curve_close->connect("pressed", this, "_close_curve"); + } } void PathEditorPlugin::_bind_methods() { - ClassDB::bind_method(D_METHOD("_mode_changed"),&PathEditorPlugin::_mode_changed); - ClassDB::bind_method(D_METHOD("_close_curve"),&PathEditorPlugin::_close_curve); + ClassDB::bind_method(D_METHOD("_mode_changed"), &PathEditorPlugin::_mode_changed); + ClassDB::bind_method(D_METHOD("_close_curve"), &PathEditorPlugin::_close_curve); } -PathEditorPlugin* PathEditorPlugin::singleton=NULL; - +PathEditorPlugin *PathEditorPlugin::singleton = NULL; PathEditorPlugin::PathEditorPlugin(EditorNode *p_node) { - path=NULL; - editor=p_node; - singleton=this; + path = NULL; + editor = p_node; + singleton = this; - path_material = Ref<SpatialMaterial>( memnew( SpatialMaterial )); - path_material->set_parameter( SpatialMaterial::PARAM_DIFFUSE,Color(0.5,0.5,1.0,0.8) ); - path_material->set_fixed_flag(SpatialMaterial::FLAG_USE_ALPHA, true); + path_material = Ref<SpatialMaterial>(memnew(SpatialMaterial)); + path_material->set_albedo(Color(0.5, 0.5, 1.0, 0.8)); + path_material->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); path_material->set_line_width(3); - path_material->set_flag(Material::FLAG_DOUBLE_SIDED,true); - path_material->set_flag(Material::FLAG_UNSHADED,true); + path_material->set_cull_mode(SpatialMaterial::CULL_DISABLED); + path_material->set_flag(SpatialMaterial::FLAG_UNSHADED, true); - path_thin_material = Ref<SpatialMaterial>( memnew( SpatialMaterial )); - path_thin_material->set_parameter( SpatialMaterial::PARAM_DIFFUSE,Color(0.5,0.5,1.0,0.4) ); - path_thin_material->set_fixed_flag(SpatialMaterial::FLAG_USE_ALPHA, true); + path_thin_material = Ref<SpatialMaterial>(memnew(SpatialMaterial)); + path_thin_material->set_albedo(Color(0.5, 0.5, 1.0, 0.4)); + path_thin_material->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); path_thin_material->set_line_width(1); - path_thin_material->set_flag(Material::FLAG_DOUBLE_SIDED,true); - path_thin_material->set_flag(Material::FLAG_UNSHADED,true); + path_thin_material->set_cull_mode(SpatialMaterial::CULL_DISABLED); + path_thin_material->set_flag(SpatialMaterial::FLAG_UNSHADED, true); //SpatialEditor::get_singleton()->add_gizmo_plugin(this); - sep = memnew( VSeparator); + sep = memnew(VSeparator); sep->hide(); SpatialEditor::get_singleton()->add_control_to_menu_panel(sep); - curve_edit = memnew( ToolButton ); - curve_edit->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("CurveEdit","EditorIcons")); + curve_edit = memnew(ToolButton); + curve_edit->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("CurveEdit", "EditorIcons")); curve_edit->set_toggle_mode(true); curve_edit->hide(); curve_edit->set_focus_mode(Control::FOCUS_NONE); - curve_edit->set_tooltip(TTR("Select Points")+"\n"+TTR("Shift+Drag: Select Control Points")+"\n"+keycode_get_string(KEY_MASK_CMD)+TTR("Click: Add Point")+"\n"+TTR("Right Click: Delete Point")); + curve_edit->set_tooltip(TTR("Select Points") + "\n" + TTR("Shift+Drag: Select Control Points") + "\n" + keycode_get_string(KEY_MASK_CMD) + TTR("Click: Add Point") + "\n" + TTR("Right Click: Delete Point")); SpatialEditor::get_singleton()->add_control_to_menu_panel(curve_edit); - curve_create = memnew( ToolButton ); - curve_create->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("CurveCreate","EditorIcons")); + curve_create = memnew(ToolButton); + curve_create->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("CurveCreate", "EditorIcons")); curve_create->set_toggle_mode(true); curve_create->hide(); curve_create->set_focus_mode(Control::FOCUS_NONE); - curve_create->set_tooltip(TTR("Add Point (in empty space)")+"\n"+TTR("Split Segment (in curve)")); + curve_create->set_tooltip(TTR("Add Point (in empty space)") + "\n" + TTR("Split Segment (in curve)")); SpatialEditor::get_singleton()->add_control_to_menu_panel(curve_create); - curve_del = memnew( ToolButton ); - curve_del->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("CurveDelete","EditorIcons")); + curve_del = memnew(ToolButton); + curve_del->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("CurveDelete", "EditorIcons")); curve_del->set_toggle_mode(true); curve_del->hide(); curve_del->set_focus_mode(Control::FOCUS_NONE); curve_del->set_tooltip(TTR("Delete Point")); SpatialEditor::get_singleton()->add_control_to_menu_panel(curve_del); - curve_close = memnew( ToolButton ); - curve_close->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("CurveClose","EditorIcons")); + curve_close = memnew(ToolButton); + curve_close->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("CurveClose", "EditorIcons")); curve_close->hide(); curve_close->set_focus_mode(Control::FOCUS_NONE); curve_close->set_tooltip(TTR("Close Curve")); SpatialEditor::get_singleton()->add_control_to_menu_panel(curve_close); - - curve_edit->set_pressed(true); /* collision_polygon_editor = memnew( PathEditor(p_node) ); @@ -607,13 +576,7 @@ PathEditorPlugin::PathEditorPlugin(EditorNode *p_node) { collision_polygon_editor->hide(); */ - - } - -PathEditorPlugin::~PathEditorPlugin() -{ +PathEditorPlugin::~PathEditorPlugin() { } - -#endif diff --git a/editor/plugins/path_editor_plugin.h b/editor/plugins/path_editor_plugin.h index 4dbda10263..651dcdaa78 100644 --- a/editor/plugins/path_editor_plugin.h +++ b/editor/plugins/path_editor_plugin.h @@ -32,30 +32,27 @@ #include "editor/spatial_editor_gizmos.h" #include "scene/3d/path.h" -#if 0 -class PathSpatialGizmo : public EditorSpatialGizmo { - GDCLASS(PathSpatialGizmo,EditorSpatialGizmo); +class PathSpatialGizmo : public EditorSpatialGizmo { - Path* path; + GDCLASS(PathSpatialGizmo, EditorSpatialGizmo); + + Path *path; mutable Vector3 original; public: - virtual String get_handle_name(int p_idx) const; virtual Variant get_handle_value(int p_idx) const; - virtual void set_handle(int p_idx,Camera *p_camera, const Point2& p_point); - virtual void commit_handle(int p_idx,const Variant& p_restore,bool p_cancel=false); + virtual void set_handle(int p_idx, Camera *p_camera, const Point2 &p_point); + virtual void commit_handle(int p_idx, const Variant &p_restore, bool p_cancel = false); void redraw(); - PathSpatialGizmo(Path* p_path=NULL); - + PathSpatialGizmo(Path *p_path = NULL); }; class PathEditorPlugin : public EditorPlugin { - GDCLASS( PathEditorPlugin, EditorPlugin ); - + GDCLASS(PathEditorPlugin, EditorPlugin); Separator *sep; ToolButton *curve_create; @@ -65,26 +62,25 @@ class PathEditorPlugin : public EditorPlugin { EditorNode *editor; - Path *path; void _mode_changed(int p_idx); - void _close_curve(); + void _close_curve(); + protected: void _notification(int p_what); static void _bind_methods(); public: - Path *get_edited_path() { return path; } - static PathEditorPlugin* singleton; + static PathEditorPlugin *singleton; Ref<SpatialMaterial> path_material; Ref<SpatialMaterial> path_thin_material; - virtual bool forward_spatial_gui_input(Camera* p_camera,const InputEvent& p_event); + virtual bool forward_spatial_gui_input(Camera *p_camera, const Ref<InputEvent> &p_event); //virtual bool forward_gui_input(const InputEvent& p_event) { return collision_polygon_editor->forward_gui_input(p_event); } - virtual Ref<SpatialEditorGizmo> create_spatial_gizmo(Spatial* p_spatial); + virtual Ref<SpatialEditorGizmo> create_spatial_gizmo(Spatial *p_spatial); virtual String get_name() const { return "Path"; } bool has_main_screen() const { return false; } virtual void edit(Object *p_node); @@ -93,8 +89,6 @@ public: PathEditorPlugin(EditorNode *p_node); ~PathEditorPlugin(); - }; -#endif #endif // PATH_EDITOR_PLUGIN_H 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 d369064050..f3941d6a16 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -38,7 +38,6 @@ #include "os/file_access.h" #include "os/input.h" #include "os/keyboard.h" -#include "os/keyboard.h" #include "os/os.h" #include "scene/main/viewport.h" @@ -48,6 +47,7 @@ void ScriptEditorBase::_bind_methods() { ADD_SIGNAL(MethodInfo("name_changed")); ADD_SIGNAL(MethodInfo("request_help_search", PropertyInfo(Variant::STRING, "topic"))); + ADD_SIGNAL(MethodInfo("request_help_index")); ADD_SIGNAL(MethodInfo("request_open_script_at_line", PropertyInfo(Variant::OBJECT, "script"), PropertyInfo(Variant::INT, "line"))); ADD_SIGNAL(MethodInfo("request_save_history")); ADD_SIGNAL(MethodInfo("go_to_help", PropertyInfo(Variant::STRING, "what"))); @@ -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"); { @@ -1039,7 +1043,7 @@ void ScriptEditor::_notification(int p_what) { EditorSettings::get_singleton()->connect("settings_changed", this, "_editor_settings_changed"); help_search->set_icon(get_icon("Help", "EditorIcons")); - site_search->set_icon(get_icon("GodotDocs", "EditorIcons")); + site_search->set_icon(get_icon("Instance", "EditorIcons")); class_search->set_icon(get_icon("ClassList", "EditorIcons")); script_forward->set_icon(get_icon("Forward", "EditorIcons")); @@ -1051,6 +1055,7 @@ void ScriptEditor::_notification(int p_what) { get_tree()->connect("tree_changed", this, "_tree_changed"); editor->connect("request_help", this, "_request_help"); editor->connect("request_help_search", this, "_help_search"); + editor->connect("request_help_index", this, "_help_index"); } if (p_what == NOTIFICATION_EXIT_TREE) { @@ -1272,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 @@ -1341,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"); @@ -1484,6 +1530,7 @@ void ScriptEditor::_update_script_names() { } } + _update_members_overview(); _update_script_colors(); } @@ -1732,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); @@ -2028,6 +2078,10 @@ void ScriptEditor::set_live_auto_reload_running_scripts(bool p_enabled) { auto_reload_running_scripts = p_enabled; } +void ScriptEditor::_help_index(String p_text) { + help_index->popup(); +} + void ScriptEditor::_help_search(String p_text) { help_search_dialog->popup(p_text); } @@ -2069,6 +2123,7 @@ void ScriptEditor::_bind_methods() { ClassDB::bind_method("_goto_script_line", &ScriptEditor::_goto_script_line); ClassDB::bind_method("_goto_script_line2", &ScriptEditor::_goto_script_line2); ClassDB::bind_method("_help_search", &ScriptEditor::_help_search); + ClassDB::bind_method("_help_index", &ScriptEditor::_help_index); ClassDB::bind_method("_save_history", &ScriptEditor::_save_history); ClassDB::bind_method("_breaked", &ScriptEditor::_breaked); @@ -2078,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); @@ -2099,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); @@ -2108,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")); @@ -2211,10 +2277,10 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { menu_hb->add_spacer(); site_search = memnew(ToolButton); - site_search->set_text(TTR("Tutorials")); + site_search->set_text(TTR("Online Docs")); site_search->connect("pressed", this, "_menu_option", varray(SEARCH_WEBSITE)); menu_hb->add_child(site_search); - site_search->set_tooltip(TTR("Open https://godotengine.org at tutorials section.")); + site_search->set_tooltip(TTR("Open Godot online documentation")); class_search = memnew(ToolButton); class_search->set_text(TTR("Classes")); diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h index fb2f108277..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); @@ -291,6 +299,7 @@ class ScriptEditor : public VBoxContainer { void _unhandled_input(const Ref<InputEvent> &p_event); void _help_search(String p_text); + void _help_index(String p_text); void _history_forward(); void _history_back(); 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 c4595b477e..2d27e218ec 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(); @@ -696,12 +696,19 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { return; //do NONE { - + EditorNode *en = editor; + EditorPluginList *force_input_forwarding_list = en->get_editor_plugins_force_input_forwarding(); + if (!force_input_forwarding_list->empty()) { + bool discard = force_input_forwarding_list->forward_spatial_gui_input(camera, p_event, true); + if (discard) + return; + } + } + { EditorNode *en = editor; EditorPluginList *over_plugin_list = en->get_editor_plugins_over(); - if (!over_plugin_list->empty()) { - bool discard = over_plugin_list->forward_spatial_gui_input(camera, p_event); + bool discard = over_plugin_list->forward_spatial_gui_input(camera, p_event, false); if (discard) return; } @@ -818,7 +825,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 +870,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 +880,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 +890,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 +898,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 +911,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 +996,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 +1033,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 +1065,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 +1073,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 +1683,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 +1731,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 +1765,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 +1787,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 +1839,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 +1881,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 +2032,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 +2354,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 +2378,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 +2410,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 +2436,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 +2773,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 +2786,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; @@ -2493,17 +2887,11 @@ Dictionary SpatialEditor::get_state() const { d["viewports"] = vpdata; - d["default_light"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_DEFAULT_LIGHT)); - d["ambient_light_color"] = settings_ambient_color->get_pick_color(); - - d["default_srgb"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_DEFAULT_SRGB)); d["show_grid"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_GRID)); d["show_origin"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_ORIGIN)); d["fov"] = get_fov(); d["znear"] = get_znear(); d["zfar"] = get_zfar(); - d["deflight_rot_x"] = settings_default_light_rot_x; - d["deflight_rot_y"] = settings_default_light_rot_y; return d; } @@ -2565,26 +2953,6 @@ void SpatialEditor::set_state(const Dictionary &p_state) { if (d.has("fov")) settings_fov->set_value(float(d["fov"])); - if (d.has("default_light")) { - bool use = d["default_light"]; - - bool existing = light_instance.is_valid(); - if (use != existing) { - if (existing) { - VisualServer::get_singleton()->free(light_instance); - light_instance = RID(); - } else { - light_instance = VisualServer::get_singleton()->instance_create2(light, get_tree()->get_root()->get_world()->get_scenario()); - VisualServer::get_singleton()->instance_set_transform(light_instance, light_transform); - } - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_DEFAULT_LIGHT), light_instance.is_valid()); - } - } - if (d.has("ambient_light_color")) { - settings_ambient_color->set_pick_color(d["ambient_light_color"]); - //viewport_environment->fx_set_param(Environment::FX_PARAM_AMBIENT_LIGHT_COLOR,d["ambient_light_color"]); - } - if (d.has("default_srgb")) { bool use = d["default_srgb"]; @@ -2607,13 +2975,6 @@ void SpatialEditor::set_state(const Dictionary &p_state) { VisualServer::get_singleton()->instance_set_visible(origin_instance, use); } } - - if (d.has("deflight_rot_x")) - settings_default_light_rot_x = d["deflight_rot_x"]; - if (d.has("deflight_rot_y")) - settings_default_light_rot_y = d["deflight_rot_y"]; - - _update_default_light_angle(); } void SpatialEditor::edit(Spatial *p_spatial) { @@ -2750,46 +3111,9 @@ void SpatialEditor::_menu_item_pressed(int p_option) { xform_dialog->popup_centered(Size2(200, 200)); } break; - case MENU_VIEW_USE_DEFAULT_LIGHT: { - - bool is_checked = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(p_option)); - - if (is_checked) { - VisualServer::get_singleton()->free(light_instance); - light_instance = RID(); - } else { - light_instance = VisualServer::get_singleton()->instance_create2(light, get_tree()->get_root()->get_world()->get_scenario()); - VisualServer::get_singleton()->instance_set_transform(light_instance, light_transform); - - _update_default_light_angle(); - } - - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(p_option), light_instance.is_valid()); - - } break; - case MENU_VIEW_USE_DEFAULT_SRGB: { - - bool is_checked = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(p_option)); - - if (is_checked) { - //viewport_environment->set_enable_fx(Environment::FX_SRGB,false); - } else { - //viewport_environment->set_enable_fx(Environment::FX_SRGB,true); - } - - is_checked = !is_checked; - - view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(p_option), is_checked); - - } 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); @@ -2801,17 +3125,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); @@ -2823,17 +3137,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); @@ -2845,21 +3149,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); @@ -2871,21 +3161,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); @@ -2897,22 +3173,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); @@ -2922,43 +3183,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)); @@ -2993,14 +3217,6 @@ void SpatialEditor::_menu_item_pressed(int p_option) { void SpatialEditor::_init_indicators() { - //make sure that the camera indicator is not selectable - light = VisualServer::get_singleton()->light_create(VisualServer::LIGHT_DIRECTIONAL); - //VisualServer::get_singleton()->light_set_shadow( light, true ); - light_instance = VisualServer::get_singleton()->instance_create2(light, get_tree()->get_root()->get_world()->get_scenario()); - - light_transform.rotate(Vector3(1, 0, 0), -Math_PI / 5.0); - VisualServer::get_singleton()->instance_set_transform(light_instance, light_transform); - //RID mat = VisualServer::get_singleton()->fixed_material_create(); ///VisualServer::get_singleton()->fixed_material_set_flag(mat, VisualServer::FIXED_MATERIAL_FLAG_USE_ALPHA,true); //VisualServer::get_singleton()->fixed_material_set_flag(mat, VisualServer::FIXED_MATERIAL_FLAG_USE_COLOR_ARRAY,true); @@ -3128,8 +3344,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); @@ -3258,8 +3474,6 @@ void SpatialEditor::_finish_indicators() { VisualServer::get_singleton()->free(grid_instance[i]); VisualServer::get_singleton()->free(grid[i]); } - VisualServer::get_singleton()->free(light_instance); - VisualServer::get_singleton()->free(light); //VisualServer::get_singleton()->free(poly); //VisualServer::get_singleton()->free(indicators_instance); //VisualServer::get_singleton()->free(indicators); @@ -3317,17 +3531,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); - } - } } } } @@ -3351,14 +3554,12 @@ void SpatialEditor::_notification(int p_what) { _menu_item_pressed(MENU_VIEW_USE_1_VIEWPORT); get_tree()->connect("node_removed", this, "_node_removed"); - VS::get_singleton()->scenario_set_fallback_environment(get_viewport()->find_world()->get_scenario(), viewport_environment->get_rid()); } if (p_what == NOTIFICATION_ENTER_TREE) { gizmos = memnew(SpatialEditorGizmos); _init_indicators(); - _update_default_light_angle(); } if (p_what == NOTIFICATION_EXIT_TREE) { @@ -3481,8 +3682,6 @@ void SpatialEditor::_bind_methods() { ClassDB::bind_method("_xform_dialog_action", &SpatialEditor::_xform_dialog_action); ClassDB::bind_method("_get_editor_data", &SpatialEditor::_get_editor_data); ClassDB::bind_method("_request_gizmo", &SpatialEditor::_request_gizmo); - ClassDB::bind_method("_default_light_angle_input", &SpatialEditor::_default_light_angle_input); - ClassDB::bind_method("_update_ambient_light_color", &SpatialEditor::_update_ambient_light_color); ClassDB::bind_method("_toggle_maximize_view", &SpatialEditor::_toggle_maximize_view); ADD_SIGNAL(MethodInfo("transform_key_request")); @@ -3490,7 +3689,7 @@ void SpatialEditor::_bind_methods() { void SpatialEditor::clear() { - settings_fov->set_value(EDITOR_DEF("editors/3d/default_fov", 60.0)); + settings_fov->set_value(EDITOR_DEF("editors/3d/default_fov", 55.0)); settings_znear->set_value(EDITOR_DEF("editors/3d/default_z_near", 0.1)); settings_zfar->set_value(EDITOR_DEF("editors/3d/default_z_far", 1500.0)); @@ -3498,9 +3697,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) { @@ -3517,43 +3713,6 @@ void SpatialEditor::clear() { } view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_GRID), true); - - settings_default_light_rot_x = Math_PI * 0.3; - settings_default_light_rot_y = Math_PI * 0.2; - - //viewport_environment->fx_set_param(Environment::FX_PARAM_AMBIENT_LIGHT_COLOR,Color(0.15,0.15,0.15)); - settings_ambient_color->set_pick_color(Color(0.15, 0.15, 0.15)); - if (!light_instance.is_valid()) - _menu_item_pressed(MENU_VIEW_USE_DEFAULT_LIGHT); - - _update_default_light_angle(); -} - -void SpatialEditor::_update_ambient_light_color(const Color &p_color) { - - //viewport_environment->fx_set_param(Environment::FX_PARAM_AMBIENT_LIGHT_COLOR,settings_ambient_color->get_color()); -} - -void SpatialEditor::_update_default_light_angle() { - - Transform t; - t.basis.rotate(Vector3(1, 0, 0), -settings_default_light_rot_x); - t.basis.rotate(Vector3(0, 1, 0), -settings_default_light_rot_y); - settings_dlight->set_transform(t); - if (light_instance.is_valid()) { - VS::get_singleton()->instance_set_transform(light_instance, t); - } -} - -void SpatialEditor::_default_light_angle_input(const Ref<InputEvent> &p_event) { - - Ref<InputEventMouseMotion> mm = p_event; - if (mm.is_valid() && mm->get_button_mask() & (0x1 | 0x2 | 0x4)) { - - settings_default_light_rot_y = Math::fposmod(settings_default_light_rot_y - mm->get_relative().x * 0.01, Math_PI * 2.0); - settings_default_light_rot_x = Math::fposmod(settings_default_light_rot_x - mm->get_relative().y * 0.01, Math_PI * 2.0); - _update_default_light_angle(); - } } SpatialEditor::SpatialEditor(EditorNode *p_editor) { @@ -3674,10 +3833,6 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { p = view_menu->get_popup(); - p->add_check_shortcut(ED_SHORTCUT("spatial_editor/use_default_light", TTR("Use Default Light")), MENU_VIEW_USE_DEFAULT_LIGHT); - p->add_check_shortcut(ED_SHORTCUT("spatial_editor/use_default_srgb", TTR("Use Default sRGB")), MENU_VIEW_USE_DEFAULT_SRGB); - p->add_separator(); - p->add_check_shortcut(ED_SHORTCUT("spatial_editor/1_viewport", TTR("1 Viewport"), KEY_MASK_CMD + KEY_1), MENU_VIEW_USE_1_VIEWPORT); p->add_check_shortcut(ED_SHORTCUT("spatial_editor/2_viewports", TTR("2 Viewports"), KEY_MASK_CMD + KEY_2), MENU_VIEW_USE_2_VIEWPORTS); p->add_check_shortcut(ED_SHORTCUT("spatial_editor/2_viewports_alt", TTR("2 Viewports (Alt)"), KEY_MASK_ALT + KEY_MASK_CMD + KEY_2), MENU_VIEW_USE_2_VIEWPORTS_ALT); @@ -3686,18 +3841,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_USE_DEFAULT_LIGHT), true); - 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); @@ -3712,7 +3860,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++) { @@ -3755,41 +3903,11 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { settings_dialog->add_child(settings_vbc); //settings_dialog->set_child_rect(settings_vbc); - settings_light_base = memnew(ViewportContainer); - settings_light_base->set_custom_minimum_size(Size2(128, 128)); - settings_light_base->connect("gui_input", this, "_default_light_angle_input"); - settings_vbc->add_margin_child(TTR("Default Light Normal:"), settings_light_base); - settings_light_vp = memnew(Viewport); - settings_light_vp->set_disable_input(true); - settings_light_vp->set_use_own_world(true); - settings_light_base->add_child(settings_light_vp); - - settings_dlight = memnew(DirectionalLight); - settings_light_vp->add_child(settings_dlight); - settings_sphere = memnew(ImmediateGeometry); - settings_sphere->begin(Mesh::PRIMITIVE_TRIANGLES, Ref<Texture>()); - settings_sphere->set_color(Color(1, 1, 1)); - settings_sphere->add_sphere(32, 16, 1); - settings_sphere->end(); - settings_light_vp->add_child(settings_sphere); - settings_camera = memnew(Camera); - settings_light_vp->add_child(settings_camera); - settings_camera->set_translation(Vector3(0, 0, 2)); - settings_camera->set_orthogonal(2.1, 0.1, 5); - - settings_default_light_rot_x = Math_PI * 0.3; - settings_default_light_rot_y = Math_PI * 0.2; - - settings_ambient_color = memnew(ColorPickerButton); - settings_vbc->add_margin_child(TTR("Ambient Light Color:"), settings_ambient_color); - settings_ambient_color->connect("color_changed", this, "_update_ambient_light_color"); - settings_ambient_color->set_pick_color(Color(0.15, 0.15, 0.15)); - settings_fov = memnew(SpinBox); settings_fov->set_max(179); settings_fov->set_min(1); settings_fov->set_step(0.01); - settings_fov->set_value(EDITOR_DEF("editors/3d/default_fov", 60.0)); + settings_fov->set_value(EDITOR_DEF("editors/3d/default_fov", 55.0)); settings_vbc->add_margin_child(TTR("Perspective FOV (deg.):"), settings_fov); settings_znear = memnew(SpinBox); diff --git a/editor/plugins/spatial_editor_plugin.h b/editor/plugins/spatial_editor_plugin.h index 1f76d9bfb8..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; @@ -321,10 +366,6 @@ private: VisualServer::ScenarioDebugMode scenario_debug; - RID light; - RID light_instance; - Transform light_transform; - RID origin; RID origin_instance; RID grid[3]; @@ -334,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; @@ -383,12 +424,6 @@ private: MENU_VIEW_USE_3_VIEWPORTS, MENU_VIEW_USE_3_VIEWPORTS_ALT, MENU_VIEW_USE_4_VIEWPORTS, - MENU_VIEW_USE_DEFAULT_LIGHT, - MENU_VIEW_USE_DEFAULT_SRGB, - 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, @@ -419,16 +454,6 @@ private: SpinBox *settings_fov; SpinBox *settings_znear; SpinBox *settings_zfar; - DirectionalLight *settings_dlight; - ImmediateGeometry *settings_sphere; - Camera *settings_camera; - float settings_default_light_rot_x; - float settings_default_light_rot_y; - - ViewportContainer *settings_light_base; - Viewport *settings_light_vp; - ColorPickerButton *settings_ambient_color; - Ref<Image> settings_light_dir_image; void _xform_dialog_action(); void _menu_item_pressed(int p_option); @@ -462,10 +487,6 @@ private: SpatialEditorGizmos *gizmos; SpatialEditor(); - void _update_ambient_light_color(const Color &p_color); - void _update_default_light_angle(); - void _default_light_angle_input(const Ref<InputEvent> &p_event); - bool is_any_freelook_active() const; protected: @@ -492,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_editor_plugin.cpp b/editor/plugins/texture_editor_plugin.cpp index 3b705aae24..676e50d61c 100644 --- a/editor/plugins/texture_editor_plugin.cpp +++ b/editor/plugins/texture_editor_plugin.cpp @@ -71,6 +71,8 @@ void TextureEditor::_notification(int p_what) { String format; if (texture->cast_to<ImageTexture>()) { format = Image::get_format_name(texture->cast_to<ImageTexture>()->get_format()); + } else if (texture->cast_to<StreamTexture>()) { + format = Image::get_format_name(texture->cast_to<StreamTexture>()->get_format()); } else { format = texture->get_class(); } 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 50b518afba..a3d3d42110 100644 --- a/editor/project_manager.cpp +++ b/editor/project_manager.cpp @@ -203,10 +203,23 @@ private: f->store_line("\n"); f->store_line("name=\"" + project_name->get_text() + "\""); f->store_line("icon=\"res://icon.png\""); - + f->store_line("[rendering]"); + f->store_line("viewport/default_environment=\"res://default_env.tres\""); memdelete(f); ResourceSaver::save(dir.plus_file("/icon.png"), get_icon("DefaultProjectIcon", "EditorIcons")); + + f = FileAccess::open(dir.plus_file("/default_env.tres"), FileAccess::WRITE); + if (!f) { + error->set_text(TTR("Couldn't create project.godot in project path.")); + } else { + f->store_line("[gd_resource type=\"Environment\" load_steps=2 format=2]"); + f->store_line("[sub_resource type=\"ProceduralSky\" id=1]"); + f->store_line("[resource]"); + f->store_line("background_mode = 2"); + f->store_line("background_sky = SubResource( 1 )"); + memdelete(f); + } } } else if (mode == MODE_INSTALL) { @@ -901,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) { @@ -1456,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..da26c84e45 100644 --- a/editor/property_editor.cpp +++ b/editor/property_editor.cpp @@ -65,6 +65,9 @@ void CustomPropertyEditor::_notification(int p_what) { VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2( 10,10,60, get_size().height-20 ), v ); }*/ } + if (p_what == MainLoop::NOTIFICATION_WM_QUIT_REQUEST) { + hide(); + } } void CustomPropertyEditor::_menu_option(int p_which) { @@ -678,8 +681,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 +736,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 +1542,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 +2313,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 +2323,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 +3545,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 +3677,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 +3863,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 +3945,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 +4052,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 +4065,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 +4143,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_create_dialog.cpp b/editor/script_create_dialog.cpp index 1e86d8db4b..dbd0758256 100644 --- a/editor/script_create_dialog.cpp +++ b/editor/script_create_dialog.cpp @@ -116,6 +116,18 @@ void ScriptCreateDialog::_parent_name_changed(const String &p_parent) { _update_dialog(); } +void ScriptCreateDialog::_template_changed(int p_template) { + + if (p_template == 0) { + //default + script_template = ""; + return; + } + String ext = ScriptServer::get_language(language_menu->get_selected())->get_extension(); + String name = template_menu->get_item_text(p_template) + "." + ext; + script_template = EditorSettings::get_singleton()->get_settings_path() + "/script_templates/" + name; +} + void ScriptCreateDialog::ok_pressed() { if (is_new_script_created) { @@ -134,7 +146,13 @@ void ScriptCreateDialog::_create_new() { if (has_named_classes) cname = class_name->get_text(); - Ref<Script> scr = ScriptServer::get_language(language_menu->get_selected())->get_template(cname, parent_name->get_text()); + Ref<Script> scr; + if (script_template != "") { + scr = ResourceLoader::load(script_template)->duplicate(); + ScriptServer::get_language(language_menu->get_selected())->make_template(cname, parent_name->get_text(), scr); + } else { + scr = ScriptServer::get_language(language_menu->get_selected())->get_template(cname, parent_name->get_text()); + } String selected_language = language_menu->get_item_text(language_menu->get_selected()); editor_settings->set_project_metadata("script_setup", "last_selected_language", selected_language); @@ -175,7 +193,8 @@ void ScriptCreateDialog::_load_exist() { void ScriptCreateDialog::_lang_changed(int l) { l = language_menu->get_selected(); - if (ScriptServer::get_language(l)->has_named_classes()) { + ScriptLanguage *language = ScriptServer::get_language(l); + if (language->has_named_classes()) { has_named_classes = true; } else { has_named_classes = false; @@ -187,7 +206,7 @@ void ScriptCreateDialog::_lang_changed(int l) { can_inherit_from_file = false; } - String selected_ext = "." + ScriptServer::get_language(l)->get_extension(); + String selected_ext = "." + language->get_extension(); String path = file_path->get_text(); String extension = ""; if (path != "") { @@ -204,7 +223,7 @@ void ScriptCreateDialog::_lang_changed(int l) { List<String> extensions; // get all possible extensions for script for (int l = 0; l < language_menu->get_item_count(); l++) { - ScriptServer::get_language(l)->get_recognized_extensions(&extensions); + language->get_recognized_extensions(&extensions); } for (List<String>::Element *E = extensions.front(); E; E = E->next()) { @@ -218,6 +237,18 @@ void ScriptCreateDialog::_lang_changed(int l) { file_path->set_text(path); } + bool use_templates = language->is_using_templates(); + template_menu->set_disabled(!use_templates); + if (use_templates) { + Vector<String> template_list = EditorSettings::get_singleton()->get_script_templates(language->get_extension()); + + template_menu->clear(); + template_menu->add_item(TTR("Default")); + for (int i = 0; i < template_list.size(); i++) { + template_menu->add_item(template_list[i]); + } + } + _update_dialog(); } @@ -471,6 +502,7 @@ void ScriptCreateDialog::_bind_methods() { ClassDB::bind_method("_browse_path", &ScriptCreateDialog::_browse_path); ClassDB::bind_method("_file_selected", &ScriptCreateDialog::_file_selected); ClassDB::bind_method("_path_changed", &ScriptCreateDialog::_path_changed); + ClassDB::bind_method("_template_changed", &ScriptCreateDialog::_template_changed); ADD_SIGNAL(MethodInfo("script_created", PropertyInfo(Variant::OBJECT, "script", PROPERTY_HINT_RESOURCE_TYPE, "Script"))); } @@ -539,10 +571,12 @@ ScriptCreateDialog::ScriptCreateDialog() { /* Margins */ empty_h = memnew(Control); + empty_h->set_name("empty_h"); //duplicate() doesn't like nodes without a name empty_h->set_h_size_flags(Control::SIZE_EXPAND_FILL); empty_h->set_v_size_flags(Control::SIZE_EXPAND_FILL); empty_h->set_custom_minimum_size(Size2(0, 10 * EDSCALE)); empty_v = memnew(Control); + empty_v->set_name("empty_v"); empty_v->set_h_size_flags(Control::SIZE_EXPAND_FILL); empty_v->set_v_size_flags(Control::SIZE_EXPAND_FILL); empty_v->set_custom_minimum_size(Size2(10, 0 * EDSCALE)); @@ -627,6 +661,16 @@ ScriptCreateDialog::ScriptCreateDialog() { gc->add_child(l); gc->add_child(class_name); + /* Templates */ + + template_menu = memnew(OptionButton); + l = memnew(Label); + l->set_text(TTR("Template")); + l->set_align(Label::ALIGN_RIGHT); + gc->add_child(l); + gc->add_child(template_menu); + template_menu->connect("item_selected", this, "_template_changed"); + /* Built-in Script */ internal = memnew(CheckButton); diff --git a/editor/script_create_dialog.h b/editor/script_create_dialog.h index 862d4f88f2..1adbfe3f7d 100644 --- a/editor/script_create_dialog.h +++ b/editor/script_create_dialog.h @@ -48,6 +48,7 @@ class ScriptCreateDialog : public ConfirmationDialog { LineEdit *parent_name; Button *parent_browse_button; OptionButton *language_menu; + OptionButton *template_menu; LineEdit *file_path; Button *path_button; EditorFileDialog *file_browse; @@ -68,6 +69,7 @@ class ScriptCreateDialog : public ConfirmationDialog { bool is_built_in; int current_language; bool re_check_path; + String script_template; void _path_changed(const String &p_path = String()); void _lang_changed(int l = 0); @@ -75,6 +77,7 @@ class ScriptCreateDialog : public ConfirmationDialog { bool _validate(const String &p_strin); void _class_name_changed(const String &p_name); void _parent_name_changed(const String &p_parent); + void _template_changed(int p_template = 0); void _browse_path(bool browse_parent); void _file_selected(const String &p_file); virtual void ok_pressed(); diff --git a/editor/script_editor_debugger.cpp b/editor/script_editor_debugger.cpp index a2bb3a0879..6d22935dcb 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; @@ -1035,14 +1035,17 @@ void ScriptEditorDebugger::start() { EditorNode::get_singleton()->make_bottom_panel_item_visible(this); } - uint16_t port = GLOBAL_GET("network/debug/remote_port"); perf_history.clear(); for (int i = 0; i < Performance::MONITOR_MAX; i++) { perf_max[i] = 0; } - server->listen(port); + int remote_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port"); + if (server->listen(remote_port) != OK) { + EditorNode::get_log()->add_message(String("** Error listening on port ") + itos(remote_port) + String(" **")); + return; + } set_process(true); } diff --git a/editor/spatial_editor_gizmos.cpp b/editor/spatial_editor_gizmos.cpp index 4781bb6a3b..76df9eb1ff 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()); } @@ -1439,20 +1439,6 @@ VehicleWheelSpatialGizmo::VehicleWheelSpatialGizmo(VehicleWheel *p_car_wheel) { car_wheel = p_car_wheel; } -/// - -void TestCubeSpatialGizmo::redraw() { - - clear(); - add_collision_triangles(SpatialEditorGizmos::singleton->test_cube_tm); -} - -TestCubeSpatialGizmo::TestCubeSpatialGizmo(TestCube *p_tc) { - - tc = p_tc; - set_spatial_node(p_tc); -} - /////////// String CollisionShapeSpatialGizmo::get_handle_name(int p_idx) const { @@ -1722,8 +1708,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 +1939,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 +1950,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 +1988,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 +2039,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 +2051,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 +2062,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 +2101,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 +2204,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 +2213,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 +2227,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 +2248,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 +2378,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 +2407,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 +2497,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; @@ -3045,12 +3031,6 @@ Ref<SpatialEditorGizmo> SpatialEditorGizmos::get_gizmo(Spatial *p_spatial) { return misg; } - if (p_spatial->cast_to<TestCube>()) { - - Ref<TestCubeSpatialGizmo> misg = memnew(TestCubeSpatialGizmo(p_spatial->cast_to<TestCube>())); - return misg; - } - if (p_spatial->cast_to<CollisionShape>()) { Ref<CollisionShapeSpatialGizmo> misg = memnew(CollisionShapeSpatialGizmo(p_spatial->cast_to<CollisionShape>())); @@ -3213,7 +3193,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 +3226,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..a8ace87530 100644 --- a/editor/spatial_editor_gizmos.h +++ b/editor/spatial_editor_gizmos.h @@ -46,7 +46,6 @@ #include "scene/3d/ray_cast.h" #include "scene/3d/reflection_probe.h" #include "scene/3d/room_instance.h" -#include "scene/3d/test_cube.h" #include "scene/3d/vehicle_body.h" #include "scene/3d/visibility_notifier.h" @@ -59,7 +58,7 @@ class EditorSpatialGizmo : public SpatialEditorGizmo { struct Instance { RID instance; - Ref<Mesh> mesh; + Ref<ArrayMesh> mesh; RID skeleton; bool billboard; bool unscaled; @@ -97,7 +96,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); @@ -187,17 +186,6 @@ public: SkeletonSpatialGizmo(Skeleton *p_skel = NULL); }; -class TestCubeSpatialGizmo : public EditorSpatialGizmo { - - GDCLASS(TestCubeSpatialGizmo, EditorSpatialGizmo); - - TestCube *tc; - -public: - void redraw(); - TestCubeSpatialGizmo(TestCube *p_tc = NULL); -}; - class RoomSpatialGizmo : public EditorSpatialGizmo { GDCLASS(RoomSpatialGizmo, EditorSpatialGizmo); @@ -454,8 +442,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; |