diff --git a/project.godot b/project.godot index 124f307..714704e 100644 --- a/project.godot +++ b/project.godot @@ -30,10 +30,10 @@ gdscript/warnings/treat_warnings_as_errors=false [display] -window/size/viewport_width=1376 -window/size/viewport_height=768 +window/size/viewport_width=1920 +window/size/viewport_height=1080 window/size/mode=2 -window/stretch/mode="canvas_items" +window/stretch/mode="viewport" window/stretch/aspect="expand" [gui] diff --git a/scenes/MainScene.gd b/scenes/MainScene.gd index bb851d2..bde945c 100644 --- a/scenes/MainScene.gd +++ b/scenes/MainScene.gd @@ -88,13 +88,16 @@ func _on_login_success(username: String): # 登录成功后的处理 current_user = username print("用户 ", username, " 登录成功!") - + # 连接到聊天服务器(在进入游戏界面之前) print("🔌 开始连接聊天服务器...") ChatManager.connect_to_chat_server() - + show_main_game() + # 登录成功后隐藏聊天框(需要按Enter才显示) + chat_ui.hide_chat() + func _on_logout_pressed(): # 登出处理 current_user = "" diff --git a/scenes/prefabs/ui/ChatMessage.gd b/scenes/prefabs/ui/ChatMessage.gd index 54e3e45..d04ef20 100644 --- a/scenes/prefabs/ui/ChatMessage.gd +++ b/scenes/prefabs/ui/ChatMessage.gd @@ -103,8 +103,8 @@ func _apply_style() -> void: # 设置面板样式 add_theme_stylebox_override("panel", _get_self_style()) - # 设置文字颜色 - username_label.add_theme_color_override("font_color", Color.WHITE) + # 设置文字颜色 - ID使用金色 #FFD700 + username_label.add_theme_color_override("font_color", Color(1.0, 0.8431373, 0.0)) timestamp_label.add_theme_color_override("font_color", Color(0.7, 0.7, 0.7)) else: # 他人的消息:左侧对齐,灰色背景 @@ -114,8 +114,8 @@ func _apply_style() -> void: # 设置面板样式 add_theme_stylebox_override("panel", _get_other_style()) - # 设置文字颜色 - username_label.add_theme_color_override("font_color", Color(0.2, 0.4, 0.8)) + # 设置文字颜色 - ID使用蓝色 #69c0ff + username_label.add_theme_color_override("font_color", Color(0.4117647, 0.7529412, 1.0)) timestamp_label.add_theme_color_override("font_color", Color(0.5, 0.5, 0.5)) # 获取自己消息的样式 diff --git a/scenes/ui/AuthScene.tscn b/scenes/ui/AuthScene.tscn index 3cf8c76..80ae516 100644 --- a/scenes/ui/AuthScene.tscn +++ b/scenes/ui/AuthScene.tscn @@ -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 diff --git a/scenes/ui/ChatUI.gd b/scenes/ui/ChatUI.gd index 780060b..f63eb38 100644 --- a/scenes/ui/ChatUI.gd +++ b/scenes/ui/ChatUI.gd @@ -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 - 消息管理 diff --git a/scenes/ui/ChatUI.tscn b/scenes/ui/ChatUI.tscn index d7fbe54..eb0cc4c 100644 --- a/scenes/ui/ChatUI.tscn +++ b/scenes/ui/ChatUI.tscn @@ -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")