You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
extends PanelContainer
|
|
|
|
|
|
|
|
onready var chat_log = $VBox/ChatLog
|
|
|
|
onready var chat_input = $VBox/ChatInput
|
|
|
|
onready var join_button = $VBox/HBox/JoinButton
|
|
|
|
onready var username = $VBox/HBox/Name
|
|
|
|
|
|
|
|
func display_message(packet):
|
|
|
|
if packet['type'] == "chat_message":
|
|
|
|
chat_log.text += packet['name'] + ": " + packet['message'] + "\n"
|
|
|
|
elif packet.has("message"):
|
|
|
|
chat_log.text += packet['message'] + "\n"
|
|
|
|
|
|
|
|
func join_chat():
|
|
|
|
if !username.text:
|
|
|
|
display_message(
|
|
|
|
{'type': "alert",
|
|
|
|
"message": "!!! Enter your username before joining chat."}
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
get_parent().join_chat(username.text)
|
|
|
|
chat_input.show()
|
|
|
|
join_button.hide()
|
|
|
|
username.hide()
|
|
|
|
|
|
|
|
func _input(event):
|
|
|
|
if event is InputEventKey and chat_input.text:
|
|
|
|
if event.pressed and event.scancode == KEY_ENTER:
|
|
|
|
get_parent().send_message(chat_input.text)
|
|
|
|
chat_input.text = ""
|
|
|
|
|
|
|
|
func _ready():
|
|
|
|
join_button.connect("button_up", self, "join_chat")
|