aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/global.gd1
-rw-r--r--client/menu/boost.webpbin0 -> 3670 bytes
-rw-r--r--client/menu/boost.webp.import34
-rw-r--r--client/menu/interact.webpbin0 -> 3604 bytes
-rw-r--r--client/menu/interact.webp.import34
-rw-r--r--client/player/controllable_player.gd3
-rw-r--r--client/player/onscreen_controls/controls.gd40
-rw-r--r--client/player/onscreen_controls/controls.tscn38
-rw-r--r--client/player/onscreen_controls/textures/joystick_base_outline.pngbin0 -> 4827 bytes
-rw-r--r--client/player/onscreen_controls/textures/joystick_base_outline.png.import34
-rw-r--r--client/player/onscreen_controls/textures/joystick_tip.pngbin0 -> 1780 bytes
-rw-r--r--client/player/onscreen_controls/textures/joystick_tip.png.import34
-rw-r--r--client/player/onscreen_controls/textures/joystick_tip_arrows.pngbin0 -> 2229 bytes
-rw-r--r--client/player/onscreen_controls/textures/joystick_tip_arrows.png.import34
-rw-r--r--client/player/onscreen_controls/virtual_joystick.gd166
-rw-r--r--client/player/onscreen_controls/virtual_joystick_scene.tscn51
16 files changed, 469 insertions, 0 deletions
diff --git a/client/global.gd b/client/global.gd
index 4ea07a4f..042752cc 100644
--- a/client/global.gd
+++ b/client/global.gd
@@ -38,6 +38,7 @@ var languages := [tr("System default"), "en", "de"]
var default_settings := {
"language": DropdownSetting.new(tr("Language"), 0, languages),
"fullscreen": ToggleSetting.new(tr("Fullscreen"), false),
+ "touch_controls": ToggleSetting.new(tr("Enable touch screen conrols"), DisplayServer.is_touchscreen_available()),
"interpolate_camera_rotation": ToggleSetting.new(tr("Interpolate the camera rotation"), true),
"invert_camera": ToggleSetting.new(tr("Invert camera movement"), false),
"server_binary": TextSetting.new(tr("Server binary (leave empty to search PATH)"), "", "Enter path"),
diff --git a/client/menu/boost.webp b/client/menu/boost.webp
new file mode 100644
index 00000000..afea92df
--- /dev/null
+++ b/client/menu/boost.webp
Binary files differ
diff --git a/client/menu/boost.webp.import b/client/menu/boost.webp.import
new file mode 100644
index 00000000..999115e7
--- /dev/null
+++ b/client/menu/boost.webp.import
@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://bnxllatlo4clg"
+path="res://.godot/imported/boost.webp-e0fa5b3507b36424ead2769ac2e73472.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://menu/boost.webp"
+dest_files=["res://.godot/imported/boost.webp-e0fa5b3507b36424ead2769ac2e73472.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
diff --git a/client/menu/interact.webp b/client/menu/interact.webp
new file mode 100644
index 00000000..cf57c4c0
--- /dev/null
+++ b/client/menu/interact.webp
Binary files differ
diff --git a/client/menu/interact.webp.import b/client/menu/interact.webp.import
new file mode 100644
index 00000000..55ec9275
--- /dev/null
+++ b/client/menu/interact.webp.import
@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://dcgt82qkya880"
+path="res://.godot/imported/interact.webp-ad70044ea6f17b27fedc400ffc5d7eb5.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://menu/interact.webp"
+dest_files=["res://.godot/imported/interact.webp-ad70044ea6f17b27fedc400ffc5d7eb5.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
diff --git a/client/player/controllable_player.gd b/client/player/controllable_player.gd
index 5c88f19b..31378f3f 100644
--- a/client/player/controllable_player.gd
+++ b/client/player/controllable_player.gd
@@ -23,6 +23,8 @@ const BOOST_FACTOR = 2.5
const BOOST_DURATION = 0.3
const BOOST_RESTORE = 0.5
+var onscreen_controls = preload("res://player/onscreen_controls/controls.tscn").instantiate()
+
var facing = Vector2(1, 0)
var velocity_ = Vector2(0, 0)
var stamina = 0
@@ -40,6 +42,7 @@ func _ready():
timer.connect("timeout", func():
game.mp.send_position(position_, rotation_)
)
+ add_child(onscreen_controls)
super()
chat_bubble.submit_message.connect(submit_message)
diff --git a/client/player/onscreen_controls/controls.gd b/client/player/onscreen_controls/controls.gd
new file mode 100644
index 00000000..395f6665
--- /dev/null
+++ b/client/player/onscreen_controls/controls.gd
@@ -0,0 +1,40 @@
+# Undercooked - a game about cooking
+# Copyright 2024 tpart
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, version 3 of the License only.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+#
+extends CanvasLayer
+
+@onready var buttons = $Buttons
+@onready var boost = $Control/Boost
+@onready var interact = $Control/Interact
+@onready var modulate_color = $MovementStick.pressed_color
+
+func _ready():
+ buttons.visible = Global.get_setting("touch_controls")
+
+func _on_boost_pressed():
+ Input.action_press("boost")
+ boost.modulate = modulate_color
+
+func _on_boost_released():
+ Input.action_release("boost")
+ boost.modulate = Color.WHITE
+
+func _on_interact_pressed():
+ Input.action_press("interact")
+ interact.modulate = modulate_color
+
+func _on_interact_released():
+ Input.action_release("interact")
+ interact.modulate = Color.WHITE
diff --git a/client/player/onscreen_controls/controls.tscn b/client/player/onscreen_controls/controls.tscn
new file mode 100644
index 00000000..36505c7b
--- /dev/null
+++ b/client/player/onscreen_controls/controls.tscn
@@ -0,0 +1,38 @@
+[gd_scene load_steps=5 format=3 uid="uid://bq2sqb1u1l5ve"]
+
+[ext_resource type="PackedScene" uid="uid://dmr0fcamx7t56" path="res://player/onscreen_controls/virtual_joystick_scene.tscn" id="1_4k4lh"]
+[ext_resource type="Script" path="res://player/onscreen_controls/controls.gd" id="1_rnoki"]
+[ext_resource type="Texture2D" uid="uid://bnxllatlo4clg" path="res://menu/boost.webp" id="2_i4ife"]
+[ext_resource type="Texture2D" uid="uid://dcgt82qkya880" path="res://menu/interact.webp" id="3_37rne"]
+
+[node name="UI" type="CanvasLayer"]
+script = ExtResource("1_rnoki")
+
+[node name="MovementStick" parent="." instance=ExtResource("1_4k4lh")]
+
+[node name="Buttons" type="Control" parent="."]
+layout_mode = 3
+anchors_preset = 3
+anchor_left = 1.0
+anchor_top = 1.0
+anchor_right = 1.0
+anchor_bottom = 1.0
+offset_left = -300.0
+offset_top = -300.0
+grow_horizontal = 0
+grow_vertical = 0
+
+[node name="Boost" type="TouchScreenButton" parent="Buttons"]
+position = Vector2(150, 25)
+scale = Vector2(0.5, 0.5)
+texture_normal = ExtResource("2_i4ife")
+
+[node name="Interact" type="TouchScreenButton" parent="Buttons"]
+position = Vector2(150, 150)
+scale = Vector2(0.5, 0.5)
+texture_normal = ExtResource("3_37rne")
+
+[connection signal="pressed" from="Buttons/Boost" to="." method="_on_boost_pressed"]
+[connection signal="released" from="Buttons/Boost" to="." method="_on_boost_released"]
+[connection signal="pressed" from="Buttons/Interact" to="." method="_on_interact_pressed"]
+[connection signal="released" from="Buttons/Interact" to="." method="_on_interact_released"]
diff --git a/client/player/onscreen_controls/textures/joystick_base_outline.png b/client/player/onscreen_controls/textures/joystick_base_outline.png
new file mode 100644
index 00000000..7cae462a
--- /dev/null
+++ b/client/player/onscreen_controls/textures/joystick_base_outline.png
Binary files differ
diff --git a/client/player/onscreen_controls/textures/joystick_base_outline.png.import b/client/player/onscreen_controls/textures/joystick_base_outline.png.import
new file mode 100644
index 00000000..c1560d60
--- /dev/null
+++ b/client/player/onscreen_controls/textures/joystick_base_outline.png.import
@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://bm30au8mjfc2f"
+path="res://.godot/imported/joystick_base_outline.png-cc0449804e4e1c71cbd1aefa7c130c92.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://player/onscreen_controls/textures/joystick_base_outline.png"
+dest_files=["res://.godot/imported/joystick_base_outline.png-cc0449804e4e1c71cbd1aefa7c130c92.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
diff --git a/client/player/onscreen_controls/textures/joystick_tip.png b/client/player/onscreen_controls/textures/joystick_tip.png
new file mode 100644
index 00000000..28c57acd
--- /dev/null
+++ b/client/player/onscreen_controls/textures/joystick_tip.png
Binary files differ
diff --git a/client/player/onscreen_controls/textures/joystick_tip.png.import b/client/player/onscreen_controls/textures/joystick_tip.png.import
new file mode 100644
index 00000000..20f9a70e
--- /dev/null
+++ b/client/player/onscreen_controls/textures/joystick_tip.png.import
@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://bkvmydfn5saxg"
+path="res://.godot/imported/joystick_tip.png-70923dcf979f5f117d9fe188032ac227.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://player/onscreen_controls/textures/joystick_tip.png"
+dest_files=["res://.godot/imported/joystick_tip.png-70923dcf979f5f117d9fe188032ac227.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
diff --git a/client/player/onscreen_controls/textures/joystick_tip_arrows.png b/client/player/onscreen_controls/textures/joystick_tip_arrows.png
new file mode 100644
index 00000000..b4caa99b
--- /dev/null
+++ b/client/player/onscreen_controls/textures/joystick_tip_arrows.png
Binary files differ
diff --git a/client/player/onscreen_controls/textures/joystick_tip_arrows.png.import b/client/player/onscreen_controls/textures/joystick_tip_arrows.png.import
new file mode 100644
index 00000000..f8017fb1
--- /dev/null
+++ b/client/player/onscreen_controls/textures/joystick_tip_arrows.png.import
@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://dt13r06u87fib"
+path="res://.godot/imported/joystick_tip_arrows.png-e2d477ae8f960dc0e3fae3a16446be82.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://player/onscreen_controls/textures/joystick_tip_arrows.png"
+dest_files=["res://.godot/imported/joystick_tip_arrows.png-e2d477ae8f960dc0e3fae3a16446be82.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
diff --git a/client/player/onscreen_controls/virtual_joystick.gd b/client/player/onscreen_controls/virtual_joystick.gd
new file mode 100644
index 00000000..55a79c25
--- /dev/null
+++ b/client/player/onscreen_controls/virtual_joystick.gd
@@ -0,0 +1,166 @@
+# Undercooked - a game about cooking
+# Copyright 2024 Marco F
+# Copyright 2024 tpart
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, version 3 of the License only.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+#
+class_name VirtualJoystick
+
+extends Control
+
+@export var pressed_color := Color.GRAY
+@export_range(0, 200, 1) var deadzone_size : float = 10
+@export_range(0, 500, 1) var clampzone_size : float = 75
+
+enum Joystick_mode {
+ FIXED,
+ DYNAMIC,
+ FOLLOWING
+}
+
+@export var joystick_mode := Joystick_mode.FIXED
+
+enum Visibility_mode {
+ ALWAYS,
+ TOUCHSCREEN_ONLY,
+ SETTING,
+ WHEN_TOUCHED
+}
+
+@export var visibility_mode := Visibility_mode.SETTING
+
+@export var use_input_actions := true
+
+@export var action_left := "left"
+@export var action_right := "right"
+@export var action_up := "forward"
+@export var action_down := "backwards"
+
+var is_pressed := false
+
+var output := Vector2.ZERO
+
+var _touch_index : int = -1
+
+@onready var _base := $Base
+@onready var _tip := $Base/Tip
+
+@onready var _base_default_position : Vector2 = _base.position
+@onready var _tip_default_position : Vector2 = _tip.position
+
+@onready var _default_color : Color = _tip.modulate
+
+func _ready() -> void:
+ if ProjectSettings.get_setting("input_devices/pointing/emulate_mouse_from_touch"):
+ printerr("The Project Setting 'emulate_mouse_from_touch' should be set to False")
+ if not ProjectSettings.get_setting("input_devices/pointing/emulate_touch_from_mouse"):
+ printerr("The Project Setting 'emulate_touch_from_mouse' should be set to True")
+
+ if not DisplayServer.is_touchscreen_available() and visibility_mode == Visibility_mode.TOUCHSCREEN_ONLY :
+ hide()
+
+ if visibility_mode == Visibility_mode.WHEN_TOUCHED:
+ hide()
+
+ if visibility_mode == Visibility_mode.SETTING and not Global.get_setting("touch_controls"):
+ hide()
+
+func _input(event: InputEvent) -> void:
+ if event is InputEventScreenTouch:
+ if event.pressed:
+ if _is_point_inside_joystick_area(event.position) and _touch_index == -1:
+ if joystick_mode == Joystick_mode.DYNAMIC or joystick_mode == Joystick_mode.FOLLOWING or (joystick_mode == Joystick_mode.FIXED and _is_point_inside_base(event.position)):
+ if joystick_mode == Joystick_mode.DYNAMIC or joystick_mode == Joystick_mode.FOLLOWING:
+ _move_base(event.position)
+ if visibility_mode == Visibility_mode.WHEN_TOUCHED:
+ show()
+ _touch_index = event.index
+ _tip.modulate = pressed_color
+ _update_joystick(event.position)
+ get_viewport().set_input_as_handled()
+ elif event.index == _touch_index:
+ _reset()
+ if visibility_mode == Visibility_mode.WHEN_TOUCHED:
+ hide()
+ get_viewport().set_input_as_handled()
+ elif event is InputEventScreenDrag:
+ if event.index == _touch_index:
+ _update_joystick(event.position)
+ get_viewport().set_input_as_handled()
+
+func _move_base(new_position: Vector2) -> void:
+ _base.global_position = new_position - _base.pivot_offset * get_global_transform_with_canvas().get_scale()
+
+func _move_tip(new_position: Vector2) -> void:
+ _tip.global_position = new_position - _tip.pivot_offset * _base.get_global_transform_with_canvas().get_scale()
+
+func _is_point_inside_joystick_area(point: Vector2) -> bool:
+ var x: bool = point.x >= global_position.x and point.x <= global_position.x + (size.x * get_global_transform_with_canvas().get_scale().x)
+ var y: bool = point.y >= global_position.y and point.y <= global_position.y + (size.y * get_global_transform_with_canvas().get_scale().y)
+ return x and y
+
+func _get_base_radius() -> Vector2:
+ return _base.size * _base.get_global_transform_with_canvas().get_scale() / 2
+
+func _is_point_inside_base(point: Vector2) -> bool:
+ var _base_radius = _get_base_radius()
+ var center : Vector2 = _base.global_position + _base_radius
+ var vector : Vector2 = point - center
+ if vector.length_squared() <= _base_radius.x * _base_radius.x:
+ return true
+ else:
+ return false
+
+func _update_joystick(touch_position: Vector2) -> void:
+ var _base_radius = _get_base_radius()
+ var center : Vector2 = _base.global_position + _base_radius
+ var vector : Vector2 = touch_position - center
+ vector = vector.limit_length(clampzone_size)
+
+ if joystick_mode == Joystick_mode.FOLLOWING and touch_position.distance_to(center) > clampzone_size:
+ _move_base(touch_position - vector)
+
+ _move_tip(center + vector)
+
+ if vector.length_squared() > deadzone_size * deadzone_size:
+ is_pressed = true
+ output = (vector - (vector.normalized() * deadzone_size)) / (clampzone_size - deadzone_size)
+ else:
+ is_pressed = false
+ output = Vector2.ZERO
+
+ if use_input_actions:
+ if output.x > 0:
+ Input.action_release(action_left)
+ Input.action_press(action_right, output.x)
+ else:
+ Input.action_release(action_right)
+ Input.action_press(action_left, -output.x)
+
+ if output.y > 0:
+ Input.action_release(action_up)
+ Input.action_press(action_down, output.y)
+ else:
+ Input.action_release(action_down)
+ Input.action_press(action_up, -output.y)
+
+func _reset():
+ is_pressed = false
+ output = Vector2.ZERO
+ _touch_index = -1
+ _tip.modulate = _default_color
+ _base.position = _base_default_position
+ _tip.position = _tip_default_position
+ if use_input_actions:
+ for action in [action_left, action_right, action_down, action_up]:
+ Input.action_release(action)
diff --git a/client/player/onscreen_controls/virtual_joystick_scene.tscn b/client/player/onscreen_controls/virtual_joystick_scene.tscn
new file mode 100644
index 00000000..13323b1d
--- /dev/null
+++ b/client/player/onscreen_controls/virtual_joystick_scene.tscn
@@ -0,0 +1,51 @@
+[gd_scene load_steps=4 format=3 uid="uid://dmr0fcamx7t56"]
+
+[ext_resource type="Script" path="res://player/onscreen_controls/virtual_joystick.gd" id="1_8x4dy"]
+[ext_resource type="Texture2D" uid="uid://bm30au8mjfc2f" path="res://player/onscreen_controls/textures/joystick_base_outline.png" id="2_jhjs2"]
+[ext_resource type="Texture2D" uid="uid://dt13r06u87fib" path="res://player/onscreen_controls/textures/joystick_tip_arrows.png" id="3_3etdg"]
+
+[node name="Virtual Joystick" type="Control"]
+layout_mode = 3
+anchors_preset = 2
+anchor_top = 1.0
+anchor_bottom = 1.0
+offset_top = -308.0
+offset_right = 300.0
+offset_bottom = -8.0
+grow_vertical = 0
+script = ExtResource("1_8x4dy")
+
+[node name="Base" type="TextureRect" parent="."]
+layout_mode = 1
+anchors_preset = 8
+anchor_left = 0.5
+anchor_top = 0.5
+anchor_right = 0.5
+anchor_bottom = 0.5
+offset_left = -100.0
+offset_top = -100.0
+offset_right = 100.0
+offset_bottom = 100.0
+grow_horizontal = 2
+grow_vertical = 2
+pivot_offset = Vector2(100, 100)
+mouse_force_pass_scroll_events = false
+texture = ExtResource("2_jhjs2")
+stretch_mode = 5
+
+[node name="Tip" type="TextureRect" parent="Base"]
+layout_mode = 1
+anchors_preset = 8
+anchor_left = 0.5
+anchor_top = 0.5
+anchor_right = 0.5
+anchor_bottom = 0.5
+offset_left = -50.0
+offset_top = -50.0
+offset_right = 50.0
+offset_bottom = 50.0
+grow_horizontal = 2
+grow_vertical = 2
+pivot_offset = Vector2(50, 50)
+texture = ExtResource("3_3etdg")
+stretch_mode = 5