57 lines
1.6 KiB
GDScript
57 lines
1.6 KiB
GDScript
extends Control
|
|
|
|
class_name GameUI
|
|
|
|
enum ServerMenuItem {
|
|
ServerInfo
|
|
}
|
|
|
|
enum PopupName {
|
|
SpaceMap,
|
|
EnergyUsage
|
|
}
|
|
|
|
onready var logs = $Logs
|
|
onready var scene = $"/root/scene"
|
|
onready var netgame = $"/root/Multiplayer"
|
|
|
|
const WHISPER_RADIUS = 32*3
|
|
const CHAT_RADIUS = 32*10
|
|
const SHOUT_RADIUS = 32*14
|
|
|
|
func _ready() -> void:
|
|
# Add options to menu buttons
|
|
var serverMenu = $Menu/Margins/Grid/Server.get_popup()
|
|
serverMenu.connect("id_pressed", self, "_server_option_chosen")
|
|
serverMenu.add_item("Server info", ServerMenuItem.ServerInfo)
|
|
|
|
func _server_option_chosen(id) -> void:
|
|
match id:
|
|
ServerMenuItem.ServerInfo:
|
|
$ServerInfoPopup.popup_centered()
|
|
|
|
func open_popup(popup_name) -> void:
|
|
match popup_name:
|
|
PopupName.SpaceMap:
|
|
$MapPopup.popup_centered_ratio()
|
|
PopupName.EnergyUsage:
|
|
pass
|
|
|
|
func close_popup(popup_name) -> void:
|
|
match popup_name:
|
|
PopupName.SpaceMap:
|
|
$MapPopup.visible = false
|
|
PopupName.EnergyUsage:
|
|
pass
|
|
|
|
const say_format = "%s says \"%s\"\n"
|
|
const shout_format = "%s shouts \"[b]%s[/b]\"\n"
|
|
const whisper_format = "[i]%s whispers \"%s\"[/i]\n"
|
|
func _send_chat(text: String) -> void:
|
|
var escaped_text = text.replace("[", "[\u8203") # Hacky way to escape BBCode
|
|
if text.ends_with("!!"):
|
|
scene.rpc("broadcast_zone", shout_format % [netgame.player_name, escaped_text], scene.world.player.global_position, SHOUT_RADIUS)
|
|
elif text.begins_with("#"):
|
|
scene.rpc("broadcast_zone", whisper_format % [netgame.player_name, escaped_text.substr(1)], scene.world.player.global_position, WHISPER_RADIUS)
|
|
else:
|
|
scene.rpc("broadcast_zone", say_format % [netgame.player_name, escaped_text], scene.world.player.global_position, CHAT_RADIUS)
|