Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mobile UI issues and add magic debug library #443

Merged
merged 2 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ snapshots/

# Generated by Cargo
# will have compiled files and executables
debug/
target/

# just root...
/debug/
/lib/debug/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock
Expand Down
Binary file not shown.
8 changes: 8 additions & 0 deletions godot/src/global.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion godot/src/logic/player/player_desktop_input.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion godot/src/logic/player/player_mobile_input.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
63 changes: 47 additions & 16 deletions godot/src/ui/components/chat/chat.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -20,15 +24,23 @@ 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")
_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:
Expand Down Expand Up @@ -68,7 +80,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):
Expand All @@ -82,16 +93,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)
23 changes: 16 additions & 7 deletions godot/src/ui/components/chat/chat.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]
51 changes: 34 additions & 17 deletions godot/src/ui/components/discover/discover.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -123,44 +123,61 @@ 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)
size_2d_override = Vector2i(1220, 121)
size_2d_override_stretch = true

[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")
}
Expand Down
2 changes: 1 addition & 1 deletion godot/src/ui/components/emotes/emote_wheel.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions godot/src/ui/components/menu/menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
1 change: 1 addition & 0 deletions godot/src/ui/components/menu/menu.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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="."]
Expand Down
4 changes: 2 additions & 2 deletions godot/src/ui/explorer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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):
Expand Down
1 change: 0 additions & 1 deletion godot/src/ui/explorer.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading