From 9d19dc41eed9162cbb37e477b0c10ce353d1fd37 Mon Sep 17 00:00:00 2001 From: Melon Bread Date: Mon, 25 Apr 2022 18:32:33 -0400 Subject: [PATCH] Added initial gamepad menu support --- README.md | 4 +- project.godot | 73 ++++++++++++++++++++++++++++++++++ src/Screens/MainMenu.gd | 6 +++ src/Screens/MainMenu.tscn | 8 +++- src/Screens/ResultsScreen.tscn | 6 +++ src/UI/GameHUD.gd | 3 ++ src/UI/GameHUD.tscn | 4 ++ 7 files changed, 101 insertions(+), 3 deletions(-) create mode 100644 src/Screens/MainMenu.gd diff --git a/README.md b/README.md index f6c89fc..dacda73 100644 --- a/README.md +++ b/README.md @@ -15,5 +15,5 @@ Pong made poorly in godot. Just trying to make a some what complete projoct and - CPU logic for single player (or CPU only) 🤖 - A settings menu that persists between launches 📓 - Some form of network multiplayer 💻 - - Select menu options via gamepad 🎮 - - More sprite effects or fx in general 🔥 \ No newline at end of file + - ~Select menu options via gamepad 🎮~ + - More sprite effects or fx in general 🔥 diff --git a/project.godot b/project.godot index e3c6bf4..c21a9ad 100644 --- a/project.godot +++ b/project.godot @@ -45,6 +45,79 @@ window=false [input] +ui_accept={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777221,"physical_scancode":0,"unicode":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777222,"physical_scancode":0,"unicode":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":32,"physical_scancode":0,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":false,"script":null) + ] +} +ui_select={ +"deadzone": 0.5, +"events": [ ] +} +ui_cancel={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777217,"physical_scancode":0,"unicode":0,"echo":false,"script":null) + ] +} +ui_focus_next={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777218,"physical_scancode":0,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":5,"pressure":0.0,"pressed":false,"script":null) + ] +} +ui_focus_prev={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":true,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777218,"physical_scancode":0,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":4,"pressure":0.0,"pressed":false,"script":null) + ] +} +ui_left={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777231,"physical_scancode":0,"unicode":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"physical_scancode":0,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":14,"pressure":0.0,"pressed":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":-1.0,"script":null) + ] +} +ui_right={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"physical_scancode":0,"unicode":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"physical_scancode":0,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":15,"pressure":0.0,"pressed":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":1.0,"script":null) + ] +} +ui_up={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777232,"physical_scancode":0,"unicode":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"physical_scancode":0,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":12,"pressure":0.0,"pressed":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":-1.0,"script":null) + ] +} +ui_down={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777234,"physical_scancode":0,"unicode":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"physical_scancode":0,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":13,"pressure":0.0,"pressed":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":1.0,"script":null) + ] +} +ui_page_up={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777235,"physical_scancode":0,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":6,"pressure":0.0,"pressed":false,"script":null) + ] +} +ui_page_down={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777236,"physical_scancode":0,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":7,"pressure":0.0,"pressed":false,"script":null) + ] +} P1_Up={ "deadzone": 0.5, "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"physical_scancode":0,"unicode":0,"echo":false,"script":null) diff --git a/src/Screens/MainMenu.gd b/src/Screens/MainMenu.gd new file mode 100644 index 0000000..2b1523f --- /dev/null +++ b/src/Screens/MainMenu.gd @@ -0,0 +1,6 @@ +extends Control + +onready var play_button: Button = $MenuButtons/PlayButton + +func _ready() -> void: + play_button.grab_focus() diff --git a/src/Screens/MainMenu.tscn b/src/Screens/MainMenu.tscn index a639d90..8345826 100644 --- a/src/Screens/MainMenu.tscn +++ b/src/Screens/MainMenu.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=9 format=2] +[gd_scene load_steps=10 format=2] [ext_resource path="res://assets-raw/BBB_Simulator_Black.otf" type="DynamicFontData" id=1] [ext_resource path="res://assets/Background.png" type="Texture" id=2] @@ -6,6 +6,7 @@ [ext_resource path="res://src/UI/QuitButton.tscn" type="PackedScene" id=4] [ext_resource path="res://src/UI/ChangeScene.tscn" type="PackedScene" id=5] [ext_resource path="res://src/UI/Title.tscn" type="PackedScene" id=6] +[ext_resource path="res://src/Screens/MainMenu.gd" type="Script" id=7] [sub_resource type="DynamicFont" id=1] font_data = ExtResource( 1 ) @@ -17,6 +18,7 @@ default_font = SubResource( 1 ) anchor_right = 1.0 anchor_bottom = 1.0 theme = ExtResource( 3 ) +script = ExtResource( 7 ) [node name="Background" type="TextureRect" parent="."] modulate = Color( 0, 0, 0, 1 ) @@ -51,6 +53,8 @@ alignment = 1 [node name="PlayButton" parent="MenuButtons" instance=ExtResource( 5 )] margin_right = 171.0 margin_bottom = 47.0 +focus_next = NodePath("../QuitButton") +focus_previous = NodePath("../QuitButton") size_flags_vertical = 3 text = "Play" next_scene_path = "res://src/Screens/Game.tscn" @@ -59,4 +63,6 @@ next_scene_path = "res://src/Screens/Game.tscn" margin_top = 51.0 margin_right = 171.0 margin_bottom = 99.0 +focus_next = NodePath("../PlayButton") +focus_previous = NodePath("../PlayButton") size_flags_vertical = 3 diff --git a/src/Screens/ResultsScreen.tscn b/src/Screens/ResultsScreen.tscn index 2096fb2..74a6af2 100644 --- a/src/Screens/ResultsScreen.tscn +++ b/src/Screens/ResultsScreen.tscn @@ -52,6 +52,8 @@ alignment = 1 [node name="Restart" parent="MenuButtons" instance=ExtResource( 5 )] margin_right = 171.0 margin_bottom = 40.0 +focus_next = NodePath("../MainMenuButton") +focus_previous = NodePath("../QuitButton") text = "Restart" next_scene_path = "res://src/Screens/Game.tscn" @@ -59,6 +61,8 @@ next_scene_path = "res://src/Screens/Game.tscn" margin_top = 44.0 margin_right = 171.0 margin_bottom = 84.0 +focus_next = NodePath("../QuitButton") +focus_previous = NodePath("../Restart") text = "Main Menu" next_scene_path = "res://src/Screens/MainMenu.tscn" @@ -66,3 +70,5 @@ next_scene_path = "res://src/Screens/MainMenu.tscn" margin_top = 88.0 margin_right = 171.0 margin_bottom = 128.0 +focus_next = NodePath("../Restart") +focus_previous = NodePath("../MainMenuButton") diff --git a/src/UI/GameHUD.gd b/src/UI/GameHUD.gd index a28fb69..6ca29e5 100644 --- a/src/UI/GameHUD.gd +++ b/src/UI/GameHUD.gd @@ -4,6 +4,7 @@ onready var scene_tree = get_tree() onready var p1_score: Label = $P1Score onready var p2_score: Label = $P2Score onready var pause_overlay: ColorRect = $PauseOverlay +onready var main_menu_button: Button = $PauseOverlay/MenuButtons/MainMenuButton var paused: = false setget set_paused @@ -28,3 +29,5 @@ func set_paused(value: bool) -> void: paused = value scene_tree.paused = value pause_overlay.visible = value + if value: + main_menu_button.grab_focus() diff --git a/src/UI/GameHUD.tscn b/src/UI/GameHUD.tscn index 6120fef..56d0926 100644 --- a/src/UI/GameHUD.tscn +++ b/src/UI/GameHUD.tscn @@ -66,6 +66,8 @@ alignment = 1 margin_top = 7.0 margin_right = 171.0 margin_bottom = 47.0 +focus_next = NodePath("../QuitButton") +focus_previous = NodePath("../QuitButton") text = "Main Menu" next_scene_path = "res://src/Screens/MainMenu.tscn" @@ -73,3 +75,5 @@ next_scene_path = "res://src/Screens/MainMenu.tscn" margin_top = 51.0 margin_right = 171.0 margin_bottom = 91.0 +focus_next = NodePath("../MainMenuButton") +focus_previous = NodePath("../MainMenuButton")