diff options
author | volzhs <volzhs@gmail.com> | 2017-06-16 00:30:03 +0900 |
---|---|---|
committer | volzhs <volzhs@gmail.com> | 2017-06-16 13:21:05 +0900 |
commit | fc2fe7ebd1ed54318ca82a3d20bb8892d9bd7fd2 (patch) | |
tree | 1c008c9e41f6c45f2d369f3382604bfce8bdf657 /editor | |
parent | 95c248e24fb6094160f9c71140402305b57469ab (diff) |
Enhance scene tabs
- show scene thumbnail on hover
- resize if has many tabs
- show full scene file name with current edited scene
- can be customized EditorSettings > Interface > Scene Tab
- close scene with mouse middle button
Diffstat (limited to 'editor')
-rw-r--r-- | editor/editor_data.cpp | 7 | ||||
-rw-r--r-- | editor/editor_node.cpp | 69 | ||||
-rw-r--r-- | editor/editor_node.h | 6 | ||||
-rw-r--r-- | editor/editor_settings.cpp | 6 | ||||
-rw-r--r-- | editor/editor_themes.cpp | 2 |
5 files changed, 88 insertions, 2 deletions
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_node.cpp b/editor/editor_node.cpp index 6587e4fe09..d912d187fc 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -342,6 +342,12 @@ 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")); + 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(); } } @@ -4269,7 +4275,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()); @@ -4760,7 +4806,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>(); @@ -4837,6 +4882,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); @@ -5181,13 +5230,31 @@ 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"); HBoxContainer *tabbar_container = memnew(HBoxContainer); scene_tabs->set_h_size_flags(Control::SIZE_EXPAND_FILL); diff --git a/editor/editor_node.h b/editor/editor_node.h index bb5b57a454..0f4561572a 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -233,6 +233,8 @@ private: //main tabs Tabs *scene_tabs; + Panel *tab_preview_panel; + TextureRect *tab_preview; int tab_closing; bool exiting; @@ -556,6 +558,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(); diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index 07c7fe97e4..c2fb700b9e 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -522,6 +522,12 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { 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", ""); diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp index b6952c3024..e6df58bc60 100644 --- a/editor/editor_themes.cpp +++ b/editor/editor_themes.cpp @@ -307,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); |