summaryrefslogtreecommitdiff
path: root/editor/project_manager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/project_manager.cpp')
-rw-r--r--editor/project_manager.cpp136
1 files changed, 96 insertions, 40 deletions
diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp
index cfb42c0741..78f6fe58d0 100644
--- a/editor/project_manager.cpp
+++ b/editor/project_manager.cpp
@@ -30,6 +30,7 @@
#include "project_manager.h"
+#include "core/config/project_settings.h"
#include "core/io/config_file.h"
#include "core/io/dir_access.h"
#include "core/io/file_access.h"
@@ -40,11 +41,11 @@
#include "core/os/os.h"
#include "core/string/translation.h"
#include "core/version.h"
-#include "core/version_hash.gen.h"
+#include "editor/editor_file_dialog.h"
+#include "editor/editor_scale.h"
+#include "editor/editor_settings.h"
+#include "editor/editor_themes.h"
#include "editor/editor_vcs_interface.h"
-#include "editor_scale.h"
-#include "editor_settings.h"
-#include "editor_themes.h"
#include "scene/gui/center_container.h"
#include "scene/gui/line_edit.h"
#include "scene/gui/margin_container.h"
@@ -54,6 +55,7 @@
#include "scene/main/window.h"
#include "servers/display_server.h"
#include "servers/navigation_server_3d.h"
+#include "servers/physics_server_2d.h"
static inline String get_project_key_from_path(const String &dir) {
return dir.replace("/", "::");
@@ -99,8 +101,8 @@ private:
LineEdit *install_path;
TextureRect *status_rect;
TextureRect *install_status_rect;
- FileDialog *fdialog;
- FileDialog *fdialog_install;
+ EditorFileDialog *fdialog;
+ EditorFileDialog *fdialog_install;
OptionButton *vcs_metadata_selection;
String zip_path;
String zip_title;
@@ -364,19 +366,19 @@ private:
fdialog->set_current_dir(project_path->get_text());
if (mode == MODE_IMPORT) {
- fdialog->set_file_mode(FileDialog::FILE_MODE_OPEN_FILE);
+ fdialog->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
fdialog->clear_filters();
fdialog->add_filter(vformat("project.godot ; %s %s", VERSION_NAME, TTR("Project")));
fdialog->add_filter("*.zip ; " + TTR("ZIP File"));
} else {
- fdialog->set_file_mode(FileDialog::FILE_MODE_OPEN_DIR);
+ fdialog->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_DIR);
}
fdialog->popup_file_dialog();
}
void _browse_install_path() {
fdialog_install->set_current_dir(install_path->get_text());
- fdialog_install->set_file_mode(FileDialog::FILE_MODE_OPEN_DIR);
+ fdialog_install->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_DIR);
fdialog_install->popup_file_dialog();
}
@@ -645,8 +647,10 @@ private:
}
void _notification(int p_what) {
- if (p_what == NOTIFICATION_WM_CLOSE_REQUEST) {
- _remove_created_folder();
+ switch (p_what) {
+ case NOTIFICATION_WM_CLOSE_REQUEST: {
+ _remove_created_folder();
+ } break;
}
}
@@ -924,12 +928,15 @@ public:
spacer->set_h_size_flags(Control::SIZE_EXPAND_FILL);
default_files_container->add_child(spacer);
- fdialog = memnew(FileDialog);
- fdialog->set_access(FileDialog::ACCESS_FILESYSTEM);
- fdialog_install = memnew(FileDialog);
- fdialog_install->set_access(FileDialog::ACCESS_FILESYSTEM);
+ fdialog = memnew(EditorFileDialog);
+ fdialog->set_previews_enabled(false); //Crucial, otherwise the engine crashes.
+ fdialog->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
+ fdialog_install = memnew(EditorFileDialog);
+ fdialog_install->set_previews_enabled(false); //Crucial, otherwise the engine crashes.
+ fdialog_install->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
add_child(fdialog);
add_child(fdialog_install);
+
project_name->connect("text_changed", callable_mp(this, &ProjectDialog::_text_changed));
project_path->connect("text_changed", callable_mp(this, &ProjectDialog::_path_text_changed));
install_path->connect("text_changed", callable_mp(this, &ProjectDialog::_path_text_changed));
@@ -973,10 +980,12 @@ public:
hover = true;
update();
} break;
+
case NOTIFICATION_MOUSE_EXIT: {
hover = false;
update();
} break;
+
case NOTIFICATION_DRAW: {
if (hover) {
draw_style_box(get_theme_stylebox(SNAME("hover"), SNAME("Tree")), Rect2(Point2(), get_size()));
@@ -1048,6 +1057,8 @@ public:
}
};
+ bool project_opening_initiated;
+
ProjectList();
~ProjectList();
@@ -1127,6 +1138,7 @@ ProjectList::ProjectList() {
add_child(_scroll_children);
_icon_load_index = 0;
+ project_opening_initiated = false;
}
ProjectList::~ProjectList() {
@@ -1138,18 +1150,20 @@ void ProjectList::update_icons_async() {
}
void ProjectList::_notification(int p_what) {
- if (p_what == NOTIFICATION_PROCESS) {
- // Load icons as a coroutine to speed up launch when you have hundreds of projects
- if (_icon_load_index < _projects.size()) {
- Item &item = _projects.write[_icon_load_index];
- if (item.control->icon_needs_reload) {
- load_project_icon(_icon_load_index);
- }
- _icon_load_index++;
+ switch (p_what) {
+ case NOTIFICATION_PROCESS: {
+ // Load icons as a coroutine to speed up launch when you have hundreds of projects
+ if (_icon_load_index < _projects.size()) {
+ Item &item = _projects.write[_icon_load_index];
+ if (item.control->icon_needs_reload) {
+ load_project_icon(_icon_load_index);
+ }
+ _icon_load_index++;
- } else {
- set_process(false);
- }
+ } else {
+ set_process(false);
+ }
+ } break;
}
}
@@ -1807,7 +1821,9 @@ void ProjectList::_panel_input(const Ref<InputEvent> &p_ev, Node *p_hb) {
emit_signal(SNAME(SIGNAL_SELECTION_CHANGED));
- if (!mb->is_ctrl_pressed() && mb->is_double_click()) {
+ // Do not allow opening a project more than once using a single project manager instance.
+ // Opening the same project in several editor instances at once can lead to various issues.
+ if (!mb->is_ctrl_pressed() && mb->is_double_click() && !project_opening_initiated) {
emit_signal(SNAME(SIGNAL_PROJECT_ASK_OPEN));
}
}
@@ -1858,6 +1874,8 @@ void ProjectList::_bind_methods() {
ADD_SIGNAL(MethodInfo(SIGNAL_PROJECT_ASK_OPEN));
}
+ProjectManager *ProjectManager::singleton = nullptr;
+
void ProjectManager::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_TRANSLATION_CHANGED:
@@ -1865,17 +1883,20 @@ void ProjectManager::_notification(int p_what) {
settings_hb->set_anchors_and_offsets_preset(Control::PRESET_TOP_RIGHT);
update();
} break;
+
case NOTIFICATION_ENTER_TREE: {
search_box->set_right_icon(get_theme_icon(SNAME("Search"), SNAME("EditorIcons")));
search_box->set_clear_button_enabled(true);
Engine::get_singleton()->set_editor_hint(false);
} break;
+
case NOTIFICATION_RESIZED: {
if (open_templates->is_visible()) {
open_templates->popup_centered();
}
} break;
+
case NOTIFICATION_READY: {
int default_sorting = (int)EditorSettings::get_singleton()->get("project_manager/sorting_order");
filter_option->select(default_sorting);
@@ -1891,18 +1912,36 @@ void ProjectManager::_notification(int p_what) {
search_box->grab_focus();
}
} break;
+
case NOTIFICATION_VISIBILITY_CHANGED: {
set_process_unhandled_key_input(is_visible_in_tree());
} break;
+
case NOTIFICATION_WM_CLOSE_REQUEST: {
_dim_window();
} break;
+
case NOTIFICATION_WM_ABOUT: {
_show_about();
} break;
}
}
+Ref<Texture2D> ProjectManager::_file_dialog_get_icon(const String &p_path) {
+ return singleton->icon_type_cache["ObjectHR"];
+}
+
+void ProjectManager::_build_icon_type_cache(Ref<Theme> p_theme) {
+ List<StringName> tl;
+ p_theme->get_icon_list(SNAME("EditorIcons"), &tl);
+ for (List<StringName>::Element *E = tl.front(); E; E = E->next()) {
+ if (!ClassDB::class_exists(E->get())) {
+ continue;
+ }
+ icon_type_cache[E->get()] = p_theme->get_icon(E->get(), SNAME("EditorIcons"));
+ }
+}
+
void ProjectManager::_dim_window() {
// This method must be called before calling `get_tree()->quit()`.
// Otherwise, its effect won't be visible
@@ -2106,6 +2145,8 @@ void ProjectManager::_open_selected_projects() {
ERR_FAIL_COND(err);
}
+ _project_list->project_opening_initiated = true;
+
_dim_window();
get_tree()->quit();
}
@@ -2459,6 +2500,8 @@ void ProjectManager::_version_button_pressed() {
}
ProjectManager::ProjectManager() {
+ singleton = this;
+
// load settings
if (!EditorSettings::get_singleton()) {
EditorSettings::create();
@@ -2501,20 +2544,13 @@ ProjectManager::ProjectManager() {
editor_set_scale(EditorSettings::get_singleton()->get("interface/editor/custom_display_scale"));
break;
}
-
- // Define a minimum window size to prevent UI elements from overlapping or being cut off
- DisplayServer::get_singleton()->window_set_min_size(Size2(750, 420) * EDSCALE);
-
- // TODO: Resize windows on hiDPI displays on Windows and Linux and remove the lines below
- float scale_factor = MAX(1, EDSCALE);
- Vector2i window_size = DisplayServer::get_singleton()->window_get_size();
- DisplayServer::get_singleton()->window_set_size(Vector2i(window_size.x * scale_factor, window_size.y * scale_factor));
+ EditorFileDialog::get_icon_func = &ProjectManager::_file_dialog_get_icon;
}
// TRANSLATORS: This refers to the application where users manage their Godot projects.
DisplayServer::get_singleton()->window_set_title(VERSION_NAME + String(" - ") + TTR("Project Manager"));
- FileDialog::set_default_show_hidden_files(EditorSettings::get_singleton()->get("filesystem/file_dialog/show_hidden_files"));
+ EditorFileDialog::set_default_show_hidden_files(EditorSettings::get_singleton()->get("filesystem/file_dialog/show_hidden_files"));
set_anchors_and_offsets_preset(Control::PRESET_WIDE);
set_theme(create_custom_theme());
@@ -2537,7 +2573,7 @@ ProjectManager::ProjectManager() {
tabs = memnew(TabContainer);
center_box->add_child(tabs);
tabs->set_anchors_and_offsets_preset(Control::PRESET_WIDE);
- tabs->set_tab_alignment(TabContainer::ALIGNMENT_LEFT);
+ tabs->set_tab_alignment(TabBar::ALIGNMENT_LEFT);
tabs->connect("tab_changed", callable_mp(this, &ProjectManager::_on_tab_changed));
HBoxContainer *projects_hb = memnew(HBoxContainer);
@@ -2745,9 +2781,10 @@ ProjectManager::ProjectManager() {
language_restart_ask->get_cancel_button()->set_text(TTR("Continue"));
add_child(language_restart_ask);
- scan_dir = memnew(FileDialog);
- scan_dir->set_access(FileDialog::ACCESS_FILESYSTEM);
- scan_dir->set_file_mode(FileDialog::FILE_MODE_OPEN_DIR);
+ scan_dir = memnew(EditorFileDialog);
+ scan_dir->set_previews_enabled(false);
+ scan_dir->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
+ scan_dir->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_DIR);
scan_dir->set_title(TTR("Select a Folder to Scan")); // must be after mode or it's overridden
scan_dir->set_current_dir(EditorSettings::get_singleton()->get("filesystem/directories/default_project_path"));
add_child(scan_dir);
@@ -2811,6 +2848,8 @@ ProjectManager::ProjectManager() {
about = memnew(EditorAbout);
add_child(about);
+
+ _build_icon_type_cache(get_theme());
}
_load_recent_projects();
@@ -2839,10 +2878,27 @@ ProjectManager::ProjectManager() {
SceneTree::get_singleton()->get_root()->connect("files_dropped", callable_mp(this, &ProjectManager::_files_dropped));
+ // Define a minimum window size to prevent UI elements from overlapping or being cut off
+ DisplayServer::get_singleton()->window_set_min_size(Size2(750, 420) * EDSCALE);
+
+ // Resize the bootsplash window based on Editor display scale EDSCALE.
+ float scale_factor = MAX(1, EDSCALE);
+ if (scale_factor > 1.0) {
+ Vector2i window_size = DisplayServer::get_singleton()->window_get_size();
+ Vector2i screen_size = DisplayServer::get_singleton()->screen_get_size();
+ window_size *= scale_factor;
+ Vector2i window_position;
+ window_position.x = (screen_size.x - window_size.x) / 2;
+ window_position.y = (screen_size.y - window_size.y) / 2;
+ DisplayServer::get_singleton()->window_set_size(window_size);
+ DisplayServer::get_singleton()->window_set_position(window_position);
+ }
+
OS::get_singleton()->set_low_processor_usage_mode(true);
}
ProjectManager::~ProjectManager() {
+ singleton = nullptr;
if (EditorSettings::get_singleton()) {
EditorSettings::destroy();
}