feat(chat-ui): 更新聊天UI和场景配置

- 优化聊天消息显示
- 调整UI布局
This commit is contained in:
王浩
2026-01-09 23:23:41 +08:00
parent 136e1344a0
commit e335a35f6c
6 changed files with 31 additions and 35 deletions

View File

@@ -1,8 +1,8 @@
[gd_scene load_steps=10 format=3 uid="uid://by7m8snb4xllf"]
[ext_resource type="Texture2D" uid="uid://bx17oy8lvaca4" path="res://assets/ui/auth/bg_auth_scene.png" id="1_background"]
[ext_resource type="Texture2D" uid="uid://de4q4s1gxivtf" path="res://assets/ui/auth/login_frame_smart_transparent.png" id="2_frame"]
[ext_resource type="Script" path="res://scenes/ui/AuthScene.gd" id="3_script"]
[ext_resource type="Texture2D" uid="uid://b6wlro1vixo8a" path="res://assets/ui/auth/清空内部组件的登录框架 (1).png" id="3_26vyf"]
[ext_resource type="Script" uid="uid://b514h2wuido0h" path="res://scenes/ui/AuthScene.gd" id="3_script"]
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_1"]
@@ -94,7 +94,7 @@ offset_right = 300.0
offset_bottom = 300.0
grow_horizontal = 2
grow_vertical = 2
texture = ExtResource("2_frame")
texture = ExtResource("3_26vyf")
expand_mode = 1
stretch_mode = 5

View File

@@ -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 - 消息管理

View File

@@ -1,4 +1,4 @@
[gd_scene load_steps=9 format=3 uid="uid://bv7k2nan4xj8q"]
[gd_scene load_steps=8 format=3 uid="uid://bv7k2nan4xj8q"]
[ext_resource type="Script" uid="uid://pibdlvhb12q8" path="res://scenes/ui/ChatUI.gd" id="1"]
[ext_resource type="Texture2D" uid="uid://cchjgp6qh7u61" path="res://assets/ui/chat/缩略框背景.png" id="2_7dhmv"]
@@ -8,8 +8,6 @@
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_xo31h"]
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_xlxdo"]
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_1ahvy"]
[node name="ChatUI" type="Control"]
@@ -104,9 +102,9 @@ expand_mode = 1
[node name="InputContainer" type="HBoxContainer" parent="ChatPanel"]
self_modulate = Color(1, 1, 1, 0.03529412)
layout_mode = 0
offset_left = 20.0
offset_left = 25.0
offset_top = 202.5
offset_right = 320.0
offset_right = 315.0
offset_bottom = 227.5
theme_override_constants/separation = 4
@@ -117,7 +115,5 @@ size_flags_horizontal = 3
localize_numeral_system = false
theme_override_font_sizes/font_size = 12
theme_override_styles/normal = SubResource("StyleBoxEmpty_xo31h")
theme_override_styles/focus = SubResource("StyleBoxEmpty_xo31h")
theme_override_styles/hover = SubResource("StyleBoxEmpty_xo31h")
theme_override_styles/read_only = SubResource("StyleBoxEmpty_xo31h")
theme_override_styles/focus = SubResource("StyleBoxEmpty_1ahvy")