feat: updated engine

This commit is contained in:
Sara Gerretsen 2026-07-10 17:04:34 +02:00
parent cbe99774ff
commit f4cf6b3999
6607 changed files with 910135 additions and 430025 deletions

View file

@ -31,6 +31,9 @@
#include "engine_update_label.h"
#include "core/io/json.h"
#include "core/object/callable_mp.h"
#include "core/os/os.h"
#include "core/version.h"
#include "editor/editor_string_names.h"
#include "editor/settings/editor_settings.h"
#include "scene/main/http_request.h"
@ -49,13 +52,13 @@ void EngineUpdateLabel::_check_update() {
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);
_set_message(TTRC("Failed to check for updates. Error: %d."), theme_cache.error_color, p_result);
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);
_set_message(TTRC("Failed to check for updates. Response code: %d."), theme_cache.error_color, p_response_code);
return;
}
@ -67,26 +70,28 @@ void EngineUpdateLabel::_http_request_completed(int p_result, int p_response_cod
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);
_set_message(TTRC("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);
_set_message(TTRC("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")));
if (update_mode == UpdateMode::AUTO) {
if (_get_version_type(GODOT_VERSION_STATUS) == VersionType::STABLE) {
update_mode = UpdateMode::NEWEST_STABLE;
} else {
update_mode = UpdateMode::NEWEST_UNSTABLE;
}
}
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);
available_newer_version = String();
for (const Variant &data_bit : version_array) {
const Dictionary version_info = data_bit;
@ -98,7 +103,7 @@ void EngineUpdateLabel::_http_request_completed(int p_result, int p_response_cod
}
int minor = version_bits[1].to_int();
if (version_bits[0].to_int() != current_major || minor < current_minor) {
if (version_bits[0].to_int() != GODOT_VERSION_MAJOR || minor < GODOT_VERSION_MINOR) {
continue;
}
@ -107,11 +112,11 @@ void EngineUpdateLabel::_http_request_completed(int p_result, int p_response_cod
patch = version_bits[2].to_int();
}
if (minor == current_minor && patch < current_patch) {
if (minor == GODOT_VERSION_MINOR && patch < GODOT_VERSION_PATCH) {
continue;
}
if (update_mode == UpdateMode::NEWEST_PATCH && minor > current_minor) {
if (update_mode == UpdateMode::NEWEST_PATCH && minor > GODOT_VERSION_MINOR) {
continue;
}
@ -126,7 +131,7 @@ void EngineUpdateLabel::_http_request_completed(int p_result, int p_response_cod
int release_index;
VersionType release_type = _get_version_type(release_string, &release_index);
if (minor > current_minor || patch > current_patch) {
if (minor > GODOT_VERSION_MINOR || patch > GODOT_VERSION_PATCH) {
if (stable_only && release_type != VersionType::STABLE) {
continue;
}
@ -136,7 +141,7 @@ void EngineUpdateLabel::_http_request_completed(int p_result, int p_response_cod
}
int current_version_index;
VersionType current_version_type = _get_version_type(current_version_info.get("status", "unknown"), &current_version_index);
VersionType current_version_type = _get_version_type(GODOT_VERSION_STATUS, &current_version_index);
if (int(release_type) > int(current_version_type)) {
break;
@ -152,19 +157,21 @@ void EngineUpdateLabel::_http_request_completed(int p_result, int p_response_cod
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);
_set_message(TTRC("Update available: %s."), theme_cache.update_color, available_newer_version);
} 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) {
void EngineUpdateLabel::_set_message(const String &p_message, const Color &p_color, const Variant &p_message_argument) {
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);
current_message = p_message;
message_argument = p_message_argument;
_update_message();
}
void EngineUpdateLabel::_set_status(UpdateStatus p_status) {
@ -181,24 +188,24 @@ void EngineUpdateLabel::_set_status(UpdateStatus p_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);
_set_message(TTRC("Offline mode, update checks disabled."), theme_cache.disabled_color);
} else {
_set_message(TTR("Update checks disabled."), theme_cache.disabled_color);
_set_message(TTRC("Update checks disabled."), theme_cache.disabled_color);
}
set_accessibility_live(DisplayServer::AccessibilityLiveMode::LIVE_OFF);
set_accessibility_live(AccessibilityServerEnums::AccessibilityLiveMode::LIVE_OFF);
set_tooltip_text("");
break;
}
case UpdateStatus::ERROR: {
set_disabled(false);
set_accessibility_live(DisplayServer::AccessibilityLiveMode::LIVE_POLITE);
set_accessibility_live(AccessibilityServerEnums::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_accessibility_live(AccessibilityServerEnums::AccessibilityLiveMode::LIVE_POLITE);
set_tooltip_text(TTR("Click to open download page."));
} break;
@ -207,6 +214,14 @@ void EngineUpdateLabel::_set_status(UpdateStatus p_status) {
}
}
void EngineUpdateLabel::_update_message() {
if (message_argument.get_type() == Variant::NIL) {
set_text(TTR(current_message));
} else {
set_text(vformat(TTR(current_message), message_argument));
}
}
EngineUpdateLabel::VersionType EngineUpdateLabel::_get_version_type(const String &p_string, int *r_index) const {
VersionType type = VersionType::UNKNOWN;
String index_string;
@ -264,6 +279,12 @@ void EngineUpdateLabel::_notification(int p_what) {
theme_cache.update_color = get_theme_color("warning_color", EditorStringName(Editor));
} break;
case NOTIFICATION_TRANSLATION_CHANGED: {
if (!current_message.is_empty()) {
_update_message();
}
} break;
case NOTIFICATION_READY: {
if (_can_check_updates()) {
_check_update();
@ -299,6 +320,7 @@ void EngineUpdateLabel::pressed() {
EngineUpdateLabel::EngineUpdateLabel() {
set_underline_mode(UNDERLINE_MODE_ON_HOVER);
set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
http = memnew(HTTPRequest);
http->set_https_proxy(EDITOR_GET("network/http_proxy/host"), EDITOR_GET("network/http_proxy/port"));