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.cpp720
1 files changed, 393 insertions, 327 deletions
diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp
index 7fcabb1e80..249504b6e8 100644
--- a/editor/project_manager.cpp
+++ b/editor/project_manager.cpp
@@ -35,18 +35,21 @@
#include "core/io/dir_access.h"
#include "core/io/file_access.h"
#include "core/io/resource_saver.h"
-#include "core/io/stream_peer_ssl.h"
+#include "core/io/stream_peer_tls.h"
#include "core/io/zip_io.h"
#include "core/os/keyboard.h"
#include "core/os/os.h"
#include "core/string/translation.h"
#include "core/version.h"
#include "editor/editor_file_dialog.h"
+#include "editor/editor_paths.h"
#include "editor/editor_scale.h"
#include "editor/editor_settings.h"
#include "editor/editor_themes.h"
#include "editor/editor_vcs_interface.h"
+#include "main/main.h"
#include "scene/gui/center_container.h"
+#include "scene/gui/check_box.h"
#include "scene/gui/line_edit.h"
#include "scene/gui/margin_container.h"
#include "scene/gui/panel_container.h"
@@ -57,9 +60,7 @@
#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("/", "::");
-}
+constexpr int GODOT4_CONFIG_VERSION = 5;
class ProjectDialog : public ConfirmationDialog {
GDCLASS(ProjectDialog, ConfirmationDialog);
@@ -92,9 +93,9 @@ private:
Container *name_container;
Container *path_container;
Container *install_path_container;
- Container *rasterizer_container;
+ Container *renderer_container;
HBoxContainer *default_files_container;
- Ref<ButtonGroup> rasterizer_button_group;
+ Ref<ButtonGroup> renderer_button_group;
Label *msg;
LineEdit *project_path;
LineEdit *project_name;
@@ -143,7 +144,11 @@ private:
install_status_rect->set_texture(new_icon);
}
- set_size(Size2i(500, 0) * EDSCALE);
+ Size2i window_size = get_size();
+ Size2 contents_min_size = get_contents_minimum_size();
+ if (window_size.x < contents_min_size.x || window_size.y < contents_min_size.y) {
+ set_size(window_size.max(contents_min_size));
+ }
}
String _test_path() {
@@ -362,8 +367,8 @@ private:
if (mode == MODE_IMPORT) {
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"));
+ fdialog->add_filter("project.godot", vformat("%s %s", VERSION_NAME, TTR("Project")));
+ fdialog->add_filter("*.zip", TTR("ZIP File"));
} else {
fdialog->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_DIR);
}
@@ -431,17 +436,17 @@ private:
return;
}
- ProjectSettings *current = memnew(ProjectSettings);
-
- int err = current->setup(dir2, "");
+ // Load project.godot as ConfigFile to set the new name.
+ ConfigFile cfg;
+ String project_godot = dir2.path_join("project.godot");
+ Error err = cfg.load(project_godot);
if (err != OK) {
- set_message(vformat(TTR("Couldn't load project.godot in project path (error %d). It may be missing or corrupted."), err), MESSAGE_ERROR);
+ set_message(vformat(TTR("Couldn't load project at '%s' (error %d). It may be missing or corrupted."), project_godot, err), MESSAGE_ERROR);
} else {
- ProjectSettings::CustomMap edited_settings;
- edited_settings["application/config/name"] = project_name->get_text().strip_edges();
-
- if (current->save_custom(dir2.plus_file("project.godot"), edited_settings, Vector<String>(), true) != OK) {
- set_message(TTR("Couldn't edit project.godot in project path."), MESSAGE_ERROR);
+ cfg.set_value("application", "config/name", project_name->get_text().strip_edges());
+ err = cfg.save(project_godot);
+ if (err != OK) {
+ set_message(vformat(TTR("Couldn't save project at '%s' (error %d)."), project_godot, err), MESSAGE_ERROR);
}
}
@@ -473,25 +478,36 @@ private:
}
PackedStringArray project_features = ProjectSettings::get_required_features();
ProjectSettings::CustomMap initial_settings;
+
// Be sure to change this code if/when renderers are changed.
- int renderer_type = rasterizer_button_group->get_pressed_button()->get_meta(SNAME("driver_name"));
- initial_settings["rendering/vulkan/rendering/back_end"] = renderer_type;
- if (renderer_type == 0) {
- project_features.push_back("Vulkan Clustered");
- } else if (renderer_type == 1) {
- project_features.push_back("Vulkan Mobile");
+ String renderer_type = renderer_button_group->get_pressed_button()->get_meta(SNAME("rendering_method"));
+ initial_settings["rendering/renderer/rendering_method"] = renderer_type;
+
+ if (renderer_type == "forward_plus") {
+ project_features.push_back("Forward Plus");
+ } else if (renderer_type == "mobile") {
+ project_features.push_back("Mobile");
} else {
WARN_PRINT("Unknown renderer type. Please report this as a bug on GitHub.");
}
+
project_features.sort();
initial_settings["application/config/features"] = project_features;
initial_settings["application/config/name"] = project_name->get_text().strip_edges();
- initial_settings["application/config/icon"] = "res://icon.png";
+ initial_settings["application/config/icon"] = "res://icon.svg";
- if (ProjectSettings::get_singleton()->save_custom(dir.plus_file("project.godot"), initial_settings, Vector<String>(), false) != OK) {
+ if (ProjectSettings::get_singleton()->save_custom(dir.path_join("project.godot"), initial_settings, Vector<String>(), false) != OK) {
set_message(TTR("Couldn't create project.godot in project path."), MESSAGE_ERROR);
} else {
- ResourceSaver::save(dir.plus_file("icon.png"), create_unscaled_default_project_icon());
+ // Store default project icon in SVG format.
+ Error err;
+ Ref<FileAccess> fa_icon = FileAccess::open(dir.path_join("icon.svg"), FileAccess::WRITE, &err);
+ fa_icon->store_string(get_default_project_icon());
+
+ if (err != OK) {
+ set_message(TTR("Couldn't create icon.svg in project path."), MESSAGE_ERROR);
+ }
+
EditorVCSInterface::create_vcs_metadata_files(EditorVCSInterface::VCSMetadata(vcs_metadata_selection->get_selected()), dir);
}
} else if (mode == MODE_INSTALL) {
@@ -531,7 +547,6 @@ private:
Vector<String> failed_files;
- int idx = 0;
while (ret == UNZ_OK) {
//get filename
unz_file_info info;
@@ -550,27 +565,26 @@ private:
String rel_path = path.substr(zip_root.length());
Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
- da->make_dir(dir.plus_file(rel_path));
+ da->make_dir(dir.path_join(rel_path));
} else {
- Vector<uint8_t> data;
- data.resize(info.uncompressed_size);
+ Vector<uint8_t> uncomp_data;
+ uncomp_data.resize(info.uncompressed_size);
String rel_path = path.substr(zip_root.length());
//read
unzOpenCurrentFile(pkg);
- ret = unzReadCurrentFile(pkg, data.ptrw(), data.size());
+ ret = unzReadCurrentFile(pkg, uncomp_data.ptrw(), uncomp_data.size());
ERR_BREAK_MSG(ret < 0, vformat("An error occurred while attempting to read from file: %s. This file will not be used.", rel_path));
unzCloseCurrentFile(pkg);
- Ref<FileAccess> f = FileAccess::open(dir.plus_file(rel_path), FileAccess::WRITE);
+ Ref<FileAccess> f = FileAccess::open(dir.path_join(rel_path), FileAccess::WRITE);
if (f.is_valid()) {
- f->store_buffer(data.ptr(), data.size());
+ f->store_buffer(uncomp_data.ptr(), uncomp_data.size());
} else {
failed_files.push_back(rel_path);
}
}
- idx++;
ret = unzGoToNextFile(pkg);
}
@@ -600,9 +614,6 @@ private:
if (dir.ends_with("/")) {
dir = dir.substr(0, dir.length() - 1);
}
- String proj = get_project_key_from_path(dir);
- EditorSettings::get_singleton()->set("projects/" + proj, dir);
- EditorSettings::get_singleton()->save();
hide();
emit_signal(SNAME("project_created"), dir);
@@ -646,14 +657,6 @@ private:
protected:
static void _bind_methods() {
- ClassDB::bind_method("_browse_path", &ProjectDialog::_browse_path);
- ClassDB::bind_method("_create_folder", &ProjectDialog::_create_folder);
- ClassDB::bind_method("_text_changed", &ProjectDialog::_text_changed);
- ClassDB::bind_method("_path_text_changed", &ProjectDialog::_path_text_changed);
- ClassDB::bind_method("_path_selected", &ProjectDialog::_path_selected);
- ClassDB::bind_method("_file_selected", &ProjectDialog::_file_selected);
- ClassDB::bind_method("_install_path_selected", &ProjectDialog::_install_path_selected);
- ClassDB::bind_method("_browse_install_path", &ProjectDialog::_browse_install_path);
ADD_SIGNAL(MethodInfo("project_created"));
ADD_SIGNAL(MethodInfo("projects_updated"));
}
@@ -681,28 +684,29 @@ public:
install_browse->hide();
set_title(TTR("Rename Project"));
- get_ok_button()->set_text(TTR("Rename"));
+ set_ok_button_text(TTR("Rename"));
name_container->show();
status_rect->hide();
msg->hide();
install_path_container->hide();
install_status_rect->hide();
- rasterizer_container->hide();
+ renderer_container->hide();
default_files_container->hide();
get_ok_button()->set_disabled(false);
- ProjectSettings *current = memnew(ProjectSettings);
-
- int err = current->setup(project_path->get_text(), "");
+ // Fetch current name from project.godot to prefill the text input.
+ ConfigFile cfg;
+ String project_godot = project_path->get_text().path_join("project.godot");
+ Error err = cfg.load(project_godot);
if (err != OK) {
- set_message(vformat(TTR("Couldn't load project.godot in project path (error %d). It may be missing or corrupted."), err), MESSAGE_ERROR);
+ set_message(vformat(TTR("Couldn't load project at '%s' (error %d). It may be missing or corrupted."), project_godot, err), MESSAGE_ERROR);
status_rect->show();
msg->show();
get_ok_button()->set_disabled(true);
- } else if (current->has_setting("application/config/name")) {
- String proj = current->get("application/config/name");
- project_name->set_text(proj);
- _text_changed(proj);
+ } else {
+ String cur_name = cfg.get_value("application", "config/name", "");
+ project_name->set_text(cur_name);
+ _text_changed(cur_name);
}
project_name->call_deferred(SNAME("grab_focus"));
@@ -710,7 +714,7 @@ public:
create_dir->hide();
} else {
- fav_dir = EditorSettings::get_singleton()->get("filesystem/directories/default_project_path");
+ fav_dir = EDITOR_GET("filesystem/directories/default_project_path");
if (!fav_dir.is_empty()) {
project_path->set_text(fav_dir);
fdialog->set_current_dir(fav_dir);
@@ -735,30 +739,30 @@ public:
if (mode == MODE_IMPORT) {
set_title(TTR("Import Existing Project"));
- get_ok_button()->set_text(TTR("Import & Edit"));
+ set_ok_button_text(TTR("Import & Edit"));
name_container->hide();
install_path_container->hide();
- rasterizer_container->hide();
+ renderer_container->hide();
default_files_container->hide();
project_path->grab_focus();
} else if (mode == MODE_NEW) {
set_title(TTR("Create New Project"));
- get_ok_button()->set_text(TTR("Create & Edit"));
+ set_ok_button_text(TTR("Create & Edit"));
name_container->show();
install_path_container->hide();
- rasterizer_container->show();
+ renderer_container->show();
default_files_container->show();
project_name->call_deferred(SNAME("grab_focus"));
project_name->call_deferred(SNAME("select_all"));
} else if (mode == MODE_INSTALL) {
set_title(TTR("Install Project:") + " " + zip_title);
- get_ok_button()->set_text(TTR("Install & Edit"));
+ set_ok_button_text(TTR("Install & Edit"));
project_name->set_text(zip_title);
name_container->show();
install_path_container->hide();
- rasterizer_container->hide();
+ renderer_container->hide();
default_files_container->hide();
project_path->grab_focus();
}
@@ -766,7 +770,7 @@ public:
_test_path();
}
- popup_centered(Size2i(500, 0) * EDSCALE);
+ popup_centered(Size2(500, 0) * EDSCALE);
}
ProjectDialog() {
@@ -846,23 +850,23 @@ public:
msg->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
vb->add_child(msg);
- // rasterizer selection
- rasterizer_container = memnew(VBoxContainer);
- vb->add_child(rasterizer_container);
+ // Renderer selection.
+ renderer_container = memnew(VBoxContainer);
+ vb->add_child(renderer_container);
l = memnew(Label);
l->set_text(TTR("Renderer:"));
- rasterizer_container->add_child(l);
- Container *rshb = memnew(HBoxContainer);
- rasterizer_container->add_child(rshb);
- rasterizer_button_group.instantiate();
+ renderer_container->add_child(l);
+ HBoxContainer *rshc = memnew(HBoxContainer);
+ renderer_container->add_child(rshc);
+ renderer_button_group.instantiate();
Container *rvb = memnew(VBoxContainer);
rvb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- rshb->add_child(rvb);
+ rshc->add_child(rvb);
Button *rs_button = memnew(CheckBox);
- rs_button->set_button_group(rasterizer_button_group);
- rs_button->set_text(TTR("Vulkan Clustered"));
- rs_button->set_meta(SNAME("driver_name"), 0); // Vulkan backend "Forward Clustered"
+ rs_button->set_button_group(renderer_button_group);
+ rs_button->set_text(TTR("Forward+"));
+ rs_button->set_meta(SNAME("rendering_method"), "forward_plus");
rs_button->set_pressed(true);
rvb->add_child(rs_button);
l = memnew(Label);
@@ -874,15 +878,15 @@ public:
l->set_modulate(Color(1, 1, 1, 0.7));
rvb->add_child(l);
- rshb->add_child(memnew(VSeparator));
+ rshc->add_child(memnew(VSeparator));
rvb = memnew(VBoxContainer);
rvb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- rshb->add_child(rvb);
+ rshc->add_child(rvb);
rs_button = memnew(CheckBox);
- rs_button->set_button_group(rasterizer_button_group);
- rs_button->set_text(TTR("Vulkan Mobile"));
- rs_button->set_meta(SNAME("driver_name"), 1); // Vulkan backend "Forward Mobile"
+ rs_button->set_button_group(renderer_button_group);
+ rs_button->set_text(TTR("Mobile"));
+ rs_button->set_meta(SNAME("rendering_method"), "mobile");
rvb->add_child(rs_button);
l = memnew(Label);
l->set_text(
@@ -900,7 +904,7 @@ public:
l->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
l->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
l->set_modulate(Color(1, 1, 1, 0.7));
- rasterizer_container->add_child(l);
+ renderer_container->add_child(l);
default_files_container = memnew(HBoxContainer);
vb->add_child(default_files_container);
@@ -967,12 +971,12 @@ public:
switch (p_what) {
case NOTIFICATION_MOUSE_ENTER: {
hover = true;
- update();
+ queue_redraw();
} break;
case NOTIFICATION_MOUSE_EXIT: {
hover = false;
- update();
+ queue_redraw();
} break;
case NOTIFICATION_DRAW: {
@@ -997,7 +1001,6 @@ public:
// Can often be passed by copy
struct Item {
- String project_key;
String project_name;
String description;
String path;
@@ -1014,8 +1017,7 @@ public:
Item() {}
- Item(const String &p_project,
- const String &p_name,
+ Item(const String &p_name,
const String &p_description,
const String &p_path,
const String &p_icon,
@@ -1026,7 +1028,6 @@ public:
bool p_grayed,
bool p_missing,
int p_version) {
- project_key = p_project;
project_name = p_name;
description = p_description;
path = p_path;
@@ -1042,7 +1043,7 @@ public:
}
_FORCE_INLINE_ bool operator==(const Item &l) const {
- return project_key == l.project_key;
+ return path == l.path;
}
};
@@ -1055,6 +1056,7 @@ public:
void _global_menu_open_project(const Variant &p_tag);
void update_dock_menu();
+ void migrate_config();
void load_projects();
void set_search_term(String p_search_term);
void set_order_option(int p_option);
@@ -1070,6 +1072,9 @@ public:
bool is_any_project_missing() const;
void erase_missing_projects();
int refresh_project(const String &dir_path);
+ void add_project(const String &dir_path, bool favorite);
+ void save_config();
+ void set_project_version(const String &p_project_path, int version);
private:
static void _bind_methods();
@@ -1090,12 +1095,15 @@ private:
String _search_term;
FilterOption _order_option;
- HashSet<String> _selected_project_keys;
+ HashSet<String> _selected_project_paths;
String _last_clicked; // Project key
VBoxContainer *_scroll_children;
int _icon_load_index;
Vector<Item> _projects;
+
+ ConfigFile _config;
+ String _config_path;
};
struct ProjectListComparator {
@@ -1111,7 +1119,7 @@ struct ProjectListComparator {
}
switch (order_option) {
case PATH:
- return a.project_key < b.project_key;
+ return a.path < b.path;
case EDIT_DATE:
return a.last_edited > b.last_edited;
default:
@@ -1128,6 +1136,7 @@ ProjectList::ProjectList() {
_icon_load_index = 0;
project_opening_initiated = false;
+ _config_path = EditorPaths::get_singleton()->get_data_dir().path_join("projects.cfg");
}
ProjectList::~ProjectList() {
@@ -1167,23 +1176,26 @@ void ProjectList::load_project_icon(int p_index) {
Error err = img->load(item.icon.replace_first("res://", item.path + "/"));
if (err == OK) {
img->resize(default_icon->get_width(), default_icon->get_height(), Image::INTERPOLATE_LANCZOS);
- Ref<ImageTexture> it = memnew(ImageTexture);
- it->create_from_image(img);
- icon = it;
+ icon = ImageTexture::create_from_image(img);
}
}
if (icon.is_null()) {
icon = default_icon;
}
+ // The default project icon is 128×128 to look crisp on hiDPI displays,
+ // but we want the actual displayed size to be 64×64 on loDPI displays.
+ item.control->icon->set_ignore_texture_size(true);
+ item.control->icon->set_custom_minimum_size(Size2(64, 64) * EDSCALE);
+ item.control->icon->set_stretch_mode(TextureRect::STRETCH_KEEP_ASPECT_CENTERED);
+
item.control->icon->set_texture(icon);
item.control->icon_needs_reload = false;
}
// Load project data from p_property_key and return it in a ProjectList::Item. p_favorite is passed directly into the Item.
-ProjectList::Item ProjectList::load_project_data(const String &p_property_key, bool p_favorite) {
- String path = EditorSettings::get_singleton()->get(p_property_key);
- String conf = path.plus_file("project.godot");
+ProjectList::Item ProjectList::load_project_data(const String &p_path, bool p_favorite) {
+ String conf = p_path.path_join("project.godot");
bool grayed = false;
bool missing = false;
@@ -1219,7 +1231,7 @@ ProjectList::Item ProjectList::load_project_data(const String &p_property_key, b
// when editing a project (but not when running it).
last_edited = FileAccess::get_modified_time(conf);
- String fscache = path.plus_file(".fscache");
+ String fscache = p_path.path_join(".fscache");
if (FileAccess::exists(fscache)) {
uint64_t cache_modified = FileAccess::get_modified_time(fscache);
if (cache_modified > last_edited) {
@@ -1232,9 +1244,39 @@ ProjectList::Item ProjectList::load_project_data(const String &p_property_key, b
print_line("Project is missing: " + conf);
}
- const String project_key = p_property_key.get_slice("/", 1);
+ return Item(project_name, description, p_path, icon, main_scene, unsupported_features, last_edited, p_favorite, grayed, missing, config_version);
+}
+
+void ProjectList::migrate_config() {
+ // Proposal #1637 moved the project list from editor settings to a separate config file
+ // If the new config file doesn't exist, populate it from EditorSettings
+ if (FileAccess::exists(_config_path)) {
+ return;
+ }
+
+ List<PropertyInfo> properties;
+ EditorSettings::get_singleton()->get_property_list(&properties);
+
+ for (const PropertyInfo &E : properties) {
+ // This is actually something like "projects/C:::Documents::Godot::Projects::MyGame"
+ String property_key = E.name;
+ if (!property_key.begins_with("projects/")) {
+ continue;
+ }
+
+ String path = EDITOR_GET(property_key);
+ print_line("Migrating legacy project '" + path + "'.");
+
+ String favoriteKey = "favorite_projects/" + property_key.get_slice("/", 1);
+ bool favorite = EditorSettings::get_singleton()->has_setting(favoriteKey);
+ add_project(path, favorite);
+ if (favorite) {
+ EditorSettings::get_singleton()->erase(favoriteKey);
+ }
+ EditorSettings::get_singleton()->erase(property_key);
+ }
- return Item(project_key, project_name, description, path, icon, main_scene, unsupported_features, last_edited, p_favorite, grayed, missing, config_version);
+ save_config();
}
void ProjectList::load_projects() {
@@ -1249,37 +1291,15 @@ void ProjectList::load_projects() {
}
_projects.clear();
_last_clicked = "";
- _selected_project_keys.clear();
-
- // Load data
- // TODO Would be nice to change how projects and favourites are stored... it complicates things a bit.
- // Use a dictionary associating project path to metadata (like is_favorite).
+ _selected_project_paths.clear();
- List<PropertyInfo> properties;
- EditorSettings::get_singleton()->get_property_list(&properties);
+ List<String> sections;
+ _config.load(_config_path);
+ _config.get_sections(&sections);
- HashSet<String> favorites;
- // Find favourites...
- for (const PropertyInfo &E : properties) {
- String property_key = E.name;
- if (property_key.begins_with("favorite_projects/")) {
- favorites.insert(property_key);
- }
- }
-
- for (const PropertyInfo &E : properties) {
- // This is actually something like "projects/C:::Documents::Godot::Projects::MyGame"
- String property_key = E.name;
- if (!property_key.begins_with("projects/")) {
- continue;
- }
-
- String project_key = property_key.get_slice("/", 1);
- bool favorite = favorites.has("favorite_projects/" + project_key);
-
- Item item = load_project_data(property_key, favorite);
-
- _projects.push_back(item);
+ for (const String &path : sections) {
+ bool favorite = _config.get_value(path, "favorite", false);
+ _projects.push_back(load_project_data(path, favorite));
}
// Create controls
@@ -1312,7 +1332,7 @@ void ProjectList::update_dock_menu() {
}
favs_added = 0;
}
- DisplayServer::get_singleton()->global_menu_add_item("_dock", _projects[i].project_name + " ( " + _projects[i].path + " )", callable_mp(this, &ProjectList::_global_menu_open_project), i);
+ DisplayServer::get_singleton()->global_menu_add_item("_dock", _projects[i].project_name + " ( " + _projects[i].path + " )", callable_mp(this, &ProjectList::_global_menu_open_project), Callable(), i);
total_added++;
}
}
@@ -1332,7 +1352,7 @@ void ProjectList::_global_menu_open_project(const Variant &p_tag) {
int idx = (int)p_tag;
if (idx >= 0 && idx < _projects.size()) {
- String conf = _projects[idx].path.plus_file("project.godot");
+ String conf = _projects[idx].path.path_join("project.godot");
List<String> args;
args.push_back(conf);
OS::get_singleton()->create_instance(args);
@@ -1350,19 +1370,19 @@ void ProjectList::create_project_item_control(int p_index) {
Color font_color = get_theme_color(SNAME("font_color"), SNAME("Tree"));
ProjectListItemControl *hb = memnew(ProjectListItemControl);
- hb->connect("draw", callable_mp(this, &ProjectList::_panel_draw), varray(hb));
- hb->connect("gui_input", callable_mp(this, &ProjectList::_panel_input), varray(hb));
+ hb->connect("draw", callable_mp(this, &ProjectList::_panel_draw).bind(hb));
+ hb->connect("gui_input", callable_mp(this, &ProjectList::_panel_input).bind(hb));
hb->add_theme_constant_override("separation", 10 * EDSCALE);
- hb->set_tooltip(item.description);
+ hb->set_tooltip_text(item.description);
VBoxContainer *favorite_box = memnew(VBoxContainer);
favorite_box->set_name("FavoriteBox");
TextureButton *favorite = memnew(TextureButton);
favorite->set_name("FavoriteButton");
- favorite->set_normal_texture(favorite_icon);
+ favorite->set_texture_normal(favorite_icon);
// This makes the project's "hover" style display correctly when hovering the favorite icon.
favorite->set_mouse_filter(MOUSE_FILTER_PASS);
- favorite->connect("pressed", callable_mp(this, &ProjectList::_favorite_pressed), varray(hb));
+ favorite->connect("pressed", callable_mp(this, &ProjectList::_favorite_pressed).bind(hb));
favorite_box->add_child(favorite);
favorite_box->set_alignment(BoxContainer::ALIGNMENT_CENTER);
hb->add_child(favorite_box);
@@ -1435,10 +1455,10 @@ void ProjectList::create_project_item_control(int p_index) {
path_hb->add_child(show);
if (!item.missing) {
- show->connect("pressed", callable_mp(this, &ProjectList::_show_project), varray(item.path));
- show->set_tooltip(TTR("Show in File Manager"));
+ show->connect("pressed", callable_mp(this, &ProjectList::_show_project).bind(item.path));
+ show->set_tooltip_text(TTR("Show in File Manager"));
} else {
- show->set_tooltip(TTR("Error: Project is missing on the filesystem."));
+ show->set_tooltip_text(TTR("Error: Project is missing on the filesystem."));
}
Label *fpath = memnew(Label(item.path));
@@ -1475,7 +1495,7 @@ void ProjectList::sort_projects() {
for (int i = 0; i < _projects.size(); ++i) {
Item &item = _projects.write[i];
- bool visible = true;
+ bool item_visible = true;
if (!_search_term.is_empty()) {
String search_path;
if (_search_term.contains("/")) {
@@ -1487,10 +1507,10 @@ void ProjectList::sort_projects() {
}
// When searching, display projects whose name or path contain the search term
- visible = item.project_name.findn(_search_term) != -1 || search_path.findn(_search_term) != -1;
+ item_visible = item.project_name.findn(_search_term) != -1 || search_path.findn(_search_term) != -1;
}
- item.control->set_visible(visible);
+ item.control->set_visible(item_visible);
}
for (int i = 0; i < _projects.size(); ++i) {
@@ -1506,19 +1526,19 @@ void ProjectList::sort_projects() {
const HashSet<String> &ProjectList::get_selected_project_keys() const {
// Faster if that's all you need
- return _selected_project_keys;
+ return _selected_project_paths;
}
Vector<ProjectList::Item> ProjectList::get_selected_projects() const {
Vector<Item> items;
- if (_selected_project_keys.size() == 0) {
+ if (_selected_project_paths.size() == 0) {
return items;
}
- items.resize(_selected_project_keys.size());
+ items.resize(_selected_project_paths.size());
int j = 0;
for (int i = 0; i < _projects.size(); ++i) {
const Item &item = _projects[i];
- if (_selected_project_keys.has(item.project_key)) {
+ if (_selected_project_paths.has(item.path)) {
items.write[j++] = item;
}
}
@@ -1532,41 +1552,40 @@ void ProjectList::ensure_project_visible(int p_index) {
}
int ProjectList::get_single_selected_index() const {
- if (_selected_project_keys.size() == 0) {
+ if (_selected_project_paths.size() == 0) {
// Default selection
return 0;
}
String key;
- if (_selected_project_keys.size() == 1) {
+ if (_selected_project_paths.size() == 1) {
// Only one selected
- key = *_selected_project_keys.begin();
+ key = *_selected_project_paths.begin();
} else {
// Multiple selected, consider the last clicked one as "main"
key = _last_clicked;
}
for (int i = 0; i < _projects.size(); ++i) {
- if (_projects[i].project_key == key) {
+ if (_projects[i].path == key) {
return i;
}
}
return 0;
}
-void ProjectList::remove_project(int p_index, bool p_update_settings) {
+void ProjectList::remove_project(int p_index, bool p_update_config) {
const Item item = _projects[p_index]; // Take a copy
- _selected_project_keys.erase(item.project_key);
+ _selected_project_paths.erase(item.path);
- if (_last_clicked == item.project_key) {
+ if (_last_clicked == item.path) {
_last_clicked = "";
}
memdelete(item.control);
_projects.remove_at(p_index);
- if (p_update_settings) {
- EditorSettings::get_singleton()->erase("projects/" + item.project_key);
- EditorSettings::get_singleton()->erase("favorite_projects/" + item.project_key);
+ if (p_update_config) {
+ _config.erase_section(item.path);
// Not actually saving the file, in case you are doing more changes to settings
}
@@ -1604,41 +1623,19 @@ void ProjectList::erase_missing_projects() {
}
print_line("Removed " + itos(deleted_count) + " projects from the list, remaining " + itos(remaining_count) + " projects");
-
- EditorSettings::get_singleton()->save();
+ save_config();
}
int ProjectList::refresh_project(const String &dir_path) {
- // Reads editor settings and reloads information about a specific project.
+ // Reloads information about a specific project.
// If it wasn't loaded and should be in the list, it is added (i.e new project).
// If it isn't in the list anymore, it is removed.
// If it is in the list but doesn't exist anymore, it is marked as missing.
- String project_key = get_project_key_from_path(dir_path);
+ bool should_be_in_list = _config.has_section(dir_path);
+ bool is_favourite = _config.get_value(dir_path, "favorite", false);
- // Read project manager settings
- bool is_favourite = false;
- bool should_be_in_list = false;
- String property_key = "projects/" + project_key;
- {
- List<PropertyInfo> properties;
- EditorSettings::get_singleton()->get_property_list(&properties);
- String favorite_property_key = "favorite_projects/" + project_key;
-
- bool found = false;
- for (const PropertyInfo &E : properties) {
- String prop = E.name;
- if (!found && prop == property_key) {
- found = true;
- } else if (!is_favourite && prop == favorite_property_key) {
- is_favourite = true;
- }
- }
-
- should_be_in_list = found;
- }
-
- bool was_selected = _selected_project_keys.has(project_key);
+ bool was_selected = _selected_project_paths.has(dir_path);
// Remove item in any case
for (int i = 0; i < _projects.size(); ++i) {
@@ -1653,7 +1650,7 @@ int ProjectList::refresh_project(const String &dir_path) {
if (should_be_in_list) {
// Recreate it with updated info
- Item item = load_project_data(property_key, is_favourite);
+ Item item = load_project_data(dir_path, is_favourite);
_projects.push_back(item);
create_project_item_control(_projects.size() - 1);
@@ -1661,7 +1658,7 @@ int ProjectList::refresh_project(const String &dir_path) {
sort_projects();
for (int i = 0; i < _projects.size(); ++i) {
- if (_projects[i].project_key == project_key) {
+ if (_projects[i].path == dir_path) {
if (was_selected) {
select_project(i);
ensure_project_visible(i);
@@ -1677,16 +1674,35 @@ int ProjectList::refresh_project(const String &dir_path) {
return index;
}
+void ProjectList::add_project(const String &dir_path, bool favorite) {
+ if (!_config.has_section(dir_path)) {
+ _config.set_value(dir_path, "favorite", favorite);
+ }
+}
+
+void ProjectList::save_config() {
+ _config.save(_config_path);
+}
+
+void ProjectList::set_project_version(const String &p_project_path, int p_version) {
+ for (ProjectList::Item &E : _projects) {
+ if (E.path == p_project_path) {
+ E.version = p_version;
+ break;
+ }
+ }
+}
+
int ProjectList::get_project_count() const {
return _projects.size();
}
void ProjectList::select_project(int p_index) {
Vector<Item> previous_selected_items = get_selected_projects();
- _selected_project_keys.clear();
+ _selected_project_paths.clear();
for (int i = 0; i < previous_selected_items.size(); ++i) {
- previous_selected_items[i].control->update();
+ previous_selected_items[i].control->queue_redraw();
}
toggle_select(p_index);
@@ -1705,7 +1721,7 @@ void ProjectList::select_first_visible_project() {
if (!found) {
// Deselect all projects if there are no visible projects in the list.
- _selected_project_keys.clear();
+ _selected_project_paths.clear();
}
}
@@ -1727,24 +1743,23 @@ void ProjectList::select_range(int p_begin, int p_end) {
void ProjectList::toggle_select(int p_index) {
Item &item = _projects.write[p_index];
- if (_selected_project_keys.has(item.project_key)) {
- _selected_project_keys.erase(item.project_key);
+ if (_selected_project_paths.has(item.path)) {
+ _selected_project_paths.erase(item.path);
} else {
- _selected_project_keys.insert(item.project_key);
+ _selected_project_paths.insert(item.path);
}
- item.control->update();
+ item.control->queue_redraw();
}
void ProjectList::erase_selected_projects(bool p_delete_project_contents) {
- if (_selected_project_keys.size() == 0) {
+ if (_selected_project_paths.size() == 0) {
return;
}
for (int i = 0; i < _projects.size(); ++i) {
Item &item = _projects.write[i];
- if (_selected_project_keys.has(item.project_key) && item.control->is_visible()) {
- EditorSettings::get_singleton()->erase("projects/" + item.project_key);
- EditorSettings::get_singleton()->erase("favorite_projects/" + item.project_key);
+ if (_selected_project_paths.has(item.path) && item.control->is_visible()) {
+ _config.erase_section(item.path);
if (p_delete_project_contents) {
OS::get_singleton()->move_to_trash(item.path);
@@ -1756,9 +1771,8 @@ void ProjectList::erase_selected_projects(bool p_delete_project_contents) {
}
}
- EditorSettings::get_singleton()->save();
-
- _selected_project_keys.clear();
+ save_config();
+ _selected_project_paths.clear();
_last_clicked = "";
update_dock_menu();
@@ -1774,9 +1788,9 @@ void ProjectList::_panel_draw(Node *p_hb) {
hb->draw_line(Point2(0, hb->get_size().y + 1), Point2(hb->get_size().x, hb->get_size().y + 1), get_theme_color(SNAME("guide_color"), SNAME("Tree")));
}
- String key = _projects[p_hb->get_index()].project_key;
+ String key = _projects[p_hb->get_index()].path;
- if (_selected_project_keys.has(key)) {
+ if (_selected_project_paths.has(key)) {
hb->draw_style_box(get_theme_stylebox(SNAME("selected"), SNAME("Tree")), Rect2(Point2(), hb->get_size()));
}
}
@@ -1788,11 +1802,11 @@ void ProjectList::_panel_input(const Ref<InputEvent> &p_ev, Node *p_hb) {
const Item &clicked_project = _projects[clicked_index];
if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) {
- if (mb->is_shift_pressed() && _selected_project_keys.size() > 0 && !_last_clicked.is_empty() && clicked_project.project_key != _last_clicked) {
+ if (mb->is_shift_pressed() && _selected_project_paths.size() > 0 && !_last_clicked.is_empty() && clicked_project.path != _last_clicked) {
int anchor_index = -1;
for (int i = 0; i < _projects.size(); ++i) {
const Item &p = _projects[i];
- if (p.project_key == _last_clicked) {
+ if (p.path == _last_clicked) {
anchor_index = p.control->get_index();
break;
}
@@ -1804,7 +1818,7 @@ void ProjectList::_panel_input(const Ref<InputEvent> &p_ev, Node *p_hb) {
toggle_select(clicked_index);
} else {
- _last_clicked = clicked_project.project_key;
+ _last_clicked = clicked_project.path;
select_project(clicked_index);
}
@@ -1826,12 +1840,8 @@ void ProjectList::_favorite_pressed(Node *p_hb) {
item.favorite = !item.favorite;
- if (item.favorite) {
- EditorSettings::get_singleton()->set("favorite_projects/" + item.project_key, item.path);
- } else {
- EditorSettings::get_singleton()->erase("favorite_projects/" + item.project_key);
- }
- EditorSettings::get_singleton()->save();
+ _config.set_value(item.path, "favorite", item.favorite);
+ save_config();
_projects.write[index] = item;
@@ -1841,7 +1851,7 @@ void ProjectList::_favorite_pressed(Node *p_hb) {
if (item.favorite) {
for (int i = 0; i < _projects.size(); ++i) {
- if (_projects[i].project_key == item.project_key) {
+ if (_projects[i].path == item.path) {
ensure_project_visible(i);
break;
}
@@ -1870,13 +1880,22 @@ void ProjectManager::_notification(int p_what) {
case NOTIFICATION_TRANSLATION_CHANGED:
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: {
settings_hb->set_anchors_and_offsets_preset(Control::PRESET_TOP_RIGHT);
- update();
+ queue_redraw();
} break;
case NOTIFICATION_ENTER_TREE: {
search_box->set_right_icon(get_theme_icon(SNAME("Search"), SNAME("EditorIcons")));
search_box->set_clear_button_enabled(true);
+ create_btn->set_icon(get_theme_icon(SNAME("Add"), SNAME("EditorIcons")));
+ import_btn->set_icon(get_theme_icon(SNAME("Load"), SNAME("EditorIcons")));
+ scan_btn->set_icon(get_theme_icon(SNAME("Search"), SNAME("EditorIcons")));
+ open_btn->set_icon(get_theme_icon(SNAME("Edit"), SNAME("EditorIcons")));
+ run_btn->set_icon(get_theme_icon(SNAME("Play"), SNAME("EditorIcons")));
+ rename_btn->set_icon(get_theme_icon(SNAME("Rename"), SNAME("EditorIcons")));
+ erase_btn->set_icon(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")));
+ erase_missing_btn->set_icon(get_theme_icon(SNAME("Clear"), SNAME("EditorIcons")));
+
Engine::get_singleton()->set_editor_hint(false);
} break;
@@ -1886,7 +1905,6 @@ void ProjectManager::_notification(int p_what) {
}
if (asset_library) {
real_t size = get_size().x / EDSCALE;
- asset_library->set_columns(size < 1000 ? 1 : 2);
// Adjust names of tabs to fit the new size.
if (size < 650) {
local_projects_hb->set_name(TTR("Local"));
@@ -1899,15 +1917,17 @@ void ProjectManager::_notification(int p_what) {
} break;
case NOTIFICATION_READY: {
- int default_sorting = (int)EditorSettings::get_singleton()->get("project_manager/sorting_order");
+ int default_sorting = (int)EDITOR_GET("project_manager/sorting_order");
filter_option->select(default_sorting);
_project_list->set_order_option(default_sorting);
+#ifndef ANDROID_ENABLED
if (_project_list->get_project_count() >= 1) {
// Focus on the search box immediately to allow the user
// to search without having to reach for their mouse
search_box->grab_focus();
}
+#endif
if (asset_library) {
// Removes extra border margins.
@@ -1992,8 +2012,8 @@ void ProjectManager::shortcut_input(const Ref<InputEvent> &p_ev) {
// Pressing Command + Q quits the Project Manager
// This is handled by the platform implementation on macOS,
// so only define the shortcut on other platforms
-#ifndef OSX_ENABLED
- if (k->get_keycode_with_modifiers() == (KeyModifierMask::CMD | Key::Q)) {
+#ifndef MACOS_ENABLED
+ if (k->get_keycode_with_modifiers() == (KeyModifierMask::META | Key::Q)) {
_dim_window();
get_tree()->quit();
}
@@ -2051,7 +2071,7 @@ void ProjectManager::shortcut_input(const Ref<InputEvent> &p_ev) {
} break;
case Key::F: {
- if (k->is_command_pressed()) {
+ if (k->is_command_or_control_pressed()) {
this->search_box->grab_focus();
} else {
keycode_handled = false;
@@ -2091,6 +2111,8 @@ void ProjectManager::_on_projects_updated() {
}
void ProjectManager::_on_project_created(const String &dir) {
+ _project_list->add_project(dir, false);
+ _project_list->save_config();
search_box->clear();
int i = _project_list->refresh_project(dir);
_project_list->select_project(i);
@@ -2106,15 +2128,13 @@ void ProjectManager::_confirm_update_settings() {
void ProjectManager::_open_selected_projects() {
// Show loading text to tell the user that the project manager is busy loading.
- // This is especially important for the HTML5 project manager.
+ // This is especially important for the Web project manager.
loading_label->show();
const HashSet<String> &selected_list = _project_list->get_selected_project_keys();
- for (const String &E : selected_list) {
- const String &selected = E;
- String path = EditorSettings::get_singleton()->get("projects/" + selected);
- String conf = path.plus_file("project.godot");
+ for (const String &path : selected_list) {
+ String conf = path.path_join("project.godot");
if (!FileAccess::exists(conf)) {
dialog_error->set_text(vformat(TTR("Can't open project at '%s'."), path));
@@ -2122,31 +2142,19 @@ void ProjectManager::_open_selected_projects() {
return;
}
- print_line("Editing project: " + path + " (" + selected + ")");
+ print_line("Editing project: " + path);
List<String> args;
+ for (const String &a : Main::get_forwardable_cli_arguments(Main::CLI_SCOPE_TOOL)) {
+ args.push_back(a);
+ }
+
args.push_back("--path");
args.push_back(path);
args.push_back("--editor");
- if (OS::get_singleton()->is_stdout_debug_enabled()) {
- args.push_back("--debug");
- }
-
- if (OS::get_singleton()->is_stdout_verbose()) {
- args.push_back("--verbose");
- }
-
- if (OS::get_singleton()->is_disable_crash_handler()) {
- args.push_back("--disable-crash-handler");
- }
-
- if (OS::get_singleton()->is_single_window()) {
- args.push_back("--single-window");
- }
-
Error err = OS::get_singleton()->create_instance(args);
ERR_FAIL_COND(err);
}
@@ -2164,9 +2172,11 @@ void ProjectManager::_open_selected_projects_ask() {
return;
}
+ const Size2i popup_min_width = Size2i(600.0 * EDSCALE, 0);
+
if (selected_list.size() > 1) {
- multi_open_ask->set_text(TTR("Are you sure to open more than one project?"));
- multi_open_ask->popup_centered();
+ multi_open_ask->set_text(vformat(TTR("You requested to open %d projects in parallel. Do you confirm?\nNote that usual checks for engine version compatibility will be bypassed."), selected_list.size()));
+ multi_open_ask->popup_centered(popup_min_width);
return;
}
@@ -2175,30 +2185,40 @@ void ProjectManager::_open_selected_projects_ask() {
return;
}
- // Update the project settings or don't open
- const String conf = project.path.plus_file("project.godot");
+ // Update the project settings or don't open.
const int config_version = project.version;
PackedStringArray unsupported_features = project.unsupported_features;
Label *ask_update_label = ask_update_settings->get_label();
ask_update_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_LEFT); // Reset in case of previous center align.
+ full_convert_button->hide();
- // Check if the config_version property was empty or 0
+ ask_update_settings->get_ok_button()->set_text("OK");
+
+ // Check if the config_version property was empty or 0.
if (config_version == 0) {
- ask_update_settings->set_text(vformat(TTR("The following project settings file does not specify the version of Godot through which it was created.\n\n%s\n\nIf you proceed with opening it, it will be converted to Godot's current configuration file format.\nWarning: You won't be able to open the project with previous versions of the engine anymore."), conf));
- ask_update_settings->popup_centered();
+ ask_update_settings->set_text(vformat(TTR("The selected project \"%s\" does not specify its supported Godot version in its configuration file (\"project.godot\").\n\nProject path: %s\n\nIf you proceed with opening it, it will be converted to Godot's current configuration file format.\n\nWarning: You won't be able to open the project with previous versions of the engine anymore."), project.project_name, project.path));
+ ask_update_settings->popup_centered(popup_min_width);
return;
}
- // Check if we need to convert project settings from an earlier engine version
+ // Check if we need to convert project settings from an earlier engine version.
if (config_version < ProjectSettings::CONFIG_VERSION) {
- ask_update_settings->set_text(vformat(TTR("The following project settings file was generated by an older engine version, and needs to be converted for this version:\n\n%s\n\nDo you want to convert it?\nWarning: You won't be able to open the project with previous versions of the engine anymore."), conf));
- ask_update_settings->popup_centered();
+ if (config_version == GODOT4_CONFIG_VERSION - 1 && ProjectSettings::CONFIG_VERSION == GODOT4_CONFIG_VERSION) { // Conversion from Godot 3 to 4.
+ full_convert_button->show();
+ ask_update_settings->set_text(vformat(TTR("The selected project \"%s\" was generated by Godot 3.x, and needs to be converted for Godot 4.x.\n\nProject path: %s\n\nYou have three options:\n- Convert only the configuration file (\"project.godot\"). Use this to open the project without attempting to convert its scenes, resources and scripts.\n- Convert the entire project including its scenes, resources and scripts (recommended if you are upgrading).\n- Do nothing and go back.\n\nWarning: If you select a conversion option, you won't be able to open the project with previous versions of the engine anymore."), project.project_name, project.path));
+ ask_update_settings->get_ok_button()->set_text(TTR("Convert project.godot Only"));
+ } else {
+ ask_update_settings->set_text(vformat(TTR("The selected project \"%s\" was generated by an older engine version, and needs to be converted for this version.\n\nProject path: %s\n\nDo you want to convert it?\n\nWarning: You won't be able to open the project with previous versions of the engine anymore."), project.project_name, project.path));
+ ask_update_settings->get_ok_button()->set_text(TTR("Convert project.godot"));
+ }
+ ask_update_settings->popup_centered(popup_min_width);
+ ask_update_settings->get_cancel_button()->grab_focus(); // To prevent accidents.
return;
}
- // Check if the file was generated by a newer, incompatible engine version
+ // Check if the file was generated by a newer, incompatible engine version.
if (config_version > ProjectSettings::CONFIG_VERSION) {
- dialog_error->set_text(vformat(TTR("Can't open project at '%s'.") + "\n" + TTR("The project settings were created by a newer engine version, whose settings are not compatible with this version."), project.path));
- dialog_error->popup_centered();
+ dialog_error->set_text(vformat(TTR("Can't open project \"%s\" at the following path:\n\n%s\n\nThe project settings were created by a newer engine version, whose settings are not compatible with this version."), project.project_name, project.path));
+ dialog_error->popup_centered(popup_min_width);
return;
}
// Check if the project is using features not supported by this build of Godot.
@@ -2227,14 +2247,46 @@ void ProjectManager::_open_selected_projects_ask() {
warning_message += TTR("Open anyway? Project will be modified.");
ask_update_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
ask_update_settings->set_text(warning_message);
- ask_update_settings->popup_centered();
+ ask_update_settings->popup_centered(popup_min_width);
return;
}
- // Open if the project is up-to-date
+ // Open if the project is up-to-date.
_open_selected_projects();
}
+void ProjectManager::_full_convert_button_pressed() {
+ ask_update_settings->hide();
+ ask_full_convert_dialog->popup_centered(Size2i(600.0 * EDSCALE, 0));
+ ask_full_convert_dialog->get_cancel_button()->grab_focus();
+}
+
+void ProjectManager::_perform_full_project_conversion() {
+ Vector<ProjectList::Item> selected_list = _project_list->get_selected_projects();
+ if (selected_list.is_empty()) {
+ return;
+ }
+
+ const String &path = selected_list[0].path;
+
+ print_line("Converting project: " + path);
+
+ Ref<ConfigFile> cf;
+ cf.instantiate();
+ cf->load(path.path_join("project.godot"));
+ cf->set_value("", "config_version", GODOT4_CONFIG_VERSION);
+ cf->save(path.path_join("project.godot"));
+ _project_list->set_project_version(path, GODOT4_CONFIG_VERSION);
+
+ List<String> args;
+ args.push_back("--path");
+ args.push_back(path);
+ args.push_back("--convert-3to4");
+
+ Error err = OS::get_singleton()->create_instance(args);
+ ERR_FAIL_COND(err);
+}
+
void ProjectManager::_run_project_confirm() {
Vector<ProjectList::Item> selected_list = _project_list->get_selected_projects();
@@ -2246,27 +2298,26 @@ void ProjectManager::_run_project_confirm() {
continue;
}
- const String &selected = selected_list[i].project_key;
- String path = EditorSettings::get_singleton()->get("projects/" + selected);
+ const String &path = selected_list[i].path;
// `.substr(6)` on `ProjectSettings::get_singleton()->get_imported_files_path()` strips away the leading "res://".
- if (!DirAccess::exists(path.plus_file(ProjectSettings::get_singleton()->get_imported_files_path().substr(6)))) {
+ if (!DirAccess::exists(path.path_join(ProjectSettings::get_singleton()->get_imported_files_path().substr(6)))) {
run_error_diag->set_text(TTR("Can't run project: Assets need to be imported.\nPlease edit the project to trigger the initial import."));
run_error_diag->popup_centered();
continue;
}
- print_line("Running project: " + path + " (" + selected + ")");
+ print_line("Running project: " + path);
List<String> args;
+ for (const String &a : Main::get_forwardable_cli_arguments(Main::CLI_SCOPE_PROJECT)) {
+ args.push_back(a);
+ }
+
args.push_back("--path");
args.push_back(path);
- if (OS::get_singleton()->is_disable_crash_handler()) {
- args.push_back("--disable-crash-handler");
- }
-
Error err = OS::get_singleton()->create_instance(args);
ERR_FAIL_COND(err);
}
@@ -2287,7 +2338,7 @@ void ProjectManager::_run_project() {
}
}
-void ProjectManager::_scan_dir(const String &path, List<String> *r_projects) {
+void ProjectManager::_scan_dir(const String &path) {
Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
Error error = da->change_dir(path);
ERR_FAIL_COND_MSG(error != OK, "Could not scan directory at: " + path);
@@ -2295,26 +2346,18 @@ void ProjectManager::_scan_dir(const String &path, List<String> *r_projects) {
String n = da->get_next();
while (!n.is_empty()) {
if (da->current_is_dir() && !n.begins_with(".")) {
- _scan_dir(da->get_current_dir().plus_file(n), r_projects);
+ _scan_dir(da->get_current_dir().path_join(n));
} else if (n == "project.godot") {
- r_projects->push_back(da->get_current_dir());
+ _project_list->add_project(da->get_current_dir(), false);
}
n = da->get_next();
}
da->list_dir_end();
}
-
void ProjectManager::_scan_begin(const String &p_base) {
print_line("Scanning projects at: " + p_base);
- List<String> projects;
- _scan_dir(p_base, &projects);
- print_line("Found " + itos(projects.size()) + " projects.");
-
- for (const String &E : projects) {
- String proj = get_project_key_from_path(E);
- EditorSettings::get_singleton()->set("projects/" + proj, E);
- }
- EditorSettings::get_singleton()->save();
+ _scan_dir(p_base);
+ _project_list->save_config();
_load_recent_projects();
}
@@ -2340,9 +2383,7 @@ void ProjectManager::_rename_project() {
}
for (const String &E : selected_list) {
- const String &selected = E;
- String path = EditorSettings::get_singleton()->get("projects/" + selected);
- npdialog->set_project_path(path);
+ npdialog->set_project_path(E);
npdialog->set_mode(ProjectDialog::MODE_RENAME);
npdialog->show_dialog();
}
@@ -2445,7 +2486,7 @@ void ProjectManager::_files_dropped(PackedStringArray p_files) {
}
if (confirm) {
multi_scan_ask->get_ok_button()->disconnect("pressed", callable_mp(this, &ProjectManager::_scan_multiple_folders));
- multi_scan_ask->get_ok_button()->connect("pressed", callable_mp(this, &ProjectManager::_scan_multiple_folders), varray(folders));
+ multi_scan_ask->get_ok_button()->connect("pressed", callable_mp(this, &ProjectManager::_scan_multiple_folders).bind(folders));
multi_scan_ask->set_text(
vformat(TTR("Are you sure to scan %s folders for existing Godot projects?\nThis could take a while."), folders.size()));
multi_scan_ask->popup_centered();
@@ -2468,6 +2509,7 @@ void ProjectManager::_on_order_option_changed(int p_idx) {
}
void ProjectManager::_on_tab_changed(int p_tab) {
+#ifndef ANDROID_ENABLED
if (p_tab == 0) { // Projects
// Automatically grab focus when the user moves from the Templates tab
// back to the Projects tab.
@@ -2476,6 +2518,7 @@ void ProjectManager::_on_tab_changed(int p_tab) {
// The Templates tab's search field is focused on display in the asset
// library editor plugin code.
+#endif
}
void ProjectManager::_on_search_term_changed(const String &p_term) {
@@ -2519,7 +2562,7 @@ ProjectManager::ProjectManager() {
EditorSettings::get_singleton()->set_optimize_save(false); //just write settings as they came
{
- int display_scale = EditorSettings::get_singleton()->get("interface/editor/display_scale");
+ int display_scale = EDITOR_GET("interface/editor/display_scale");
switch (display_scale) {
case 0:
@@ -2545,7 +2588,7 @@ ProjectManager::ProjectManager() {
editor_set_scale(2.0);
break;
default:
- editor_set_scale(EditorSettings::get_singleton()->get("interface/editor/custom_display_scale"));
+ editor_set_scale(EDITOR_GET("interface/editor/custom_display_scale"));
break;
}
EditorFileDialog::get_icon_func = &ProjectManager::_file_dialog_get_icon;
@@ -2554,21 +2597,27 @@ ProjectManager::ProjectManager() {
// TRANSLATORS: This refers to the application where users manage their Godot projects.
DisplayServer::get_singleton()->window_set_title(VERSION_NAME + String(" - ") + TTR("Project Manager", "Application"));
- EditorFileDialog::set_default_show_hidden_files(EditorSettings::get_singleton()->get("filesystem/file_dialog/show_hidden_files"));
+ EditorFileDialog::set_default_show_hidden_files(EDITOR_GET("filesystem/file_dialog/show_hidden_files"));
- set_anchors_and_offsets_preset(Control::PRESET_WIDE);
+ int swap_cancel_ok = EDITOR_GET("interface/editor/accept_dialog_cancel_ok_buttons");
+ if (swap_cancel_ok != 0) { // 0 is auto, set in register_scene based on DisplayServer.
+ // Swap on means OK first.
+ AcceptDialog::set_swap_cancel_ok(swap_cancel_ok == 2);
+ }
+
+ set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
set_theme(create_custom_theme());
- set_anchors_and_offsets_preset(Control::PRESET_WIDE);
+ set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
Panel *panel = memnew(Panel);
add_child(panel);
- panel->set_anchors_and_offsets_preset(Control::PRESET_WIDE);
+ panel->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
panel->add_theme_style_override("panel", get_theme_stylebox(SNAME("Background"), SNAME("EditorStyles")));
VBoxContainer *vb = memnew(VBoxContainer);
panel->add_child(vb);
- vb->set_anchors_and_offsets_preset(Control::PRESET_WIDE, Control::PRESET_MODE_MINSIZE, 8 * EDSCALE);
+ vb->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT, Control::PRESET_MODE_MINSIZE, 8 * EDSCALE);
Control *center_box = memnew(Control);
center_box->set_v_size_flags(Control::SIZE_EXPAND_FILL);
@@ -2576,7 +2625,7 @@ ProjectManager::ProjectManager() {
tabs = memnew(TabContainer);
center_box->add_child(tabs);
- tabs->set_anchors_and_offsets_preset(Control::PRESET_WIDE);
+ tabs->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
tabs->connect("tab_changed", callable_mp(this, &ProjectManager::_on_tab_changed));
local_projects_hb = memnew(HBoxContainer);
@@ -2595,7 +2644,7 @@ ProjectManager::ProjectManager() {
search_box = memnew(LineEdit);
search_box->set_placeholder(TTR("Filter Projects"));
- search_box->set_tooltip(TTR("This field filters projects by name and last path component.\nTo filter projects by name and full path, the query must contain at least one `/` character."));
+ search_box->set_tooltip_text(TTR("This field filters projects by name and last path component.\nTo filter projects by name and full path, the query must contain at least one `/` character."));
search_box->connect("text_changed", callable_mp(this, &ProjectManager::_on_search_term_changed));
search_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
hb->add_child(search_box);
@@ -2627,7 +2676,7 @@ ProjectManager::ProjectManager() {
}
PanelContainer *pc = memnew(PanelContainer);
- pc->add_theme_style_override("panel", get_theme_stylebox(SNAME("bg"), SNAME("Tree")));
+ pc->add_theme_style_override("panel", get_theme_stylebox(SNAME("panel"), SNAME("Tree")));
pc->set_v_size_flags(Control::SIZE_EXPAND_FILL);
search_tree_vb->add_child(pc);
@@ -2644,40 +2693,48 @@ ProjectManager::ProjectManager() {
tree_vb->set_custom_minimum_size(Size2(120, 120));
local_projects_hb->add_child(tree_vb);
- Button *create = memnew(Button);
- create->set_text(TTR("New Project"));
- create->set_shortcut(ED_SHORTCUT("project_manager/new_project", TTR("New Project"), KeyModifierMask::CMD | Key::N));
- create->connect("pressed", callable_mp(this, &ProjectManager::_new_project));
- tree_vb->add_child(create);
-
- Button *import = memnew(Button);
- import->set_text(TTR("Import"));
- import->set_shortcut(ED_SHORTCUT("project_manager/import_project", TTR("Import Project"), KeyModifierMask::CMD | Key::I));
- import->connect("pressed", callable_mp(this, &ProjectManager::_import_project));
- tree_vb->add_child(import);
-
- Button *scan = memnew(Button);
- scan->set_text(TTR("Scan"));
- scan->set_shortcut(ED_SHORTCUT("project_manager/scan_projects", TTR("Scan Projects"), KeyModifierMask::CMD | Key::S));
- scan->connect("pressed", callable_mp(this, &ProjectManager::_scan_projects));
- tree_vb->add_child(scan);
+ const int btn_h_separation = int(6 * EDSCALE);
+
+ create_btn = memnew(Button);
+ create_btn->set_text(TTR("New Project"));
+ create_btn->add_theme_constant_override("h_separation", btn_h_separation);
+ create_btn->set_shortcut(ED_SHORTCUT("project_manager/new_project", TTR("New Project"), KeyModifierMask::CMD_OR_CTRL | Key::N));
+ create_btn->connect("pressed", callable_mp(this, &ProjectManager::_new_project));
+ tree_vb->add_child(create_btn);
+
+ import_btn = memnew(Button);
+ import_btn->set_text(TTR("Import"));
+ import_btn->add_theme_constant_override("h_separation", btn_h_separation);
+ import_btn->set_shortcut(ED_SHORTCUT("project_manager/import_project", TTR("Import Project"), KeyModifierMask::CMD_OR_CTRL | Key::I));
+ import_btn->connect("pressed", callable_mp(this, &ProjectManager::_import_project));
+ tree_vb->add_child(import_btn);
+
+ scan_btn = memnew(Button);
+ scan_btn->set_text(TTR("Scan"));
+ scan_btn->add_theme_constant_override("h_separation", btn_h_separation);
+ scan_btn->set_shortcut(ED_SHORTCUT("project_manager/scan_projects", TTR("Scan Projects"), KeyModifierMask::CMD_OR_CTRL | Key::S));
+ scan_btn->connect("pressed", callable_mp(this, &ProjectManager::_scan_projects));
+ tree_vb->add_child(scan_btn);
tree_vb->add_child(memnew(HSeparator));
open_btn = memnew(Button);
open_btn->set_text(TTR("Edit"));
- open_btn->set_shortcut(ED_SHORTCUT("project_manager/edit_project", TTR("Edit Project"), KeyModifierMask::CMD | Key::E));
+ open_btn->add_theme_constant_override("h_separation", btn_h_separation);
+ open_btn->set_shortcut(ED_SHORTCUT("project_manager/edit_project", TTR("Edit Project"), KeyModifierMask::CMD_OR_CTRL | Key::E));
open_btn->connect("pressed", callable_mp(this, &ProjectManager::_open_selected_projects_ask));
tree_vb->add_child(open_btn);
run_btn = memnew(Button);
run_btn->set_text(TTR("Run"));
- run_btn->set_shortcut(ED_SHORTCUT("project_manager/run_project", TTR("Run Project"), KeyModifierMask::CMD | Key::R));
+ run_btn->add_theme_constant_override("h_separation", btn_h_separation);
+ run_btn->set_shortcut(ED_SHORTCUT("project_manager/run_project", TTR("Run Project"), KeyModifierMask::CMD_OR_CTRL | Key::R));
run_btn->connect("pressed", callable_mp(this, &ProjectManager::_run_project));
tree_vb->add_child(run_btn);
rename_btn = memnew(Button);
rename_btn->set_text(TTR("Rename"));
+ rename_btn->add_theme_constant_override("h_separation", btn_h_separation);
// The F2 shortcut isn't overridden with Enter on macOS as Enter is already used to edit a project.
rename_btn->set_shortcut(ED_SHORTCUT("project_manager/rename_project", TTR("Rename Project"), Key::F2));
rename_btn->connect("pressed", callable_mp(this, &ProjectManager::_rename_project));
@@ -2685,12 +2742,14 @@ ProjectManager::ProjectManager() {
erase_btn = memnew(Button);
erase_btn->set_text(TTR("Remove"));
+ erase_btn->add_theme_constant_override("h_separation", btn_h_separation);
erase_btn->set_shortcut(ED_SHORTCUT("project_manager/remove_project", TTR("Remove Project"), Key::KEY_DELETE));
erase_btn->connect("pressed", callable_mp(this, &ProjectManager::_erase_project));
tree_vb->add_child(erase_btn);
erase_missing_btn = memnew(Button);
erase_missing_btn->set_text(TTR("Remove Missing"));
+ erase_missing_btn->add_theme_constant_override("h_separation", btn_h_separation);
erase_missing_btn->connect("pressed", callable_mp(this, &ProjectManager::_erase_missing_projects));
tree_vb->add_child(erase_missing_btn);
@@ -2725,7 +2784,7 @@ ProjectManager::ProjectManager() {
// Fade the version label to be less prominent, but still readable.
version_btn->set_self_modulate(Color(1, 1, 1, 0.6));
version_btn->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER);
- version_btn->set_tooltip(TTR("Click to copy."));
+ version_btn->set_tooltip_text(TTR("Click to copy."));
version_btn->connect("pressed", callable_mp(this, &ProjectManager::_version_button_pressed));
spacer_vb->add_child(version_btn);
@@ -2735,9 +2794,10 @@ ProjectManager::ProjectManager() {
settings_hb->add_child(h_spacer);
language_btn = memnew(OptionButton);
- language_btn->set_flat(true);
language_btn->set_icon(get_theme_icon(SNAME("Environment"), SNAME("EditorIcons")));
language_btn->set_focus_mode(Control::FOCUS_NONE);
+ language_btn->set_fit_to_longest_item(false);
+ language_btn->set_flat(true);
language_btn->connect("item_selected", callable_mp(this, &ProjectManager::_language_selected));
#ifdef ANDROID_ENABLED
// The language selection dropdown doesn't work on Android (as the setting isn't saved), see GH-60353.
@@ -2756,7 +2816,7 @@ ProjectManager::ProjectManager() {
}
}
- String current_lang = EditorSettings::get_singleton()->get("interface/editor/editor_language");
+ String current_lang = EDITOR_GET("interface/editor/editor_language");
language_btn->set_text(current_lang);
for (int i = 0; i < editor_languages.size(); i++) {
@@ -2773,25 +2833,21 @@ ProjectManager::ProjectManager() {
center_box->add_child(settings_hb);
}
- // Asset Library can't work on Web editor for now as most assets are sourced
- // directly from GitHub which does not set CORS.
-#ifndef JAVASCRIPT_ENABLED
- if (StreamPeerSSL::is_available()) {
+ if (AssetLibraryEditorPlugin::is_available()) {
asset_library = memnew(EditorAssetLibrary(true));
asset_library->set_name(TTR("Asset Library Projects"));
tabs->add_child(asset_library);
asset_library->connect("install_asset", callable_mp(this, &ProjectManager::_install_project));
} else {
- WARN_PRINT("Asset Library not available, as it requires SSL to work.");
+ print_verbose("Asset Library not available (due to using Web editor, or SSL support disabled).");
}
-#endif
{
// Dialogs
language_restart_ask = memnew(ConfirmationDialog);
- language_restart_ask->get_ok_button()->set_text(TTR("Restart Now"));
+ language_restart_ask->set_ok_button_text(TTR("Restart Now"));
language_restart_ask->get_ok_button()->connect("pressed", callable_mp(this, &ProjectManager::_restart_confirm));
- language_restart_ask->get_cancel_button()->set_text(TTR("Continue"));
+ language_restart_ask->set_cancel_button_text(TTR("Continue"));
add_child(language_restart_ask);
scan_dir = memnew(EditorFileDialog);
@@ -2799,17 +2855,17 @@ ProjectManager::ProjectManager() {
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"));
+ scan_dir->set_current_dir(EDITOR_GET("filesystem/directories/default_project_path"));
add_child(scan_dir);
scan_dir->connect("dir_selected", callable_mp(this, &ProjectManager::_scan_begin));
erase_missing_ask = memnew(ConfirmationDialog);
- erase_missing_ask->get_ok_button()->set_text(TTR("Remove All"));
+ erase_missing_ask->set_ok_button_text(TTR("Remove All"));
erase_missing_ask->get_ok_button()->connect("pressed", callable_mp(this, &ProjectManager::_erase_missing_projects_confirm));
add_child(erase_missing_ask);
erase_ask = memnew(ConfirmationDialog);
- erase_ask->get_ok_button()->set_text(TTR("Remove"));
+ erase_ask->set_ok_button_text(TTR("Remove"));
erase_ask->get_ok_button()->connect("pressed", callable_mp(this, &ProjectManager::_erase_project_confirm));
add_child(erase_ask);
@@ -2824,23 +2880,32 @@ ProjectManager::ProjectManager() {
erase_ask_vb->add_child(delete_project_contents);
multi_open_ask = memnew(ConfirmationDialog);
- multi_open_ask->get_ok_button()->set_text(TTR("Edit"));
+ multi_open_ask->set_ok_button_text(TTR("Edit"));
multi_open_ask->get_ok_button()->connect("pressed", callable_mp(this, &ProjectManager::_open_selected_projects));
add_child(multi_open_ask);
multi_run_ask = memnew(ConfirmationDialog);
- multi_run_ask->get_ok_button()->set_text(TTR("Run"));
+ multi_run_ask->set_ok_button_text(TTR("Run"));
multi_run_ask->get_ok_button()->connect("pressed", callable_mp(this, &ProjectManager::_run_project_confirm));
add_child(multi_run_ask);
multi_scan_ask = memnew(ConfirmationDialog);
- multi_scan_ask->get_ok_button()->set_text(TTR("Scan"));
+ multi_scan_ask->set_ok_button_text(TTR("Scan"));
add_child(multi_scan_ask);
ask_update_settings = memnew(ConfirmationDialog);
+ ask_update_settings->set_autowrap(true);
ask_update_settings->get_ok_button()->connect("pressed", callable_mp(this, &ProjectManager::_confirm_update_settings));
+ full_convert_button = ask_update_settings->add_button("Convert Full Project", !GLOBAL_GET("gui/common/swap_cancel_ok"));
+ full_convert_button->connect("pressed", callable_mp(this, &ProjectManager::_full_convert_button_pressed));
add_child(ask_update_settings);
+ ask_full_convert_dialog = memnew(ConfirmationDialog);
+ ask_full_convert_dialog->set_autowrap(true);
+ ask_full_convert_dialog->set_text(TTR("This option will perform full project conversion, updating scenes, resources and scripts from Godot 3.x to work in Godot 4.0.\n\nNote that this is a best-effort conversion, i.e. it makes upgrading the project easier, but it will not open out-of-the-box and will still require manual adjustments.\n\nIMPORTANT: Make sure to backup your project before converting, as this operation makes it impossible to open it in older versions of Godot."));
+ ask_full_convert_dialog->connect("confirmed", callable_mp(this, &ProjectManager::_perform_full_project_conversion));
+ add_child(ask_full_convert_dialog);
+
npdialog = memnew(ProjectDialog);
npdialog->connect("projects_updated", callable_mp(this, &ProjectManager::_on_projects_updated));
npdialog->connect("project_created", callable_mp(this, &ProjectManager::_on_project_created));
@@ -2856,7 +2921,7 @@ ProjectManager::ProjectManager() {
if (asset_library) {
open_templates = memnew(ConfirmationDialog);
open_templates->set_text(TTR("You currently don't have any projects.\nWould you like to explore official example projects in the Asset Library?"));
- open_templates->get_ok_button()->set_text(TTR("Open Asset Library"));
+ open_templates->set_ok_button_text(TTR("Open Asset Library"));
open_templates->connect("confirmed", callable_mp(this, &ProjectManager::_open_asset_library));
add_child(open_templates);
}
@@ -2867,11 +2932,12 @@ ProjectManager::ProjectManager() {
_build_icon_type_cache(get_theme());
}
+ _project_list->migrate_config();
_load_recent_projects();
Ref<DirAccess> dir_access = DirAccess::create(DirAccess::AccessType::ACCESS_FILESYSTEM);
- String default_project_path = EditorSettings::get_singleton()->get("filesystem/directories/default_project_path");
+ String default_project_path = EDITOR_GET("filesystem/directories/default_project_path");
if (!dir_access->dir_exists(default_project_path)) {
Error error = dir_access->make_dir_recursive(default_project_path);
if (error != OK) {
@@ -2879,7 +2945,7 @@ ProjectManager::ProjectManager() {
}
}
- String autoscan_path = EditorSettings::get_singleton()->get("filesystem/directories/autoscan_project_path");
+ String autoscan_path = EDITOR_GET("filesystem/directories/autoscan_project_path");
if (!autoscan_path.is_empty()) {
if (dir_access->dir_exists(autoscan_path)) {
_scan_begin(autoscan_path);