mirror of
https://github.com/godotengine/godot.git
synced 2024-11-21 11:32:13 +00:00
Reorganize project manager code
- Extract individual components to their own files. - Improve order of declarations and definitions within those files. - ProjectDialog is only extracted as there are upcoming PRs touching on it.
This commit is contained in:
parent
107f2961cc
commit
691450bc08
@ -113,6 +113,7 @@ if env.editor_build:
|
||||
SConscript("icons/SCsub")
|
||||
SConscript("import/SCsub")
|
||||
SConscript("plugins/SCsub")
|
||||
SConscript("project_manager/SCsub")
|
||||
SConscript("themes/SCsub")
|
||||
|
||||
lib = env.add_library("editor", env.editor_sources)
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -31,315 +31,68 @@
|
||||
#ifndef PROJECT_MANAGER_H
|
||||
#define PROJECT_MANAGER_H
|
||||
|
||||
#include "core/io/config_file.h"
|
||||
#include "editor/editor_about.h"
|
||||
#include "scene/gui/dialogs.h"
|
||||
#include "scene/gui/file_dialog.h"
|
||||
#include "scene/gui/scroll_container.h"
|
||||
|
||||
class CheckBox;
|
||||
class EditorAbout;
|
||||
class EditorAssetLibrary;
|
||||
class EditorFileDialog;
|
||||
class HFlowContainer;
|
||||
class LineEdit;
|
||||
class LinkButton;
|
||||
class OptionButton;
|
||||
class PanelContainer;
|
||||
class ProjectDialog;
|
||||
class ProjectList;
|
||||
|
||||
class ProjectDialog : public ConfirmationDialog {
|
||||
GDCLASS(ProjectDialog, ConfirmationDialog);
|
||||
|
||||
public:
|
||||
enum Mode {
|
||||
MODE_NEW,
|
||||
MODE_IMPORT,
|
||||
MODE_INSTALL,
|
||||
MODE_RENAME,
|
||||
};
|
||||
|
||||
private:
|
||||
enum MessageType {
|
||||
MESSAGE_ERROR,
|
||||
MESSAGE_WARNING,
|
||||
MESSAGE_SUCCESS,
|
||||
};
|
||||
|
||||
enum InputType {
|
||||
PROJECT_PATH,
|
||||
INSTALL_PATH,
|
||||
};
|
||||
|
||||
Mode mode = MODE_NEW;
|
||||
bool is_folder_empty = true;
|
||||
|
||||
Button *browse = nullptr;
|
||||
Button *install_browse = nullptr;
|
||||
Button *create_dir = nullptr;
|
||||
Container *name_container = nullptr;
|
||||
Container *path_container = nullptr;
|
||||
Container *install_path_container = nullptr;
|
||||
|
||||
Container *renderer_container = nullptr;
|
||||
Label *renderer_info = nullptr;
|
||||
HBoxContainer *default_files_container = nullptr;
|
||||
Ref<ButtonGroup> renderer_button_group;
|
||||
|
||||
Label *msg = nullptr;
|
||||
LineEdit *project_path = nullptr;
|
||||
LineEdit *project_name = nullptr;
|
||||
LineEdit *install_path = nullptr;
|
||||
TextureRect *status_rect = nullptr;
|
||||
TextureRect *install_status_rect = nullptr;
|
||||
|
||||
OptionButton *vcs_metadata_selection = nullptr;
|
||||
|
||||
EditorFileDialog *fdialog = nullptr;
|
||||
EditorFileDialog *fdialog_install = nullptr;
|
||||
AcceptDialog *dialog_error = nullptr;
|
||||
|
||||
String zip_path;
|
||||
String zip_title;
|
||||
String fav_dir;
|
||||
|
||||
String created_folder_path;
|
||||
|
||||
void _set_message(const String &p_msg, MessageType p_type = MESSAGE_SUCCESS, InputType input_type = PROJECT_PATH);
|
||||
|
||||
String _test_path();
|
||||
void _update_path(const String &p_path);
|
||||
void _path_text_changed(const String &p_path);
|
||||
void _path_selected(const String &p_path);
|
||||
void _file_selected(const String &p_path);
|
||||
void _install_path_selected(const String &p_path);
|
||||
|
||||
void _browse_path();
|
||||
void _browse_install_path();
|
||||
void _create_folder();
|
||||
|
||||
void _text_changed(const String &p_text);
|
||||
void _nonempty_confirmation_ok_pressed();
|
||||
void _renderer_selected();
|
||||
void _remove_created_folder();
|
||||
|
||||
void ok_pressed() override;
|
||||
void cancel_pressed() override;
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
void set_zip_path(const String &p_path);
|
||||
void set_zip_title(const String &p_title);
|
||||
void set_mode(Mode p_mode);
|
||||
void set_project_path(const String &p_path);
|
||||
|
||||
void ask_for_path_and_show();
|
||||
void show_dialog();
|
||||
|
||||
ProjectDialog();
|
||||
};
|
||||
|
||||
class ProjectListItemControl : public HBoxContainer {
|
||||
GDCLASS(ProjectListItemControl, HBoxContainer)
|
||||
|
||||
VBoxContainer *main_vbox = nullptr;
|
||||
TextureButton *favorite_button = nullptr;
|
||||
Button *explore_button = nullptr;
|
||||
|
||||
TextureRect *project_icon = nullptr;
|
||||
Label *project_title = nullptr;
|
||||
Label *project_path = nullptr;
|
||||
TextureRect *project_unsupported_features = nullptr;
|
||||
HBoxContainer *tag_container = nullptr;
|
||||
|
||||
bool project_is_missing = false;
|
||||
bool icon_needs_reload = true;
|
||||
bool is_selected = false;
|
||||
bool is_hovering = false;
|
||||
|
||||
void _favorite_button_pressed();
|
||||
void _explore_button_pressed();
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
void set_project_title(const String &p_title);
|
||||
void set_project_path(const String &p_path);
|
||||
void set_tags(const PackedStringArray &p_tags, ProjectList *p_parent_list);
|
||||
void set_project_icon(const Ref<Texture2D> &p_icon);
|
||||
void set_unsupported_features(PackedStringArray p_features);
|
||||
|
||||
bool should_load_project_icon() const;
|
||||
void set_selected(bool p_selected);
|
||||
|
||||
void set_is_favorite(bool p_favorite);
|
||||
void set_is_missing(bool p_missing);
|
||||
void set_is_grayed(bool p_grayed);
|
||||
|
||||
ProjectListItemControl();
|
||||
};
|
||||
|
||||
class ProjectList : public ScrollContainer {
|
||||
GDCLASS(ProjectList, ScrollContainer)
|
||||
|
||||
friend class ProjectManager;
|
||||
|
||||
public:
|
||||
enum FilterOption {
|
||||
EDIT_DATE,
|
||||
NAME,
|
||||
PATH,
|
||||
TAGS,
|
||||
};
|
||||
|
||||
// Can often be passed by copy
|
||||
struct Item {
|
||||
String project_name;
|
||||
String description;
|
||||
PackedStringArray tags;
|
||||
String tag_sort_string;
|
||||
String path;
|
||||
String icon;
|
||||
String main_scene;
|
||||
PackedStringArray unsupported_features;
|
||||
uint64_t last_edited = 0;
|
||||
bool favorite = false;
|
||||
bool grayed = false;
|
||||
bool missing = false;
|
||||
int version = 0;
|
||||
|
||||
ProjectListItemControl *control = nullptr;
|
||||
|
||||
Item() {}
|
||||
|
||||
Item(const String &p_name,
|
||||
const String &p_description,
|
||||
const PackedStringArray &p_tags,
|
||||
const String &p_path,
|
||||
const String &p_icon,
|
||||
const String &p_main_scene,
|
||||
const PackedStringArray &p_unsupported_features,
|
||||
uint64_t p_last_edited,
|
||||
bool p_favorite,
|
||||
bool p_grayed,
|
||||
bool p_missing,
|
||||
int p_version) {
|
||||
project_name = p_name;
|
||||
description = p_description;
|
||||
tags = p_tags;
|
||||
path = p_path;
|
||||
icon = p_icon;
|
||||
main_scene = p_main_scene;
|
||||
unsupported_features = p_unsupported_features;
|
||||
last_edited = p_last_edited;
|
||||
favorite = p_favorite;
|
||||
grayed = p_grayed;
|
||||
missing = p_missing;
|
||||
version = p_version;
|
||||
control = nullptr;
|
||||
|
||||
PackedStringArray sorted_tags = tags;
|
||||
sorted_tags.sort();
|
||||
tag_sort_string = String().join(sorted_tags);
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ bool operator==(const Item &l) const {
|
||||
return path == l.path;
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
bool project_opening_initiated = false;
|
||||
|
||||
String _search_term;
|
||||
FilterOption _order_option = FilterOption::EDIT_DATE;
|
||||
HashSet<String> _selected_project_paths;
|
||||
String _last_clicked; // Project key
|
||||
VBoxContainer *_scroll_children = nullptr;
|
||||
int _icon_load_index = 0;
|
||||
|
||||
Vector<Item> _projects;
|
||||
|
||||
ConfigFile _config;
|
||||
String _config_path;
|
||||
|
||||
void _panel_input(const Ref<InputEvent> &p_ev, Node *p_hb);
|
||||
void _favorite_pressed(Node *p_hb);
|
||||
void _show_project(const String &p_path);
|
||||
|
||||
void _migrate_config();
|
||||
void _scan_folder_recursive(const String &p_path, List<String> *r_projects);
|
||||
|
||||
void _clear_project_selection();
|
||||
void _toggle_project(int p_index);
|
||||
void _select_project_nocheck(int p_index);
|
||||
void _deselect_project_nocheck(int p_index);
|
||||
void _select_project_range(int p_begin, int p_end);
|
||||
|
||||
void _create_project_item_control(int p_index);
|
||||
void _remove_project(int p_index, bool p_update_settings);
|
||||
|
||||
static Item load_project_data(const String &p_property_key, bool p_favorite);
|
||||
void _update_icons_async();
|
||||
void _load_project_icon(int p_index);
|
||||
|
||||
void _global_menu_new_window(const Variant &p_tag);
|
||||
void _global_menu_open_project(const Variant &p_tag);
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
static const char *SIGNAL_LIST_CHANGED;
|
||||
static const char *SIGNAL_SELECTION_CHANGED;
|
||||
static const char *SIGNAL_PROJECT_ASK_OPEN;
|
||||
|
||||
void update_project_list();
|
||||
int get_project_count() const;
|
||||
|
||||
void find_projects(const String &p_path);
|
||||
void find_projects_multiple(const PackedStringArray &p_paths);
|
||||
void sort_projects();
|
||||
|
||||
void add_project(const String &dir_path, bool favorite);
|
||||
void set_project_version(const String &p_project_path, int version);
|
||||
int refresh_project(const String &dir_path);
|
||||
void ensure_project_visible(int p_index);
|
||||
|
||||
void select_project(int p_index);
|
||||
void select_first_visible_project();
|
||||
void erase_selected_projects(bool p_delete_project_contents);
|
||||
Vector<Item> get_selected_projects() const;
|
||||
const HashSet<String> &get_selected_project_keys() const;
|
||||
int get_single_selected_index() const;
|
||||
|
||||
bool is_any_project_missing() const;
|
||||
void erase_missing_projects();
|
||||
|
||||
void set_search_term(String p_search_term);
|
||||
void add_search_tag(const String &p_tag);
|
||||
void set_order_option(int p_option);
|
||||
|
||||
void update_dock_menu();
|
||||
void save_config();
|
||||
|
||||
ProjectList();
|
||||
};
|
||||
class TabContainer;
|
||||
|
||||
class ProjectManager : public Control {
|
||||
GDCLASS(ProjectManager, Control);
|
||||
|
||||
static ProjectManager *singleton;
|
||||
|
||||
// Utility data.
|
||||
|
||||
static Ref<Texture2D> _file_dialog_get_icon(const String &p_path);
|
||||
static Ref<Texture2D> _file_dialog_get_thumbnail(const String &p_path);
|
||||
|
||||
HashMap<String, Ref<Texture2D>> icon_type_cache;
|
||||
|
||||
void _build_icon_type_cache(Ref<Theme> p_theme);
|
||||
|
||||
static ProjectManager *singleton;
|
||||
// Main layout.
|
||||
|
||||
void _update_size_limits();
|
||||
|
||||
Panel *background_panel = nullptr;
|
||||
Button *about_btn = nullptr;
|
||||
LinkButton *version_btn = nullptr;
|
||||
|
||||
ConfirmationDialog *open_templates = nullptr;
|
||||
EditorAbout *about = nullptr;
|
||||
|
||||
void _show_about();
|
||||
void _version_button_pressed();
|
||||
|
||||
TabContainer *tabs = nullptr;
|
||||
VBoxContainer *local_projects_vb = nullptr;
|
||||
EditorAssetLibrary *asset_library = nullptr;
|
||||
|
||||
void _on_tab_changed(int p_tab);
|
||||
void _open_asset_library();
|
||||
|
||||
// Quick settings.
|
||||
|
||||
OptionButton *language_btn = nullptr;
|
||||
ConfirmationDialog *restart_required_dialog = nullptr;
|
||||
|
||||
void _language_selected(int p_id);
|
||||
void _restart_confirm();
|
||||
void _dim_window();
|
||||
|
||||
// Project list.
|
||||
|
||||
ProjectList *_project_list = nullptr;
|
||||
|
||||
LineEdit *search_box = nullptr;
|
||||
@ -356,29 +109,17 @@ class ProjectManager : public Control {
|
||||
Button *manage_tags_btn = nullptr;
|
||||
Button *erase_btn = nullptr;
|
||||
Button *erase_missing_btn = nullptr;
|
||||
Button *about_btn = nullptr;
|
||||
|
||||
VBoxContainer *local_projects_vb = nullptr;
|
||||
EditorAssetLibrary *asset_library = nullptr;
|
||||
|
||||
Ref<StyleBox> tag_stylebox;
|
||||
|
||||
EditorFileDialog *scan_dir = nullptr;
|
||||
ConfirmationDialog *language_restart_ask = nullptr;
|
||||
|
||||
ConfirmationDialog *erase_ask = nullptr;
|
||||
Label *erase_ask_label = nullptr;
|
||||
// Comment out for now until we have a better warning system to
|
||||
// ensure users delete their project only.
|
||||
//CheckBox *delete_project_contents = nullptr;
|
||||
|
||||
ConfirmationDialog *erase_missing_ask = nullptr;
|
||||
ConfirmationDialog *multi_open_ask = nullptr;
|
||||
ConfirmationDialog *multi_run_ask = nullptr;
|
||||
ConfirmationDialog *ask_full_convert_dialog = nullptr;
|
||||
ConfirmationDialog *ask_update_settings = nullptr;
|
||||
ConfirmationDialog *open_templates = nullptr;
|
||||
EditorAbout *about = nullptr;
|
||||
|
||||
HBoxContainer *settings_hb = nullptr;
|
||||
|
||||
@ -386,30 +127,13 @@ class ProjectManager : public Control {
|
||||
AcceptDialog *dialog_error = nullptr;
|
||||
ProjectDialog *npdialog = nullptr;
|
||||
|
||||
Button *full_convert_button = nullptr;
|
||||
OptionButton *language_btn = nullptr;
|
||||
LinkButton *version_btn = nullptr;
|
||||
|
||||
HashSet<String> tag_set;
|
||||
PackedStringArray current_project_tags;
|
||||
PackedStringArray forbidden_tag_characters{ "/", "\\", "-" };
|
||||
ConfirmationDialog *tag_manage_dialog = nullptr;
|
||||
HFlowContainer *project_tags = nullptr;
|
||||
HFlowContainer *all_tags = nullptr;
|
||||
Label *tag_edit_error = nullptr;
|
||||
Button *create_tag_btn = nullptr;
|
||||
ConfirmationDialog *create_tag_dialog = nullptr;
|
||||
LineEdit *new_tag_name = nullptr;
|
||||
Label *tag_error = nullptr;
|
||||
|
||||
void _open_asset_library();
|
||||
void _scan_projects();
|
||||
void _run_project();
|
||||
void _run_project_confirm();
|
||||
void _open_selected_projects();
|
||||
void _open_selected_projects_ask();
|
||||
void _full_convert_button_pressed();
|
||||
void _perform_full_project_conversion();
|
||||
|
||||
void _install_project(const String &p_zip_path, const String &p_title);
|
||||
void _import_project();
|
||||
void _new_project();
|
||||
void _rename_project();
|
||||
@ -417,11 +141,30 @@ class ProjectManager : public Control {
|
||||
void _erase_missing_projects();
|
||||
void _erase_project_confirm();
|
||||
void _erase_missing_projects_confirm();
|
||||
void _show_about();
|
||||
void _update_project_buttons();
|
||||
void _language_selected(int p_id);
|
||||
void _restart_confirm();
|
||||
void _confirm_update_settings();
|
||||
|
||||
void _on_project_created(const String &dir);
|
||||
void _on_projects_updated();
|
||||
|
||||
void _on_order_option_changed(int p_idx);
|
||||
void _on_search_term_changed(const String &p_term);
|
||||
void _on_search_term_submitted(const String &p_text);
|
||||
|
||||
// Project tag management.
|
||||
|
||||
HashSet<String> tag_set;
|
||||
PackedStringArray current_project_tags;
|
||||
PackedStringArray forbidden_tag_characters{ "/", "\\", "-" };
|
||||
|
||||
ConfirmationDialog *tag_manage_dialog = nullptr;
|
||||
HFlowContainer *project_tags = nullptr;
|
||||
HFlowContainer *all_tags = nullptr;
|
||||
Label *tag_edit_error = nullptr;
|
||||
|
||||
Button *create_tag_btn = nullptr;
|
||||
ConfirmationDialog *create_tag_dialog = nullptr;
|
||||
LineEdit *new_tag_name = nullptr;
|
||||
Label *tag_error = nullptr;
|
||||
|
||||
void _manage_project_tags();
|
||||
void _add_project_tag(const String &p_tag);
|
||||
@ -430,52 +173,37 @@ class ProjectManager : public Control {
|
||||
void _set_new_tag_name(const String p_name);
|
||||
void _create_new_tag();
|
||||
|
||||
void _on_project_created(const String &dir);
|
||||
void _on_projects_updated();
|
||||
// Project converter/migration tool.
|
||||
|
||||
void _install_project(const String &p_zip_path, const String &p_title);
|
||||
ConfirmationDialog *ask_full_convert_dialog = nullptr;
|
||||
ConfirmationDialog *ask_update_settings = nullptr;
|
||||
Button *full_convert_button = nullptr;
|
||||
|
||||
void _full_convert_button_pressed();
|
||||
void _perform_full_project_conversion();
|
||||
|
||||
// Input and I/O.
|
||||
|
||||
void _dim_window();
|
||||
virtual void shortcut_input(const Ref<InputEvent> &p_ev) override;
|
||||
|
||||
void _files_dropped(PackedStringArray p_files);
|
||||
|
||||
void _version_button_pressed();
|
||||
void _on_order_option_changed(int p_idx);
|
||||
void _on_tab_changed(int p_tab);
|
||||
void _on_search_term_changed(const String &p_term);
|
||||
void _on_search_term_submitted(const String &p_text);
|
||||
|
||||
static Ref<Texture2D> _file_dialog_get_icon(const String &p_path);
|
||||
static Ref<Texture2D> _file_dialog_get_thumbnail(const String &p_path);
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
|
||||
public:
|
||||
static ProjectManager *get_singleton() { return singleton; }
|
||||
|
||||
// Project list.
|
||||
|
||||
LineEdit *get_search_box();
|
||||
|
||||
// Project tag management.
|
||||
|
||||
void add_new_tag(const String &p_tag);
|
||||
|
||||
ProjectManager();
|
||||
~ProjectManager();
|
||||
};
|
||||
|
||||
class ProjectTag : public HBoxContainer {
|
||||
GDCLASS(ProjectTag, HBoxContainer);
|
||||
|
||||
String tag_string;
|
||||
Button *button = nullptr;
|
||||
bool display_close = false;
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
|
||||
public:
|
||||
ProjectTag(const String &p_text, bool p_display_close = false);
|
||||
|
||||
void connect_button_to(const Callable &p_callable);
|
||||
const String get_tag() const;
|
||||
};
|
||||
|
||||
#endif // PROJECT_MANAGER_H
|
||||
|
5
editor/project_manager/SCsub
Normal file
5
editor/project_manager/SCsub
Normal file
@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
Import("env")
|
||||
|
||||
env.add_source_files(env.editor_sources, "*.cpp")
|
977
editor/project_manager/project_dialog.cpp
Normal file
977
editor/project_manager/project_dialog.cpp
Normal file
@ -0,0 +1,977 @@
|
||||
/**************************************************************************/
|
||||
/* project_dialog.cpp */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#include "project_dialog.h"
|
||||
|
||||
#include "core/config/project_settings.h"
|
||||
#include "core/io/dir_access.h"
|
||||
#include "core/io/zip_io.h"
|
||||
#include "core/version.h"
|
||||
#include "editor/editor_settings.h"
|
||||
#include "editor/editor_string_names.h"
|
||||
#include "editor/editor_vcs_interface.h"
|
||||
#include "editor/gui/editor_file_dialog.h"
|
||||
#include "editor/themes/editor_icons.h"
|
||||
#include "editor/themes/editor_scale.h"
|
||||
#include "scene/gui/check_box.h"
|
||||
#include "scene/gui/line_edit.h"
|
||||
#include "scene/gui/option_button.h"
|
||||
#include "scene/gui/separator.h"
|
||||
#include "scene/gui/texture_rect.h"
|
||||
|
||||
void ProjectDialog::_set_message(const String &p_msg, MessageType p_type, InputType input_type) {
|
||||
msg->set_text(p_msg);
|
||||
Ref<Texture2D> current_path_icon = status_rect->get_texture();
|
||||
Ref<Texture2D> current_install_icon = install_status_rect->get_texture();
|
||||
Ref<Texture2D> new_icon;
|
||||
|
||||
switch (p_type) {
|
||||
case MESSAGE_ERROR: {
|
||||
msg->add_theme_color_override("font_color", get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
|
||||
msg->set_modulate(Color(1, 1, 1, 1));
|
||||
new_icon = get_editor_theme_icon(SNAME("StatusError"));
|
||||
|
||||
} break;
|
||||
case MESSAGE_WARNING: {
|
||||
msg->add_theme_color_override("font_color", get_theme_color(SNAME("warning_color"), EditorStringName(Editor)));
|
||||
msg->set_modulate(Color(1, 1, 1, 1));
|
||||
new_icon = get_editor_theme_icon(SNAME("StatusWarning"));
|
||||
|
||||
} break;
|
||||
case MESSAGE_SUCCESS: {
|
||||
msg->remove_theme_color_override("font_color");
|
||||
msg->set_modulate(Color(1, 1, 1, 0));
|
||||
new_icon = get_editor_theme_icon(SNAME("StatusSuccess"));
|
||||
|
||||
} break;
|
||||
}
|
||||
|
||||
if (current_path_icon != new_icon && input_type == PROJECT_PATH) {
|
||||
status_rect->set_texture(new_icon);
|
||||
} else if (current_install_icon != new_icon && input_type == INSTALL_PATH) {
|
||||
install_status_rect->set_texture(new_icon);
|
||||
}
|
||||
}
|
||||
|
||||
static bool is_zip_file(Ref<DirAccess> p_d, const String &p_path) {
|
||||
return p_path.ends_with(".zip") && p_d->file_exists(p_path);
|
||||
}
|
||||
|
||||
String ProjectDialog::_test_path() {
|
||||
Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
||||
const String base_path = project_path->get_text();
|
||||
String valid_path, valid_install_path;
|
||||
bool is_zip = false;
|
||||
if (d->change_dir(base_path) == OK) {
|
||||
valid_path = base_path;
|
||||
} else if (is_zip_file(d, base_path)) {
|
||||
valid_path = base_path;
|
||||
is_zip = true;
|
||||
} else if (d->change_dir(base_path.strip_edges()) == OK) {
|
||||
valid_path = base_path.strip_edges();
|
||||
} else if (is_zip_file(d, base_path.strip_edges())) {
|
||||
valid_path = base_path.strip_edges();
|
||||
is_zip = true;
|
||||
}
|
||||
|
||||
if (valid_path.is_empty()) {
|
||||
_set_message(TTR("The path specified doesn't exist."), MESSAGE_ERROR);
|
||||
get_ok_button()->set_disabled(true);
|
||||
return "";
|
||||
}
|
||||
|
||||
if (mode == MODE_IMPORT && is_zip) {
|
||||
if (d->change_dir(install_path->get_text()) == OK) {
|
||||
valid_install_path = install_path->get_text();
|
||||
} else if (d->change_dir(install_path->get_text().strip_edges()) == OK) {
|
||||
valid_install_path = install_path->get_text().strip_edges();
|
||||
}
|
||||
|
||||
if (valid_install_path.is_empty()) {
|
||||
_set_message(TTR("The install path specified doesn't exist."), MESSAGE_ERROR, INSTALL_PATH);
|
||||
get_ok_button()->set_disabled(true);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
if (mode == MODE_IMPORT || mode == MODE_RENAME) {
|
||||
if (!d->file_exists("project.godot")) {
|
||||
if (is_zip) {
|
||||
Ref<FileAccess> io_fa;
|
||||
zlib_filefunc_def io = zipio_create_io(&io_fa);
|
||||
|
||||
unzFile pkg = unzOpen2(valid_path.utf8().get_data(), &io);
|
||||
if (!pkg) {
|
||||
_set_message(TTR("Error opening package file (it's not in ZIP format)."), MESSAGE_ERROR);
|
||||
get_ok_button()->set_disabled(true);
|
||||
unzClose(pkg);
|
||||
return "";
|
||||
}
|
||||
|
||||
int ret = unzGoToFirstFile(pkg);
|
||||
while (ret == UNZ_OK) {
|
||||
unz_file_info info;
|
||||
char fname[16384];
|
||||
ret = unzGetCurrentFileInfo(pkg, &info, fname, 16384, nullptr, 0, nullptr, 0);
|
||||
if (ret != UNZ_OK) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (String::utf8(fname).ends_with("project.godot")) {
|
||||
break;
|
||||
}
|
||||
|
||||
ret = unzGoToNextFile(pkg);
|
||||
}
|
||||
|
||||
if (ret == UNZ_END_OF_LIST_OF_FILE) {
|
||||
_set_message(TTR("Invalid \".zip\" project file; it doesn't contain a \"project.godot\" file."), MESSAGE_ERROR);
|
||||
get_ok_button()->set_disabled(true);
|
||||
unzClose(pkg);
|
||||
return "";
|
||||
}
|
||||
|
||||
unzClose(pkg);
|
||||
|
||||
// check if the specified install folder is empty, even though this is not an error, it is good to check here
|
||||
d->list_dir_begin();
|
||||
is_folder_empty = true;
|
||||
String n = d->get_next();
|
||||
while (!n.is_empty()) {
|
||||
if (!n.begins_with(".")) {
|
||||
// Allow `.`, `..` (reserved current/parent folder names)
|
||||
// and hidden files/folders to be present.
|
||||
// For instance, this lets users initialize a Git repository
|
||||
// and still be able to create a project in the directory afterwards.
|
||||
is_folder_empty = false;
|
||||
break;
|
||||
}
|
||||
n = d->get_next();
|
||||
}
|
||||
d->list_dir_end();
|
||||
|
||||
if (!is_folder_empty) {
|
||||
_set_message(TTR("Please choose an empty install folder."), MESSAGE_WARNING, INSTALL_PATH);
|
||||
get_ok_button()->set_disabled(true);
|
||||
return "";
|
||||
}
|
||||
|
||||
} else {
|
||||
_set_message(TTR("Please choose a \"project.godot\", a directory with it, or a \".zip\" file."), MESSAGE_ERROR);
|
||||
install_path_container->hide();
|
||||
get_ok_button()->set_disabled(true);
|
||||
return "";
|
||||
}
|
||||
|
||||
} else if (is_zip) {
|
||||
_set_message(TTR("The install directory already contains a Godot project."), MESSAGE_ERROR, INSTALL_PATH);
|
||||
get_ok_button()->set_disabled(true);
|
||||
return "";
|
||||
}
|
||||
|
||||
} else {
|
||||
// Check if the specified folder is empty, even though this is not an error, it is good to check here.
|
||||
d->list_dir_begin();
|
||||
is_folder_empty = true;
|
||||
String n = d->get_next();
|
||||
while (!n.is_empty()) {
|
||||
if (!n.begins_with(".")) {
|
||||
// Allow `.`, `..` (reserved current/parent folder names)
|
||||
// and hidden files/folders to be present.
|
||||
// For instance, this lets users initialize a Git repository
|
||||
// and still be able to create a project in the directory afterwards.
|
||||
is_folder_empty = false;
|
||||
break;
|
||||
}
|
||||
n = d->get_next();
|
||||
}
|
||||
d->list_dir_end();
|
||||
|
||||
if (!is_folder_empty) {
|
||||
if (valid_path == OS::get_singleton()->get_environment("HOME") || valid_path == OS::get_singleton()->get_system_dir(OS::SYSTEM_DIR_DOCUMENTS) || valid_path == OS::get_singleton()->get_executable_path().get_base_dir()) {
|
||||
_set_message(TTR("You cannot save a project in the selected path. Please make a new folder or choose a new path."), MESSAGE_ERROR);
|
||||
get_ok_button()->set_disabled(true);
|
||||
return "";
|
||||
}
|
||||
|
||||
_set_message(TTR("The selected path is not empty. Choosing an empty folder is highly recommended."), MESSAGE_WARNING);
|
||||
get_ok_button()->set_disabled(false);
|
||||
return valid_path;
|
||||
}
|
||||
}
|
||||
|
||||
_set_message("");
|
||||
_set_message("", MESSAGE_SUCCESS, INSTALL_PATH);
|
||||
get_ok_button()->set_disabled(false);
|
||||
return valid_path;
|
||||
}
|
||||
|
||||
void ProjectDialog::_update_path(const String &p_path) {
|
||||
String sp = _test_path();
|
||||
if (!sp.is_empty()) {
|
||||
// If the project name is empty or default, infer the project name from the selected folder name
|
||||
if (project_name->get_text().strip_edges().is_empty() || project_name->get_text().strip_edges() == TTR("New Game Project")) {
|
||||
sp = sp.replace("\\", "/");
|
||||
int lidx = sp.rfind("/");
|
||||
|
||||
if (lidx != -1) {
|
||||
sp = sp.substr(lidx + 1, sp.length()).capitalize();
|
||||
}
|
||||
if (sp.is_empty() && mode == MODE_IMPORT) {
|
||||
sp = TTR("Imported Project");
|
||||
}
|
||||
|
||||
project_name->set_text(sp);
|
||||
_text_changed(sp);
|
||||
}
|
||||
}
|
||||
|
||||
if (!created_folder_path.is_empty() && created_folder_path != p_path) {
|
||||
_remove_created_folder();
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectDialog::_path_text_changed(const String &p_path) {
|
||||
Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
||||
if (mode == MODE_IMPORT && is_zip_file(d, p_path)) {
|
||||
install_path->set_text(p_path.get_base_dir());
|
||||
install_path_container->show();
|
||||
} else if (mode == MODE_IMPORT && is_zip_file(d, p_path.strip_edges())) {
|
||||
install_path->set_text(p_path.strip_edges().get_base_dir());
|
||||
install_path_container->show();
|
||||
} else {
|
||||
install_path_container->hide();
|
||||
}
|
||||
|
||||
_update_path(p_path.simplify_path());
|
||||
}
|
||||
|
||||
void ProjectDialog::_file_selected(const String &p_path) {
|
||||
// If not already shown.
|
||||
show_dialog();
|
||||
|
||||
String p = p_path;
|
||||
if (mode == MODE_IMPORT) {
|
||||
if (p.ends_with("project.godot")) {
|
||||
p = p.get_base_dir();
|
||||
install_path_container->hide();
|
||||
get_ok_button()->set_disabled(false);
|
||||
} else if (p.ends_with(".zip")) {
|
||||
install_path->set_text(p.get_base_dir());
|
||||
install_path_container->show();
|
||||
get_ok_button()->set_disabled(false);
|
||||
} else {
|
||||
_set_message(TTR("Please choose a \"project.godot\" or \".zip\" file."), MESSAGE_ERROR);
|
||||
get_ok_button()->set_disabled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
String sp = p.simplify_path();
|
||||
project_path->set_text(sp);
|
||||
_update_path(sp);
|
||||
if (p.ends_with(".zip")) {
|
||||
callable_mp((Control *)install_path, &Control::grab_focus).call_deferred();
|
||||
} else {
|
||||
callable_mp((Control *)get_ok_button(), &Control::grab_focus).call_deferred();
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectDialog::_path_selected(const String &p_path) {
|
||||
// If not already shown.
|
||||
show_dialog();
|
||||
|
||||
String sp = p_path.simplify_path();
|
||||
project_path->set_text(sp);
|
||||
_update_path(sp);
|
||||
callable_mp((Control *)get_ok_button(), &Control::grab_focus).call_deferred();
|
||||
}
|
||||
|
||||
void ProjectDialog::_install_path_selected(const String &p_path) {
|
||||
String sp = p_path.simplify_path();
|
||||
install_path->set_text(sp);
|
||||
_update_path(sp);
|
||||
callable_mp((Control *)get_ok_button(), &Control::grab_focus).call_deferred();
|
||||
}
|
||||
|
||||
void ProjectDialog::_browse_path() {
|
||||
fdialog->set_current_dir(project_path->get_text());
|
||||
|
||||
if (mode == MODE_IMPORT) {
|
||||
fdialog->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_ANY);
|
||||
fdialog->clear_filters();
|
||||
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);
|
||||
}
|
||||
fdialog->popup_file_dialog();
|
||||
}
|
||||
|
||||
void ProjectDialog::_browse_install_path() {
|
||||
fdialog_install->set_current_dir(install_path->get_text());
|
||||
fdialog_install->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_DIR);
|
||||
fdialog_install->popup_file_dialog();
|
||||
}
|
||||
|
||||
void ProjectDialog::_create_folder() {
|
||||
const String project_name_no_edges = project_name->get_text().strip_edges();
|
||||
if (project_name_no_edges.is_empty() || !created_folder_path.is_empty() || project_name_no_edges.ends_with(".")) {
|
||||
_set_message(TTR("Invalid project name."), MESSAGE_WARNING);
|
||||
return;
|
||||
}
|
||||
|
||||
Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
||||
if (d->change_dir(project_path->get_text()) == OK) {
|
||||
if (!d->dir_exists(project_name_no_edges)) {
|
||||
if (d->make_dir(project_name_no_edges) == OK) {
|
||||
d->change_dir(project_name_no_edges);
|
||||
String dir_str = d->get_current_dir();
|
||||
project_path->set_text(dir_str);
|
||||
_update_path(dir_str);
|
||||
created_folder_path = d->get_current_dir();
|
||||
create_dir->set_disabled(true);
|
||||
} else {
|
||||
dialog_error->set_text(TTR("Couldn't create folder."));
|
||||
dialog_error->popup_centered();
|
||||
}
|
||||
} else {
|
||||
dialog_error->set_text(TTR("There is already a folder in this path with the specified name."));
|
||||
dialog_error->popup_centered();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectDialog::_text_changed(const String &p_text) {
|
||||
if (mode != MODE_NEW) {
|
||||
return;
|
||||
}
|
||||
|
||||
_test_path();
|
||||
|
||||
if (p_text.strip_edges().is_empty()) {
|
||||
_set_message(TTR("It would be a good idea to name your project."), MESSAGE_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectDialog::_nonempty_confirmation_ok_pressed() {
|
||||
is_folder_empty = true;
|
||||
ok_pressed();
|
||||
}
|
||||
|
||||
void ProjectDialog::_renderer_selected() {
|
||||
ERR_FAIL_NULL(renderer_button_group->get_pressed_button());
|
||||
|
||||
String renderer_type = renderer_button_group->get_pressed_button()->get_meta(SNAME("rendering_method"));
|
||||
|
||||
if (renderer_type == "forward_plus") {
|
||||
renderer_info->set_text(
|
||||
String::utf8("• ") + TTR("Supports desktop platforms only.") +
|
||||
String::utf8("\n• ") + TTR("Advanced 3D graphics available.") +
|
||||
String::utf8("\n• ") + TTR("Can scale to large complex scenes.") +
|
||||
String::utf8("\n• ") + TTR("Uses RenderingDevice backend.") +
|
||||
String::utf8("\n• ") + TTR("Slower rendering of simple scenes."));
|
||||
} else if (renderer_type == "mobile") {
|
||||
renderer_info->set_text(
|
||||
String::utf8("• ") + TTR("Supports desktop + mobile platforms.") +
|
||||
String::utf8("\n• ") + TTR("Less advanced 3D graphics.") +
|
||||
String::utf8("\n• ") + TTR("Less scalable for complex scenes.") +
|
||||
String::utf8("\n• ") + TTR("Uses RenderingDevice backend.") +
|
||||
String::utf8("\n• ") + TTR("Fast rendering of simple scenes."));
|
||||
} else if (renderer_type == "gl_compatibility") {
|
||||
renderer_info->set_text(
|
||||
String::utf8("• ") + TTR("Supports desktop, mobile + web platforms.") +
|
||||
String::utf8("\n• ") + TTR("Least advanced 3D graphics (currently work-in-progress).") +
|
||||
String::utf8("\n• ") + TTR("Intended for low-end/older devices.") +
|
||||
String::utf8("\n• ") + TTR("Uses OpenGL 3 backend (OpenGL 3.3/ES 3.0/WebGL2).") +
|
||||
String::utf8("\n• ") + TTR("Fastest rendering of simple scenes."));
|
||||
} else {
|
||||
WARN_PRINT("Unknown renderer type. Please report this as a bug on GitHub.");
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectDialog::_remove_created_folder() {
|
||||
if (!created_folder_path.is_empty()) {
|
||||
Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
||||
d->remove(created_folder_path);
|
||||
|
||||
create_dir->set_disabled(false);
|
||||
created_folder_path = "";
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectDialog::ok_pressed() {
|
||||
String dir = project_path->get_text();
|
||||
|
||||
if (mode == MODE_RENAME) {
|
||||
String dir2 = _test_path();
|
||||
if (dir2.is_empty()) {
|
||||
_set_message(TTR("Invalid project path (changed anything?)."), MESSAGE_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
// 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 at '%s' (error %d). It may be missing or corrupted."), project_godot, err), MESSAGE_ERROR);
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
hide();
|
||||
emit_signal(SNAME("projects_updated"));
|
||||
|
||||
} else {
|
||||
if (mode == MODE_IMPORT) {
|
||||
if (project_path->get_text().ends_with(".zip")) {
|
||||
mode = MODE_INSTALL;
|
||||
ok_pressed();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (mode == MODE_NEW) {
|
||||
// Before we create a project, check that the target folder is empty.
|
||||
// If not, we need to ask the user if they're sure they want to do this.
|
||||
if (!is_folder_empty) {
|
||||
ConfirmationDialog *cd = memnew(ConfirmationDialog);
|
||||
cd->set_title(TTR("Warning: This folder is not empty"));
|
||||
cd->set_text(TTR("You are about to create a Godot project in a non-empty folder.\nThe entire contents of this folder will be imported as project resources!\n\nAre you sure you wish to continue?"));
|
||||
cd->get_ok_button()->connect("pressed", callable_mp(this, &ProjectDialog::_nonempty_confirmation_ok_pressed));
|
||||
get_parent()->add_child(cd);
|
||||
cd->popup_centered();
|
||||
cd->grab_focus();
|
||||
return;
|
||||
}
|
||||
PackedStringArray project_features = ProjectSettings::get_required_features();
|
||||
ProjectSettings::CustomMap initial_settings;
|
||||
|
||||
// Be sure to change this code if/when renderers are changed.
|
||||
// Default values are "forward_plus" for the main setting, "mobile" for the mobile override,
|
||||
// and "gl_compatibility" for the web override.
|
||||
String renderer_type = renderer_button_group->get_pressed_button()->get_meta(SNAME("rendering_method"));
|
||||
initial_settings["rendering/renderer/rendering_method"] = renderer_type;
|
||||
|
||||
EditorSettings::get_singleton()->set("project_manager/default_renderer", renderer_type);
|
||||
EditorSettings::get_singleton()->save();
|
||||
|
||||
if (renderer_type == "forward_plus") {
|
||||
project_features.push_back("Forward Plus");
|
||||
} else if (renderer_type == "mobile") {
|
||||
project_features.push_back("Mobile");
|
||||
} else if (renderer_type == "gl_compatibility") {
|
||||
project_features.push_back("GL Compatibility");
|
||||
// Also change the default rendering method for the mobile override.
|
||||
initial_settings["rendering/renderer/rendering_method.mobile"] = "gl_compatibility";
|
||||
} 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.svg";
|
||||
|
||||
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 {
|
||||
// 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) {
|
||||
if (project_path->get_text().ends_with(".zip")) {
|
||||
dir = install_path->get_text();
|
||||
zip_path = project_path->get_text();
|
||||
}
|
||||
|
||||
Ref<FileAccess> io_fa;
|
||||
zlib_filefunc_def io = zipio_create_io(&io_fa);
|
||||
|
||||
unzFile pkg = unzOpen2(zip_path.utf8().get_data(), &io);
|
||||
if (!pkg) {
|
||||
dialog_error->set_text(TTR("Error opening package file, not in ZIP format."));
|
||||
dialog_error->popup_centered();
|
||||
return;
|
||||
}
|
||||
|
||||
// Find the zip_root
|
||||
String zip_root;
|
||||
int ret = unzGoToFirstFile(pkg);
|
||||
while (ret == UNZ_OK) {
|
||||
unz_file_info info;
|
||||
char fname[16384];
|
||||
unzGetCurrentFileInfo(pkg, &info, fname, 16384, nullptr, 0, nullptr, 0);
|
||||
|
||||
String name = String::utf8(fname);
|
||||
if (name.ends_with("project.godot")) {
|
||||
zip_root = name.substr(0, name.rfind("project.godot"));
|
||||
break;
|
||||
}
|
||||
|
||||
ret = unzGoToNextFile(pkg);
|
||||
}
|
||||
|
||||
ret = unzGoToFirstFile(pkg);
|
||||
|
||||
Vector<String> failed_files;
|
||||
|
||||
while (ret == UNZ_OK) {
|
||||
//get filename
|
||||
unz_file_info info;
|
||||
char fname[16384];
|
||||
ret = unzGetCurrentFileInfo(pkg, &info, fname, 16384, nullptr, 0, nullptr, 0);
|
||||
if (ret != UNZ_OK) {
|
||||
break;
|
||||
}
|
||||
|
||||
String path = String::utf8(fname);
|
||||
|
||||
if (path.is_empty() || path == zip_root || !zip_root.is_subsequence_of(path)) {
|
||||
//
|
||||
} else if (path.ends_with("/")) { // a dir
|
||||
path = path.substr(0, path.length() - 1);
|
||||
String rel_path = path.substr(zip_root.length());
|
||||
|
||||
Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
||||
da->make_dir(dir.path_join(rel_path));
|
||||
} else {
|
||||
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, 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.path_join(rel_path), FileAccess::WRITE);
|
||||
if (f.is_valid()) {
|
||||
f->store_buffer(uncomp_data.ptr(), uncomp_data.size());
|
||||
} else {
|
||||
failed_files.push_back(rel_path);
|
||||
}
|
||||
}
|
||||
|
||||
ret = unzGoToNextFile(pkg);
|
||||
}
|
||||
|
||||
unzClose(pkg);
|
||||
|
||||
if (failed_files.size()) {
|
||||
String err_msg = TTR("The following files failed extraction from package:") + "\n\n";
|
||||
for (int i = 0; i < failed_files.size(); i++) {
|
||||
if (i > 15) {
|
||||
err_msg += "\nAnd " + itos(failed_files.size() - i) + " more files.";
|
||||
break;
|
||||
}
|
||||
err_msg += failed_files[i] + "\n";
|
||||
}
|
||||
|
||||
dialog_error->set_text(err_msg);
|
||||
dialog_error->popup_centered();
|
||||
|
||||
} else if (!project_path->get_text().ends_with(".zip")) {
|
||||
dialog_error->set_text(TTR("Package installed successfully!"));
|
||||
dialog_error->popup_centered();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dir = dir.replace("\\", "/");
|
||||
if (dir.ends_with("/")) {
|
||||
dir = dir.substr(0, dir.length() - 1);
|
||||
}
|
||||
|
||||
hide();
|
||||
emit_signal(SNAME("project_created"), dir);
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectDialog::cancel_pressed() {
|
||||
_remove_created_folder();
|
||||
|
||||
project_path->clear();
|
||||
_update_path("");
|
||||
project_name->clear();
|
||||
_text_changed("");
|
||||
|
||||
if (status_rect->get_texture() == get_editor_theme_icon(SNAME("StatusError"))) {
|
||||
msg->show();
|
||||
}
|
||||
|
||||
if (install_status_rect->get_texture() == get_editor_theme_icon(SNAME("StatusError"))) {
|
||||
msg->show();
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectDialog::set_zip_path(const String &p_path) {
|
||||
zip_path = p_path;
|
||||
}
|
||||
|
||||
void ProjectDialog::set_zip_title(const String &p_title) {
|
||||
zip_title = p_title;
|
||||
}
|
||||
|
||||
void ProjectDialog::set_mode(Mode p_mode) {
|
||||
mode = p_mode;
|
||||
}
|
||||
|
||||
void ProjectDialog::set_project_path(const String &p_path) {
|
||||
project_path->set_text(p_path);
|
||||
}
|
||||
|
||||
void ProjectDialog::ask_for_path_and_show() {
|
||||
// Workaround: for the file selection dialog content to be rendered we need to show its parent dialog.
|
||||
show_dialog();
|
||||
_set_message("");
|
||||
|
||||
_browse_path();
|
||||
}
|
||||
|
||||
void ProjectDialog::show_dialog() {
|
||||
if (mode == MODE_RENAME) {
|
||||
project_path->set_editable(false);
|
||||
browse->hide();
|
||||
install_browse->hide();
|
||||
|
||||
set_title(TTR("Rename Project"));
|
||||
set_ok_button_text(TTR("Rename"));
|
||||
name_container->show();
|
||||
status_rect->hide();
|
||||
msg->hide();
|
||||
install_path_container->hide();
|
||||
install_status_rect->hide();
|
||||
renderer_container->hide();
|
||||
default_files_container->hide();
|
||||
get_ok_button()->set_disabled(false);
|
||||
|
||||
// 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 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 {
|
||||
String cur_name = cfg.get_value("application", "config/name", "");
|
||||
project_name->set_text(cur_name);
|
||||
_text_changed(cur_name);
|
||||
}
|
||||
|
||||
callable_mp((Control *)project_name, &Control::grab_focus).call_deferred();
|
||||
|
||||
create_dir->hide();
|
||||
|
||||
} else {
|
||||
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);
|
||||
} else {
|
||||
Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
||||
project_path->set_text(d->get_current_dir());
|
||||
fdialog->set_current_dir(d->get_current_dir());
|
||||
}
|
||||
|
||||
if (project_name->get_text().is_empty()) {
|
||||
String proj = TTR("New Game Project");
|
||||
project_name->set_text(proj);
|
||||
_text_changed(proj);
|
||||
}
|
||||
|
||||
project_path->set_editable(true);
|
||||
browse->set_disabled(false);
|
||||
browse->show();
|
||||
install_browse->set_disabled(false);
|
||||
install_browse->show();
|
||||
create_dir->show();
|
||||
status_rect->show();
|
||||
install_status_rect->show();
|
||||
msg->show();
|
||||
|
||||
if (mode == MODE_IMPORT) {
|
||||
set_title(TTR("Import Existing Project"));
|
||||
set_ok_button_text(TTR("Import & Edit"));
|
||||
name_container->hide();
|
||||
install_path_container->hide();
|
||||
renderer_container->hide();
|
||||
default_files_container->hide();
|
||||
project_path->grab_focus();
|
||||
|
||||
} else if (mode == MODE_NEW) {
|
||||
set_title(TTR("Create New Project"));
|
||||
set_ok_button_text(TTR("Create & Edit"));
|
||||
name_container->show();
|
||||
install_path_container->hide();
|
||||
renderer_container->show();
|
||||
default_files_container->show();
|
||||
callable_mp((Control *)project_name, &Control::grab_focus).call_deferred();
|
||||
callable_mp(project_name, &LineEdit::select_all).call_deferred();
|
||||
|
||||
} else if (mode == MODE_INSTALL) {
|
||||
set_title(TTR("Install Project:") + " " + zip_title);
|
||||
set_ok_button_text(TTR("Install & Edit"));
|
||||
project_name->set_text(zip_title);
|
||||
name_container->show();
|
||||
install_path_container->hide();
|
||||
renderer_container->hide();
|
||||
default_files_container->hide();
|
||||
project_path->grab_focus();
|
||||
}
|
||||
|
||||
_test_path();
|
||||
}
|
||||
|
||||
popup_centered(Size2(500, 0) * EDSCALE);
|
||||
}
|
||||
|
||||
void ProjectDialog::_notification(int p_what) {
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_WM_CLOSE_REQUEST: {
|
||||
_remove_created_folder();
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectDialog::_bind_methods() {
|
||||
ADD_SIGNAL(MethodInfo("project_created"));
|
||||
ADD_SIGNAL(MethodInfo("projects_updated"));
|
||||
}
|
||||
|
||||
ProjectDialog::ProjectDialog() {
|
||||
VBoxContainer *vb = memnew(VBoxContainer);
|
||||
add_child(vb);
|
||||
|
||||
name_container = memnew(VBoxContainer);
|
||||
vb->add_child(name_container);
|
||||
|
||||
Label *l = memnew(Label);
|
||||
l->set_text(TTR("Project Name:"));
|
||||
name_container->add_child(l);
|
||||
|
||||
HBoxContainer *pnhb = memnew(HBoxContainer);
|
||||
name_container->add_child(pnhb);
|
||||
|
||||
project_name = memnew(LineEdit);
|
||||
project_name->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
||||
pnhb->add_child(project_name);
|
||||
|
||||
create_dir = memnew(Button);
|
||||
pnhb->add_child(create_dir);
|
||||
create_dir->set_text(TTR("Create Folder"));
|
||||
create_dir->connect("pressed", callable_mp(this, &ProjectDialog::_create_folder));
|
||||
|
||||
path_container = memnew(VBoxContainer);
|
||||
vb->add_child(path_container);
|
||||
|
||||
l = memnew(Label);
|
||||
l->set_text(TTR("Project Path:"));
|
||||
path_container->add_child(l);
|
||||
|
||||
HBoxContainer *pphb = memnew(HBoxContainer);
|
||||
path_container->add_child(pphb);
|
||||
|
||||
project_path = memnew(LineEdit);
|
||||
project_path->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
||||
project_path->set_structured_text_bidi_override(TextServer::STRUCTURED_TEXT_FILE);
|
||||
pphb->add_child(project_path);
|
||||
|
||||
install_path_container = memnew(VBoxContainer);
|
||||
vb->add_child(install_path_container);
|
||||
|
||||
l = memnew(Label);
|
||||
l->set_text(TTR("Project Installation Path:"));
|
||||
install_path_container->add_child(l);
|
||||
|
||||
HBoxContainer *iphb = memnew(HBoxContainer);
|
||||
install_path_container->add_child(iphb);
|
||||
|
||||
install_path = memnew(LineEdit);
|
||||
install_path->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
||||
install_path->set_structured_text_bidi_override(TextServer::STRUCTURED_TEXT_FILE);
|
||||
iphb->add_child(install_path);
|
||||
|
||||
// status icon
|
||||
status_rect = memnew(TextureRect);
|
||||
status_rect->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED);
|
||||
pphb->add_child(status_rect);
|
||||
|
||||
browse = memnew(Button);
|
||||
browse->set_text(TTR("Browse"));
|
||||
browse->connect("pressed", callable_mp(this, &ProjectDialog::_browse_path));
|
||||
pphb->add_child(browse);
|
||||
|
||||
// install status icon
|
||||
install_status_rect = memnew(TextureRect);
|
||||
install_status_rect->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED);
|
||||
iphb->add_child(install_status_rect);
|
||||
|
||||
install_browse = memnew(Button);
|
||||
install_browse->set_text(TTR("Browse"));
|
||||
install_browse->connect("pressed", callable_mp(this, &ProjectDialog::_browse_install_path));
|
||||
iphb->add_child(install_browse);
|
||||
|
||||
msg = memnew(Label);
|
||||
msg->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
|
||||
msg->set_custom_minimum_size(Size2(200, 0) * EDSCALE);
|
||||
vb->add_child(msg);
|
||||
|
||||
// Renderer selection.
|
||||
renderer_container = memnew(VBoxContainer);
|
||||
vb->add_child(renderer_container);
|
||||
l = memnew(Label);
|
||||
l->set_text(TTR("Renderer:"));
|
||||
renderer_container->add_child(l);
|
||||
HBoxContainer *rshc = memnew(HBoxContainer);
|
||||
renderer_container->add_child(rshc);
|
||||
renderer_button_group.instantiate();
|
||||
|
||||
// Left hand side, used for checkboxes to select renderer.
|
||||
Container *rvb = memnew(VBoxContainer);
|
||||
rshc->add_child(rvb);
|
||||
|
||||
String default_renderer_type = "forward_plus";
|
||||
if (EditorSettings::get_singleton()->has_setting("project_manager/default_renderer")) {
|
||||
default_renderer_type = EditorSettings::get_singleton()->get_setting("project_manager/default_renderer");
|
||||
}
|
||||
|
||||
Button *rs_button = memnew(CheckBox);
|
||||
rs_button->set_button_group(renderer_button_group);
|
||||
rs_button->set_text(TTR("Forward+"));
|
||||
#if defined(WEB_ENABLED)
|
||||
rs_button->set_disabled(true);
|
||||
#endif
|
||||
rs_button->set_meta(SNAME("rendering_method"), "forward_plus");
|
||||
rs_button->connect("pressed", callable_mp(this, &ProjectDialog::_renderer_selected));
|
||||
rvb->add_child(rs_button);
|
||||
if (default_renderer_type == "forward_plus") {
|
||||
rs_button->set_pressed(true);
|
||||
}
|
||||
rs_button = memnew(CheckBox);
|
||||
rs_button->set_button_group(renderer_button_group);
|
||||
rs_button->set_text(TTR("Mobile"));
|
||||
#if defined(WEB_ENABLED)
|
||||
rs_button->set_disabled(true);
|
||||
#endif
|
||||
rs_button->set_meta(SNAME("rendering_method"), "mobile");
|
||||
rs_button->connect("pressed", callable_mp(this, &ProjectDialog::_renderer_selected));
|
||||
rvb->add_child(rs_button);
|
||||
if (default_renderer_type == "mobile") {
|
||||
rs_button->set_pressed(true);
|
||||
}
|
||||
rs_button = memnew(CheckBox);
|
||||
rs_button->set_button_group(renderer_button_group);
|
||||
rs_button->set_text(TTR("Compatibility"));
|
||||
#if !defined(GLES3_ENABLED)
|
||||
rs_button->set_disabled(true);
|
||||
#endif
|
||||
rs_button->set_meta(SNAME("rendering_method"), "gl_compatibility");
|
||||
rs_button->connect("pressed", callable_mp(this, &ProjectDialog::_renderer_selected));
|
||||
rvb->add_child(rs_button);
|
||||
#if defined(GLES3_ENABLED)
|
||||
if (default_renderer_type == "gl_compatibility") {
|
||||
rs_button->set_pressed(true);
|
||||
}
|
||||
#endif
|
||||
rshc->add_child(memnew(VSeparator));
|
||||
|
||||
// Right hand side, used for text explaining each choice.
|
||||
rvb = memnew(VBoxContainer);
|
||||
rvb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
||||
rshc->add_child(rvb);
|
||||
renderer_info = memnew(Label);
|
||||
renderer_info->set_modulate(Color(1, 1, 1, 0.7));
|
||||
rvb->add_child(renderer_info);
|
||||
_renderer_selected();
|
||||
|
||||
l = memnew(Label);
|
||||
l->set_text(TTR("The renderer can be changed later, but scenes may need to be adjusted."));
|
||||
// Add some extra spacing to separate it from the list above and the buttons below.
|
||||
l->set_custom_minimum_size(Size2(0, 40) * EDSCALE);
|
||||
l->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
|
||||
l->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
|
||||
l->set_modulate(Color(1, 1, 1, 0.7));
|
||||
renderer_container->add_child(l);
|
||||
|
||||
default_files_container = memnew(HBoxContainer);
|
||||
vb->add_child(default_files_container);
|
||||
l = memnew(Label);
|
||||
l->set_text(TTR("Version Control Metadata:"));
|
||||
default_files_container->add_child(l);
|
||||
vcs_metadata_selection = memnew(OptionButton);
|
||||
vcs_metadata_selection->set_custom_minimum_size(Size2(100, 20));
|
||||
vcs_metadata_selection->add_item(TTR("None"), (int)EditorVCSInterface::VCSMetadata::NONE);
|
||||
vcs_metadata_selection->add_item(TTR("Git"), (int)EditorVCSInterface::VCSMetadata::GIT);
|
||||
vcs_metadata_selection->select((int)EditorVCSInterface::VCSMetadata::GIT);
|
||||
default_files_container->add_child(vcs_metadata_selection);
|
||||
Control *spacer = memnew(Control);
|
||||
spacer->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
||||
default_files_container->add_child(spacer);
|
||||
|
||||
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::_update_path));
|
||||
fdialog->connect("dir_selected", callable_mp(this, &ProjectDialog::_path_selected));
|
||||
fdialog->connect("file_selected", callable_mp(this, &ProjectDialog::_file_selected));
|
||||
fdialog_install->connect("dir_selected", callable_mp(this, &ProjectDialog::_install_path_selected));
|
||||
fdialog_install->connect("file_selected", callable_mp(this, &ProjectDialog::_install_path_selected));
|
||||
|
||||
set_hide_on_ok(false);
|
||||
|
||||
dialog_error = memnew(AcceptDialog);
|
||||
add_child(dialog_error);
|
||||
}
|
136
editor/project_manager/project_dialog.h
Normal file
136
editor/project_manager/project_dialog.h
Normal file
@ -0,0 +1,136 @@
|
||||
/**************************************************************************/
|
||||
/* project_dialog.h */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef PROJECT_DIALOG_H
|
||||
#define PROJECT_DIALOG_H
|
||||
|
||||
#include "scene/gui/dialogs.h"
|
||||
|
||||
class Button;
|
||||
class EditorFileDialog;
|
||||
class LineEdit;
|
||||
class OptionButton;
|
||||
class TextureRect;
|
||||
|
||||
class ProjectDialog : public ConfirmationDialog {
|
||||
GDCLASS(ProjectDialog, ConfirmationDialog);
|
||||
|
||||
public:
|
||||
enum Mode {
|
||||
MODE_NEW,
|
||||
MODE_IMPORT,
|
||||
MODE_INSTALL,
|
||||
MODE_RENAME,
|
||||
};
|
||||
|
||||
private:
|
||||
enum MessageType {
|
||||
MESSAGE_ERROR,
|
||||
MESSAGE_WARNING,
|
||||
MESSAGE_SUCCESS,
|
||||
};
|
||||
|
||||
enum InputType {
|
||||
PROJECT_PATH,
|
||||
INSTALL_PATH,
|
||||
};
|
||||
|
||||
Mode mode = MODE_NEW;
|
||||
bool is_folder_empty = true;
|
||||
|
||||
Button *browse = nullptr;
|
||||
Button *install_browse = nullptr;
|
||||
Button *create_dir = nullptr;
|
||||
VBoxContainer *name_container = nullptr;
|
||||
VBoxContainer *path_container = nullptr;
|
||||
VBoxContainer *install_path_container = nullptr;
|
||||
|
||||
VBoxContainer *renderer_container = nullptr;
|
||||
Label *renderer_info = nullptr;
|
||||
HBoxContainer *default_files_container = nullptr;
|
||||
Ref<ButtonGroup> renderer_button_group;
|
||||
|
||||
Label *msg = nullptr;
|
||||
LineEdit *project_path = nullptr;
|
||||
LineEdit *project_name = nullptr;
|
||||
LineEdit *install_path = nullptr;
|
||||
TextureRect *status_rect = nullptr;
|
||||
TextureRect *install_status_rect = nullptr;
|
||||
|
||||
OptionButton *vcs_metadata_selection = nullptr;
|
||||
|
||||
EditorFileDialog *fdialog = nullptr;
|
||||
EditorFileDialog *fdialog_install = nullptr;
|
||||
AcceptDialog *dialog_error = nullptr;
|
||||
|
||||
String zip_path;
|
||||
String zip_title;
|
||||
String fav_dir;
|
||||
|
||||
String created_folder_path;
|
||||
|
||||
void _set_message(const String &p_msg, MessageType p_type = MESSAGE_SUCCESS, InputType input_type = PROJECT_PATH);
|
||||
|
||||
String _test_path();
|
||||
void _update_path(const String &p_path);
|
||||
void _path_text_changed(const String &p_path);
|
||||
void _path_selected(const String &p_path);
|
||||
void _file_selected(const String &p_path);
|
||||
void _install_path_selected(const String &p_path);
|
||||
|
||||
void _browse_path();
|
||||
void _browse_install_path();
|
||||
void _create_folder();
|
||||
|
||||
void _text_changed(const String &p_text);
|
||||
void _nonempty_confirmation_ok_pressed();
|
||||
void _renderer_selected();
|
||||
void _remove_created_folder();
|
||||
|
||||
void ok_pressed() override;
|
||||
void cancel_pressed() override;
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
void set_zip_path(const String &p_path);
|
||||
void set_zip_title(const String &p_title);
|
||||
void set_mode(Mode p_mode);
|
||||
void set_project_path(const String &p_path);
|
||||
|
||||
void ask_for_path_and_show();
|
||||
void show_dialog();
|
||||
|
||||
ProjectDialog();
|
||||
};
|
||||
|
||||
#endif // PROJECT_DIALOG_H
|
1074
editor/project_manager/project_list.cpp
Normal file
1074
editor/project_manager/project_list.cpp
Normal file
File diff suppressed because it is too large
Load Diff
264
editor/project_manager/project_list.h
Normal file
264
editor/project_manager/project_list.h
Normal file
@ -0,0 +1,264 @@
|
||||
/**************************************************************************/
|
||||
/* project_list.h */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef PROJECT_LIST_H
|
||||
#define PROJECT_LIST_H
|
||||
|
||||
#include "core/io/config_file.h"
|
||||
#include "scene/gui/box_container.h"
|
||||
#include "scene/gui/scroll_container.h"
|
||||
|
||||
class Button;
|
||||
class Label;
|
||||
class ProjectList;
|
||||
class TextureButton;
|
||||
class TextureRect;
|
||||
|
||||
class ProjectListItemControl : public HBoxContainer {
|
||||
GDCLASS(ProjectListItemControl, HBoxContainer)
|
||||
|
||||
VBoxContainer *main_vbox = nullptr;
|
||||
TextureButton *favorite_button = nullptr;
|
||||
Button *explore_button = nullptr;
|
||||
|
||||
TextureRect *project_icon = nullptr;
|
||||
Label *project_title = nullptr;
|
||||
Label *project_path = nullptr;
|
||||
TextureRect *project_unsupported_features = nullptr;
|
||||
HBoxContainer *tag_container = nullptr;
|
||||
|
||||
bool project_is_missing = false;
|
||||
bool icon_needs_reload = true;
|
||||
bool is_selected = false;
|
||||
bool is_hovering = false;
|
||||
|
||||
void _favorite_button_pressed();
|
||||
void _explore_button_pressed();
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
void set_project_title(const String &p_title);
|
||||
void set_project_path(const String &p_path);
|
||||
void set_tags(const PackedStringArray &p_tags, ProjectList *p_parent_list);
|
||||
void set_project_icon(const Ref<Texture2D> &p_icon);
|
||||
void set_unsupported_features(PackedStringArray p_features);
|
||||
|
||||
bool should_load_project_icon() const;
|
||||
void set_selected(bool p_selected);
|
||||
|
||||
void set_is_favorite(bool p_favorite);
|
||||
void set_is_missing(bool p_missing);
|
||||
void set_is_grayed(bool p_grayed);
|
||||
|
||||
ProjectListItemControl();
|
||||
};
|
||||
|
||||
class ProjectList : public ScrollContainer {
|
||||
GDCLASS(ProjectList, ScrollContainer)
|
||||
|
||||
friend class ProjectManager;
|
||||
|
||||
public:
|
||||
enum FilterOption {
|
||||
EDIT_DATE,
|
||||
NAME,
|
||||
PATH,
|
||||
TAGS,
|
||||
};
|
||||
|
||||
// Can often be passed by copy.
|
||||
struct Item {
|
||||
String project_name;
|
||||
String description;
|
||||
PackedStringArray tags;
|
||||
String tag_sort_string;
|
||||
String path;
|
||||
String icon;
|
||||
String main_scene;
|
||||
PackedStringArray unsupported_features;
|
||||
uint64_t last_edited = 0;
|
||||
bool favorite = false;
|
||||
bool grayed = false;
|
||||
bool missing = false;
|
||||
int version = 0;
|
||||
|
||||
ProjectListItemControl *control = nullptr;
|
||||
|
||||
Item() {}
|
||||
|
||||
Item(const String &p_name,
|
||||
const String &p_description,
|
||||
const PackedStringArray &p_tags,
|
||||
const String &p_path,
|
||||
const String &p_icon,
|
||||
const String &p_main_scene,
|
||||
const PackedStringArray &p_unsupported_features,
|
||||
uint64_t p_last_edited,
|
||||
bool p_favorite,
|
||||
bool p_grayed,
|
||||
bool p_missing,
|
||||
int p_version) {
|
||||
project_name = p_name;
|
||||
description = p_description;
|
||||
tags = p_tags;
|
||||
path = p_path;
|
||||
icon = p_icon;
|
||||
main_scene = p_main_scene;
|
||||
unsupported_features = p_unsupported_features;
|
||||
last_edited = p_last_edited;
|
||||
favorite = p_favorite;
|
||||
grayed = p_grayed;
|
||||
missing = p_missing;
|
||||
version = p_version;
|
||||
|
||||
control = nullptr;
|
||||
|
||||
PackedStringArray sorted_tags = tags;
|
||||
sorted_tags.sort();
|
||||
tag_sort_string = String().join(sorted_tags);
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ bool operator==(const Item &l) const {
|
||||
return path == l.path;
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
String _config_path;
|
||||
ConfigFile _config;
|
||||
|
||||
Vector<Item> _projects;
|
||||
|
||||
int _icon_load_index = 0;
|
||||
bool project_opening_initiated = false;
|
||||
|
||||
String _search_term;
|
||||
FilterOption _order_option = FilterOption::EDIT_DATE;
|
||||
HashSet<String> _selected_project_paths;
|
||||
String _last_clicked; // Project key
|
||||
|
||||
VBoxContainer *project_list_vbox = nullptr;
|
||||
|
||||
// Initialization & loading.
|
||||
|
||||
void _migrate_config();
|
||||
|
||||
static Item load_project_data(const String &p_property_key, bool p_favorite);
|
||||
void _update_icons_async();
|
||||
void _load_project_icon(int p_index);
|
||||
|
||||
// Project list updates.
|
||||
|
||||
void _scan_folder_recursive(const String &p_path, List<String> *r_projects);
|
||||
|
||||
// Project list items.
|
||||
|
||||
void _create_project_item_control(int p_index);
|
||||
void _toggle_project(int p_index);
|
||||
void _remove_project(int p_index, bool p_update_settings);
|
||||
|
||||
void _list_item_input(const Ref<InputEvent> &p_ev, Node *p_hb);
|
||||
void _on_favorite_pressed(Node *p_hb);
|
||||
void _on_explore_pressed(const String &p_path);
|
||||
|
||||
// Project list selection.
|
||||
|
||||
void _clear_project_selection();
|
||||
void _select_project_nocheck(int p_index);
|
||||
void _deselect_project_nocheck(int p_index);
|
||||
void _select_project_range(int p_begin, int p_end);
|
||||
|
||||
// Global menu integration.
|
||||
|
||||
void _global_menu_new_window(const Variant &p_tag);
|
||||
void _global_menu_open_project(const Variant &p_tag);
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
static const char *SIGNAL_LIST_CHANGED;
|
||||
static const char *SIGNAL_SELECTION_CHANGED;
|
||||
static const char *SIGNAL_PROJECT_ASK_OPEN;
|
||||
|
||||
static bool project_feature_looks_like_version(const String &p_feature);
|
||||
|
||||
// Initialization & loading.
|
||||
|
||||
void save_config();
|
||||
|
||||
// Project list updates.
|
||||
|
||||
void update_project_list();
|
||||
void sort_projects();
|
||||
int get_project_count() const;
|
||||
|
||||
void find_projects(const String &p_path);
|
||||
void find_projects_multiple(const PackedStringArray &p_paths);
|
||||
|
||||
// Project list items.
|
||||
|
||||
void add_project(const String &dir_path, bool favorite);
|
||||
void set_project_version(const String &p_project_path, int version);
|
||||
int refresh_project(const String &dir_path);
|
||||
void ensure_project_visible(int p_index);
|
||||
|
||||
// Project list selection.
|
||||
|
||||
void select_project(int p_index);
|
||||
void select_first_visible_project();
|
||||
Vector<Item> get_selected_projects() const;
|
||||
const HashSet<String> &get_selected_project_keys() const;
|
||||
int get_single_selected_index() const;
|
||||
void erase_selected_projects(bool p_delete_project_contents);
|
||||
|
||||
// Missing projects.
|
||||
|
||||
bool is_any_project_missing() const;
|
||||
void erase_missing_projects();
|
||||
|
||||
// Project list sorting and filtering.
|
||||
|
||||
void set_search_term(String p_search_term);
|
||||
void add_search_tag(const String &p_tag);
|
||||
void set_order_option(int p_option);
|
||||
|
||||
// Global menu integration.
|
||||
|
||||
void update_dock_menu();
|
||||
|
||||
ProjectList();
|
||||
};
|
||||
|
||||
#endif // PROJECT_LIST_H
|
74
editor/project_manager/project_tag.cpp
Normal file
74
editor/project_manager/project_tag.cpp
Normal file
@ -0,0 +1,74 @@
|
||||
/**************************************************************************/
|
||||
/* project_tag.cpp */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#include "project_tag.h"
|
||||
|
||||
#include "editor/themes/editor_scale.h"
|
||||
#include "scene/gui/button.h"
|
||||
#include "scene/gui/color_rect.h"
|
||||
|
||||
void ProjectTag::_notification(int p_what) {
|
||||
if (display_close && p_what == NOTIFICATION_THEME_CHANGED) {
|
||||
button->set_icon(get_theme_icon(SNAME("close"), SNAME("TabBar")));
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectTag::connect_button_to(const Callable &p_callable) {
|
||||
button->connect(SNAME("pressed"), p_callable, CONNECT_DEFERRED);
|
||||
}
|
||||
|
||||
const String ProjectTag::get_tag() const {
|
||||
return tag_string;
|
||||
}
|
||||
|
||||
ProjectTag::ProjectTag(const String &p_text, bool p_display_close) {
|
||||
add_theme_constant_override(SNAME("separation"), 0);
|
||||
set_v_size_flags(SIZE_SHRINK_CENTER);
|
||||
tag_string = p_text;
|
||||
display_close = p_display_close;
|
||||
|
||||
Color tag_color = Color(1, 0, 0);
|
||||
tag_color.set_ok_hsl_s(0.8);
|
||||
tag_color.set_ok_hsl_h(float(p_text.hash() * 10001 % UINT32_MAX) / float(UINT32_MAX));
|
||||
set_self_modulate(tag_color);
|
||||
|
||||
ColorRect *cr = memnew(ColorRect);
|
||||
add_child(cr);
|
||||
cr->set_custom_minimum_size(Vector2(4, 0) * EDSCALE);
|
||||
cr->set_color(tag_color);
|
||||
|
||||
button = memnew(Button);
|
||||
add_child(button);
|
||||
button->set_auto_translate(false);
|
||||
button->set_text(p_text.capitalize());
|
||||
button->set_focus_mode(FOCUS_NONE);
|
||||
button->set_icon_alignment(HORIZONTAL_ALIGNMENT_RIGHT);
|
||||
button->set_theme_type_variation(SNAME("ProjectTag"));
|
||||
}
|
56
editor/project_manager/project_tag.h
Normal file
56
editor/project_manager/project_tag.h
Normal file
@ -0,0 +1,56 @@
|
||||
/**************************************************************************/
|
||||
/* project_tag.h */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef PROJECT_TAG_H
|
||||
#define PROJECT_TAG_H
|
||||
|
||||
#include "scene/gui/box_container.h"
|
||||
|
||||
class Button;
|
||||
|
||||
class ProjectTag : public HBoxContainer {
|
||||
GDCLASS(ProjectTag, HBoxContainer);
|
||||
|
||||
String tag_string;
|
||||
bool display_close = false;
|
||||
|
||||
Button *button = nullptr;
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
|
||||
public:
|
||||
void connect_button_to(const Callable &p_callable);
|
||||
const String get_tag() const;
|
||||
|
||||
ProjectTag(const String &p_text, bool p_display_close = false);
|
||||
};
|
||||
|
||||
#endif // PROJECT_TAG_H
|
Loading…
Reference in New Issue
Block a user