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.

34 lines
1.0 KiB
GDScript

extends Control
# Lemonland Shoutbox UI
onready var chat_display = $VBox/ChatDisplay
onready var chat_input = $VBox/ChatInput
onready var leave_button = $VBox/VBox/HBox/LeaveButton
onready var join_button = $VBox/VBox/HBox/JoinButton
onready var username = $VBox/VBox/HBox/Name
func display_message(packet): # shout, alert, server_message, user_joined, user_left
if packet['type'] == "shout":
chat_display.text += packet['name'] + ": " + packet['message'] + "\n"
else:
chat_display.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 get_parent().chat_name:
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")