51 lines
1.5 KiB
GDScript
51 lines
1.5 KiB
GDScript
extends Node
|
|
|
|
func _ready():
|
|
%Logout.success.emit()
|
|
pause(true)
|
|
|
|
%Login.success.connect(on_login)
|
|
%Logout.success.connect(on_logout)
|
|
%Login.send_login()
|
|
|
|
func _input(event):
|
|
if event.is_action_pressed("toggle_fullscreen"):
|
|
toggle_fullscreen()
|
|
get_viewport().set_input_as_handled()
|
|
|
|
func on_login():
|
|
print("[%s] Login succeeded." % Global.username)
|
|
print("[%s] ID: %s" % [Global.username, Global.account_id])
|
|
print("[%s] Auth token: %s" % [Global.username, Global.auth_token])
|
|
|
|
DisplayServer.window_set_title("%s - %s" % [Global.username, Global.account_id])
|
|
DisplayServer.window_set_position(Vector2((Global.instance_id % 2) * 960, (Global.instance_id / 2 % 2) * 540))
|
|
pause(false)
|
|
|
|
func on_logout():
|
|
print("[%s] Logout." % Global.username)
|
|
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)
|
|
|
|
func toggle_fullscreen():
|
|
var mode = DisplayServer.window_get_mode()
|
|
|
|
match mode:
|
|
DisplayServer.WINDOW_MODE_FULLSCREEN:
|
|
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
|
|
center_window()
|
|
_:
|
|
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) |