From 779a5f82d1ef0a773555f5bfe6951c10816320dd Mon Sep 17 00:00:00 2001 From: "Mateo \"Kuruk\" Miccino" Date: Mon, 19 Aug 2024 10:04:36 -0300 Subject: [PATCH] mobile ui fixes discover banner resize fixed chat shows on messages, and line edit for sending messages shows when the virtual keyboard appears fix focus issues with menu --- godot/src/global.gd | 8 +++ .../src/logic/player/player_desktop_input.gd | 2 +- godot/src/logic/player/player_mobile_input.gd | 2 +- godot/src/ui/components/chat/chat.gd | 66 ++++++++++++++----- godot/src/ui/components/chat/chat.tscn | 23 +++++-- .../src/ui/components/discover/discover.tscn | 50 +++++++++----- godot/src/ui/components/emotes/emote_wheel.gd | 2 +- godot/src/ui/components/menu/menu.gd | 1 + godot/src/ui/components/menu/menu.tscn | 1 + godot/src/ui/explorer.gd | 4 +- godot/src/ui/explorer.tscn | 1 - 11 files changed, 114 insertions(+), 46 deletions(-) diff --git a/godot/src/global.gd b/godot/src/global.gd index f2f40efdf..9f0d2b2da 100644 --- a/godot/src/global.gd +++ b/godot/src/global.gd @@ -176,6 +176,14 @@ func explorer_grab_focus() -> void: explorer.ui_root.grab_focus.call_deferred() +func explorer_release_focus() -> void: + var explorer = get_explorer() + if explorer == null: + return + + explorer.ui_root.release_focus.call_deferred() + + func capture_mouse(): var explorer = get_node_or_null("/root/explorer") if is_instance_valid(explorer): diff --git a/godot/src/logic/player/player_desktop_input.gd b/godot/src/logic/player/player_desktop_input.gd index 75d5ea4b8..fd0b4fceb 100644 --- a/godot/src/logic/player/player_desktop_input.gd +++ b/godot/src/logic/player/player_desktop_input.gd @@ -30,7 +30,7 @@ func _input(event): # Toggle first or third person camera if event is InputEventMouseButton: - if !_player.camera_mode_change_blocked: + if !_player.camera_mode_change_blocked and Global.explorer_has_focus(): if event.button_index == MOUSE_BUTTON_WHEEL_DOWN: if _player.camera.get_camera_mode() == Global.CameraMode.FIRST_PERSON: _player.set_camera_mode(Global.CameraMode.THIRD_PERSON) diff --git a/godot/src/logic/player/player_mobile_input.gd b/godot/src/logic/player/player_mobile_input.gd index 0e1c5cd04..78724fc61 100644 --- a/godot/src/logic/player/player_mobile_input.gd +++ b/godot/src/logic/player/player_mobile_input.gd @@ -26,7 +26,7 @@ func _input(event): # Receives touchscreen motion if Global.is_mobile() and (event is InputEventScreenTouch or event is InputEventScreenDrag): var input_dir := Input.get_vector("ia_left", "ia_right", "ia_forward", "ia_backward") - if input_dir == Vector2.ZERO and event.index < 2: # Not walking + if input_dir == Vector2.ZERO and event.index < 2 and Global.explorer_has_focus(): # Not walking if event is InputEventScreenTouch: _positions[event.index] = event.position if event.index == 1: diff --git a/godot/src/ui/components/chat/chat.gd b/godot/src/ui/components/chat/chat.gd index 81cedd1d9..a871a6084 100644 --- a/godot/src/ui/components/chat/chat.gd +++ b/godot/src/ui/components/chat/chat.gd @@ -6,9 +6,13 @@ const EMOTE: String = "␐" const REQUEST_PING: String = "␑" const ACK: String = "␆" -@onready var rich_text_label_chat = $MarginContainer/VBoxContainer/RichTextLabel_Chat -@onready -var line_edit_command = $MarginContainer/VBoxContainer/HBoxContainer_LineEdit/LineEdit_Command +var hide_tween = null + +@onready var rich_text_label_chat = %RichTextLabel_Chat +@onready var h_box_container_line_edit = %HBoxContainer_LineEdit +@onready var line_edit_command = %LineEdit_Command + +@onready var timer_hide = %Timer_Hide func _ready(): @@ -20,15 +24,26 @@ func _ready(): submit_message.connect(self._on_submit_message) + h_box_container_line_edit.hide() -func _on_submit_message(): + +func _on_submit_message(_message: String): UiSounds.play_sound("widget_chat_message_private_send") + if Global.is_mobile(): + line_edit_command.grab_focus() + else: + _set_open_chat(false) func add_chat_message(bb_text: String) -> void: rich_text_label_chat.append_text(bb_text) rich_text_label_chat.newline() + if hide_tween != null: + hide_tween.stop() + modulate = Color.WHITE + timer_hide.start() + func on_chats_arrived(chats: Array): for chat in chats: @@ -68,7 +83,6 @@ func on_chats_arrived(chats: Array): func _on_button_send_pressed(): submit_message.emit(line_edit_command.text) line_edit_command.text = "" - line_edit_command.grab_focus() func _on_line_edit_command_text_submitted(new_text): @@ -82,16 +96,36 @@ func finish(): line_edit_command.text = "" -func _on_visibility_changed(): - if is_instance_valid(line_edit_command): - line_edit_command.text = "" - if visible: - line_edit_command.grab_focus() - UiSounds.play_sound("widget_chat_open") - else: - Global.explorer_grab_focus() - UiSounds.play_sound("widget_chat_close") +func _on_line_edit_command_focus_exited(): + _set_open_chat(false) -func _on_line_edit_command_focus_exited(): - self.hide() +func toggle_open_chat(): + _set_open_chat(not h_box_container_line_edit.visible) + + +func _set_open_chat(value: bool): + h_box_container_line_edit.visible = value + + if hide_tween != null: + hide_tween.stop() + + if value: + line_edit_command.grab_focus() + UiSounds.play_sound("widget_chat_open") + timer_hide.stop() + modulate = Color.WHITE + else: + Global.explorer_grab_focus() + UiSounds.play_sound("widget_chat_close") + timer_hide.start() + modulate = Color.WHITE + + +func _on_timer_hide_timeout(): + if hide_tween != null: + hide_tween.stop() + + hide_tween = get_tree().create_tween() + modulate = Color.WHITE + hide_tween.tween_property(self, "modulate", Color.TRANSPARENT, 0.5) diff --git a/godot/src/ui/components/chat/chat.tscn b/godot/src/ui/components/chat/chat.tscn index c190b04d5..9a9154b34 100644 --- a/godot/src/ui/components/chat/chat.tscn +++ b/godot/src/ui/components/chat/chat.tscn @@ -34,16 +34,13 @@ theme_override_constants/margin_bottom = 8 [node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"] layout_mode = 2 -[node name="RichTextLabel_Chat" type="RichTextLabel" parent="MarginContainer/VBoxContainer"] -layout_mode = 2 -size_flags_vertical = 3 -bbcode_enabled = true -scroll_following = true - [node name="HBoxContainer_LineEdit" type="HBoxContainer" parent="MarginContainer/VBoxContainer"] +unique_name_in_owner = true +visible = false layout_mode = 2 [node name="LineEdit_Command" type="LineEdit" parent="MarginContainer/VBoxContainer/HBoxContainer_LineEdit"] +unique_name_in_owner = true layout_mode = 2 size_flags_horizontal = 3 theme_override_font_sizes/font_size = 0 @@ -58,7 +55,19 @@ icon = ExtResource("3_umu3q") icon_alignment = 1 expand_icon = true -[connection signal="visibility_changed" from="." to="." method="_on_visibility_changed"] +[node name="RichTextLabel_Chat" type="RichTextLabel" parent="MarginContainer/VBoxContainer"] +unique_name_in_owner = true +layout_mode = 2 +size_flags_vertical = 3 +bbcode_enabled = true +scroll_following = true + +[node name="Timer_Hide" type="Timer" parent="."] +unique_name_in_owner = true +wait_time = 3.0 +one_shot = true + [connection signal="focus_exited" from="MarginContainer/VBoxContainer/HBoxContainer_LineEdit/LineEdit_Command" to="." method="_on_line_edit_command_focus_exited"] [connection signal="text_submitted" from="MarginContainer/VBoxContainer/HBoxContainer_LineEdit/LineEdit_Command" to="." method="_on_line_edit_command_text_submitted"] [connection signal="pressed" from="MarginContainer/VBoxContainer/HBoxContainer_LineEdit/Button_Send" to="." method="_on_button_send_pressed"] +[connection signal="timeout" from="Timer_Hide" to="." method="_on_timer_hide_timeout"] diff --git a/godot/src/ui/components/discover/discover.tscn b/godot/src/ui/components/discover/discover.tscn index 608870eb9..4237df2ab 100644 --- a/godot/src/ui/components/discover/discover.tscn +++ b/godot/src/ui/components/discover/discover.tscn @@ -41,14 +41,14 @@ loop_mode = 1 tracks/0/type = "value" tracks/0/imported = false tracks/0/enabled = true -tracks/0/path = NodePath(".:position") +tracks/0/path = NodePath(".:position:y") tracks/0/interp = 1 tracks/0/loop_wrap = true tracks/0/keys = { "times": PackedFloat32Array(0, 14, 15, 29), "transitions": PackedFloat32Array(1, 1, 1, 1), "update": 0, -"values": [Vector2(0, 0), Vector2(0, 0), Vector2(0, -121), Vector2(0, -121)] +"values": [0.0, 0.0, -121.0, -121.0] } [sub_resource type="AnimationLibrary" id="AnimationLibrary_5pduq"] @@ -123,44 +123,60 @@ theme_override_constants/margin_top = 10 theme_override_constants/margin_right = 30 theme_override_constants/margin_bottom = 0 -[node name="Control" type="Control" parent="TextureRect/ScrollContainer/VBoxContainer/MarginContainer"] +[node name="ViewportContainer" type="SubViewportContainer" parent="TextureRect/ScrollContainer/VBoxContainer/MarginContainer"] clip_contents = true custom_minimum_size = Vector2(0, 121) layout_mode = 2 +stretch = true -[node name="Content" type="Control" parent="TextureRect/ScrollContainer/VBoxContainer/MarginContainer/Control"] -layout_mode = 1 -anchors_preset = 10 +[node name="SubViewport" type="SubViewport" parent="TextureRect/ScrollContainer/VBoxContainer/MarginContainer/ViewportContainer"] +disable_3d = true +transparent_bg = true +handle_input_locally = false +gui_disable_input = true +size = Vector2i(1220, 121) +render_target_update_mode = 4 + +[node name="Content" type="Control" parent="TextureRect/ScrollContainer/VBoxContainer/MarginContainer/ViewportContainer/SubViewport"] +clip_children = 2 +layout_mode = 3 +anchors_preset = 15 anchor_right = 1.0 -offset_right = 4874.0 +anchor_bottom = 1.0 grow_horizontal = 2 +grow_vertical = 2 -[node name="TextureRect_GenesisCity" type="TextureRect" parent="TextureRect/ScrollContainer/VBoxContainer/MarginContainer/Control/Content"] +[node name="TextureRect_GenesisCity" type="TextureRect" parent="TextureRect/ScrollContainer/VBoxContainer/MarginContainer/ViewportContainer/SubViewport/Content"] custom_minimum_size = Vector2(0, 121) -layout_mode = 2 -offset_right = 1214.0 -offset_bottom = 121.0 +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 grow_horizontal = 2 +grow_vertical = 2 size_flags_horizontal = 3 size_flags_vertical = 3 texture = ExtResource("4_2pq8h") expand_mode = 2 stretch_mode = 5 -[node name="TextureRect_Worlds" type="TextureRect" parent="TextureRect/ScrollContainer/VBoxContainer/MarginContainer/Control/Content"] +[node name="TextureRect_Worlds" type="TextureRect" parent="TextureRect/ScrollContainer/VBoxContainer/MarginContainer/ViewportContainer/SubViewport/Content"] custom_minimum_size = Vector2(0, 121) -layout_mode = 2 -offset_top = 121.0 -offset_right = 1214.0 -offset_bottom = 242.0 +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_top = 125.0 +offset_bottom = 125.0 grow_horizontal = 2 +grow_vertical = 2 size_flags_horizontal = 3 size_flags_vertical = 3 texture = ExtResource("5_1hjun") expand_mode = 2 stretch_mode = 5 -[node name="AnimationPlayer" type="AnimationPlayer" parent="TextureRect/ScrollContainer/VBoxContainer/MarginContainer/Control/Content"] +[node name="AnimationPlayer" type="AnimationPlayer" parent="TextureRect/ScrollContainer/VBoxContainer/MarginContainer/ViewportContainer/SubViewport/Content"] libraries = { "": SubResource("AnimationLibrary_5pduq") } diff --git a/godot/src/ui/components/emotes/emote_wheel.gd b/godot/src/ui/components/emotes/emote_wheel.gd index 7f8f444b0..5ce3c55e8 100644 --- a/godot/src/ui/components/emotes/emote_wheel.gd +++ b/godot/src/ui/components/emotes/emote_wheel.gd @@ -60,7 +60,7 @@ func _gui_input(event): func _physics_process(_delta): - if Input.is_action_just_pressed("ia_open_emote_wheel"): + if Input.is_action_just_pressed("ia_open_emote_wheel") and Global.explorer_has_focus(): if not is_visible_in_tree(): UiSounds.play_sound("widget_emotes_open") show() diff --git a/godot/src/ui/components/menu/menu.gd b/godot/src/ui/components/menu/menu.gd index 944896ded..72ed4df77 100644 --- a/godot/src/ui/components/menu/menu.gd +++ b/godot/src/ui/components/menu/menu.gd @@ -206,6 +206,7 @@ func _on_visibility_changed(): if is_visible_in_tree(): UiSounds.play_sound("mainmenu_widget_open") grab_focus() + Global.explorer_release_focus() else: UiSounds.play_sound("mainmenu_widget_close") diff --git a/godot/src/ui/components/menu/menu.tscn b/godot/src/ui/components/menu/menu.tscn index 7cd0d55af..68ac11086 100644 --- a/godot/src/ui/components/menu/menu.tscn +++ b/godot/src/ui/components/menu/menu.tscn @@ -70,6 +70,7 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 +mouse_force_pass_scroll_events = false script = ExtResource("2_cgghr") [node name="VBoxContainer" type="VBoxContainer" parent="."] diff --git a/godot/src/ui/explorer.gd b/godot/src/ui/explorer.gd index 1f1e22217..7154204b2 100644 --- a/godot/src/ui/explorer.gd +++ b/godot/src/ui/explorer.gd @@ -236,7 +236,7 @@ func _unhandled_input(event): release_mouse() if event.pressed and event.keycode == KEY_ENTER: - panel_chat.show() + panel_chat.toggle_open_chat() func _on_control_minimap_request_open_map(): @@ -432,7 +432,7 @@ func _on_button_jump_gui_input(event): func _on_button_open_chat_pressed(): - panel_chat.visible = not panel_chat.visible + panel_chat.toggle_open_chat() func set_cursor_position(position: Vector2): diff --git a/godot/src/ui/explorer.tscn b/godot/src/ui/explorer.tscn index f0168c4ba..36f571e06 100644 --- a/godot/src/ui/explorer.tscn +++ b/godot/src/ui/explorer.tscn @@ -241,7 +241,6 @@ expand_icon = true layout_mode = 1 [node name="Panel_Chat" parent="UI/SafeMarginContainer/InteractableHUD" instance=ExtResource("9_4ktln")] -visible = false layout_mode = 0 offset_left = 20.0 offset_top = 90.0