Fix Escape
This commit is contained in:
+16
-6
@@ -1,8 +1,8 @@
|
||||
extends CanvasLayer
|
||||
|
||||
@onready var chat_log = $Control/ChatLog
|
||||
@onready var chat_messages_container = $Control/ChatLog/ChatMessages
|
||||
@onready var chat_input = $Control/InputContainer/ChatInput
|
||||
@onready var chat_log = $Control/VBoxContainer/ChatLog
|
||||
@onready var chat_messages_container = $Control/VBoxContainer/ChatLog/ChatMessages
|
||||
@onready var chat_input = $Control/VBoxContainer/InputContainer/ChatInput
|
||||
|
||||
const MAX_MESSAGES = 50
|
||||
const TYPE_COLORS = {
|
||||
@@ -13,6 +13,7 @@ const TYPE_COLORS = {
|
||||
}
|
||||
|
||||
func _ready():
|
||||
print("[ChatUI] _ready called")
|
||||
chat_input.text_submitted.connect(_on_message_submitted)
|
||||
|
||||
visible = false
|
||||
@@ -21,13 +22,20 @@ func _ready():
|
||||
call_deferred("_connect_gamestate")
|
||||
|
||||
func _connect_gamestate():
|
||||
print("[ChatUI] _connect_gamestate called")
|
||||
if GameState:
|
||||
print("[ChatUI] Connecting to GameState.chat_message_received signal")
|
||||
GameState.chat_message_received.connect(_on_chat_message)
|
||||
print("[ChatUI] Signal connected successfully")
|
||||
else:
|
||||
print("[ChatUI] ERROR: GameState not found!")
|
||||
|
||||
func _on_chat_message(sender: String, message: String, type: String):
|
||||
print("[ChatUI] _on_chat_message received - Sender: '%s', Message: '%s', Type: '%s'" % [sender, message, type])
|
||||
_add_message(sender, message, type)
|
||||
|
||||
func _add_message(sender: String, message: String, type: String = "normal"):
|
||||
print("[ChatUI] Adding message to chat log")
|
||||
var label = RichTextLabel.new()
|
||||
label.bbcode_enabled = true
|
||||
label.fit_content = true
|
||||
@@ -35,13 +43,14 @@ func _add_message(sender: String, message: String, type: String = "normal"):
|
||||
|
||||
var color = TYPE_COLORS.get(type, Color.WHITE)
|
||||
var color_hex = color.to_html(false)
|
||||
|
||||
print("[ChatUI] set type")
|
||||
if type == "system":
|
||||
label.text = "[color=#%s][System] %s[/color]" % [color_hex, message]
|
||||
else:
|
||||
label.text = "[color=#ffd700]%s:[/color] [color=#%s]%s[/color]" % [sender, color_hex, message]
|
||||
|
||||
print("[ChatUI] Bout to add")
|
||||
chat_messages_container.add_child(label)
|
||||
print("[ChatUI] Message added: %s" % label.text)
|
||||
|
||||
# Limit messages
|
||||
while chat_messages_container.get_child_count() > MAX_MESSAGES:
|
||||
@@ -58,7 +67,8 @@ func _on_message_submitted(text: String):
|
||||
if text.strip_edges().is_empty():
|
||||
_close()
|
||||
return
|
||||
|
||||
_add_message(GameState.character.get("name"),text,"normal")
|
||||
print("[ChatUI] Sending chat message: %s" % text)
|
||||
GameState.send_chat(text)
|
||||
chat_input.text = ""
|
||||
_close()
|
||||
|
||||
Reference in New Issue
Block a user