initial commit, 4.5 stable
Some checks failed
🔗 GHA / 📊 Static checks (push) Has been cancelled
🔗 GHA / 🤖 Android (push) Has been cancelled
🔗 GHA / 🍏 iOS (push) Has been cancelled
🔗 GHA / 🐧 Linux (push) Has been cancelled
🔗 GHA / 🍎 macOS (push) Has been cancelled
🔗 GHA / 🏁 Windows (push) Has been cancelled
🔗 GHA / 🌐 Web (push) Has been cancelled

This commit is contained in:
2025-09-16 20:46:46 -04:00
commit 9d30169a8d
13378 changed files with 7050105 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
#!/usr/bin/env python
from misc.utility.scons_hints import *
Import("env")
env.add_source_files(env.editor_sources, "*.cpp")

View File

@@ -0,0 +1,307 @@
/**************************************************************************/
/* engine_update_label.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 "engine_update_label.h"
#include "core/io/json.h"
#include "editor/editor_string_names.h"
#include "editor/settings/editor_settings.h"
#include "scene/main/http_request.h"
bool EngineUpdateLabel::_can_check_updates() const {
return int(EDITOR_GET("network/connection/network_mode")) == EditorSettings::NETWORK_ONLINE &&
UpdateMode(int(EDITOR_GET("network/connection/check_for_updates"))) != UpdateMode::DISABLED;
}
void EngineUpdateLabel::_check_update() {
checked_update = true;
_set_status(UpdateStatus::BUSY);
http->request("https://godotengine.org/versions.json");
}
void EngineUpdateLabel::_http_request_completed(int p_result, int p_response_code, const PackedStringArray &p_headers, const PackedByteArray &p_body) {
if (p_result != OK) {
_set_status(UpdateStatus::ERROR);
_set_message(vformat(TTR("Failed to check for updates. Error: %d."), p_result), theme_cache.error_color);
return;
}
if (p_response_code != 200) {
_set_status(UpdateStatus::ERROR);
_set_message(vformat(TTR("Failed to check for updates. Response code: %d."), p_response_code), theme_cache.error_color);
return;
}
Array version_array;
{
const uint8_t *r = p_body.ptr();
String s = String::utf8((const char *)r, p_body.size());
Variant result = JSON::parse_string(s);
if (result == Variant()) {
_set_status(UpdateStatus::ERROR);
_set_message(TTR("Failed to parse version JSON."), theme_cache.error_color);
return;
}
if (result.get_type() != Variant::ARRAY) {
_set_status(UpdateStatus::ERROR);
_set_message(TTR("Received JSON data is not a valid version array."), theme_cache.error_color);
return;
}
version_array = result;
}
UpdateMode update_mode = UpdateMode(int(EDITOR_GET("network/connection/check_for_updates")));
bool stable_only = update_mode == UpdateMode::NEWEST_STABLE || update_mode == UpdateMode::NEWEST_PATCH;
const Dictionary current_version_info = Engine::get_singleton()->get_version_info();
int current_major = current_version_info.get("major", 0);
int current_minor = current_version_info.get("minor", 0);
int current_patch = current_version_info.get("patch", 0);
for (const Variant &data_bit : version_array) {
const Dictionary version_info = data_bit;
const String base_version_string = version_info.get("name", "");
const PackedStringArray version_bits = base_version_string.split(".");
if (version_bits.size() < 2) {
continue;
}
int minor = version_bits[1].to_int();
if (version_bits[0].to_int() != current_major || minor < current_minor) {
continue;
}
int patch = 0;
if (version_bits.size() >= 3) {
patch = version_bits[2].to_int();
}
if (minor == current_minor && patch < current_patch) {
continue;
}
if (update_mode == UpdateMode::NEWEST_PATCH && minor > current_minor) {
continue;
}
const Array releases = version_info.get("releases", Array());
if (releases.is_empty()) {
continue;
}
const Dictionary newest_release = releases[0];
const String release_string = newest_release.get("name", "unknown");
int release_index;
VersionType release_type = _get_version_type(release_string, &release_index);
if (minor > current_minor || patch > current_patch) {
if (stable_only && release_type != VersionType::STABLE) {
continue;
}
available_newer_version = vformat("%s-%s", base_version_string, release_string);
break;
}
int current_version_index;
VersionType current_version_type = _get_version_type(current_version_info.get("status", "unknown"), &current_version_index);
if (int(release_type) > int(current_version_type)) {
break;
}
if (int(release_type) == int(current_version_type) && release_index <= current_version_index) {
break;
}
available_newer_version = vformat("%s-%s", base_version_string, release_string);
break;
}
if (!available_newer_version.is_empty()) {
_set_status(UpdateStatus::UPDATE_AVAILABLE);
_set_message(vformat(TTR("Update available: %s."), available_newer_version), theme_cache.update_color);
} else if (available_newer_version.is_empty()) {
_set_status(UpdateStatus::UP_TO_DATE);
}
}
void EngineUpdateLabel::_set_message(const String &p_message, const Color &p_color) {
if (is_disabled()) {
add_theme_color_override("font_disabled_color", p_color);
} else {
add_theme_color_override(SceneStringName(font_color), p_color);
}
set_text(p_message);
}
void EngineUpdateLabel::_set_status(UpdateStatus p_status) {
status = p_status;
if (status == UpdateStatus::BUSY || status == UpdateStatus::UP_TO_DATE) {
// Hide the label to prevent unnecessary distraction.
hide();
return;
} else {
show();
}
switch (status) {
case UpdateStatus::OFFLINE: {
set_disabled(false);
if (int(EDITOR_GET("network/connection/network_mode")) == EditorSettings::NETWORK_OFFLINE) {
_set_message(TTR("Offline mode, update checks disabled."), theme_cache.disabled_color);
} else {
_set_message(TTR("Update checks disabled."), theme_cache.disabled_color);
}
set_accessibility_live(DisplayServer::AccessibilityLiveMode::LIVE_OFF);
set_tooltip_text("");
break;
}
case UpdateStatus::ERROR: {
set_disabled(false);
set_accessibility_live(DisplayServer::AccessibilityLiveMode::LIVE_POLITE);
set_tooltip_text(TTR("An error has occurred. Click to try again."));
} break;
case UpdateStatus::UPDATE_AVAILABLE: {
set_disabled(false);
set_accessibility_live(DisplayServer::AccessibilityLiveMode::LIVE_POLITE);
set_tooltip_text(TTR("Click to open download page."));
} break;
default: {
}
}
}
EngineUpdateLabel::VersionType EngineUpdateLabel::_get_version_type(const String &p_string, int *r_index) const {
VersionType type = VersionType::UNKNOWN;
String index_string;
static HashMap<String, VersionType> type_map;
if (type_map.is_empty()) {
type_map["stable"] = VersionType::STABLE;
type_map["rc"] = VersionType::RC;
type_map["beta"] = VersionType::BETA;
type_map["alpha"] = VersionType::ALPHA;
type_map["dev"] = VersionType::DEV;
}
for (const KeyValue<String, VersionType> &kv : type_map) {
if (p_string.begins_with(kv.key)) {
index_string = p_string.trim_prefix(kv.key);
type = kv.value;
break;
}
}
if (r_index) {
if (index_string.is_empty()) {
*r_index = DEV_VERSION;
} else {
*r_index = index_string.to_int();
}
}
return type;
}
String EngineUpdateLabel::_extract_sub_string(const String &p_line) const {
int j = p_line.find_char('"') + 1;
return p_line.substr(j, p_line.find_char('"', j) - j);
}
void EngineUpdateLabel::_notification(int p_what) {
switch (p_what) {
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
if (!EditorSettings::get_singleton()->check_changed_settings_in_group("network/connection")) {
break;
}
if (_can_check_updates()) {
_check_update();
} else {
_set_status(UpdateStatus::OFFLINE);
}
} break;
case NOTIFICATION_THEME_CHANGED: {
theme_cache.default_color = get_theme_color(SceneStringName(font_color), "Button");
theme_cache.disabled_color = get_theme_color("font_disabled_color", "Button");
theme_cache.error_color = get_theme_color("error_color", EditorStringName(Editor));
theme_cache.update_color = get_theme_color("warning_color", EditorStringName(Editor));
} break;
case NOTIFICATION_READY: {
if (_can_check_updates()) {
_check_update();
} else {
_set_status(UpdateStatus::OFFLINE);
}
} break;
}
}
void EngineUpdateLabel::_bind_methods() {
ADD_SIGNAL(MethodInfo("offline_clicked"));
}
void EngineUpdateLabel::pressed() {
switch (status) {
case UpdateStatus::OFFLINE: {
emit_signal("offline_clicked");
} break;
case UpdateStatus::ERROR: {
_check_update();
} break;
case UpdateStatus::UPDATE_AVAILABLE: {
OS::get_singleton()->shell_open("https://godotengine.org/download/archive/" + available_newer_version);
} break;
default: {
}
}
}
EngineUpdateLabel::EngineUpdateLabel() {
set_underline_mode(UNDERLINE_MODE_ON_HOVER);
http = memnew(HTTPRequest);
http->set_https_proxy(EDITOR_GET("network/http_proxy/host"), EDITOR_GET("network/http_proxy/port"));
http->set_timeout(10.0);
add_child(http);
http->connect("request_completed", callable_mp(this, &EngineUpdateLabel::_http_request_completed));
}

View File

@@ -0,0 +1,100 @@
/**************************************************************************/
/* engine_update_label.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. */
/**************************************************************************/
#pragma once
#include "scene/gui/link_button.h"
class HTTPRequest;
class EngineUpdateLabel : public LinkButton {
GDCLASS(EngineUpdateLabel, LinkButton);
public:
enum class UpdateMode {
DISABLED,
NEWEST_UNSTABLE,
NEWEST_STABLE,
NEWEST_PATCH,
};
private:
static constexpr int DEV_VERSION = 9999; // Version index for unnumbered builds (assumed to always be newest).
enum class VersionType {
STABLE,
RC,
BETA,
ALPHA,
DEV,
UNKNOWN,
};
enum class UpdateStatus {
NONE,
OFFLINE,
BUSY,
ERROR,
UPDATE_AVAILABLE,
UP_TO_DATE,
};
struct ThemeCache {
Color default_color;
Color disabled_color;
Color error_color;
Color update_color;
} theme_cache;
HTTPRequest *http = nullptr;
UpdateStatus status = UpdateStatus::NONE;
bool checked_update = false;
String available_newer_version;
bool _can_check_updates() const;
void _check_update();
void _http_request_completed(int p_result, int p_response_code, const PackedStringArray &p_headers, const PackedByteArray &p_body);
void _set_message(const String &p_message, const Color &p_color);
void _set_status(UpdateStatus p_status);
VersionType _get_version_type(const String &p_string, int *r_index) const;
String _extract_sub_string(const String &p_line) const;
protected:
void _notification(int p_what);
static void _bind_methods();
virtual void pressed() override;
public:
EngineUpdateLabel();
};

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,157 @@
/**************************************************************************/
/* 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. */
/**************************************************************************/
#pragma once
#include "scene/gui/dialogs.h"
class Button;
class CheckBox;
class CheckButton;
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,
MODE_DUPLICATE,
};
private:
enum MessageType {
MESSAGE_ERROR,
MESSAGE_WARNING,
MESSAGE_SUCCESS,
};
enum InputType {
PROJECT_PATH,
INSTALL_PATH,
};
Mode mode = MODE_NEW;
bool is_folder_empty = true;
ConfirmationDialog *nonempty_confirmation = nullptr;
CheckButton *create_dir = nullptr;
Button *project_browse = nullptr;
Button *install_browse = nullptr;
VBoxContainer *name_container = nullptr;
VBoxContainer *project_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;
bool rendering_device_supported = false;
Label *rd_not_supported = nullptr;
Label *msg = nullptr;
LineEdit *project_name = nullptr;
LineEdit *project_path = nullptr;
LineEdit *install_path = nullptr;
TextureRect *project_status_rect = nullptr;
TextureRect *install_status_rect = nullptr;
OptionButton *vcs_metadata_selection = nullptr;
CheckBox *edit_check_box = nullptr;
EditorFileDialog *fdialog_project = nullptr;
EditorFileDialog *fdialog_install = nullptr;
AcceptDialog *dialog_error = nullptr;
String zip_path;
String zip_title;
String original_project_path;
bool duplicate_can_edit = false;
void _set_message(const String &p_msg, MessageType p_type, InputType input_type = PROJECT_PATH);
void _validate_path();
// Project path for MODE_NEW and MODE_INSTALL. Install path for MODE_IMPORT.
// Install path is only visible when importing a ZIP.
String _get_target_path();
void _set_target_path(const String &p_text);
// Calculated from project name / ZIP name.
String auto_dir;
// Updates `auto_dir`. If the target path dir name is equal to `auto_dir` (the default state), the target path is also updated.
void _update_target_auto_dir();
// While `create_dir` is disabled, stores the last target path dir name, or an empty string if equal to `auto_dir`.
String last_custom_target_dir;
void _create_dir_toggled(bool p_pressed);
void _project_name_changed();
void _project_path_changed();
void _install_path_changed();
void _browse_project_path();
void _browse_install_path();
void _project_path_selected(const String &p_path);
void _install_path_selected(const String &p_path);
void _reset_name();
void _renderer_selected();
void _nonempty_confirmation_ok_pressed();
void ok_pressed() override;
protected:
static void _bind_methods();
void _notification(int p_what);
public:
void set_mode(Mode p_mode);
void set_project_name(const String &p_name);
void set_project_path(const String &p_path);
void set_zip_path(const String &p_path);
void set_zip_title(const String &p_title);
void set_original_project_path(const String &p_path);
void set_duplicate_can_edit(bool p_duplicate_can_edit);
void ask_for_path_and_show();
void show_dialog(bool p_reset_name = true);
ProjectDialog();
};

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,307 @@
/**************************************************************************/
/* 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. */
/**************************************************************************/
#pragma once
#include "core/io/config_file.h"
#include "core/os/time.h"
#include "scene/gui/box_container.h"
#include "scene/gui/scroll_container.h"
class AcceptDialog;
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;
Label *last_edited_info = nullptr;
Label *project_version = 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();
ProjectList *get_list() const;
void _accessibility_action_open(const Variant &p_data);
void _accessibility_action_scroll_into_view(const Variant &p_data);
void _accessibility_action_focus(const Variant &p_data);
void _accessibility_action_blur(const Variant &p_data);
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_last_edited_info(const String &p_info);
void set_project_version(const String &p_version);
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;
friend class ProjectListItemControl;
public:
enum FilterOption {
EDIT_DATE,
NAME,
PATH,
TAGS,
};
// Can often be passed by copy.
struct Item {
String project_name;
String description;
String project_version;
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;
bool recovery_mode = false;
int version = 0;
ProjectListItemControl *control = nullptr;
Item() {}
Item(const String &p_name,
const String &p_description,
const String &p_project_version,
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,
bool p_recovery_mode,
int p_version) {
project_name = p_name;
description = p_description;
project_version = p_project_version;
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;
recovery_mode = p_recovery_mode;
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;
}
String get_last_edited_string() const {
if (missing) {
return TTR("Missing Date");
}
OS::TimeZoneInfo tz = OS::get_singleton()->get_time_zone_info();
return Time::get_singleton()->get_datetime_string_from_unix_time(last_edited + tz.bias * 60, true);
}
};
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;
// Projects scan.
struct ScanData {
Thread *thread = nullptr;
PackedStringArray paths_to_scan;
List<String> found_projects;
SafeFlag scan_in_progress;
};
ScanData *scan_data = nullptr;
AcceptDialog *scan_progress = nullptr;
static void _scan_thread(void *p_scan_data);
void _scan_finished();
// 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.
static void _scan_folder_recursive(const String &p_path, List<String> *r_projects, const SafeFlag &p_scan_active);
// 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 load_project_list();
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);
int get_index(const ProjectListItemControl *p_control) const;
// Project list selection.
void select_project(int p_index);
void deselect_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();
};

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,286 @@
/**************************************************************************/
/* project_manager.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. */
/**************************************************************************/
#pragma once
#include "scene/gui/dialogs.h"
#include "scene/gui/scroll_container.h"
class CheckBox;
class EditorAbout;
class EditorAssetLibrary;
class EditorFileDialog;
class EditorTitleBar;
class HFlowContainer;
class LineEdit;
class MarginContainer;
class OptionButton;
class PanelContainer;
class PopupMenu;
class ProjectDialog;
class ProjectList;
class QuickSettingsDialog;
class RichTextLabel;
class TabContainer;
class VBoxContainer;
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);
enum PostDuplicateAction {
POST_DUPLICATE_ACTION_NONE,
POST_DUPLICATE_ACTION_OPEN,
POST_DUPLICATE_ACTION_FULL_CONVERSION,
};
PostDuplicateAction post_duplicate_action = POST_DUPLICATE_ACTION_NONE;
// Main layout.
Ref<Theme> theme;
void _update_size_limits();
void _update_theme(bool p_skip_creation = false);
void _titlebar_resized();
MarginContainer *root_container = nullptr;
Panel *background_panel = nullptr;
VBoxContainer *main_vbox = nullptr;
EditorTitleBar *title_bar = nullptr;
Control *left_menu_spacer = nullptr;
Control *left_spacer = nullptr;
Control *right_menu_spacer = nullptr;
Control *right_spacer = nullptr;
Button *title_bar_logo = nullptr;
HBoxContainer *main_view_toggles = nullptr;
Button *quick_settings_button = nullptr;
enum MainViewTab {
MAIN_VIEW_PROJECTS,
MAIN_VIEW_ASSETLIB,
MAIN_VIEW_MAX
};
MainViewTab current_main_view = MAIN_VIEW_PROJECTS;
HashMap<MainViewTab, Control *> main_view_map;
HashMap<MainViewTab, Button *> main_view_toggle_map;
PanelContainer *main_view_container = nullptr;
Ref<ButtonGroup> main_view_toggles_group;
Button *_add_main_view(MainViewTab p_id, const String &p_name, const Ref<Texture2D> &p_icon, Control *p_view_control);
void _set_main_view_icon(MainViewTab p_id, const Ref<Texture2D> &p_icon);
void _select_main_view(int p_id);
VBoxContainer *local_projects_vb = nullptr;
EditorAssetLibrary *asset_library = nullptr;
EditorAbout *about_dialog = nullptr;
void _show_about();
void _open_asset_library_confirmed();
AcceptDialog *error_dialog = nullptr;
void _show_error(const String &p_message, const Size2 &p_min_size = Size2());
void _dim_window();
// Quick settings.
QuickSettingsDialog *quick_settings_dialog = nullptr;
void _show_quick_settings();
void _restart_confirmed();
// Project list.
VBoxContainer *empty_list_placeholder = nullptr;
RichTextLabel *empty_list_message = nullptr;
Button *empty_list_create_project = nullptr;
Button *empty_list_import_project = nullptr;
Button *empty_list_open_assetlib = nullptr;
Label *empty_list_online_warning = nullptr;
void _update_list_placeholder();
ProjectList *project_list = nullptr;
bool initialized = false;
LineEdit *search_box = nullptr;
Label *loading_label = nullptr;
Label *sort_label = nullptr;
OptionButton *filter_option = nullptr;
PanelContainer *project_list_panel = nullptr;
Button *create_btn = nullptr;
Button *import_btn = nullptr;
Button *scan_btn = nullptr;
Button *open_btn = nullptr;
Button *open_options_btn = nullptr;
Button *run_btn = nullptr;
Button *rename_btn = nullptr;
Button *duplicate_btn = nullptr;
Button *manage_tags_btn = nullptr;
Button *erase_btn = nullptr;
Button *erase_missing_btn = nullptr;
HBoxContainer *open_btn_container = nullptr;
PopupMenu *open_options_popup = nullptr;
EditorFileDialog *scan_dir = 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 *open_recovery_mode_ask = nullptr;
ProjectDialog *project_dialog = nullptr;
void _scan_projects();
void _run_project();
void _run_project_confirm();
void _open_selected_projects();
void _open_selected_projects_with_migration();
void _open_selected_projects_check_warnings();
void _open_selected_projects_check_recovery_mode();
void _install_project(const String &p_zip_path, const String &p_title);
void _import_project();
void _new_project();
void _rename_project();
void _duplicate_project();
void _duplicate_project_with_action(PostDuplicateAction p_action);
void _erase_project();
void _erase_missing_projects();
void _erase_project_confirm();
void _erase_missing_projects_confirm();
void _update_project_buttons();
void _open_options_popup();
void _open_recovery_mode_ask(bool manual = false);
void _on_project_created(const String &dir, bool edit);
void _on_project_duplicated(const String &p_original_path, const String &p_duplicate_path, bool p_edit);
void _on_projects_updated();
void _on_open_options_selected(int p_option);
void _on_recovery_mode_popup_open_normal();
void _on_recovery_mode_popup_open_recovery();
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);
void _delete_project_tag(const String &p_tag);
void _apply_project_tags();
void _set_new_tag_name(const String p_name);
void _create_new_tag();
// Project converter/migration tool.
ConfirmationDialog *ask_full_convert_dialog = nullptr;
ConfirmationDialog *ask_update_settings = nullptr;
VBoxContainer *ask_update_vb = nullptr;
Label *ask_update_label = nullptr;
CheckBox *ask_update_backup = nullptr;
Button *full_convert_button = nullptr;
Button *migration_guide_button = nullptr;
String version_convert_feature;
bool open_in_recovery_mode = false;
bool open_in_verbose_mode = false;
#ifndef DISABLE_DEPRECATED
void _minor_project_migrate();
#endif
void _full_convert_button_pressed();
void _migration_guide_button_pressed();
void _perform_full_project_conversion();
// Input and I/O.
virtual void shortcut_input(const Ref<InputEvent> &p_ev) override;
void _files_dropped(PackedStringArray p_files);
protected:
void _notification(int p_what);
public:
static ProjectManager *get_singleton() { return singleton; }
static constexpr int DEFAULT_WINDOW_WIDTH = 1152;
static constexpr int DEFAULT_WINDOW_HEIGHT = 800;
// Project list.
bool is_initialized() const { return initialized; }
LineEdit *get_search_box();
// Project tag management.
void add_new_tag(const String &p_tag);
ProjectManager();
~ProjectManager();
};

View File

@@ -0,0 +1,75 @@
/**************************************************************************/
/* 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_button_icon(get_theme_icon(SNAME("close"), SNAME("TabBar")));
}
}
void ProjectTag::connect_button_to(const Callable &p_callable) {
button->connect(SceneStringName(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_mode(AUTO_TRANSLATE_MODE_DISABLED);
button->set_text(p_text.capitalize());
button->set_focus_mode(FOCUS_ACCESSIBILITY);
button->set_accessibility_name(vformat(TTR("Project Tag: %s"), p_text));
button->set_icon_alignment(HORIZONTAL_ALIGNMENT_RIGHT);
button->set_theme_type_variation(SNAME("ProjectTagButton"));
}

View File

@@ -0,0 +1,53 @@
/**************************************************************************/
/* 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. */
/**************************************************************************/
#pragma once
#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);
};

View File

@@ -0,0 +1,389 @@
/**************************************************************************/
/* quick_settings_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 "quick_settings_dialog.h"
#include "core/string/translation_server.h"
#include "editor/editor_string_names.h"
#include "editor/settings/editor_settings.h"
#include "editor/themes/editor_scale.h"
#include "scene/gui/box_container.h"
#include "scene/gui/button.h"
#include "scene/gui/label.h"
#include "scene/gui/option_button.h"
#include "scene/gui/panel_container.h"
void QuickSettingsDialog::_fetch_setting_values() {
#ifndef ANDROID_ENABLED
editor_languages.clear();
#endif
editor_themes.clear();
editor_scales.clear();
editor_network_modes.clear();
editor_check_for_updates.clear();
editor_directory_naming_conventions.clear();
{
List<PropertyInfo> editor_settings_properties;
EditorSettings::get_singleton()->get_property_list(&editor_settings_properties);
for (const PropertyInfo &pi : editor_settings_properties) {
if (pi.name == "interface/editor/editor_language") {
#ifndef ANDROID_ENABLED
editor_languages = pi.hint_string.split(",");
#endif
} else if (pi.name == "interface/theme/preset") {
editor_themes = pi.hint_string.split(",");
} else if (pi.name == "interface/editor/display_scale") {
editor_scales = pi.hint_string.split(",");
} else if (pi.name == "network/connection/network_mode") {
editor_network_modes = pi.hint_string.split(",");
} else if (pi.name == "network/connection/check_for_updates") {
editor_check_for_updates = pi.hint_string.split(",");
} else if (pi.name == "project_manager/directory_naming_convention") {
editor_directory_naming_conventions = pi.hint_string.split(",");
}
}
}
}
void QuickSettingsDialog::_update_current_values() {
#ifndef ANDROID_ENABLED
// Language options.
{
const String current_lang = EDITOR_GET("interface/editor/editor_language");
for (int i = 0; i < editor_languages.size(); i++) {
const String &lang_value = editor_languages[i];
if (current_lang == lang_value) {
language_option_button->set_text(current_lang);
language_option_button->select(i);
}
}
}
#endif
// Theme options.
{
const String current_theme = EDITOR_GET("interface/theme/preset");
for (int i = 0; i < editor_themes.size(); i++) {
const String &theme_value = editor_themes[i];
if (current_theme == theme_value) {
theme_option_button->set_text(current_theme);
theme_option_button->select(i);
theme_option_button->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
custom_theme_label->set_visible(current_theme == "Custom");
}
}
}
// Scale options.
{
const int current_scale = EDITOR_GET("interface/editor/display_scale");
for (int i = 0; i < editor_scales.size(); i++) {
const String &scale_value = editor_scales[i];
if (current_scale == i) {
scale_option_button->set_text(scale_value);
scale_option_button->select(i);
}
}
}
// Network mode options.
{
const int current_network_mode = EDITOR_GET("network/connection/network_mode");
for (int i = 0; i < editor_network_modes.size(); i++) {
const String &network_mode_value = editor_network_modes[i];
if (current_network_mode == i) {
network_mode_option_button->set_text(network_mode_value);
network_mode_option_button->select(i);
}
}
}
// Check for updates options.
{
const int current_update_mode = EDITOR_GET("network/connection/check_for_updates");
for (int i = 0; i < editor_check_for_updates.size(); i++) {
const String &check_for_update_value = editor_check_for_updates[i];
if (current_update_mode == i) {
check_for_update_button->set_text(check_for_update_value);
check_for_update_button->select(i);
// Disables Check for Updates selection if Network mode is set to Offline.
check_for_update_button->set_disabled(!EDITOR_GET("network/connection/network_mode"));
}
}
}
// Project directory naming options.
{
const int current_directory_naming = EDITOR_GET("project_manager/directory_naming_convention");
for (int i = 0; i < editor_directory_naming_conventions.size(); i++) {
const String &directory_naming_value = editor_directory_naming_conventions[i];
if (current_directory_naming == i) {
directory_naming_convention_button->set_text(directory_naming_value);
directory_naming_convention_button->select(i);
}
}
}
}
void QuickSettingsDialog::_add_setting_control(const String &p_text, Control *p_control) {
HBoxContainer *container = memnew(HBoxContainer);
settings_list->add_child(container);
Label *label = memnew(Label(p_text));
label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
container->add_child(label);
p_control->set_h_size_flags(Control::SIZE_EXPAND_FILL);
p_control->set_stretch_ratio(2.0);
container->add_child(p_control);
}
#ifndef ANDROID_ENABLED
void QuickSettingsDialog::_language_selected(int p_id) {
const String selected_language = language_option_button->get_item_metadata(p_id);
_set_setting_value("interface/editor/editor_language", selected_language);
}
#endif
void QuickSettingsDialog::_theme_selected(int p_id) {
const String selected_theme = theme_option_button->get_item_text(p_id);
_set_setting_value("interface/theme/preset", selected_theme);
custom_theme_label->set_visible(selected_theme == "Custom");
}
void QuickSettingsDialog::_scale_selected(int p_id) {
_set_setting_value("interface/editor/display_scale", p_id, true);
}
void QuickSettingsDialog::_network_mode_selected(int p_id) {
_set_setting_value("network/connection/network_mode", p_id);
// Disables Check for Updates selection if Network mode is set to Offline.
check_for_update_button->set_disabled(!p_id);
}
void QuickSettingsDialog::_check_for_update_selected(int p_id) {
_set_setting_value("network/connection/check_for_updates", p_id);
}
void QuickSettingsDialog::_directory_naming_convention_selected(int p_id) {
_set_setting_value("project_manager/directory_naming_convention", p_id);
}
void QuickSettingsDialog::_set_setting_value(const String &p_setting, const Variant &p_value, bool p_restart_required) {
EditorSettings::get_singleton()->set(p_setting, p_value);
EditorSettings::get_singleton()->notify_changes();
EditorSettings::get_singleton()->save();
if (p_restart_required) {
restart_required_label->show();
if (!restart_required_button) {
int ed_swap_cancel_ok = EDITOR_GET("interface/editor/accept_dialog_cancel_ok_buttons");
if (ed_swap_cancel_ok == 0) {
ed_swap_cancel_ok = DisplayServer::get_singleton()->get_swap_cancel_ok() ? 2 : 1;
}
restart_required_button = add_button(TTRC("Restart Now"), ed_swap_cancel_ok != 2);
restart_required_button->connect(SceneStringName(pressed), callable_mp(this, &QuickSettingsDialog::_request_restart));
}
}
}
void QuickSettingsDialog::_request_restart() {
emit_signal("restart_required");
}
void QuickSettingsDialog::update_size_limits(const Size2 &p_max_popup_size) {
#ifndef ANDROID_ENABLED
language_option_button->get_popup()->set_max_size(p_max_popup_size);
#endif
}
void QuickSettingsDialog::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_THEME_CHANGED: {
settings_list_panel->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SNAME("Background"), EditorStringName(EditorStyles)));
restart_required_label->add_theme_color_override(SceneStringName(font_color), get_theme_color(SNAME("warning_color"), EditorStringName(Editor)));
custom_theme_label->add_theme_color_override(SceneStringName(font_color), get_theme_color(SNAME("font_placeholder_color"), EditorStringName(Editor)));
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
if (is_visible()) {
_update_current_values();
}
} break;
}
}
void QuickSettingsDialog::_bind_methods() {
ADD_SIGNAL(MethodInfo("restart_required"));
}
QuickSettingsDialog::QuickSettingsDialog() {
set_title(TTRC("Quick Settings"));
set_ok_button_text(TTRC("Close"));
VBoxContainer *main_vbox = memnew(VBoxContainer);
add_child(main_vbox);
main_vbox->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
// Settings grid.
{
_fetch_setting_values();
settings_list_panel = memnew(PanelContainer);
main_vbox->add_child(settings_list_panel);
settings_list = memnew(VBoxContainer);
settings_list_panel->add_child(settings_list);
#ifndef ANDROID_ENABLED
// Language options.
{
language_option_button = memnew(OptionButton);
language_option_button->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
language_option_button->set_fit_to_longest_item(false);
language_option_button->connect(SceneStringName(item_selected), callable_mp(this, &QuickSettingsDialog::_language_selected));
for (int i = 0; i < editor_languages.size(); i++) {
const String &lang_value = editor_languages[i];
String lang_name = TranslationServer::get_singleton()->get_locale_name(lang_value);
language_option_button->add_item(vformat("[%s] %s", lang_value, lang_name), i);
language_option_button->set_item_metadata(i, lang_value);
}
_add_setting_control(TTRC("Language"), language_option_button);
}
#endif
// Theme options.
{
theme_option_button = memnew(OptionButton);
theme_option_button->set_fit_to_longest_item(false);
theme_option_button->connect(SceneStringName(item_selected), callable_mp(this, &QuickSettingsDialog::_theme_selected));
for (int i = 0; i < editor_themes.size(); i++) {
const String &theme_value = editor_themes[i];
theme_option_button->add_item(theme_value, i);
}
_add_setting_control(TTRC("Interface Theme"), theme_option_button);
custom_theme_label = memnew(Label(TTRC("Custom preset can be further configured in the editor.")));
custom_theme_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_RIGHT);
custom_theme_label->set_custom_minimum_size(Size2(220, 0) * EDSCALE);
custom_theme_label->set_autowrap_mode(TextServer::AUTOWRAP_WORD);
custom_theme_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
custom_theme_label->set_stretch_ratio(2.0);
custom_theme_label->hide();
settings_list->add_child(custom_theme_label);
}
// Scale options.
{
scale_option_button = memnew(OptionButton);
scale_option_button->set_fit_to_longest_item(false);
scale_option_button->connect(SceneStringName(item_selected), callable_mp(this, &QuickSettingsDialog::_scale_selected));
for (int i = 0; i < editor_scales.size(); i++) {
const String &scale_value = editor_scales[i];
scale_option_button->add_item(scale_value, i);
}
_add_setting_control(TTRC("Display Scale"), scale_option_button);
}
// Network mode options.
{
network_mode_option_button = memnew(OptionButton);
network_mode_option_button->set_fit_to_longest_item(false);
network_mode_option_button->connect(SceneStringName(item_selected), callable_mp(this, &QuickSettingsDialog::_network_mode_selected));
for (int i = 0; i < editor_network_modes.size(); i++) {
const String &network_mode_value = editor_network_modes[i];
network_mode_option_button->add_item(network_mode_value, i);
}
_add_setting_control(TTRC("Network Mode"), network_mode_option_button);
}
// Check for updates options.
{
check_for_update_button = memnew(OptionButton);
check_for_update_button->set_fit_to_longest_item(false);
check_for_update_button->connect(SceneStringName(item_selected), callable_mp(this, &QuickSettingsDialog::_check_for_update_selected));
for (int i = 0; i < editor_check_for_updates.size(); i++) {
const String &check_for_update_value = editor_check_for_updates[i];
check_for_update_button->add_item(check_for_update_value, i);
}
_add_setting_control(TTRC("Check for Updates"), check_for_update_button);
}
// Project directory naming options.
{
directory_naming_convention_button = memnew(OptionButton);
directory_naming_convention_button->set_fit_to_longest_item(false);
directory_naming_convention_button->connect(SceneStringName(item_selected), callable_mp(this, &QuickSettingsDialog::_directory_naming_convention_selected));
for (int i = 0; i < editor_directory_naming_conventions.size(); i++) {
const String &directory_naming_convention = editor_directory_naming_conventions[i];
directory_naming_convention_button->add_item(directory_naming_convention, i);
}
_add_setting_control(TTRC("Directory Naming Convention"), directory_naming_convention_button);
}
_update_current_values();
}
// Restart required panel.
{
restart_required_label = memnew(Label(TTRC("Settings changed! The project manager must be restarted for changes to take effect.")));
restart_required_label->set_custom_minimum_size(Size2(560, 0) * EDSCALE);
restart_required_label->set_autowrap_mode(TextServer::AUTOWRAP_WORD);
restart_required_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
restart_required_label->hide();
main_vbox->add_child(restart_required_label);
}
}

View File

@@ -0,0 +1,98 @@
/**************************************************************************/
/* quick_settings_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. */
/**************************************************************************/
#pragma once
#include "scene/gui/dialogs.h"
class Button;
class Label;
class MarginContainer;
class OptionButton;
class PanelContainer;
class VBoxContainer;
class QuickSettingsDialog : public AcceptDialog {
GDCLASS(QuickSettingsDialog, AcceptDialog);
#ifndef ANDROID_ENABLED
Vector<String> editor_languages;
#endif
Vector<String> editor_themes;
Vector<String> editor_scales;
Vector<String> editor_network_modes;
Vector<String> editor_check_for_updates;
Vector<String> editor_directory_naming_conventions;
void _fetch_setting_values();
void _update_current_values();
PanelContainer *settings_list_panel = nullptr;
VBoxContainer *settings_list = nullptr;
void _add_setting_control(const String &p_text, Control *p_control);
#ifndef ANDROID_ENABLED
// The language selection dropdown doesn't work on Android (as the setting isn't saved), see GH-60353.
// Also, the dropdown it spawns is very tall and can't be scrolled without a hardware mouse.
OptionButton *language_option_button = nullptr;
#endif
OptionButton *theme_option_button = nullptr;
OptionButton *scale_option_button = nullptr;
OptionButton *network_mode_option_button = nullptr;
OptionButton *check_for_update_button = nullptr;
OptionButton *directory_naming_convention_button = nullptr;
Label *custom_theme_label = nullptr;
#ifndef ANDROID_ENABLED
void _language_selected(int p_id);
#endif
void _theme_selected(int p_id);
void _scale_selected(int p_id);
void _network_mode_selected(int p_id);
void _check_for_update_selected(int p_id);
void _directory_naming_convention_selected(int p_id);
void _set_setting_value(const String &p_setting, const Variant &p_value, bool p_restart_required = false);
Label *restart_required_label = nullptr;
Button *restart_required_button = nullptr;
void _request_restart();
protected:
void _notification(int p_what);
static void _bind_methods();
public:
void update_size_limits(const Size2 &p_max_popup_size);
QuickSettingsDialog();
};