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

92 lines
2.6 KiB
GDScript3
Raw Normal View History

2020-07-10 13:37:13 +00:00
extends Control
const REFRESH_SERVER_DELAY = 5.0
2020-07-13 00:20:09 +00:00
export var scale = 4 setget set_scale
export var upThreshold = 1.0/59.0
2020-07-10 13:20:56 +00:00
export var downThreshold = 1.0/30.0
export var delay = 1.0
export var refresh_server_remaining = REFRESH_SERVER_DELAY
2020-07-10 13:20:56 +00:00
onready var viewport = $Viewport
onready var background = $Background
2020-07-13 23:59:45 +00:00
onready var netgame = $"/root/Multiplayer"
onready var server_list = $Popup/MarginContainer/VBoxContainer/ItemList
2020-07-13 23:59:45 +00:00
var servers = []
func _ready() -> void:
2020-07-10 13:20:56 +00:00
set_scale(scale)
2020-07-10 13:37:13 +00:00
$"/root/Music/BGM".play()
2020-07-13 23:59:45 +00:00
netgame.connect("ms_updated", self, "_ms_update")
request_servers()
2020-07-14 14:20:06 +00:00
if netgame.gotm_mode:
# Hide manual connect
$Popup/MarginContainer/VBoxContainer/Label2.visible = false
$Popup/MarginContainer/VBoxContainer/HBoxContainer.visible = false
2020-07-10 13:20:56 +00:00
2020-07-13 23:59:45 +00:00
func _process(delta: float) -> void:
refresh_server_remaining -= delta
if refresh_server_remaining <= 0:
request_servers()
refresh_server_remaining = REFRESH_SERVER_DELAY
2020-07-10 13:20:56 +00:00
# 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)
2020-07-12 15:26:40 +00:00
elif delta < upThreshold and scale > 2:
2020-07-10 13:20:56 +00:00
print("GPU is taking it easy (", delta, "s < ", upThreshold, "s), adjusting shader scale")
set_scale(scale-1)
2020-07-13 23:59:45 +00:00
func request_servers():
netgame.ms_get_entries()
func _ms_update(action, result):
if action == "list_games":
# Reset server list
server_list.clear()
2020-07-14 14:20:06 +00:00
if netgame.gotm_mode:
servers = result
for server in servers:
server_list.add_item(server.name + " (" + server.id + ") - " + str(server.peers.size()) + "/" + str(server.get_property("max_players")) + " players")
else:
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")
2020-07-13 23:59:45 +00:00
func set_scale(val) -> void:
2020-07-10 13:20:56 +00:00
scale = val
if viewport:
viewport.size = rect_size / scale
background.update()
2020-07-10 13:20:56 +00:00
2020-07-13 23:59:45 +00:00
func _on_resized() -> void:
if viewport:
viewport.size = rect_size / scale
background.update()
2020-07-12 15:26:40 +00:00
2020-07-13 23:59:45 +00:00
func _host_pressed() -> void:
2020-07-12 15:26:40 +00:00
$"/root/Music/BGM".stop()
$"/root/Multiplayer".host()
2020-07-13 23:59:45 +00:00
func _join_pressed() -> void:
$Popup.popup_centered_ratio()
2020-07-14 14:20:06 +00:00
func join_server(server) -> void:
$"/root/Music/BGM".stop()
2020-07-14 14:20:06 +00:00
netgame.join(server)
2020-07-13 23:59:45 +00:00
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)
2020-07-12 15:26:40 +00:00
2020-07-13 23:59:45 +00:00
func _server_item_clicked(index):
2020-07-14 14:20:06 +00:00
$"/root/Music/BGM".stop()
join_server(servers[index])