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/UI.gd

58 lines
1.6 KiB
GDScript3
Raw Normal View History

2020-07-06 22:00:39 +00:00
extends Control
2020-07-20 09:15:39 +00:00
class_name GameUI
2020-07-10 11:31:16 +00:00
enum ServerMenuItem {
2020-07-20 09:15:39 +00:00
ServerInfo
}
enum PopupName {
SpaceMap,
EnergyUsage
2020-07-10 11:31:16 +00:00
}
2020-07-21 17:47:33 +00:00
onready var logs = $Logs
2020-07-22 13:57:33 +00:00
onready var scene = $"/root/scene"
2020-07-23 08:51:39 +00:00
onready var netgame = $"/root/Multiplayer"
2020-07-22 13:57:33 +00:00
2020-07-23 08:51:39 +00:00
const WHISPER_RADIUS = 32*3
2020-07-22 15:34:04 +00:00
const CHAT_RADIUS = 32*10
2020-07-23 08:51:39 +00:00
const SHOUT_RADIUS = 32*14
2020-07-21 17:47:33 +00:00
2020-07-10 11:31:16 +00:00
func _ready() -> void:
# Add options to menu buttons
var serverMenu = $Menu/Margins/Grid/Server.get_popup()
serverMenu.connect("id_pressed", self, "_server_option_chosen")
2020-07-20 09:15:39 +00:00
serverMenu.add_item("Server info", ServerMenuItem.ServerInfo)
2020-07-10 11:31:16 +00:00
func _server_option_chosen(id) -> void:
match id:
2020-07-20 09:15:39 +00:00
ServerMenuItem.ServerInfo:
2020-07-10 11:31:16 +00:00
$ServerInfoPopup.popup_centered()
2020-07-23 08:51:39 +00:00
func open_popup(popup_name) -> void:
match popup_name:
2020-07-20 09:15:39 +00:00
PopupName.SpaceMap:
$MapPopup.popup_centered_ratio()
PopupName.EnergyUsage:
pass
2020-07-23 08:51:39 +00:00
func close_popup(popup_name) -> void:
match popup_name:
2020-07-20 09:15:39 +00:00
PopupName.SpaceMap:
$MapPopup.visible = false
PopupName.EnergyUsage:
pass
2020-07-22 13:57:33 +00:00
2020-07-23 08:51:39 +00:00
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)