This repository has been archived on 2020-09-30. You can view files and clone it, but cannot push or open issues or pull requests.
odyssey-old/Scenes/Menu.gd
2020-07-14 01:59:45 +02:00

74 lines
2 KiB
GDScript

extends Control
export var scale = 4 setget set_scale
export var upThreshold = 1.0/59.0
export var downThreshold = 1.0/30.0
export var delay = 1.0
onready var viewport = $Viewport
onready var background = $Background
onready var netgame = $"/root/Multiplayer"
onready var server_list = $Popup/MarginContainer/VBoxContainer/ItemList
var servers = []
func _ready() -> void:
set_scale(scale)
$"/root/Music/BGM".play()
netgame.connect("ms_updated", self, "_ms_update")
request_servers()
func _process(delta: float) -> void:
# Give the system time to adjust
if delay > 0:
delay -= delta
return
if delta > downThreshold:
print("GPU is taking too much (", delta, "s < ", downThreshold, "s), adjusting shader scale")
set_scale(scale+1)
elif delta < upThreshold and scale > 2:
print("GPU is taking it easy (", delta, "s < ", upThreshold, "s), adjusting shader scale")
set_scale(scale-1)
func request_servers():
netgame.ms_get_entries()
func _ms_update(action, result):
if action == "list_games":
# Reset server list
server_list.clear()
servers = result
for server in servers:
server_list.add_item(server.data.name + " (" + server.address + ") - " + str(server.data.players) + "/" + str(server.data.max_players) + " players")
func set_scale(val) -> void:
scale = val
if viewport:
viewport.size = rect_size / scale
background.update()
func _on_resized() -> void:
if viewport:
viewport.size = rect_size / scale
background.update()
func _host_pressed() -> void:
$"/root/Music/BGM".stop()
$"/root/Multiplayer".host()
func _join_pressed() -> void:
$Popup.popup_centered_ratio()
func join_server(addr: String) -> void:
$"/root/Music/BGM".stop()
$"/root/Multiplayer".join(addr)
func _server_addr_changed(new_text: String) -> void:
$Popup/MarginContainer/VBoxContainer/HBoxContainer/Button.disabled = new_text.length() < 1
func _manual_join_pressed():
join_server($Popup/MarginContainer/VBoxContainer/HBoxContainer/LineEdit.text)
func _server_item_clicked(index):
join_server(servers[index].address)