extends Control # UI Shoutbox 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 var shoutbox_pr 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: shoutbox_pr.join_chat(username.text) chat_input.show() join_button.hide() username.hide() func _input(event): if event is InputEventKey: if event.pressed and event.scancode == KEY_ENTER: shoutbox_pr.send_message(chat_input.text) chat_input.text = "" func setup(): #join_button.connect("button_up", shoutbox_pr, "join_chat") join_button.connect("button_up", self, "join_chat") func _ready(): add_to_group("shoutbox_ui") add_to_group("setup") #func get_username(): # return username.text #func _server_disconnected(): # chat_display.text += "Disconnected from Server\n" #func user_entered(id): # chat_display.text += str(id) + " joined the room\n" #func user_exited(id): # chat_display.text += str(id) + " left the room\n" #func enter_room(): # chat_display.text = "Successfully joined room\n" # leave_button.show() # chat_input.show() # join_button.hide() # username.hide() #func leave_room(): # chat_display.text += "Left Room\n" # leave_button.hide() # join_button.show() # chat_input.hide() # username.show() #func _input(event): # if event is InputEventKey: # if event.pressed and event.scancode == KEY_ENTER: # shoutbox_programmatic.send_message(username.text, chat_input.text) # chat_input.text = "" #func display_message(id, msg): # chat_display.text += id + ": " + msg + "\n"