feat(chat-ui): 更新聊天UI和场景配置
- 优化聊天消息显示 - 调整UI布局
This commit is contained in:
@@ -68,14 +68,12 @@ var _current_username: String = ""
|
||||
|
||||
# 准备就绪
|
||||
func _ready() -> void:
|
||||
print("ChatUI 初始化完成")
|
||||
|
||||
# 初始隐藏聊天框
|
||||
hide_chat()
|
||||
|
||||
# 创建隐藏计时器
|
||||
_create_hide_timer()
|
||||
|
||||
|
||||
# 订阅事件(Call Down via EventSystem)
|
||||
_subscribe_to_events()
|
||||
|
||||
@@ -110,18 +108,24 @@ func _handle_enter_pressed() -> void:
|
||||
# 如果聊天框未显示,显示它
|
||||
if not _is_chat_visible:
|
||||
show_chat()
|
||||
chat_input.grab_focus()
|
||||
# 使用 call_deferred 避免在同一个事件周期内触发 LineEdit 的 text_submitted 信号
|
||||
call_deferred("_grab_input_focus")
|
||||
return
|
||||
|
||||
# 如果聊天框已显示且输入框有焦点,发送消息
|
||||
# 如果聊天框已显示且输入框有焦点,检查输入框内容
|
||||
if chat_input.has_focus():
|
||||
# 发送消息
|
||||
_on_send_button_pressed()
|
||||
# 如果输入框有内容,发送消息
|
||||
if not chat_input.text.is_empty():
|
||||
_on_send_button_pressed()
|
||||
return
|
||||
|
||||
# 如果聊天框已显示但输入框无焦点,重新聚焦(取消倒计时)
|
||||
chat_input.grab_focus()
|
||||
print("🔄 重新聚焦输入框,取消隐藏倒计时")
|
||||
|
||||
# 延迟获取输入框焦点(避免事件冲突)
|
||||
func _grab_input_focus() -> void:
|
||||
if chat_input:
|
||||
chat_input.grab_focus()
|
||||
|
||||
# 处理 GUI 输入(鼠标点击)
|
||||
func _gui_input(event: InputEvent) -> void:
|
||||
@@ -137,7 +141,6 @@ func _handle_click_outside() -> void:
|
||||
# 延迟释放输入框焦点,避免事件冲突
|
||||
if chat_input.has_focus():
|
||||
call_deferred("_release_input_focus")
|
||||
print("🖱️ 点击外部,取消输入状态")
|
||||
|
||||
# 延迟释放输入框焦点(由 call_deferred 调用)
|
||||
func _release_input_focus() -> void:
|
||||
@@ -155,7 +158,6 @@ func show_chat() -> void:
|
||||
|
||||
_is_chat_visible = true
|
||||
chat_panel.show()
|
||||
print("👁️ 聊天框已显示")
|
||||
|
||||
# 停止隐藏计时器
|
||||
_stop_hide_timer()
|
||||
@@ -167,7 +169,6 @@ func hide_chat() -> void:
|
||||
|
||||
_is_chat_visible = false
|
||||
chat_panel.hide()
|
||||
print("🚫 聊天框已隐藏")
|
||||
|
||||
# 停止隐藏计时器
|
||||
_stop_hide_timer()
|
||||
@@ -187,7 +188,6 @@ func _start_hide_timer() -> void:
|
||||
|
||||
_stop_hide_timer() # 先停止之前的计时器
|
||||
_hide_timer.start()
|
||||
print("⏱️ 开始 5 秒倒计时...")
|
||||
|
||||
# 停止隐藏倒计时
|
||||
func _stop_hide_timer() -> void:
|
||||
@@ -215,7 +215,6 @@ func _connect_ui_signals() -> void:
|
||||
func _on_input_focus_entered() -> void:
|
||||
_is_typing = true
|
||||
_stop_hide_timer() # 停止隐藏计时器
|
||||
print("✍️ 开始输入")
|
||||
|
||||
# 输入框失去焦点
|
||||
func _on_input_focus_exited() -> void:
|
||||
@@ -224,7 +223,6 @@ func _on_input_focus_exited() -> void:
|
||||
if not _is_chat_visible:
|
||||
return
|
||||
_start_hide_timer()
|
||||
print("🚫 停止输入,开始 5 秒隐藏倒计时")
|
||||
|
||||
# 发送按钮点击处理
|
||||
func _on_send_button_pressed() -> void:
|
||||
@@ -281,7 +279,7 @@ func _on_chat_message_received(data: Dictionary) -> void:
|
||||
func _on_chat_error(data: Dictionary) -> void:
|
||||
var error_code: String = data.get("error_code", "")
|
||||
var message: String = data.get("message", "")
|
||||
|
||||
|
||||
print("❌ ChatUI 错误: [", error_code, "] ", message)
|
||||
|
||||
# 处理连接状态变化
|
||||
@@ -292,7 +290,6 @@ func _on_connection_state_changed(data: Dictionary) -> void:
|
||||
# 处理登录成功
|
||||
func _on_login_success(data: Dictionary) -> void:
|
||||
_current_username = data.get("username", "")
|
||||
print("✅ ChatUI: 登录成功,用户名: ", _current_username)
|
||||
|
||||
# ============================================================================
|
||||
# 公共 API - 消息管理
|
||||
|
||||
Reference in New Issue
Block a user