forked from datawhale/whale-town-front
fix: 修复聊天系统编译错误
- 修复 WebSocketManager/SocketIOClient 函数缩进错误 - 重命名 is_connected() 避免与 Object 基类冲突 - 修复 tscn 文件多余前导空格 - 修复测试文件 GUT 断言函数调用 - 添加 GUT 测试框架
This commit is contained in:
@@ -328,7 +328,7 @@ func _on_login_enter(_text: String):
|
||||
# ============ 控制器信号处理 ============
|
||||
|
||||
# 登录成功处理
|
||||
func _on_controller_login_success(username: String):
|
||||
func _on_controller_login_success(username: String) -> void:
|
||||
# 清空表单
|
||||
login_username.text = ""
|
||||
login_password.text = ""
|
||||
@@ -336,7 +336,13 @@ func _on_controller_login_success(username: String):
|
||||
_hide_field_error(login_username_error)
|
||||
_hide_field_error(login_password_error)
|
||||
_hide_field_error(login_verification_error)
|
||||
|
||||
|
||||
# 设置 token 给 ChatManager(用于 WebSocket 聊天认证)
|
||||
var token: String = auth_manager.get_access_token()
|
||||
if not token.is_empty():
|
||||
ChatManager.set_game_token(token)
|
||||
print("✅ 已设置 ChatManager token: ", token.substr(0, 20) + "...")
|
||||
|
||||
# 发送登录成功信号给上层
|
||||
login_success.emit(username)
|
||||
|
||||
|
||||
@@ -297,16 +297,17 @@ func _on_chat_error(data: Dictionary) -> void:
|
||||
|
||||
# 3秒后恢复状态
|
||||
var timer := get_tree().create_timer(3.0)
|
||||
timer.timeout.connect(func():
|
||||
_update_connection_status(ChatManager.is_connected())
|
||||
)
|
||||
var timeout_callback := func():
|
||||
_update_connection_status(ChatManager.is_chat_connected())
|
||||
timer.timeout.connect(timeout_callback)
|
||||
|
||||
# 处理连接状态变化
|
||||
func _on_connection_state_changed(data: Dictionary) -> void:
|
||||
var state: WebSocketManager.ConnectionState = data.get("state", WebSocketManager.ConnectionState.DISCONNECTED)
|
||||
var state_names := ["DISCONNECTED", "CONNECTING", "CONNECTED", "RECONNECTING", "ERROR"]
|
||||
var state: int = data.get("state", 0)
|
||||
|
||||
match state:
|
||||
WebSocketManager.ConnectionState.CONNECTED:
|
||||
2: # CONNECTED
|
||||
_update_connection_status(true)
|
||||
_:
|
||||
_update_connection_status(false)
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://bv7k2m9n4xj8q"]
|
||||
[gd_scene load_steps=3 format=3 uid="uid://bv7k2nan4xj8q"]
|
||||
|
||||
[ext_resource type="Script" path="res://scenes/ui/ChatUI.gd" id="1"]
|
||||
[ext_resource type="Script" uid="uid://pibdlvhb12q8" path="res://scenes/ui/ChatUI.gd" id="1"]
|
||||
[ext_resource type="Texture2D" uid="uid://flepo0gpb55h" path="res://assets/ui/chat/缩略框背景.png" id="2_7dhmv"]
|
||||
|
||||
[node name="ChatUI" type="Control"]
|
||||
custom_minimum_size = Vector2(10, 20)
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
@@ -10,19 +12,28 @@ anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
mouse_filter = 2
|
||||
unique_name_in_owner = true
|
||||
script = ExtResource("1")
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="."]
|
||||
layout_mode = 0
|
||||
offset_left = 10.0
|
||||
offset_top = 358.0
|
||||
offset_right = 460.0
|
||||
offset_bottom = 758.0
|
||||
texture = ExtResource("2_7dhmv")
|
||||
expand_mode = 1
|
||||
|
||||
[node name="ChatPanel" type="Panel" parent="."]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 1
|
||||
anchors_preset = 3
|
||||
anchor_left = 1.0
|
||||
anchors_preset = 2
|
||||
anchor_top = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = -450.0
|
||||
offset_top = -400.0
|
||||
grow_horizontal = 0
|
||||
offset_left = 10.0
|
||||
offset_top = -410.0
|
||||
offset_right = 460.0
|
||||
offset_bottom = -10.0
|
||||
grow_vertical = 0
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="ChatPanel"]
|
||||
@@ -30,13 +41,13 @@ layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
theme_override_constants/separation = 8
|
||||
offset_left = 10.0
|
||||
offset_top = 10.0
|
||||
offset_right = -10.0
|
||||
offset_bottom = -10.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
theme_override_constants/separation = 8
|
||||
|
||||
[node name="HeaderContainer" type="HBoxContainer" parent="ChatPanel/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
Reference in New Issue
Block a user