fix volume loading + working on touch joystick compatibility !

using 4 touch screen buttons for interaction & joystick.gd for visual feedback (=
This commit is contained in:
Harmony Honey Monroe 2024-03-27 02:43:11 -04:00
parent 36e5210d36
commit c2a973ba35
5 changed files with 111 additions and 44 deletions

View file

@ -331,9 +331,13 @@ func load_options(path := options_path):
if !dict.empty():
if dict.has("sfx"):
bus_volume[1] = int(dict["sfx"])
var v = int(dict["sfx"])
bus_volume[1] = v
set_bus_volume(1, v)
if dict.has("music"):
bus_volume[2] = int(dict["music"])
var v = int(dict["music"])
bus_volume[2] = v
set_bus_volume(2, v)
if dict.has("fullscreen"):
set_fullscreen(bool(dict["fullscreen"]))

View file

@ -1,7 +1,8 @@
[gd_scene load_steps=11 format=2]
[gd_scene load_steps=16 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/joystick/round_button.gd" type="Script" id=3]
[ext_resource path="res://src/menu/joystick.gd" type="Script" id=4]
[ext_resource path="res://media/font/NicoPaint-Regular.ttf" type="DynamicFontData" id=5]
[ext_resource path="res://media/image/diamond16.png" type="Texture" id=7]
@ -22,6 +23,18 @@ radius = 15.0
[sub_resource type="CircleShape2D" id=5]
radius = 15.0
[sub_resource type="ConvexPolygonShape2D" id=7]
points = PoolVector2Array( 2.12132, 2.12132, 3, 0, 2.12132, -2.12132, 42.4264, -42.4264, 55.4328, -22.961, 60, 0, 55.4328, 22.961, 42.4264, 42.4264 )
[sub_resource type="ConvexPolygonShape2D" id=8]
points = PoolVector2Array( -2.12132, 2.12132, -1.31134e-07, 3, 2.12132, 2.12132, 42.4264, 42.4264, 22.961, 55.4328, -2.62268e-06, 60, -22.961, 55.4328, -42.4264, 42.4264 )
[sub_resource type="ConvexPolygonShape2D" id=9]
points = PoolVector2Array( -2.12132, -2.12132, -3, -2.62268e-07, -2.12132, 2.12132, -42.4264, 42.4264, -55.4328, 22.961, -60, -5.24537e-06, -55.4328, -22.961, -42.4264, -42.4264 )
[sub_resource type="ConvexPolygonShape2D" id=10]
points = PoolVector2Array( 2.12132, -2.12132, 3.57746e-08, -3, -2.12132, -2.12132, -42.4264, -42.4264, -22.961, -55.4328, 7.15493e-07, -60, 22.961, -55.4328, 42.4264, -42.4264 )
[node name="TouchScreen" type="CanvasLayer"]
pause_mode = 2
layer = 6
@ -160,9 +173,8 @@ margin_left = 26.0
margin_top = 98.0
margin_right = 26.0
margin_bottom = 98.0
rect_pivot_offset = Vector2( -84, -71 )
script = ExtResource( 4 )
max_range = 30.0
dead_zone = 3.0
[node name="Base" type="Control" parent="Control/Joystick"]
grow_horizontal = 2
@ -171,6 +183,7 @@ size_flags_horizontal = 4
size_flags_vertical = 4
script = ExtResource( 8 )
radius = 20.0
points = 16
[node name="Guide" type="Control" parent="Control/Joystick/Base"]
modulate = Color( 1, 1, 1, 0.509804 )
@ -208,3 +221,34 @@ size_flags_horizontal = 4
size_flags_vertical = 4
texture = ExtResource( 7 )
stretch_mode = 4
[node name="Buttons" type="Control" parent="Control/Joystick"]
margin_right = 40.0
margin_bottom = 40.0
[node name="0" type="TouchScreenButton" parent="Control/Joystick/Buttons"]
shape = SubResource( 7 )
shape_centered = false
action = "ui_right"
script = ExtResource( 3 )
[node name="1" type="TouchScreenButton" parent="Control/Joystick/Buttons"]
shape = SubResource( 8 )
shape_centered = false
action = "ui_down"
script = ExtResource( 3 )
angle = 90.0
[node name="2" type="TouchScreenButton" parent="Control/Joystick/Buttons"]
shape = SubResource( 9 )
shape_centered = false
action = "ui_left"
script = ExtResource( 3 )
angle = 180.0
[node name="3" type="TouchScreenButton" parent="Control/Joystick/Buttons"]
shape = SubResource( 10 )
shape_centered = false
action = "ui_up"
script = ExtResource( 3 )
angle = 270.0

View file

@ -5,15 +5,23 @@ extends CanvasItem
export var radius := 16.0 setget set_radius
export var offset := Vector2.ZERO
export var is_solid := false
export var points := 16
export var width := 1.0
export var points := 15 setget set_points
export var width := 1.0 setget set_width
func _draw():
if is_solid:
draw_circle(offset, radius, Color.white)
else:
draw_arc(offset, radius, 0, TAU, points, Color.white, width, false)
draw_arc(offset, radius, 0, TAU, points + 1, Color.white, width, false)
func set_radius(arg := radius):
radius = arg
update()
func set_points(arg := points):
points = arg
update()
func set_width(arg := width):
width = arg
update()

View file

@ -2,23 +2,17 @@ tool
extends Control
export var radius := 20.0
export var max_range := 40.0
export var dead_zone := 2.0
export var max_range := 60.0
onready var base := $Base
onready var tip := $Tip
export var action_up := "ui_up"
export var action_down := "ui_down"
export var action_left := "ui_left"
export var action_right := "ui_right"
onready var buttons := $Buttons.get_children()
var vec := Vector2.ZERO
var vl := 0.0
var joy = Vector2.ZERO
var is_joy := false
var last_val = -1
var index := -1
var is_input = true
func _input(event):
@ -27,46 +21,25 @@ func _input(event):
var is_touch = event is InputEventScreenTouch
var is_drag = event is InputEventScreenDrag
if (is_drag or is_touch) and (event.index == index or index == -1):
if (is_drag or is_touch):
vec = event.position - rect_global_position
vl = vec.length()
joy = vec.normalized()
if is_touch:
is_joy = vl < max_range if event.pressed else false
index = event.index if is_joy else -1
is_joy = vl < max_range
if is_touch and !event.pressed:
is_joy = false
vec = vec.limit_length(radius)
tip.modulate = Color.red if is_joy else Color.white
tip.rect_position = vec if is_joy else Vector2.ZERO
send_input()
func send_input():
var ja = wrapf(rad2deg(joy.angle()) + 45.0, 0.0, 360.0)
var val = int(ja / 90.0) if is_joy and vl > dead_zone else -1
var a = [action_right , action_down, action_left, action_up]
for i in 4:
if i != val: Input.action_release(a[i])
if val > -1:
var u = InputEventAction.new()
u.action = a[val]
u.pressed = true
Input.parse_input_event(u)
print(val, " ", u.action, " ", vec, " index: ", index)
func _physics_process(delta):
if Engine.editor_hint: return
func set_actions(_up, _down, _left, _right):
is_joy = false
index = -1
send_input()
action_up = _up
action_down = _down
action_left = _left
action_right = _right
for i in 4:
buttons[i].action = [_right, _down, _left, _up][i]
buttons[i].passby_press = !("ui_" in _up)

View file

@ -0,0 +1,38 @@
tool
extends TouchScreenButton
export var radius := 60.0 setget set_radius
export var points := 5 setget set_points
export var angle := 0.0 setget set_angle
export var deadzone := 3.0 setget set_deadzone
func set_radius(arg := radius):
radius = arg
act()
func set_points(arg := points):
points = arg
act()
func set_angle(arg := angle):
angle = arg
act()
func set_deadzone(arg := deadzone):
deadzone = arg
act()
func act():
var r = Vector2(radius, 0)
var vec = PoolVector2Array()
for i in [1, 0, -1]:
vec.append(Vector2(deadzone, 0).rotated(deg2rad(angle + (i * 45))))
for i in points:
var f = i / float(points - 1)
vec.append(r.rotated(deg2rad(angle + lerp(-45, 45, f))))
shape = ConvexPolygonShape2D.new()
shape.points = vec