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

feat: mobile interactions with input actions #196

Merged
merged 6 commits into from
Jan 26, 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
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source_md5="d1c113904bb780b7527db4ed071e7af9"
dest_md5="95be8e38c1c1ced2c6edb51cd37ecd96"

10 changes: 10 additions & 0 deletions godot/assets/themes/icons/InteractiveIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions godot/assets/themes/icons/InteractiveIcon.svg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://72xpjysoxgwo"
path="res://.godot/imported/InteractiveIcon.svg-611c41dc3e36c5573498421a2e82e8b1.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://assets/themes/icons/InteractiveIcon.svg"
dest_files=["res://.godot/imported/InteractiveIcon.svg-611c41dc3e36c5573498421a2e82e8b1.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
2 changes: 1 addition & 1 deletion godot/src/config/config_data.gd
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func load_from_default():
self.scene_radius = 4
self.limit_fps = 0

if Global.is_mobile:
if Global.is_mobile():
self.skybox = 0
else:
self.skybox = 1
Expand Down
7 changes: 4 additions & 3 deletions godot/src/global.gd
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ var nft_frame_loader: NftFrameStyleLoader
var standalone = false
var dcl_android_plugin

@onready var is_mobile = OS.has_feature("mobile")
#@onready var is_mobile = true


func _ready():
# First
# _set_is_mobile(true) # Test

# Setup
http_requester = RustHttpQueueRequester.new()
animation_importer = AnimationImporter.new()
nft_frame_loader = NftFrameStyleLoader.new()
Expand Down
2 changes: 1 addition & 1 deletion godot/src/logic/player/emote_input_handler.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var animation_key_pressed = false

func _input(event):
# Receives mouse motion
if not Global.is_mobile && event:
if not Global.is_mobile() && event:
# Release mouse
if event is InputEventKey:
# Play emotes
Expand Down
4 changes: 2 additions & 2 deletions godot/src/logic/player/player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func _clamp_camera_rotation():

func _input(event):
# Receives touchscreen motion
if Global.is_mobile:
if Global.is_mobile():
if event is InputEventScreenDrag:
_touch_position = event.relative
rotate_y(deg_to_rad(-_touch_position.x) * horizontal_sens)
Expand All @@ -113,7 +113,7 @@ func _input(event):
_clamp_camera_rotation()

# Receives mouse motion
if not Global.is_mobile && event:
if not Global.is_mobile() && event:
if event is InputEventMouseMotion && Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
_mouse_position = event.relative
rotate_y(deg_to_rad(-_mouse_position.x) * horizontal_sens)
Expand Down
2 changes: 1 addition & 1 deletion godot/src/main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func start():
else:
print("Running from Server")

if Global.is_mobile:
if Global.is_mobile():
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)

self._start.call_deferred()
Expand Down
2 changes: 1 addition & 1 deletion godot/src/mobile/joystick/virtual_joystick.gd
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func _ready() -> void:


func _input(event: InputEvent) -> void:
if Global.is_mobile:
if Global.is_mobile():
if event is InputEventScreenTouch:
if event.pressed:
if _is_point_inside_joystick_area(event.position) and _touch_index == -1:
Expand Down
6 changes: 3 additions & 3 deletions godot/src/ui/components/minimap/minimap.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ signal request_open_map


func _ready():
if Global.is_mobile:
if Global.is_mobile():
panel_background.hide()
button_menu.show()
else:
Expand All @@ -28,7 +28,7 @@ func set_center_position(player_position: Vector2):

func _on_control_map_shader_gui_input(event):
if (
not Global.is_mobile
not Global.is_mobile()
&& event is InputEventMouseButton
and event.pressed
and event.button_index == MOUSE_BUTTON_LEFT
Expand All @@ -37,5 +37,5 @@ func _on_control_map_shader_gui_input(event):


func _on_button_menu_pressed():
if Global.is_mobile:
if Global.is_mobile():
emit_signal("request_open_map")
6 changes: 5 additions & 1 deletion godot/src/ui/components/pointer_tooltip/pointer_tooltip.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ func set_pointer_data(interacts_array: Array):
child.queue_free()
var i = 0
for interact in interacts_array:
if i >= angles.size():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this discard the remaining interactions?

Copy link
Member Author

@kuruk-mm kuruk-mm Jan 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. It avoids a crash. In the Foundation Client is crashing. And Godot was crashing too due to not having enough angles.
There is no limit to how many tooltip interactions you can have from SDK7. So the Explorer having a hard limit of 5 it's more than ok for me at least.

break
var tooltip_scene_instance = tooltip_scene.instantiate()
tooltip_scene_instance.set_position(Vector2(0, -95).rotated(deg_to_rad(angles[i])))
var tooltip_position = tooltip_scene_instance.get_position()
tooltip_scene_instance.set_position(Vector2(tooltip_position.x, tooltip_position.y - 20))
control_center.add_child(tooltip_scene_instance)
tooltip_scene_instance.set_tooltip_data(
interact.get("text", ""), interact.get("action", "")
interact.get("text_pet_down", ""),
interact.get("text_pet_up", ""),
interact.get("action", "")
)

i = i + 1
90 changes: 70 additions & 20 deletions godot/src/ui/components/pointer_tooltip/tooltip_label.gd
Original file line number Diff line number Diff line change
@@ -1,19 +1,45 @@
extends Control
extends PanelContainer

const BG_COLOR_NORMAL: String = "#00000080"
const BG_COLOR_PRESSED: String = "#44444480"

var action_to_trigger: String = ""

@onready
var label_action = $PanelContainer/MarginContainer/HBoxContainer/PanelContainer/MarginContainer/Label_Action
@onready var label_text = $PanelContainer/MarginContainer/HBoxContainer/Label_Text
var text_down := ""
var text_up := ""
var last_state_pressed := false

var stylebox: StyleBox

@onready var label_action = %Label_Action
@onready var texture_rect_action_icon = %TextureRect_ActionIcon

@onready var label_text = %Label_Text

@onready var icon_left_click = preload("res://assets/themes/icons/LeftClickIcn.png")
@onready var icon_interactive_pointer = preload("res://assets/themes/icons/InteractiveIcon.svg")

@onready var panel_action = $MarginContainer/HBoxContainer/PanelContainer


func _ready():
if Global.is_mobile:
stylebox = self.get_theme_stylebox("panel").duplicate()
add_theme_stylebox_override("panel", stylebox)

set_bg_color(BG_COLOR_NORMAL)
if Global.is_mobile():
self.gui_input.connect(self.mobile_on_panel_container_gui_input)


func set_tooltip_data(text: String, action: String):
var key: String
func set_bg_color(color):
stylebox.bg_color = color


func set_tooltip_data(text_pet_down: String, text_pet_up, action: String):
text_down = text_pet_down if !text_pet_down.is_empty() else text_pet_up
text_up = text_pet_up if !text_pet_up.is_empty() else text_pet_down

var key: Variant = null
var action_lower: String = action.to_lower()
var index: int = InputMap.get_actions().find(action_lower, 0)
if label_text:
Expand All @@ -22,31 +48,55 @@ func set_tooltip_data(text: String, action: String):
elif index != -1:
var event = InputMap.action_get_events(InputMap.get_actions()[index])[0]
if event is InputEventKey:
key = char(event.unicode).to_upper()
key = (
icon_interactive_pointer
if Global.is_mobile()
else char(event.unicode).to_upper()
)
elif event is InputEventMouseButton:
if event.button_index == 1:
key = "Mouse Left Button"
if event.button_index == 2:
key = "Mouse Right Button"
if event.button_index == 0:
key = "Mouse Wheel Button"
key = icon_left_click

if not key.is_empty():
if key != null:
show()
if key is String:
set_action_text(key)
else:
set_action_icon(key)

action_to_trigger = action_lower
label_action.text = key
label_text.text = text
label_text.text = text_down
else:
hide()
action_to_trigger = ""
printerr("Action doesn't exist ", action)


func mobile_on_panel_container_gui_input(event):
if action_to_trigger.is_empty():
return
func set_action_icon(icon):
texture_rect_action_icon.show()
label_action.hide()
texture_rect_action_icon.texture = icon


func set_action_text(text: String):
label_action.show()
texture_rect_action_icon.hide()
label_action.text = text

if event is InputEventMouseButton:

func _physics_process(_delta):
var new_pressed = Input.is_action_pressed(action_to_trigger)
if last_state_pressed != new_pressed:
set_bg_color(BG_COLOR_PRESSED if new_pressed else BG_COLOR_NORMAL)
panel_action.position = Vector2i(-1, -1) if new_pressed else Vector2i.ZERO
label_text.text = text_up if new_pressed else text_down
last_state_pressed = new_pressed


func mobile_on_panel_container_gui_input(event):
if event is InputEventScreenTouch:
if action_to_trigger.is_empty():
return
if event.pressed:
Input.action_press(action_to_trigger)
else:
Expand Down
68 changes: 35 additions & 33 deletions godot/src/ui/components/pointer_tooltip/tooltip_label.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -3,63 +3,65 @@
[ext_resource type="FontFile" uid="uid://cmc7ku5u0efdy" path="res://assets/themes/fonts/lato_family/Lato-Bold.ttf" id="1_1lcoh"]
[ext_resource type="Script" path="res://src/ui/components/pointer_tooltip/tooltip_label.gd" id="1_ut63f"]

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_14y5s"]
bg_color = Color(0, 0, 0, 0.627451)
corner_radius_top_left = 6
corner_radius_top_right = 6
corner_radius_bottom_right = 6
corner_radius_bottom_left = 6
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_473nw"]
bg_color = Color(0, 0, 0, 0.501961)
corner_radius_top_left = 8
corner_radius_top_right = 8
corner_radius_bottom_right = 8
corner_radius_bottom_left = 8

[node name="Control_TooltipLabel" type="Control"]
custom_minimum_size = Vector2(20, 20)
layout_mode = 3
anchors_preset = 0
offset_right = 84.0
[node name="PanelContainer" type="PanelContainer"]
offset_right = 85.0
offset_bottom = 40.0
pivot_offset = Vector2(0, 20)
size_flags_horizontal = 4
theme_override_styles/panel = SubResource("StyleBoxFlat_473nw")
script = ExtResource("1_ut63f")

[node name="PanelContainer" type="PanelContainer" parent="."]
layout_mode = 2
offset_right = 84.0
offset_bottom = 40.0
mouse_filter = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_14y5s")

[node name="MarginContainer" type="MarginContainer" parent="PanelContainer"]
[node name="MarginContainer" type="MarginContainer" parent="."]
layout_mode = 2
mouse_filter = 2
theme_override_constants/margin_left = 10
theme_override_constants/margin_top = 8
theme_override_constants/margin_right = 10
theme_override_constants/margin_bottom = 8

[node name="HBoxContainer" type="HBoxContainer" parent="PanelContainer/MarginContainer"]
[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer"]
layout_mode = 2
mouse_filter = 2
theme_override_constants/separation = 10

[node name="PanelContainer" type="PanelContainer" parent="PanelContainer/MarginContainer/HBoxContainer"]
[node name="PanelContainer" type="PanelContainer" parent="MarginContainer/HBoxContainer"]
custom_minimum_size = Vector2(24, 24)
layout_mode = 2
mouse_filter = 2

[node name="MarginContainer" type="MarginContainer" parent="PanelContainer/MarginContainer/HBoxContainer/PanelContainer"]
layout_mode = 2
mouse_filter = 2
theme_override_constants/margin_left = 8
theme_override_constants/margin_top = 0
theme_override_constants/margin_right = 8
theme_override_constants/margin_bottom = 0

[node name="Label_Action" type="Label" parent="PanelContainer/MarginContainer/HBoxContainer/PanelContainer/MarginContainer"]
[node name="Label_Action" type="Label" parent="MarginContainer/HBoxContainer/PanelContainer"]
unique_name_in_owner = true
visible = false
layout_mode = 2
size_flags_vertical = 1
theme_override_colors/font_color = Color(0, 0, 0, 1)
theme_override_font_sizes/font_size = 12
text = "1"
horizontal_alignment = 1
vertical_alignment = 1

[node name="Label_Text" type="Label" parent="PanelContainer/MarginContainer/HBoxContainer"]
[node name="MarginContainer" type="MarginContainer" parent="MarginContainer/HBoxContainer/PanelContainer"]
layout_mode = 2
theme_override_constants/margin_left = 3
theme_override_constants/margin_top = 3
theme_override_constants/margin_right = 3
theme_override_constants/margin_bottom = 3

[node name="TextureRect_ActionIcon" type="TextureRect" parent="MarginContainer/HBoxContainer/PanelContainer/MarginContainer"]
unique_name_in_owner = true
visible = false
self_modulate = Color(0, 0, 0, 1)
layout_mode = 2
expand_mode = 1
stretch_mode = 5

[node name="Label_Text" type="Label" parent="MarginContainer/HBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
theme_override_colors/font_color = Color(1, 1, 1, 1)
theme_override_fonts/font = ExtResource("1_1lcoh")
Expand Down
Loading
Loading