2023-11-08 14:28:55 +11:00
|
|
|
extends Control
|
|
|
|
class_name Chatbox
|
|
|
|
|
|
|
|
signal opened
|
|
|
|
signal closed
|
|
|
|
|
|
|
|
var text_selected := false
|
|
|
|
var username := "default"
|
|
|
|
|
|
|
|
func _input(event: InputEvent) -> void:
|
2023-11-09 17:56:08 +11:00
|
|
|
if !text_selected and event.is_action_pressed("Open Text Chat"):
|
|
|
|
get_viewport().set_input_as_handled()
|
|
|
|
opened.emit()
|
|
|
|
$VBoxContainer/LineEdit.visible = true
|
|
|
|
$VBoxContainer/LineEdit.grab_focus()
|
|
|
|
text_selected = true
|
|
|
|
return
|
|
|
|
if text_selected and event is InputEventKey and event.pressed == true:
|
|
|
|
if event.keycode == KEY_ENTER:
|
2023-11-09 20:37:12 +11:00
|
|
|
get_viewport().set_input_as_handled()
|
2023-11-08 14:28:55 +11:00
|
|
|
closed.emit()
|
|
|
|
$VBoxContainer/LineEdit.deselect()
|
|
|
|
$VBoxContainer/LineEdit.visible = false
|
|
|
|
text_selected = false
|
|
|
|
if $VBoxContainer/LineEdit.text.length() != 0:
|
|
|
|
if $VBoxContainer/LineEdit.text.begins_with("/"):
|
|
|
|
Game.parse_command($VBoxContainer/LineEdit.text, multiplayer.get_unique_id())
|
|
|
|
else:
|
|
|
|
rpc("append_message", username, $VBoxContainer/LineEdit.text)
|
|
|
|
$VBoxContainer/LineEdit.clear()
|
2023-11-09 17:56:08 +11:00
|
|
|
if event.keycode == KEY_ESCAPE:
|
2023-11-09 20:37:12 +11:00
|
|
|
get_viewport().set_input_as_handled()
|
2023-11-09 17:56:08 +11:00
|
|
|
closed.emit()
|
|
|
|
$VBoxContainer/LineEdit.deselect()
|
|
|
|
$VBoxContainer/LineEdit.visible = false
|
|
|
|
text_selected = false
|
2023-11-08 14:28:55 +11:00
|
|
|
|
|
|
|
|
|
|
|
func change_username(old_name, new_name):
|
|
|
|
append_message("server", old_name + " has changed their display name to " + new_name)
|
|
|
|
|
|
|
|
|
|
|
|
@rpc("reliable","call_local","any_peer")
|
|
|
|
func append_message(user, content):
|
|
|
|
$VBoxContainer/RichTextLabel.append_text("[" + user + "] " + content + "\n")
|