add steam overlay, achievements and stats managers

This commit is contained in:
2026-06-23 11:17:31 +02:00
parent efb7a78cf1
commit 298e6cd229
54 changed files with 1031 additions and 13 deletions

View File

@@ -0,0 +1,59 @@
@tool
extends ConfirmationDialog
signal cancel_update
signal continue_update
@onready var cancel_button: Button = %Cancel
@onready var continue_button: Button = %Continue
@onready var downloading: ProgressBar = %Downloading
@onready var message: Label = %Message
@onready var version_title: Label = %VersionTitle
func _ready() -> void:
connect_signals()
set_defaults()
#region Setup
func set_defaults() -> void:
size = Vector2(450, 330)
get_ok_button().visible = false
get_cancel_button().visible = false
#endregion
#region Signals
func connect_signals() -> void:
cancel_button.pressed.connect(_on_cancel_pressed)
continue_button.pressed.connect(_on_continue_pressed)
func _on_cancel_pressed() -> void:
cancel_update.emit()
queue_free()
func _on_continue_pressed() -> void:
continue_update.emit()
#endregion
#region Updating text
func update_interface(version_string: String, is_downloader: bool) -> void:
if not is_node_ready(): await ready
cancel_button.visible = true
continue_button.visible = not is_downloader
downloading.visible = is_downloader
if is_downloader:
message.text = "You are downloading the update, please wait. Closing this window will cancel the update."
version_title.text = "Downloading GodotSteam %s" % version_string
else:
message.text = "You are about to update plug-in version to %s. The editor will restart at the end of this process." % version_string
version_title.text = "Update To GodotSteam %s" % version_string
func update_progress(new_percentage: int) -> void:
downloading.value = new_percentage
#endregion

View File

@@ -0,0 +1 @@
uid://bjb747gou4fbo

View File

@@ -0,0 +1,174 @@
[gd_scene format=3 uid="uid://bb6pyk4s77qvo"]
[ext_resource type="Script" uid="uid://bjb747gou4fbo" path="res://addons/godotsteam/editor/updates/confirmation.gd" id="1_fskym"]
[ext_resource type="Texture2D" uid="uid://dhn3vkdxvetbn" path="res://addons/godotsteam/editor/ui/steam.svg" id="1_xklt4"]
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_cnr4s"]
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_jjufo"]
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_fskym"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_0ql43"]
content_margin_left = 10.0
content_margin_top = 5.0
content_margin_right = 10.0
content_margin_bottom = 5.0
bg_color = Color(0.3372549, 0.61960787, 1, 1)
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_apu4b"]
content_margin_left = 10.0
content_margin_top = 5.0
content_margin_right = 10.0
content_margin_bottom = 5.0
bg_color = Color(0.09803922, 0.09803922, 0.09803922, 1)
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_bi3ss"]
content_margin_left = 10.0
content_margin_top = 5.0
content_margin_right = 10.0
content_margin_bottom = 5.0
bg_color = Color(0, 0, 0, 1)
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_cnr4s"]
content_margin_top = 2.0
content_margin_bottom = 2.0
bg_color = Color(0.09803922, 0.09803922, 0.09803922, 1)
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_jjufo"]
content_margin_top = 2.0
content_margin_bottom = 2.0
bg_color = Color(0.3372549, 0.61960787, 1, 1)
[sub_resource type="Theme" id="Theme_cnr4s"]
AcceptDialog/constants/title_height = 0
AcceptDialog/styles/embedded_border = SubResource("StyleBoxEmpty_cnr4s")
AcceptDialog/styles/embedded_unfocused_border = SubResource("StyleBoxEmpty_jjufo")
AcceptDialog/styles/panel = SubResource("StyleBoxEmpty_fskym")
Button/colors/font_color = Color(1, 1, 1, 1)
Button/styles/hover = SubResource("StyleBoxFlat_0ql43")
Button/styles/normal = SubResource("StyleBoxFlat_apu4b")
Button/styles/pressed = SubResource("StyleBoxFlat_bi3ss")
ProgressBar/styles/background = SubResource("StyleBoxFlat_cnr4s")
ProgressBar/styles/fill = SubResource("StyleBoxFlat_jjufo")
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_fskym"]
bg_color = Color(0.15686275, 0.15686275, 0.15686275, 1)
border_width_bottom = 3
border_color = Color(0.3372549, 0.61960787, 1, 1)
[node name="Confirmation" type="ConfirmationDialog" unique_id=1649782113]
transparent_bg = true
oversampling_override = 1.0
title = "Updating GodotSteam"
initial_position = 1
size = Vector2i(450, 330)
visible = true
wrap_controls = false
unresizable = true
borderless = true
min_size = Vector2i(450, 200)
keep_title_visible = false
content_scale_mode = 1
theme = SubResource("Theme_cnr4s")
ok_button_text = "Continue"
dialog_hide_on_ok = false
dialog_close_on_escape = false
script = ExtResource("1_fskym")
metadata/_edit_lock_ = true
[node name="Panel" type="Panel" parent="." unique_id=336687509]
custom_minimum_size = Vector2(450, 330)
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -225.0
offset_top = -165.0
offset_right = 225.0
offset_bottom = 165.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 4
size_flags_vertical = 4
theme_override_styles/panel = SubResource("StyleBoxFlat_fskym")
metadata/_edit_lock_ = true
[node name="Margin" type="MarginContainer" parent="Panel" unique_id=598549467]
custom_minimum_size = Vector2(450, 330)
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme_override_constants/margin_left = 50
theme_override_constants/margin_top = 50
theme_override_constants/margin_right = 50
theme_override_constants/margin_bottom = 50
metadata/_edit_lock_ = true
[node name="VFrame" type="VBoxContainer" parent="Panel/Margin" unique_id=7442794]
layout_mode = 2
theme_override_constants/separation = 15
metadata/_edit_lock_ = true
[node name="HFrame" type="HBoxContainer" parent="Panel/Margin/VFrame" unique_id=1314013334]
layout_mode = 2
theme_override_constants/separation = 15
metadata/_edit_lock_ = true
[node name="Icon" type="TextureRect" parent="Panel/Margin/VFrame/HFrame" unique_id=521288466]
custom_minimum_size = Vector2(26, 30)
layout_mode = 2
texture = ExtResource("1_xklt4")
expand_mode = 1
stretch_mode = 5
metadata/_edit_lock_ = true
[node name="VersionTitle" type="Label" parent="Panel/Margin/VFrame/HFrame" unique_id=906249057]
unique_name_in_owner = true
custom_minimum_size = Vector2(275, 30)
layout_mode = 2
theme_override_colors/font_outline_color = Color(1, 1, 1, 1)
theme_override_constants/outline_size = 1
theme_override_font_sizes/font_size = 18
text = "Downloading GodotSteam 99.99"
metadata/_edit_lock_ = true
[node name="Message" type="Label" parent="Panel/Margin/VFrame" unique_id=345793881]
unique_name_in_owner = true
custom_minimum_size = Vector2(315, 85)
layout_mode = 2
size_flags_vertical = 0
text = "You are about to update plug-in version to %s. The editor will restart at the end of this process."
autowrap_mode = 3
metadata/_edit_lock_ = true
[node name="Downloading" type="ProgressBar" parent="Panel/Margin/VFrame" unique_id=1922739661]
unique_name_in_owner = true
custom_minimum_size = Vector2(0, 30)
layout_mode = 2
step = 1.0
value = 50.0
metadata/_edit_lock_ = true
[node name="Options" type="HBoxContainer" parent="Panel/Margin/VFrame" unique_id=2126576529]
layout_mode = 2
size_flags_vertical = 10
theme_override_constants/separation = 15
alignment = 2
metadata/_edit_lock_ = true
[node name="Continue" type="Button" parent="Panel/Margin/VFrame/Options" unique_id=851000998]
unique_name_in_owner = true
layout_mode = 2
text = "Continue"
metadata/_edit_lock_ = true
[node name="Cancel" type="Button" parent="Panel/Margin/VFrame/Options" unique_id=1895267580]
unique_name_in_owner = true
layout_mode = 2
text = "Cancel"
metadata/_edit_lock_ = true

View File

@@ -0,0 +1,186 @@
@tool
extends MarginContainer
###
# Super-huge thanks to Nathan Hoad and Marcus Skov for ideas and inspiration on how to create a
# plug-in updater.
###
const TEMP_FILE = "user://update.zip"
const VERSION_URL: StringName = "https://godotengine.org/asset-library/api/asset/2445"
var download_location: String = ""
var downloading_update: bool = false
# This will act as both our version checker and update downloader
var http_request: HTTPRequest = null
var is_actively_downloading: bool = false
var new_version: String = ""
@onready var cancel_button: Button = %CancelButton
@onready var downloading: ProgressBar = %Downloading
@onready var install_button: Button = %InstallButton
@onready var installed_label: Label = %InstalledLabel
@onready var update_label: Label = %UpdateLabel
@onready var update_button: Button = %UpdateButton
func _ready() -> void:
connect_signals()
set_defaults()
check_for_updates()
func _process(delta: float) -> void:
if is_actively_downloading:
downloading.value = http_request.get_downloaded_bytes() * 100 / http_request.get_body_size()
#region Setup
func set_defaults() -> void:
downloading.value = 0
installed_label.text = "Installed version %s" % Steam.get_godotsteam_version()
update_button.text = "Up-to-date"
update_button.disabled = true
update_label.text = ""
updating_visibility(false, false, false, true)
#endregion
#region Signals
func connect_signals() -> void:
cancel_button.pressed.connect(_on_cancel_pressed)
install_button.pressed.connect(_on_install_pressed)
update_button.pressed.connect(_on_update_pressed)
#endregion
#region Checking for updates
func check_for_updates() -> void:
if not ProjectSettings.get_setting("steam/updates/godotsteam/check_for_updates"):
return
http_request = HTTPRequest.new()
add_child(http_request)
http_request.request_completed.connect(_on_http_request_completed)
if http_request.request(VERSION_URL) != OK:
printerr("Failed to request GodotSteam plug-in remote current version")
func _on_http_request_completed(result: int, _response_code: int, _headers: PackedStringArray, body: PackedByteArray) -> void:
http_request.request_completed.disconnect(_on_http_request_completed)
http_request.queue_free()
if result != HTTPRequest.RESULT_SUCCESS:
return
var response = JSON.parse_string(body.get_string_from_utf8())
if response == null:
return
download_location = response.download_url
new_version = response.version_string
if convert_version(new_version) > convert_version(Steam.get_godotsteam_version()):
print("New GodotSteam version %s available" % new_version)
update_label.text = "New version %s" % new_version
update_button.text = "Download"
update_button.disabled = false
#endregion
#region Updating versions
func _on_cancel_pressed() -> void:
updating_visibility(false, false, false, true)
if is_actively_downloading:
http_request.cancel_request()
http_request.queue_free()
is_actively_downloading = false
update_label.text = "Canceling %s plug-in update download" % new_version
else:
DirAccess.remove_absolute(TEMP_FILE)
update_label.text = "Canceling %s plug-in update and deleting temporary files" % new_version
update_button.text = "Download"
update_button.disabled = false
update_label.text = "New version %s" % new_version
func _on_install_pressed() -> void:
print("Removing older GodotSteam %s plug-in" % Steam.get_godotsteam_version())
OS.move_to_trash(ProjectSettings.globalize_path("res://addons/godotsteam"))
update_button.text = "Unpacking"
print("Unpacking new %s plug-in" % new_version)
var zip_reader: ZIPReader = ZIPReader.new()
zip_reader.open(TEMP_FILE)
var files: PackedStringArray = zip_reader.get_files()
var base_path := files[1]
# Remove archive folder
files.remove_at(0)
# Remove assets folder
files.remove_at(0)
for path in files:
var new_file_path: String = path.replace(base_path, "")
if path.ends_with("/"):
DirAccess.make_dir_recursive_absolute("res://addons/%s" % new_file_path)
else:
var file: FileAccess = FileAccess.open("res://addons/%s" % new_file_path, FileAccess.WRITE)
file.store_buffer(zip_reader.read_file(path))
zip_reader.close()
restart_post_update()
func _on_update_pressed() -> void:
is_actively_downloading = true
update_label.text = "Downloading %s plug-in update, please wait" % new_version
updating_visibility(true, true, false, false)
http_request = HTTPRequest.new()
add_child(http_request)
http_request.request_completed.connect(_on_download_request_completed)
if http_request.request(download_location) != OK:
printerr("Failed to request %s plug-in update download" % new_version)
is_actively_downloading = false
update_button.text = "Failed"
update_button.disabled = false
return
func _on_download_request_completed(result: int, _response_code: int, _headers: PackedStringArray, body: PackedByteArray) -> void:
http_request.request_completed.disconnect(_on_download_request_completed)
http_request.queue_free()
is_actively_downloading = false
updating_visibility(true, false, true, false)
if result != HTTPRequest.RESULT_SUCCESS:
printerr("Failed to download new GodotSteam version %s" % result)
update_button.disabled = false
return
update_label.text = "Update downloaded, ready to install %s" % new_version
var zip_file: FileAccess = FileAccess.open(TEMP_FILE, FileAccess.WRITE)
zip_file.store_buffer(body)
zip_file.close()
func restart_post_update() -> void:
update_button.text = "Restarting"
update_label.text = "Updated to version %s, restarting the editor" % new_version
DirAccess.remove_absolute(TEMP_FILE)
EditorInterface.restart_editor(true)
#endregion
#region Helpers
func convert_version(version_string: String) -> int:
return int(version_string.replace(".", "").rpad(4, "0"))
func updating_visibility(cancel: bool, download: bool, install: bool, update: bool) -> void:
cancel_button.visible = cancel
downloading.visible = download
install_button.visible = install
update_button.visible = update
#endregion

View File

@@ -0,0 +1 @@
uid://b4nvgu7h84u53