The new 'Only show games available on this platform' checkbox in the plugin settings drops games whose platforms don't include the OS OpenGamepadUI is running on (e.g. Windows-only games on Linux). Games with no platform info at all (HTML5) are kept since there's nothing to filter on. The setting is read on every library load, so toggling it reloads the itch.io library without a restart.
84 lines
3.1 KiB
GDScript
84 lines
3.1 KiB
GDScript
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
|
|
@onready var filter_check: CheckBox = $%FilterUnsupported
|
|
|
|
@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
|
|
|
|
filter_check.button_pressed = settings_manager.get_value("plugin.itch", "filter_unsupported", true) as bool
|
|
|
|
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)
|
|
filter_check.toggled.connect(_on_filter_toggled)
|
|
|
|
|
|
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)
|
|
|
|
|
|
## 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")
|