gamepad test

This commit is contained in:
Page Asgardius 2024-01-27 09:12:30 -07:00
parent 2c525d1658
commit 2f221bbb7a
4 changed files with 250 additions and 1 deletions

View file

@ -2,7 +2,7 @@ extends Control
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
Global.debug = true
$"VBoxContainer/Scene Selector".grab_focus()
$"VBoxContainer/Gamepad Test".grab_focus()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
@ -37,3 +37,7 @@ func _on_sound_test_pressed():
func _on_back_pressed():
Global.debug = false
get_tree().change_scene_to_file("res://levels/tmenu.tscn")
func _on_gamepad_test_pressed():
get_tree().change_scene_to_file("res://levels/gamepadtest.tscn")

View file

@ -54,6 +54,12 @@ offset_right = 129.5
grow_horizontal = 2
grow_vertical = 0
[node name="Gamepad Test" type="Button" parent="VBoxContainer"]
layout_mode = 2
theme_override_font_sizes/font_size = 80
theme_override_styles/focus = SubResource("StyleBoxFlat_821nm")
text = "Gamepad Test"
[node name="Scene Selector" type="Button" parent="VBoxContainer"]
layout_mode = 2
theme_override_font_sizes/font_size = 80
@ -76,6 +82,7 @@ text = "Back"
layout_mode = 1
[connection signal="finished" from="nebula" to="nebula" method="_on_finished"]
[connection signal="pressed" from="VBoxContainer/Gamepad Test" to="." method="_on_gamepad_test_pressed"]
[connection signal="pressed" from="VBoxContainer/Scene Selector" to="." method="_on_scene_selector_pressed"]
[connection signal="pressed" from="VBoxContainer/Sound Test" to="." method="_on_sound_test_pressed"]
[connection signal="pressed" from="VBoxContainer/Back" to="." method="_on_back_pressed"]

79
levels/gamepadtest.gd Normal file
View file

@ -0,0 +1,79 @@
extends Control
var joyname
var lxaxis
var lyaxis
var rxaxis
var ryaxis
var dpadup
var dpaddown
var dpadleft
var dpadright
var lt
var rt
var ls
var rs
var l3
var r3
var view
var menu
var xb
var yb
var ab
var bb
# Called when the node enters the scene tree for the first time.
func _ready():
joyname = $Info
lxaxis = $"BoxContainer/VBoxContainer/Left X Axis"
lyaxis = $"BoxContainer/VBoxContainer/Left Y Axis"
rxaxis = $"BoxContainer/VBoxContainer2/Right X Axis"
ryaxis = $"BoxContainer/VBoxContainer2/Right Y Axis"
dpadup = $"BoxContainer/VBoxContainer/DPAD Up"
dpaddown = $"BoxContainer/VBoxContainer2/DPAD Down"
dpadleft = $"BoxContainer/VBoxContainer/DPAD Left"
dpadright = $"BoxContainer/VBoxContainer2/DPAD Right"
lt = $"BoxContainer/VBoxContainer/Left Trigger"
rt = $"BoxContainer/VBoxContainer2/Right Trigger"
ls = $"BoxContainer/VBoxContainer/Left Shoulder"
rs = $"BoxContainer/VBoxContainer2/Right Shoulder"
l3 = $"BoxContainer/VBoxContainer/Left Stick"
r3 = $"BoxContainer/VBoxContainer2/Right Stick"
view = $BoxContainer/VBoxContainer/View
menu = $BoxContainer/VBoxContainer2/Menu
xb = $BoxContainer/VBoxContainer/X
yb = $BoxContainer/VBoxContainer2/Y
ab = $BoxContainer/VBoxContainer/A
bb = $BoxContainer/VBoxContainer2/B
#pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func _input(event):
if Input.is_key_pressed(KEY_ESCAPE) || (Input.is_joy_button_pressed(0,JOY_BUTTON_A) && (Input.is_joy_button_pressed(0,JOY_BUTTON_B))):
get_tree().change_scene_to_file("res://levels/debug.tscn")
joyname.set_text("Current Device: "+str(Input.get_joy_name(0))+"\nIf drift threshold is 0.2 or higher, your gamepad need new sticks")
lxaxis.set_text("Left X Axis "+str(Input.get_joy_axis(0,JOY_AXIS_LEFT_X)))
lyaxis.set_text("Left Y Axis "+str(Input.get_joy_axis(0,JOY_AXIS_LEFT_Y)))
rxaxis.set_text("Right X Axis "+str(Input.get_joy_axis(0,JOY_AXIS_RIGHT_X)))
ryaxis.set_text("Right Y Axis "+str(Input.get_joy_axis(0,JOY_AXIS_RIGHT_Y)))
dpadup.set_text("DPAD Up "+str(Input.is_joy_button_pressed(0,JOY_BUTTON_DPAD_UP)))
dpaddown.set_text("DPAD Down "+str(Input.is_joy_button_pressed(0,JOY_BUTTON_DPAD_DOWN)))
dpadleft.set_text("DPAD Left "+str(Input.is_joy_button_pressed(0,JOY_BUTTON_DPAD_LEFT)))
dpadright.set_text("DPAD Right "+str(Input.is_joy_button_pressed(0,JOY_BUTTON_DPAD_RIGHT)))
lt.set_text("Left Trigger "+str(Input.get_joy_axis(0,JOY_AXIS_TRIGGER_LEFT)))
rt.set_text("Right Trigger "+str(Input.get_joy_axis(0,JOY_AXIS_TRIGGER_RIGHT)))
ls.set_text("Left Shoulder "+str(Input.is_joy_button_pressed(0,JOY_BUTTON_LEFT_SHOULDER)))
rs.set_text("Right Shoulder "+str(Input.is_joy_button_pressed(0,JOY_BUTTON_RIGHT_SHOULDER)))
l3.set_text("Left Stick "+str(Input.is_joy_button_pressed(0,JOY_BUTTON_LEFT_STICK)))
r3.set_text("Right Stick "+str(Input.is_joy_button_pressed(0,JOY_BUTTON_RIGHT_STICK)))
view.set_text("View "+str(Input.is_joy_button_pressed(0,JOY_BUTTON_BACK)))
menu.set_text("Menu "+str(Input.is_joy_button_pressed(0,JOY_BUTTON_START)))
xb.set_text("X "+str(Input.is_joy_button_pressed(0,JOY_BUTTON_X)))
yb.set_text("Y "+str(Input.is_joy_button_pressed(0,JOY_BUTTON_Y)))
ab.set_text("A "+str(Input.is_joy_button_pressed(0,JOY_BUTTON_A)))
bb.set_text("B "+str(Input.is_joy_button_pressed(0,JOY_BUTTON_B)))

159
levels/gamepadtest.tscn Normal file
View file

@ -0,0 +1,159 @@
[gd_scene load_steps=5 format=3 uid="uid://qun4scsrsp00"]
[ext_resource type="Script" path="res://levels/gamepadtest.gd" id="1_w4qrm"]
[ext_resource type="VideoStream" path="res://backgounds/nebula_-_6044 (720p).ogv" id="2_i62na"]
[ext_resource type="Script" path="res://nebula.gd" id="3_5yjm5"]
[ext_resource type="PackedScene" uid="uid://d31udhuuwrajn" path="res://levels/bottomhud.tscn" id="4_88ejd"]
[node name="Gamepadtest" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_w4qrm")
[node name="nebula" type="VideoStreamPlayer" parent="."]
layout_mode = 0
offset_right = 640.0
offset_bottom = 368.0
scale = Vector2(2, 1.96)
stream = ExtResource("2_i62na")
autoplay = true
script = ExtResource("3_5yjm5")
[node name="Label" type="Label" parent="."]
layout_mode = 0
offset_right = 40.0
offset_bottom = 23.0
[node name="Game name" type="Label" parent="."]
layout_mode = 0
offset_left = 496.0
offset_top = 3.0
offset_right = 790.0
offset_bottom = 73.0
theme_override_font_sizes/font_size = 40
text = "Gamepad Test"
[node name="Info" type="Label" parent="."]
layout_mode = 0
offset_left = 28.0
offset_top = 94.0
offset_right = 322.0
offset_bottom = 164.0
theme_override_font_sizes/font_size = 20
[node name="Stop" type="Label" parent="."]
layout_mode = 0
offset_left = 5.0
offset_top = 672.0
offset_right = 444.0
offset_bottom = 708.0
theme_override_font_sizes/font_size = 22
text = "Press Escape or A + B to return"
[node name="BoxContainer" type="BoxContainer" parent="."]
layout_mode = 1
anchors_preset = 3
anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -640.0
offset_top = -419.0
grow_horizontal = 0
grow_vertical = 0
[node name="VBoxContainer" type="VBoxContainer" parent="BoxContainer"]
layout_mode = 2
[node name="Left X Axis" type="Label" parent="BoxContainer/VBoxContainer"]
layout_mode = 2
text = "Left X Axis"
[node name="Left Y Axis" type="Label" parent="BoxContainer/VBoxContainer"]
layout_mode = 2
text = "Left Y Axis"
[node name="DPAD Up" type="Label" parent="BoxContainer/VBoxContainer"]
layout_mode = 2
text = "DPAD Up"
[node name="DPAD Left" type="Label" parent="BoxContainer/VBoxContainer"]
layout_mode = 2
text = "DPAD Left"
[node name="Left Trigger" type="Label" parent="BoxContainer/VBoxContainer"]
layout_mode = 2
text = "Left Trigger"
[node name="Left Shoulder" type="Label" parent="BoxContainer/VBoxContainer"]
layout_mode = 2
text = "Left Shoulder"
[node name="Left Stick" type="Label" parent="BoxContainer/VBoxContainer"]
layout_mode = 2
text = "Left Stick"
[node name="View" type="Label" parent="BoxContainer/VBoxContainer"]
layout_mode = 2
text = "View"
[node name="X" type="Label" parent="BoxContainer/VBoxContainer"]
layout_mode = 2
text = "X"
[node name="A" type="Label" parent="BoxContainer/VBoxContainer"]
layout_mode = 2
text = "A"
[node name="VBoxContainer2" type="VBoxContainer" parent="BoxContainer"]
layout_mode = 2
[node name="Right X Axis" type="Label" parent="BoxContainer/VBoxContainer2"]
layout_mode = 2
text = "Right X Axis"
[node name="Right Y Axis" type="Label" parent="BoxContainer/VBoxContainer2"]
layout_mode = 2
text = "Right Y Axis"
[node name="DPAD Down" type="Label" parent="BoxContainer/VBoxContainer2"]
layout_mode = 2
text = "DPAD Down
"
[node name="DPAD Right" type="Label" parent="BoxContainer/VBoxContainer2"]
layout_mode = 2
text = "DPAD Right"
[node name="Right Trigger" type="Label" parent="BoxContainer/VBoxContainer2"]
layout_mode = 2
text = "Right Trigger"
[node name="Right Shoulder" type="Label" parent="BoxContainer/VBoxContainer2"]
layout_mode = 2
text = "Right Shoulder"
[node name="Right Stick" type="Label" parent="BoxContainer/VBoxContainer2"]
layout_mode = 2
text = "Right Stick"
[node name="Menu" type="Label" parent="BoxContainer/VBoxContainer2"]
layout_mode = 2
text = "Menu"
[node name="Y" type="Label" parent="BoxContainer/VBoxContainer2"]
layout_mode = 2
text = "Y"
[node name="B" type="Label" parent="BoxContainer/VBoxContainer2"]
layout_mode = 2
text = "B"
[node name="Bottomhud" parent="." instance=ExtResource("4_88ejd")]
layout_mode = 1
[connection signal="finished" from="nebula" to="nebula" method="_on_finished"]