diary/user_interface/chat_panel/message_box.gd
2022-06-05 14:22:08 +02:00

36 lines
1.0 KiB
GDScript

extends PanelContainer
onready var text_edit = get_node("MarginContainer/ContentFitTextEdit")
onready var message_denied_sound = get_node("MessageDeniedSound")
func _ready():
# warning-ignore:return_value_discarded
Users.connect("switched", self, "_on_user_switched")
func _input(event):
if not text_edit.has_focus() or not text_edit.text.empty():
return
if event is InputEventKey and event.scancode == KEY_UP:
if event.is_pressed() and not event.is_echo():
Data.messages.get_last_message_of_user(
Users.get_current()
).associated_node._enable_edit_mode()
func _on_message_box_confirmed(content):
if PingSystem.unhandled_ping_count == 0 and not content.empty():
text_edit.text = ""
text_edit._on_text_changed() # To go back to minimum height.
else:
message_denied_sound.play()
func _on_user_switched():
Users.get_inactive().message_box_content = text_edit.text
text_edit.text = Users.get_current().message_box_content
text_edit._on_text_changed() # To adjust height.
text_edit.select_all()