2021-06-04 00:38:30 +02:00
|
|
|
extends Control
|
|
|
|
|
|
|
|
@onready var main = get_tree().get_root().get_node("Main")
|
2021-06-06 01:58:04 +02:00
|
|
|
@onready var player = main.player
|
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
|
2021-06-06 01:58:04 +02:00
|
|
|
|
2021-06-04 00:38:30 +02:00
|
|
|
enum ChatState {INACTIVE, TYPING_ALL, TYPING_TEAM}
|
2021-06-04 02:33:26 +02:00
|
|
|
enum GameFocus {MENU, GAME, CHAT, AWAY} # copied from Main.gd TODO: delete this
|
|
|
|
|
2021-06-04 00:38:30 +02:00
|
|
|
var state = ChatState.INACTIVE :
|
|
|
|
set(new_state):
|
|
|
|
state = new_state
|
|
|
|
match new_state:
|
2021-06-04 02:33:26 +02:00
|
|
|
0: #ChatState.INACTIVE:
|
2021-06-07 11:56:16 +02:00
|
|
|
chat_typing.hide()
|
|
|
|
chat_editor.release_focus()
|
2021-06-04 02:33:26 +02:00
|
|
|
1: #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 = ''
|
2021-06-04 02:33:26 +02:00
|
|
|
2: #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 = ''
|
2021-06-04 00:38:30 +02:00
|
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
func _ready():
|
2021-06-06 01:58:04 +02:00
|
|
|
pass
|
2021-06-04 00:38:30 +02:00
|
|
|
|
2021-06-07 11:56:16 +02:00
|
|
|
func _input(_event) -> void:
|
2021-06-06 01:58:04 +02:00
|
|
|
if state == ChatState.INACTIVE:
|
|
|
|
if Input.is_action_just_pressed("say_all"):
|
|
|
|
main.focus = 2 #main.GameFocus.CHAT
|
|
|
|
state = 1 #ChatState.TYPING_ALL
|
2021-06-07 00:54:43 +02:00
|
|
|
get_tree().get_root().set_input_as_handled()
|
2021-06-07 11:56:16 +02:00
|
|
|
|
2021-06-06 01:58:04 +02:00
|
|
|
if Input.is_action_just_pressed("say_team"):
|
|
|
|
main.focus = 2 #main.GameFocus.CHAT
|
|
|
|
state = 2 #ChatState.TYPING_TEAM
|
2021-06-07 00:54:43 +02:00
|
|
|
get_tree().get_root().set_input_as_handled()
|
2021-06-07 11:56:16 +02:00
|
|
|
|
2021-06-06 01:58:04 +02:00
|
|
|
elif Input.is_action_just_pressed("say_cancel"):
|
|
|
|
main.focus = 1 #main.GameFocus.GAME
|
|
|
|
state = 0 #ChatState.INACTIVE
|
2021-06-04 00:38:30 +02:00
|
|
|
|
2021-06-07 11:56:16 +02:00
|
|
|
func _unhandled_input(_event) -> void:
|
2021-06-04 02:33:26 +02:00
|
|
|
if state != 0: #ChatState.INACTIVE:
|
|
|
|
get_tree().get_root().set_input_as_handled()
|
2021-06-06 01:58:04 +02:00
|
|
|
|
2021-06-07 11:56:16 +02:00
|
|
|
# doesn't work over network due to missing RPC implementation in Godot 4
|
|
|
|
@remotesync func chat_message(sender_id: int, recipient_team, message: String) -> void:
|
|
|
|
chat_history.text += '\n' + str(sender_id) + " | " + message
|
2021-06-06 01:58:04 +02:00
|
|
|
|
|
|
|
func _on_LineEdit_text_entered(new_text):
|
|
|
|
# RPC is currently not implemented in the engine
|
|
|
|
var sender_id = get_tree().get_network_unique_id()
|
2021-06-07 11:56:16 +02:00
|
|
|
var new_message = [sender_id, 0, new_text]
|
2021-06-07 19:11:42 +02:00
|
|
|
rpc(&'chat_message',sender_id, 0, new_text)
|
2021-06-07 11:56:16 +02:00
|
|
|
chat_editor.text = ''
|
2021-06-06 01:58:04 +02:00
|
|
|
state = 0 #ChatState.INACTIVE
|
|
|
|
main.focus = 0 #main.GameFocus.GAME
|