From af8a42246732e2b9a617b8cb8bfd5b15c8450d03 Mon Sep 17 00:00:00 2001 From: Harmony Honey Monroe Date: Sun, 22 Sep 2024 18:10:49 -0400 Subject: [PATCH] fix touch screen buttons ghosting! release() all actions when changing action sets --- src/autoload/touch_screen.gd | 8 ++++++-- src/autoload/touch_screen.tscn | 33 +++++++++++---------------------- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/src/autoload/touch_screen.gd b/src/autoload/touch_screen.gd index e47c739..64e7aa2 100644 --- a/src/autoload/touch_screen.gd +++ b/src/autoload/touch_screen.gd @@ -5,9 +5,9 @@ onready var top := $Control/HBoxTop onready var keys := [$Control/HBoxRight/C, $Control/HBoxRight/X] onready var buttons := [$Control/HBoxRight/C/Control/Button, $Control/HBoxRight/X/Control/Button] -onready var joystick := $Control/Joystick -onready var btns := $Control/Joystick/Buttons.get_children() +onready var btns := $Control/DPad/Buttons.get_children() +onready var actions := InputMap.get_actions() func _ready(): connect("visibility_changed", self, "vis") @@ -31,6 +31,10 @@ func set_game(arg := false): set_actions(i + "up", i + "down", i + "left", i + "right") buttons[0].action = "action" if arg else "ui_no" buttons[1].action = "jump" if arg else "ui_yes" + + for a in actions: + Input.action_release(a) + for f in buttons: f.passby_press = arg diff --git a/src/autoload/touch_screen.tscn b/src/autoload/touch_screen.tscn index ca63029..13c7d94 100644 --- a/src/autoload/touch_screen.tscn +++ b/src/autoload/touch_screen.tscn @@ -1,11 +1,10 @@ -[gd_scene load_steps=15 format=2] +[gd_scene load_steps=14 format=2] [ext_resource path="res://src/autoload/touch_screen.gd" type="Script" id=1] [ext_resource path="res://media/image/circle.png" type="Texture" id=2] [ext_resource path="res://src/menu/round_button.gd" type="Script" id=3] [ext_resource path="res://src/menu/button_modulate.gd" type="Script" id=4] [ext_resource path="res://media/font/NicoPaint-Regular.ttf" type="DynamicFontData" id=5] -[ext_resource path="res://src/circle.gd" type="Script" id=8] [sub_resource type="CircleShape2D" id=3] radius = 15.0 @@ -175,28 +174,18 @@ margin_top = -6.0 margin_right = 5.0 margin_bottom = 6.0 -[node name="Joystick" type="Control" parent="Control"] +[node name="DPad" type="Control" parent="Control"] margin_left = 26.0 margin_top = 98.0 margin_right = 26.0 margin_bottom = 98.0 rect_pivot_offset = Vector2( -84, -71 ) -[node name="Base" type="Control" parent="Control/Joystick"] -visible = false -grow_horizontal = 2 -grow_vertical = 2 -size_flags_horizontal = 4 -size_flags_vertical = 4 -script = ExtResource( 8 ) -radius = 20.0 -points = 16 - -[node name="Buttons" type="Control" parent="Control/Joystick"] +[node name="Buttons" type="Control" parent="Control/DPad"] margin_right = 40.0 margin_bottom = 40.0 -[node name="0" type="TouchScreenButton" parent="Control/Joystick/Buttons"] +[node name="0" type="TouchScreenButton" parent="Control/DPad/Buttons"] shape = SubResource( 7 ) shape_centered = false action = "ui_right" @@ -205,7 +194,7 @@ poly_path = NodePath("Polygon2D") inner_radius = 18.0 inner_offset = 2.0 -[node name="Polygon2D" type="Polygon2D" parent="Control/Joystick/Buttons/0"] +[node name="Polygon2D" type="Polygon2D" parent="Control/DPad/Buttons/0"] modulate = Color( 1, 1, 1, 0.3 ) position = Vector2( 2, 0 ) polygon = PoolVector2Array( 2.12132, 2.12132, 3, 0, 2.12132, -2.12132, 12.7279, -12.7279, 16.6298, -6.8883, 18, 0, 16.6298, 6.8883, 12.7279, 12.7279 ) @@ -213,7 +202,7 @@ script = ExtResource( 4 ) button_path = NodePath("..") idle_color = Color( 1, 1, 1, 0.501961 ) -[node name="1" type="TouchScreenButton" parent="Control/Joystick/Buttons"] +[node name="1" type="TouchScreenButton" parent="Control/DPad/Buttons"] shape = SubResource( 8 ) shape_centered = false action = "ui_down" @@ -223,14 +212,14 @@ poly_path = NodePath("Polygon2D") inner_radius = 18.0 inner_offset = 2.0 -[node name="Polygon2D" type="Polygon2D" parent="Control/Joystick/Buttons/1"] +[node name="Polygon2D" type="Polygon2D" parent="Control/DPad/Buttons/1"] modulate = Color( 1, 1, 1, 0.3 ) position = Vector2( -8.74228e-08, 2 ) polygon = PoolVector2Array( -2.12132, 2.12132, -1.31134e-07, 3, 2.12132, 2.12132, 12.7279, 12.7279, 6.8883, 16.6298, -7.86805e-07, 18, -6.8883, 16.6298, -12.7279, 12.7279 ) script = ExtResource( 4 ) button_path = NodePath("..") -[node name="2" type="TouchScreenButton" parent="Control/Joystick/Buttons"] +[node name="2" type="TouchScreenButton" parent="Control/DPad/Buttons"] shape = SubResource( 9 ) shape_centered = false action = "ui_left" @@ -240,14 +229,14 @@ poly_path = NodePath("Polygon2D") inner_radius = 18.0 inner_offset = 2.0 -[node name="Polygon2D" type="Polygon2D" parent="Control/Joystick/Buttons/2"] +[node name="Polygon2D" type="Polygon2D" parent="Control/DPad/Buttons/2"] modulate = Color( 1, 1, 1, 0.3 ) position = Vector2( -2, -1.74846e-07 ) polygon = PoolVector2Array( -2.12132, -2.12132, -3, -2.62268e-07, -2.12132, 2.12132, -12.7279, 12.7279, -16.6298, 6.8883, -18, -1.57361e-06, -16.6298, -6.8883, -12.7279, -12.7279 ) script = ExtResource( 4 ) button_path = NodePath("..") -[node name="3" type="TouchScreenButton" parent="Control/Joystick/Buttons"] +[node name="3" type="TouchScreenButton" parent="Control/DPad/Buttons"] shape = SubResource( 10 ) shape_centered = false action = "ui_up" @@ -257,7 +246,7 @@ poly_path = NodePath("Polygon2D") inner_radius = 18.0 inner_offset = 2.0 -[node name="Polygon2D" type="Polygon2D" parent="Control/Joystick/Buttons/3"] +[node name="Polygon2D" type="Polygon2D" parent="Control/DPad/Buttons/3"] modulate = Color( 1, 1, 1, 0.3 ) position = Vector2( 2.38498e-08, -2 ) polygon = PoolVector2Array( 2.12132, -2.12132, 3.57746e-08, -3, -2.12132, -2.12132, -12.7279, -12.7279, -6.8883, -16.6298, 2.14648e-07, -18, 6.8883, -16.6298, 12.7279, -12.7279 )