summaryrefslogtreecommitdiff
path: root/ui/mobile
diff options
context:
space:
mode:
Diffstat (limited to 'ui/mobile')
-rw-r--r--ui/mobile/button.gd45
-rw-r--r--ui/mobile/button.tscn43
-rw-r--r--ui/mobile/mobile_controls.gd17
-rw-r--r--ui/mobile/mobile_controls.tscn78
4 files changed, 183 insertions, 0 deletions
diff --git a/ui/mobile/button.gd b/ui/mobile/button.gd
new file mode 100644
index 0000000..2e3653c
--- /dev/null
+++ b/ui/mobile/button.gd
@@ -0,0 +1,45 @@
+@tool
+extends Panel
+
+
+@export var texture: Texture2D:
+ set(value):
+ texture = value
+ $TouchScreenButton.texture_normal = value
+ _on_resized()
+
+@export var label: String:
+ set(value):
+ label = value
+ $Label.text = value
+
+@export var action: StringName = "":
+ set(value):
+ action = value
+ $TouchScreenButton.action = value
+
+
+func _ready() -> void:
+ _on_resized()
+
+
+func _on_resized() -> void:
+ $TouchScreenButton.shape.size = size
+
+ var texture_size := Vector2.ZERO
+ if texture:
+ texture_size = texture.get_size()
+
+ $TouchScreenButton.position = Vector2(
+ (size.x - texture_size.x) / 2,
+ (size.y - texture_size.y) / 2
+ )
+
+ $Label.size = size
+
+
+func _on_touch_screen_button_pressed() -> void:
+ modulate = Color(0.5, 0.5, 0.5, 1.0)
+
+func _on_touch_screen_button_released() -> void:
+ modulate = Color(1.0, 1.0, 1.0, 1.0)
diff --git a/ui/mobile/button.tscn b/ui/mobile/button.tscn
new file mode 100644
index 0000000..64a413f
--- /dev/null
+++ b/ui/mobile/button.tscn
@@ -0,0 +1,43 @@
+[gd_scene load_steps=5 format=3 uid="uid://evppekv62x0g"]
+
+[ext_resource type="Script" path="res://ui/mobile/button.gd" id="1_2pd68"]
+[ext_resource type="Theme" uid="uid://b067xhqktnmhr" path="res://ui/theme.tres" id="2_rnfal"]
+
+[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_qy0ya"]
+bg_color = Color(0.0297164, 0.155372, 0.181691, 1)
+border_width_left = 1
+border_width_top = 1
+border_width_right = 1
+border_width_bottom = 1
+border_color = Color(0, 0, 0, 1)
+border_blend = true
+
+[sub_resource type="RectangleShape2D" id="RectangleShape2D_cuu3o"]
+resource_local_to_scene = true
+size = Vector2(160, 20)
+
+[node name="Button" type="Panel"]
+texture_filter = 1
+offset_right = 160.0
+offset_bottom = 20.0
+theme_override_styles/panel = SubResource("StyleBoxFlat_qy0ya")
+script = ExtResource("1_2pd68")
+
+[node name="TouchScreenButton" type="TouchScreenButton" parent="."]
+position = Vector2(80, 10)
+shape = SubResource("RectangleShape2D_cuu3o")
+shape_visible = false
+visibility_mode = 1
+
+[node name="Label" type="Label" parent="."]
+layout_mode = 0
+offset_right = 160.0
+offset_bottom = 20.0
+theme = ExtResource("2_rnfal")
+theme_override_colors/font_color = Color(1, 1, 1, 1)
+horizontal_alignment = 1
+vertical_alignment = 1
+
+[connection signal="resized" from="." to="." method="_on_resized"]
+[connection signal="pressed" from="TouchScreenButton" to="." method="_on_touch_screen_button_pressed"]
+[connection signal="released" from="TouchScreenButton" to="." method="_on_touch_screen_button_released"]
diff --git a/ui/mobile/mobile_controls.gd b/ui/mobile/mobile_controls.gd
new file mode 100644
index 0000000..a87ceea
--- /dev/null
+++ b/ui/mobile/mobile_controls.gd
@@ -0,0 +1,17 @@
+class_name MobileControls
+extends CanvasLayer
+
+
+var size: Vector2:
+ get():
+ return (get_child(0) as Control).size
+
+
+func _init() -> void:
+ visible = false
+ process_mode = ProcessMode.PROCESS_MODE_DISABLED
+
+
+func enable() -> void:
+ process_mode = ProcessMode.PROCESS_MODE_ALWAYS
+ visible = true
diff --git a/ui/mobile/mobile_controls.tscn b/ui/mobile/mobile_controls.tscn
new file mode 100644
index 0000000..333b0ad
--- /dev/null
+++ b/ui/mobile/mobile_controls.tscn
@@ -0,0 +1,78 @@
+[gd_scene load_steps=7 format=3 uid="uid://cvx1vj47uf5k2"]
+
+[ext_resource type="Script" path="res://ui/mobile/mobile_controls.gd" id="1_ts8mv"]
+[ext_resource type="PackedScene" uid="uid://evppekv62x0g" path="res://ui/mobile/button.tscn" id="2_7um2b"]
+[ext_resource type="Texture2D" uid="uid://cywefso7qpdan" path="res://ui/assets/tilemap_white.png" id="2_n84be"]
+
+[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_e3qjv"]
+bg_color = Color(0.0313726, 0.156863, 0.180392, 1)
+
+[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_hxyr7"]
+bg_color = Color(0.0297164, 0.155372, 0.181691, 1)
+border_width_left = 1
+border_width_top = 2
+border_width_right = 1
+border_width_bottom = 1
+border_color = Color(0, 0, 0, 1)
+border_blend = true
+
+[sub_resource type="AtlasTexture" id="AtlasTexture_kr7mh"]
+atlas = ExtResource("2_n84be")
+region = Rect2(445, 292, 10, 10)
+filter_clip = true
+
+[node name="MobileControls" type="CanvasLayer"]
+script = ExtResource("1_ts8mv")
+
+[node name="Control" type="Panel" parent="."]
+offset_top = 144.0
+offset_right = 160.0
+offset_bottom = 249.0
+theme_override_styles/panel = SubResource("StyleBoxFlat_e3qjv")
+
+[node name="Up" parent="Control" instance=ExtResource("2_7um2b")]
+layout_mode = 0
+offset_bottom = 26.0
+theme_override_styles/panel = SubResource("StyleBoxFlat_hxyr7")
+texture = SubResource("AtlasTexture_kr7mh")
+label = ""
+action = &"ui_up"
+
+[node name="Down" parent="Control" instance=ExtResource("2_7um2b")]
+layout_mode = 0
+offset_left = 160.0
+offset_top = 92.0
+offset_right = 320.0
+offset_bottom = 118.0
+rotation = 3.14159
+texture = SubResource("AtlasTexture_kr7mh")
+label = ""
+action = &"ui_down"
+
+[node name="Left" parent="Control" instance=ExtResource("2_7um2b")]
+layout_mode = 0
+offset_left = 160.0
+offset_top = 26.0
+offset_right = 200.0
+offset_bottom = 106.0
+rotation = 1.5708
+texture = SubResource("AtlasTexture_kr7mh")
+label = ""
+action = &"ui_right"
+
+[node name="Right" parent="Control" instance=ExtResource("2_7um2b")]
+layout_mode = 0
+offset_top = 66.0
+offset_right = 40.0
+offset_bottom = 146.0
+rotation = -1.5708
+texture = SubResource("AtlasTexture_kr7mh")
+label = ""
+action = &"ui_left"
+
+[node name="Start" parent="Control" instance=ExtResource("2_7um2b")]
+layout_mode = 0
+offset_top = 92.0
+offset_bottom = 105.0
+label = "Start"
+action = &"ui_accept"