0.2.0-dev Download ZIP
202 lines ·7.4 KB Raw
| 1 | /**************************************************************************/ |
| 2 | /* editor_main_screen.cpp */ |
| 3 | /**************************************************************************/ |
| 4 | /* This file is part of: */ |
| 5 | /* GODOT ENGINE */ |
| 6 | /* https://godotengine.org */ |
| 7 | /**************************************************************************/ |
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
| 10 | /* */ |
| 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
| 12 | /* a copy of this software and associated documentation files (the */ |
| 13 | /* "Software"), to deal in the Software without restriction, including */ |
| 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
| 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
| 16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
| 17 | /* the following conditions: */ |
| 18 | /* */ |
| 19 | /* The above copyright notice and this permission notice shall be */ |
| 20 | /* included in all copies or substantial portions of the Software. */ |
| 21 | /* */ |
| 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
| 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
| 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
| 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
| 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
| 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
| 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 29 | /**************************************************************************/ |
| 30 | |
| 31 | #include "editor_main_screen.h" |
| 32 | |
| 33 | #include "core/object/callable_mp.h" |
| 34 | #include "editor/docks/editor_dock.h" |
| 35 | #include "editor/docks/editor_dock_manager.h" |
| 36 | #include "editor/editor_node.h" |
| 37 | #include "editor/plugins/editor_plugin.h" |
| 38 | #include "editor/scene/3d/node_3d_editor_plugin.h" |
| 39 | #include "editor/script/script_editor_plugin.h" |
| 40 | #include "editor/settings/editor_settings.h" |
| 41 | #include "editor/themes/editor_scale.h" |
| 42 | |
| 43 | #ifndef DISABLE_DEPRECATED |
| 44 | void LegacyMainScreenContainer::_force_dock_visible(EditorDock *p_dock, CanvasItem *p_child) { |
| 45 | if (p_dock->is_visible_in_tree()) { |
| 46 | p_child->show(); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | void LegacyMainScreenContainer::add_child_notify(Node *p_child) { |
| 51 | EditorMainScreen *ms = EditorNode::get_editor_main_screen(); |
| 52 | if (!ms->adding_plugin || !ms->adding_plugin->has_main_screen()) { |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | EditorDock *dock = memnew(EditorDock); |
| 57 | dock->set_default_slot(EditorDock::DOCK_SLOT_MAIN_SCREEN); |
| 58 | dock->set_available_layouts(EditorDock::DOCK_LAYOUT_MAIN_SCREEN); |
| 59 | dock->set_title(ms->adding_plugin->get_plugin_name()); |
| 60 | dock->set_dock_icon(ms->adding_plugin->get_plugin_icon()); |
| 61 | dock->set_icon_name(ms->adding_plugin->get_plugin_name()); |
| 62 | EditorDockManager::get_singleton()->add_dock(dock); |
| 63 | |
| 64 | ms->adding_plugin->set_meta("_dock", dock); |
| 65 | |
| 66 | CanvasItem *ci_child = Object::cast_to<CanvasItem>(p_child); |
| 67 | if (ci_child) { |
| 68 | ci_child->show(); |
| 69 | dock->connect(SceneStringName(visibility_changed), callable_mp(this, &LegacyMainScreenContainer::_force_dock_visible).bind(dock, ci_child)); |
| 70 | } |
| 71 | |
| 72 | callable_mp(p_child, &Node::reparent).call_deferred(dock, false); |
| 73 | } |
| 74 | #endif |
| 75 | |
| 76 | void EditorMainScreen::_on_tab_changed(int p_tab) { |
| 77 | EditorNode::get_singleton()->update_distraction_free_mode(); |
| 78 | |
| 79 | EditorDock *dock = get_dock(p_tab); |
| 80 | if (!dock) { |
| 81 | return; |
| 82 | } |
| 83 | const String new_main_screen = dock->get_display_title(); |
| 84 | |
| 85 | EditorData &editor_data = EditorNode::get_editor_data(); |
| 86 | int plugin_count = editor_data.get_editor_plugin_count(); |
| 87 | for (int i = 0; i < plugin_count; i++) { |
| 88 | editor_data.get_editor_plugin(i)->notify_main_screen_changed(new_main_screen); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | void EditorMainScreen::_notification(int p_what) { |
| 93 | switch (p_what) { |
| 94 | case NOTIFICATION_POSTINITIALIZE: { |
| 95 | set_tab_alignment(TabBar::ALIGNMENT_CENTER); |
| 96 | get_internal_container()->set_alignment(BoxContainer::ALIGNMENT_CENTER); |
| 97 | connect("tab_changed", callable_mp(this, &EditorMainScreen::_on_tab_changed)); |
| 98 | } break; |
| 99 | |
| 100 | case NOTIFICATION_READY: { |
| 101 | set_popup(nullptr); |
| 102 | |
| 103 | for (int i = 0; i < get_tab_count(); i++) { |
| 104 | EditorDock *dock = get_dock(i); |
| 105 | if (dock == Node3DEditor::get_singleton()) { |
| 106 | dock->make_visible(); |
| 107 | break; |
| 108 | } |
| 109 | } |
| 110 | } break; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | DockTabContainer::TabStyle EditorMainScreen::get_tab_style() const { |
| 115 | return (TabStyle)EDITOR_GET("interface/editor/docks/main_screen_dock_tab_style").operator int(); |
| 116 | } |
| 117 | |
| 118 | Rect2 EditorMainScreen::get_drag_hint_rect() const { |
| 119 | const Rect2 tab_rect = get_internal_container()->get_global_rect(); |
| 120 | const Rect2 content_rect = get_global_rect(); |
| 121 | Rect2 final_rect = tab_rect.merge(content_rect); |
| 122 | if (get_tab_count() > 0) { |
| 123 | float tab_x = get_tab_bar()->get_global_transform().xform(get_tab_bar()->get_tab_rect(0).position).x; |
| 124 | final_rect.position.x = MIN(tab_x, content_rect.position.x); |
| 125 | tab_x = get_tab_bar()->get_global_transform().xform(get_tab_bar()->get_tab_rect(-1).get_end()).x; |
| 126 | final_rect.set_end(Vector2(MAX(tab_x, content_rect.get_end().x), final_rect.get_end().y)); |
| 127 | } |
| 128 | return final_rect; |
| 129 | } |
| 130 | |
| 131 | bool EditorMainScreen::can_switch_dock() const { |
| 132 | if (get_current_tab() == -1) { |
| 133 | return true; |
| 134 | } |
| 135 | EditorDock *dock = get_dock(get_current_tab()); |
| 136 | return dock->is_allow_switch_screen(); |
| 137 | } |
| 138 | |
| 139 | void EditorMainScreen::select_next() { |
| 140 | if (get_tab_count() == 0) { |
| 141 | return; |
| 142 | } |
| 143 | if (get_current_tab() < get_tab_count() - 1) { |
| 144 | set_current_tab(get_current_tab() + 1); |
| 145 | } else { |
| 146 | set_current_tab(0); |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | void EditorMainScreen::select_prev() { |
| 151 | if (get_tab_count() == 0) { |
| 152 | return; |
| 153 | } |
| 154 | if (get_current_tab() > 0) { |
| 155 | set_current_tab(get_current_tab() - 1); |
| 156 | } else { |
| 157 | set_current_tab(get_tab_count() - 1); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | #ifndef DISABLE_DEPRECATED |
| 162 | VBoxContainer *EditorMainScreen::get_control() const { |
| 163 | return main_screen_vbox; |
| 164 | } |
| 165 | |
| 166 | void EditorMainScreen::add_main_plugin(EditorPlugin *p_editor) { |
| 167 | editor_table.push_back(p_editor); |
| 168 | } |
| 169 | |
| 170 | void EditorMainScreen::remove_main_plugin(EditorPlugin *p_editor) { |
| 171 | if (p_editor->has_meta("_dock")) { |
| 172 | EditorDock *dock = Object::cast_to<EditorDock>(p_editor->get_meta("_dock").get_validated_object()); |
| 173 | if (dock) { |
| 174 | EditorDockManager::get_singleton()->remove_dock(dock); |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | editor_table.erase(p_editor); |
| 179 | } |
| 180 | #endif |
| 181 | |
| 182 | EditorMainScreen::EditorMainScreen() : |
| 183 | DockTabContainer(EditorDock::DOCK_SLOT_MAIN_SCREEN) { |
| 184 | layout = EditorDock::DOCK_LAYOUT_MAIN_SCREEN; |
| 185 | grid_rect = Rect2i(2, 0, 4, 4); |
| 186 | |
| 187 | set_theme_type_variation("MainScreenContainer"); |
| 188 | set_custom_minimum_size(Size2(0, 80) * EDSCALE); |
| 189 | set_v_size_flags(Control::SIZE_EXPAND_FILL); |
| 190 | set_draw_behind_parent(true); |
| 191 | get_tab_bar()->set_mouse_filter(Control::MOUSE_FILTER_PASS); |
| 192 | |
| 193 | #ifndef DISABLE_DEPRECATED |
| 194 | main_screen_vbox = memnew(LegacyMainScreenContainer); |
| 195 | main_screen_vbox->hide(); |
| 196 | EditorNode::get_singleton()->get_gui_base()->add_child(main_screen_vbox); |
| 197 | #endif |
| 198 | |
| 199 | Ref<StyleBoxEmpty> sb; |
| 200 | sb.instantiate(); |
| 201 | add_theme_style_override(SceneStringName(panel), sb); |
| 202 | } |