75 lines
2.0 KiB
GDScript3
Raw Normal View History

2024-01-14 11:22:14 +00:00
extends Node
2024-02-17 18:43:47 +00:00
@export var ui: UIManager
func _enter_tree():
connect_main()
connect_ui()
2024-01-29 22:16:06 +00:00
pause(true)
2024-02-12 08:48:58 +00:00
2024-02-17 18:43:47 +00:00
func _ready():
2024-02-15 15:28:27 +00:00
var args := OS.get_cmdline_args()
var offline := args.has("--offline")
if offline:
2024-02-16 19:04:50 +00:00
Global.account.id = "test"
Global.account.name = "Local"
Global.account.auth_token = "test"
Global.player = %PlayerAdd.spawn_player(Global.account.id)
2024-02-15 15:28:27 +00:00
%Login.success.emit()
else:
%Login.send_login()
2024-01-29 11:32:06 +00:00
2024-01-14 11:22:14 +00:00
func _input(event):
if event.is_action_pressed("toggle_fullscreen"):
2024-01-15 23:22:14 +00:00
toggle_fullscreen()
2024-01-29 11:32:06 +00:00
get_viewport().set_input_as_handled()
func on_login():
2024-02-17 18:43:47 +00:00
%Client.log("Login succeeded.")
%Client.log("ID: %s" % Global.account.id)
%Client.log("Auth token: %s" % Global.account.auth_token)
2024-01-29 22:16:06 +00:00
2024-02-16 19:04:50 +00:00
DisplayServer.window_set_title("%s - %s" % [Global.account.name, Global.account.id])
2024-01-29 11:32:06 +00:00
DisplayServer.window_set_position(Vector2((Global.instance_id % 2) * 960, (Global.instance_id / 2 % 2) * 540))
2024-01-29 22:16:06 +00:00
pause(false)
func on_logout():
2024-02-17 18:43:47 +00:00
%Client.log("[%s] Logout." % Global.account.name)
2024-01-29 22:16:06 +00:00
pause(true)
func pause(enabled: bool):
get_tree().paused = enabled
mute_audio(enabled)
func mute_audio(enabled: bool):
var master_sound = AudioServer.get_bus_index("Master")
AudioServer.set_bus_mute(master_sound, enabled)
2024-01-14 11:22:14 +00:00
2024-02-17 18:43:47 +00:00
func connect_main():
%Login.success.connect(on_login)
%Logout.success.connect(on_logout)
func connect_ui():
ui.login = %Login.success
ui.logout = %Logout.success
ui.ping_changed = %Ping.changed
ui.download_changed = %Client.download_changed
ui.upload_changed = %Client.upload_changed
ui.message_received = %Chat.message_received
2024-01-15 23:22:14 +00:00
func toggle_fullscreen():
var mode = DisplayServer.window_get_mode()
2024-01-14 11:22:14 +00:00
2024-01-15 23:22:14 +00:00
match mode:
DisplayServer.WINDOW_MODE_FULLSCREEN:
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
2024-02-06 11:03:32 +00:00
center_window()
2024-01-15 23:22:14 +00:00
_:
2024-02-06 11:03:32 +00:00
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
func center_window():
var screen_center := DisplayServer.screen_get_position() + DisplayServer.screen_get_size() / 2
var window := get_window()
var window_size = window.get_size_with_decorations()
window.set_position(screen_center - window_size / 2)