Add chat format

This commit is contained in:
Hamcha 2020-07-23 10:51:39 +02:00
parent 6ddb52c27c
commit f57e1c433b
Signed by: hamcha
GPG key ID: 41467804B19A3315
4 changed files with 25 additions and 12 deletions

View file

@ -13,6 +13,7 @@ onready var physics = world.get_world_2d().direct_space_state
var writing = false var writing = false
func _ready() -> void: func _ready() -> void:
$"/root/Music/BGM".stop()
randomize() randomize()
if netgame.hosting: if netgame.hosting:
world.load_map(netgame.get_current_map()) world.load_map(netgame.get_current_map())

View file

@ -13,8 +13,11 @@ enum PopupName {
onready var logs = $Logs onready var logs = $Logs
onready var scene = $"/root/scene" onready var scene = $"/root/scene"
onready var netgame = $"/root/Multiplayer"
const WHISPER_RADIUS = 32*3
const CHAT_RADIUS = 32*10 const CHAT_RADIUS = 32*10
const SHOUT_RADIUS = 32*14
func _ready() -> void: func _ready() -> void:
# Add options to menu buttons # Add options to menu buttons
@ -27,19 +30,28 @@ func _server_option_chosen(id) -> void:
ServerMenuItem.ServerInfo: ServerMenuItem.ServerInfo:
$ServerInfoPopup.popup_centered() $ServerInfoPopup.popup_centered()
func open_popup(map_name) -> void: func open_popup(popup_name) -> void:
match map_name: match popup_name:
PopupName.SpaceMap: PopupName.SpaceMap:
$MapPopup.popup_centered_ratio() $MapPopup.popup_centered_ratio()
PopupName.EnergyUsage: PopupName.EnergyUsage:
pass pass
func close_popup(map_name) -> void: func close_popup(popup_name) -> void:
match map_name: match popup_name:
PopupName.SpaceMap: PopupName.SpaceMap:
$MapPopup.visible = false $MapPopup.visible = false
PopupName.EnergyUsage: PopupName.EnergyUsage:
pass pass
func _send_chat(text): const say_format = "%s says \"%s\"\n"
scene.rpc("broadcast_zone", text + "\n", scene.world.player.global_position, CHAT_RADIUS) 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)

View file

@ -11,5 +11,5 @@ dest_files=[ "res://.import/neutral-bi-beep.ogg-b80d5dd9b7ca71aa0d191c8ef7940dc5
[params] [params]
loop=true loop=false
loop_offset=0 loop_offset=0

View file

@ -11,11 +11,11 @@ dest_files=[ "res://.import/radio-message.wav-ce2c91f356066e01259b32b652b758a3.s
[params] [params]
force/8_bit=false force/8_bit=true
force/mono=false force/mono=true
force/max_rate=false force/max_rate=false
force/max_rate_hz=44100 force/max_rate_hz=44100
edit/trim=false edit/trim=true
edit/normalize=false edit/normalize=true
edit/loop=false edit/loop=false
compress/mode=0 compress/mode=1