71 lines
2.4 KiB
GDScript3
71 lines
2.4 KiB
GDScript3
|
|
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 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
|
||
|
|
|
||
|
|
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)
|
||
|
|
|
||
|
|
|
||
|
|
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)
|