82 lines
2.2 KiB
GDScript
82 lines
2.2 KiB
GDScript
extends Node
|
|
|
|
@export var ui: UI
|
|
|
|
func _ready():
|
|
connect_events()
|
|
pause(true)
|
|
|
|
var args := OS.get_cmdline_args()
|
|
var offline := args.has("--offline")
|
|
|
|
if offline:
|
|
start_offline()
|
|
else:
|
|
start_online()
|
|
|
|
func connect_events():
|
|
%Login.success.connect(on_login)
|
|
%Logout.success.connect(on_logout)
|
|
|
|
%Login.success.connect(ui.reconnect.hide)
|
|
%Logout.success.connect(ui.reconnect.show)
|
|
|
|
%Ping.changed.connect(ui.network.set_ping)
|
|
%Client.download_changed.connect(ui.network.set_download)
|
|
%Client.upload_changed.connect(ui.network.set_upload)
|
|
|
|
%Chat.message_received.connect(ui.chat.add_message)
|
|
ui.chat.message_submitted.connect(%Chat.send_message)
|
|
|
|
func start_offline():
|
|
Global.account.id = "test"
|
|
Global.account.name = "Local"
|
|
Global.account.auth_token = "test"
|
|
Global.player = %PlayerAdd.spawn_player(Global.account.id, Global.account.name, Vector3.ZERO)
|
|
%Login.success.emit()
|
|
|
|
func start_online():
|
|
%Login.send_login()
|
|
|
|
func _input(event):
|
|
if event.is_action_pressed("toggle_fullscreen"):
|
|
toggle_fullscreen()
|
|
get_viewport().set_input_as_handled()
|
|
|
|
func on_login():
|
|
%Client.log("Login succeeded.")
|
|
%Client.log("ID: %s" % Global.account.id)
|
|
%Client.log("Auth token: %s" % Global.account.auth_token)
|
|
|
|
DisplayServer.window_set_title("%s - %s" % [Global.account.name, Global.account.id])
|
|
DisplayServer.window_set_position(Vector2((Global.instance_id % 2) * 960, (Global.instance_id / 2 % 2) * 540))
|
|
pause(false)
|
|
|
|
func on_logout():
|
|
%Client.log("[%s] Logout." % Global.account.name)
|
|
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)
|