From 38e12182bff6ec49099d2ff799aa71ca5630f7ff Mon Sep 17 00:00:00 2001 From: Luke Hubmayer-Werner Date: Sat, 23 Mar 2024 19:42:17 +1030 Subject: [PATCH] Step pad monitor --- scenes/JoypadMonitor6Btn.gd | 42 +++++++++ scenes/JoypadMonitor6Btn.tscn | 157 ++++++++++++++++++++++++++++++++++ 2 files changed, 199 insertions(+) create mode 100644 scenes/JoypadMonitor6Btn.gd create mode 100644 scenes/JoypadMonitor6Btn.tscn diff --git a/scenes/JoypadMonitor6Btn.gd b/scenes/JoypadMonitor6Btn.gd new file mode 100644 index 0000000..a35c7ef --- /dev/null +++ b/scenes/JoypadMonitor6Btn.gd @@ -0,0 +1,42 @@ +extends VBoxContainer + +export var joypad_index = 0 + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + pass # Replace with function body. + +const color_off = Color.blue +const color_on = Color.white + +var id_left = 0 +var id_down = 1 +var id_up = 2 +var id_right = 3 +var id_start = 4 +var id_back = 5 + +func set_name(name): + $Label.text = name + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + var left = Input.get_joy_axis(joypad_index, id_left) + var down = Input.get_joy_axis(joypad_index, id_down) + var up = Input.get_joy_axis(joypad_index, id_up) + var right = Input.get_joy_axis(joypad_index, id_right) + var start = Input.get_joy_axis(joypad_index, id_start) + var back = Input.get_joy_axis(joypad_index, id_back) + $Grid/left/Label.text = "%.03f" % left + $Grid/down/Label.text = "%.03f" % down + $Grid/up/Label.text = "%.03f" % up + $Grid/right/Label.text = "%.03f" % right + $TopRow/lbl_start.text = "start\n%.03f" % start + $TopRow/lbl_back.text = "back\n%.03f" % back + + $Grid/left/t.modulate = color_on if Input.is_joy_button_pressed(joypad_index, id_left) else color_off + $Grid/down/t.modulate = color_on if Input.is_joy_button_pressed(joypad_index, id_down) else color_off + $Grid/up/t.modulate = color_on if Input.is_joy_button_pressed(joypad_index, id_up) else color_off + $Grid/right/t.modulate = color_on if Input.is_joy_button_pressed(joypad_index, id_right) else color_off + $TopRow/lbl_start.uppercase = Input.is_joy_button_pressed(joypad_index, id_start) + $TopRow/lbl_back.uppercase = Input.is_joy_button_pressed(joypad_index, id_back) diff --git a/scenes/JoypadMonitor6Btn.tscn b/scenes/JoypadMonitor6Btn.tscn new file mode 100644 index 0000000..f0c91b8 --- /dev/null +++ b/scenes/JoypadMonitor6Btn.tscn @@ -0,0 +1,157 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://assets/step_arrow_2048_atlas_texture.tres" type="Texture" id=1] +[ext_resource path="res://scenes/JoypadMonitor6Btn.gd" type="Script" id=2] + +[node name="JoypadMonitor" type="VBoxContainer"] +margin_right = 160.0 +margin_bottom = 200.0 +script = ExtResource( 2 ) + +[node name="Label" type="Label" parent="."] +margin_right = 200.0 +margin_bottom = 14.0 +text = "Joypad Name" +align = 1 + +[node name="TopRow" type="Control" parent="."] +margin_top = 18.0 +margin_right = 200.0 +margin_bottom = 34.0 +rect_min_size = Vector2( 160, 16 ) + +[node name="lbl_back" type="Label" parent="TopRow"] +margin_right = 40.0 +margin_bottom = 14.0 +text = "BACK" + +[node name="lbl_start" type="Label" parent="TopRow"] +anchor_right = 1.0 +margin_bottom = 14.0 +text = "START" +align = 2 + +[node name="Grid" type="GridContainer" parent="."] +margin_top = 38.0 +margin_right = 200.0 +margin_bottom = 238.0 +rect_min_size = Vector2( 192, 192 ) +columns = 3 + +[node name="up_left" type="Control" parent="Grid"] +margin_right = 64.0 +margin_bottom = 64.0 +rect_min_size = Vector2( 64, 64 ) + +[node name="up" type="Control" parent="Grid"] +margin_left = 68.0 +margin_right = 132.0 +margin_bottom = 64.0 +rect_min_size = Vector2( 64, 64 ) + +[node name="t" type="TextureRect" parent="Grid/up"] +margin_right = 512.0 +margin_bottom = 512.0 +rect_scale = Vector2( 0.125, 0.125 ) +texture = ExtResource( 1 ) +stretch_mode = 1 + +[node name="Label" type="Label" parent="Grid/up"] +anchor_right = 1.0 +anchor_bottom = 1.0 +text = "0.00" +align = 1 +valign = 1 + +[node name="up_right" type="Control" parent="Grid"] +margin_left = 136.0 +margin_right = 200.0 +margin_bottom = 64.0 +rect_min_size = Vector2( 64, 64 ) + +[node name="left" type="Control" parent="Grid"] +margin_top = 68.0 +margin_right = 64.0 +margin_bottom = 132.0 +rect_min_size = Vector2( 64, 64 ) + +[node name="t" type="TextureRect" parent="Grid/left"] +margin_top = 64.0 +margin_right = 512.0 +margin_bottom = 576.0 +rect_rotation = -90.0 +rect_scale = Vector2( 0.125, 0.125 ) +texture = ExtResource( 1 ) +stretch_mode = 1 + +[node name="Label" type="Label" parent="Grid/left"] +anchor_right = 1.0 +anchor_bottom = 1.0 +text = "0.00" +align = 1 +valign = 1 + +[node name="center" type="Control" parent="Grid"] +margin_left = 68.0 +margin_top = 68.0 +margin_right = 132.0 +margin_bottom = 132.0 +rect_min_size = Vector2( 64, 64 ) + +[node name="right" type="Control" parent="Grid"] +margin_left = 136.0 +margin_top = 68.0 +margin_right = 200.0 +margin_bottom = 132.0 +rect_min_size = Vector2( 64, 64 ) + +[node name="t" type="TextureRect" parent="Grid/right"] +margin_left = 64.0 +margin_right = 576.0 +margin_bottom = 512.0 +rect_rotation = 90.0 +rect_scale = Vector2( 0.125, 0.125 ) +texture = ExtResource( 1 ) +stretch_mode = 1 + +[node name="Label" type="Label" parent="Grid/right"] +anchor_right = 1.0 +anchor_bottom = 1.0 +text = "0.00" +align = 1 +valign = 1 + +[node name="down_left" type="Control" parent="Grid"] +margin_top = 136.0 +margin_right = 64.0 +margin_bottom = 200.0 +rect_min_size = Vector2( 64, 64 ) + +[node name="down" type="Control" parent="Grid"] +margin_left = 68.0 +margin_top = 136.0 +margin_right = 132.0 +margin_bottom = 200.0 +rect_min_size = Vector2( 64, 64 ) + +[node name="t" type="TextureRect" parent="Grid/down"] +margin_right = 512.0 +margin_bottom = 512.0 +rect_scale = Vector2( 0.125, 0.125 ) +texture = ExtResource( 1 ) +stretch_mode = 1 +flip_v = true + +[node name="Label" type="Label" parent="Grid/down"] +anchor_right = 1.0 +anchor_bottom = 1.0 +text = "0.00" +align = 1 +valign = 1 + +[node name="down_right" type="Control" parent="Grid"] +margin_left = 136.0 +margin_top = 136.0 +margin_right = 200.0 +margin_bottom = 200.0 +rect_min_size = Vector2( 64, 64 )