2020-07-10 13:37:13 +00:00
|
|
|
extends Control
|
|
|
|
|
2020-07-14 07:21:52 +00:00
|
|
|
const REFRESH_SERVER_DELAY = 5.0
|
|
|
|
|
2020-07-13 00:20:09 +00:00
|
|
|
export var scale = 4 setget set_scale
|
2020-07-13 09:20:51 +00:00
|
|
|
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
|
2020-07-14 07:21:52 +00:00
|
|
|
export var refresh_server_remaining = REFRESH_SERVER_DELAY
|
2020-07-10 13:20:56 +00:00
|
|
|
|
2020-07-13 09:20:51 +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 09:20:51 +00:00
|
|
|
|
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:
|
2020-07-14 07:21:52 +00:00
|
|
|
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
|
2020-07-13 09:20:51 +00:00
|
|
|
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:
|
2020-07-13 09:20:51 +00:00
|
|
|
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:
|
2020-07-13 09:20:51 +00:00
|
|
|
$"/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])
|