2026-08-05 17:27:43 -03:00
|
|
|
extends Control
|
|
|
|
|
|
|
|
|
|
## itch.io plugin settings screen
|
|
|
|
|
##
|
|
|
|
|
## NOTE: this uses plain Godot Controls rather than OpenGamepadUI's themed
|
|
|
|
|
## widget set (the ones used by the built-in Steam plugin's settings scene,
|
|
|
|
|
## e.g. its custom StatusIndicator/TextInput components), since this plugin
|
|
|
|
|
## was written without editor access to those scene resources. Swap the
|
|
|
|
|
## nodes below for the themed equivalents if you want it to match the rest
|
|
|
|
|
## of the settings UI pixel-for-pixel.
|
|
|
|
|
|
|
|
|
|
const ItchClient := preload("res://plugins/itch/core/itch_client.gd")
|
|
|
|
|
var settings_manager := load("res://core/global/settings_manager.tres") as SettingsManager
|
|
|
|
|
var notification_manager := load("res://core/global/notification_manager.tres") as NotificationManager
|
|
|
|
|
const icon := preload("res://plugins/itch/assets/itch.svg")
|
|
|
|
|
|
|
|
|
|
@onready var status_label: Label = $%StatusLabel
|
|
|
|
|
@onready var api_key_box: LineEdit = $%ApiKeyInput
|
|
|
|
|
@onready var save_button: Button = $%SaveButton
|
|
|
|
|
@onready var help_label: Label = $%HelpLabel
|
2026-08-07 18:41:39 -03:00
|
|
|
@onready var filter_check: CheckBox = $%FilterUnsupported
|
2026-08-05 17:27:43 -03:00
|
|
|
|
|
|
|
|
@onready var itch: ItchClient = get_tree().get_first_node_in_group("itch_client")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
|
var api_key := settings_manager.get_value("plugin.itch", "api_key", "") as String
|
|
|
|
|
api_key_box.text = api_key
|
|
|
|
|
api_key_box.secret = true
|
|
|
|
|
|
2026-08-07 18:41:39 -03:00
|
|
|
filter_check.button_pressed = settings_manager.get_value("plugin.itch", "filter_unsupported", true) as bool
|
|
|
|
|
|
2026-08-05 17:27:43 -03:00
|
|
|
help_label.text = "Get an API key from https://itch.io/user/settings/api-keys"
|
|
|
|
|
|
|
|
|
|
_update_status()
|
|
|
|
|
itch.client_ready.connect(_update_status)
|
|
|
|
|
itch.logged_in.connect(_on_login)
|
|
|
|
|
|
|
|
|
|
save_button.pressed.connect(_on_save_button)
|
2026-08-07 18:41:39 -03:00
|
|
|
filter_check.toggled.connect(_on_filter_toggled)
|
2026-08-05 17:27:43 -03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
func _update_status() -> void:
|
|
|
|
|
if not itch:
|
|
|
|
|
status_label.text = "Status: itch client not found"
|
|
|
|
|
return
|
|
|
|
|
if itch.state == itch.STATE.BOOT:
|
|
|
|
|
status_label.text = "Status: starting butlerd..."
|
|
|
|
|
return
|
|
|
|
|
if not itch.is_logged_in:
|
|
|
|
|
status_label.text = "Status: connected, not logged in"
|
|
|
|
|
return
|
|
|
|
|
var username: String = itch.profile.get("user", {}).get("username", "")
|
|
|
|
|
status_label.text = "Status: logged in as " + username
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _on_login(status: ItchClient.LOGIN_STATUS, _profile: Dictionary) -> void:
|
|
|
|
|
_update_status()
|
|
|
|
|
|
|
|
|
|
var notify := Notification.new("")
|
|
|
|
|
notify.icon = icon
|
|
|
|
|
if status == ItchClient.LOGIN_STATUS.OK:
|
|
|
|
|
notify.text = "Successfully logged in to itch.io"
|
|
|
|
|
else:
|
|
|
|
|
notify.text = "itch.io login failed. Double check your API key."
|
|
|
|
|
notification_manager.show(notify)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _on_save_button() -> void:
|
|
|
|
|
var api_key: String = api_key_box.text.strip_edges()
|
|
|
|
|
settings_manager.set_value("plugin.itch", "api_key", api_key)
|
|
|
|
|
if api_key == "":
|
|
|
|
|
return
|
|
|
|
|
itch.login_with_api_key(api_key)
|
2026-08-07 18:41:39 -03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
## Persists the platform filter and reloads the itch.io library so the
|
|
|
|
|
## change applies without restarting. The setting is read back by
|
|
|
|
|
## library_itch.gd on every library load, so toggling just re-filters.
|
|
|
|
|
func _on_filter_toggled(pressed: bool) -> void:
|
|
|
|
|
settings_manager.set_value("plugin.itch", "filter_unsupported", pressed)
|
|
|
|
|
var library_manager := load("res://core/global/library_manager.tres") as LibraryManager
|
|
|
|
|
if library_manager:
|
|
|
|
|
library_manager.load_library("itch")
|