liblast/Game/Assets/HUD/Chat.gd

71 lines
2.3 KiB
GDScript
Raw Normal View History

extends Control
@onready var main = get_tree().get_root().get_node("Main")
2021-06-07 11:56:16 +02:00
@onready var chat_history = $VBoxContainer/ChatHistory
@onready var chat_typing = $VBoxContainer/Typing
@onready var chat_editor = $VBoxContainer/Typing/Editor
@onready var chat_label = $VBoxContainer/Typing/Label
enum ChatState {INACTIVE, TYPING_ALL, TYPING_TEAM}
var state = ChatState.INACTIVE :
set(new_state):
state = new_state
match new_state:
ChatState.INACTIVE:
2021-06-07 11:56:16 +02:00
chat_typing.hide()
chat_editor.release_focus()
ChatState.TYPING_ALL:
2021-06-07 11:56:16 +02:00
chat_label.text = "all: "
chat_typing.show()
chat_editor.grab_focus()
chat_editor.text = ''
ChatState.TYPING_TEAM:
2021-06-07 11:56:16 +02:00
chat_label.text = "team: "
chat_typing.show()
chat_editor.grab_focus()
chat_editor.text = ''
# Called when the node enters the scene tree for the first time.
func _ready():
pass
2021-06-07 11:56:16 +02:00
func _input(_event) -> void:
if state == ChatState.INACTIVE:
if Input.is_action_just_pressed("say_all"):
main.focus = main.GameFocus.CHAT
state = ChatState.TYPING_ALL
get_tree().get_root().set_input_as_handled()
2021-06-07 11:56:16 +02:00
if Input.is_action_just_pressed("say_team"):
main.focus = main.GameFocus.CHAT
state = ChatState.TYPING_TEAM
get_tree().get_root().set_input_as_handled()
2021-06-07 11:56:16 +02:00
elif Input.is_action_just_pressed("say_cancel"):
main.focus = main.GameFocus.GAME
state = ChatState.INACTIVE
2021-06-07 11:56:16 +02:00
func _unhandled_input(_event) -> void:
if state != ChatState.INACTIVE:
get_tree().get_root().set_input_as_handled()
2021-06-07 11:56:16 +02:00
# doesn't work over network due to missing RPC implementation in Godot 4
@rpc(sync, any, reliable) func chat_message(sender_pid: int, recipient_team, message: String) -> void:
var sender_info = main.player_list.get(sender_pid)
chat_history.append_text('\n' + '[b][color=' + sender_info.color.to_html() +']' + str(sender_info.name) + '[/color][/b] : [i]' + message + '[/i]')
2021-09-26 02:26:13 +02:00
$Message.play()
2021-09-04 22:37:13 +02:00
@rpc func chat_notification(message: String) -> void:
chat_history.append_text('\n · ' + '[i]' + message + '[/i]')
2021-09-26 02:26:13 +02:00
$Message.play()
2021-07-16 03:42:22 +02:00
func _on_Editor_text_submitted(new_text):
# RPC is currently not implemented in the engine
2021-09-25 18:13:18 +02:00
var sender_id = get_tree().multiplayer.get_unique_id()
2021-06-07 11:56:16 +02:00
var new_message = [sender_id, 0, new_text]
rpc(&'chat_message',sender_id, 0, new_text)
2021-06-07 11:56:16 +02:00
chat_editor.text = ''
state = ChatState.INACTIVE
main.focus = main.GameFocus.GAME