From db54202198db1876a79f263e9e23d8778d278e1b Mon Sep 17 00:00:00 2001 From: Harmony Honey Date: Sat, 20 Jan 2024 23:08:12 -0500 Subject: [PATCH] KeyMenu Wip! (; --- project.godot | 6 ++ src/menu/options/Key.gd | 9 ++- src/menu/options/KeyMenu.gd | 65 ++++++++++++++++ src/menu/options/KeyMenu.tscn | 118 ++++++++++++++---------------- src/menu/options/OpenKeyMenu.gd | 6 ++ src/menu/options/OptionsMenu.tscn | 44 ++++++++--- 6 files changed, 171 insertions(+), 77 deletions(-) create mode 100644 src/menu/options/KeyMenu.gd create mode 100644 src/menu/options/OpenKeyMenu.gd diff --git a/project.godot b/project.godot index 7672a70..e1681a7 100644 --- a/project.godot +++ b/project.godot @@ -44,6 +44,11 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://src/actor/Exit.gd" }, { +"base": "Control", +"class": "Key", +"language": "GDScript", +"path": "res://src/menu/options/Key.gd" +}, { "base": "Actor", "class": "Passthrough", "language": "GDScript", @@ -72,6 +77,7 @@ _global_script_class_icons={ "EaseMover": "", "EditorTheme": "", "Exit": "", +"Key": "", "Passthrough": "", "Player": "", "Switch": "", diff --git a/src/menu/options/Key.gd b/src/menu/options/Key.gd index 8113907..4fa58dc 100644 --- a/src/menu/options/Key.gd +++ b/src/menu/options/Key.gd @@ -1,5 +1,6 @@ tool extends Control +class_name Key export var action := "" setget set_action export var text := "key" setget set_text @@ -88,16 +89,16 @@ func set_action(arg := action): var e = null for i in l: - if is_type(i): + if is_type(i, is_gamepad): e = i if e: parse_event(e) -func is_type(event): - var test = !is_gamepad and event is InputEventKey +static func is_type(event, _is_gamepad := is_gamepad): + var test = !_is_gamepad and event is InputEventKey if !test: - test = is_gamepad and (event is InputEventJoypadButton or event is InputEventJoypadMotion) + test = _is_gamepad and (event is InputEventJoypadButton or event is InputEventJoypadMotion) return test diff --git a/src/menu/options/KeyMenu.gd b/src/menu/options/KeyMenu.gd new file mode 100644 index 0000000..890b0f7 --- /dev/null +++ b/src/menu/options/KeyMenu.gd @@ -0,0 +1,65 @@ +extends CanvasLayer + +var is_open = false +onready var default_keys := {} + +export var is_gamepad := false + +onready var control := $Control + +onready var list_node := $Control/VBox +onready var row_node := $Control/VBox/Row + +export var keys_action := { +"up" : "up", +"down" : "down", +"left" : "left", +"right": "right", +"jump" : "jump", +"action" : "lift", +"pause": "menu", +} + +func _ready(): + open(false) + + # get default key binds + for i in InputMap.get_actions(): + default_keys[i] = InputMap.get_action_list(i) + + # setup list + for i in keys_action.keys(): + if InputMap.has_action(i): + var r = row_node.duplicate() + r.get_node("Label").text = keys_action[i] + list_node.add_child(r) + + var a = InputMap.get_action_list(i) + var k := [] + + for y in a: + if Key.is_type(y, is_gamepad): + k.append(y.as_text()) + + var keys = r.get_node("Keys").get_children() + for x in keys.size(): + var less = x < k.size() + keys[x].visible = less + if less: + keys[x].text = k[x] + + + row_node.queue_free() + +func _input(event): + if !is_open or Wipe.is_wipe: return + + if event.is_action_pressed("action"): + open(false) + OptionsMenu.open(true) + +func open(arg := false): + is_open = arg + control.visible = is_open + + diff --git a/src/menu/options/KeyMenu.tscn b/src/menu/options/KeyMenu.tscn index 6f551ea..ad3369c 100644 --- a/src/menu/options/KeyMenu.tscn +++ b/src/menu/options/KeyMenu.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=5 format=2] [ext_resource path="res://media/font/QuinqueFive.ttf" type="DynamicFontData" id=1] [ext_resource path="res://src/menu/options/Key.tscn" type="PackedScene" id=2] +[ext_resource path="res://src/menu/options/KeyMenu.gd" type="Script" id=3] [sub_resource type="DynamicFont" id=1] size = 5 @@ -11,20 +12,50 @@ extra_spacing_bottom = -1 font_data = ExtResource( 1 ) [node name="KeyMenu" type="CanvasLayer"] +script = ExtResource( 3 ) [node name="Control" type="Control" parent="."] margin_right = 228.0 margin_bottom = 128.0 +[node name="Back" type="ColorRect" parent="Control"] +modulate = Color( 0, 0, 0, 0.5 ) +anchor_right = 1.0 +anchor_bottom = 1.0 + [node name="VBox" type="VBoxContainer" parent="Control"] -margin_left = 52.0 -margin_top = 31.0 -margin_right = 200.0 -margin_bottom = 101.0 +margin_left = 51.0 +margin_top = 32.0 +margin_right = 178.0 +margin_bottom = 102.0 + +[node name="Guide" type="HBoxContainer" parent="Control/VBox"] +margin_right = 127.0 +margin_bottom = 5.0 + +[node name="Label" type="Label" parent="Control/VBox/Guide"] +margin_right = 36.0 +margin_bottom = 5.0 +custom_fonts/font = SubResource( 1 ) +text = "action" + +[node name="Spacer" type="Control" parent="Control/VBox/Guide"] +margin_left = 40.0 +margin_right = 99.0 +margin_bottom = 5.0 +size_flags_horizontal = 3 + +[node name="Label2" type="Label" parent="Control/VBox/Guide"] +margin_left = 103.0 +margin_right = 127.0 +margin_bottom = 5.0 +custom_fonts/font = SubResource( 1 ) +text = "keys" [node name="Row" type="HBoxContainer" parent="Control/VBox"] -margin_right = 148.0 -margin_bottom = 7.0 +margin_top = 9.0 +margin_right = 127.0 +margin_bottom = 16.0 [node name="Label" type="Label" parent="Control/VBox/Row"] margin_top = 1.0 @@ -35,76 +66,35 @@ text = "jump" [node name="Spacer" type="Control" parent="Control/VBox/Row"] margin_left = 28.0 -margin_right = 68.0 +margin_right = 47.0 margin_bottom = 7.0 size_flags_horizontal = 3 -[node name="Key" parent="Control/VBox/Row" instance=ExtResource( 2 )] -margin_left = 72.0 -margin_right = 79.0 +[node name="Keys" type="HBoxContainer" parent="Control/VBox/Row"] +margin_left = 51.0 +margin_right = 127.0 +margin_bottom = 7.0 + +[node name="Key" parent="Control/VBox/Row/Keys" instance=ExtResource( 2 )] action = "" text = "k" -[node name="Key2" parent="Control/VBox/Row" instance=ExtResource( 2 )] -margin_left = 83.0 -margin_right = 114.0 +[node name="Key2" parent="Control/VBox/Row/Keys" instance=ExtResource( 2 )] +margin_left = 11.0 +margin_right = 42.0 rect_min_size = Vector2( 31, 7 ) action = "" text = "space" -[node name="Key3" parent="Control/VBox/Row" instance=ExtResource( 2 )] -margin_left = 118.0 -margin_right = 125.0 +[node name="Key3" parent="Control/VBox/Row/Keys" instance=ExtResource( 2 )] +margin_left = 46.0 +margin_right = 53.0 action = "" text = "x" -[node name="Key4" parent="Control/VBox/Row" instance=ExtResource( 2 )] -margin_left = 129.0 -margin_right = 148.0 +[node name="Key4" parent="Control/VBox/Row/Keys" instance=ExtResource( 2 )] +margin_left = 57.0 +margin_right = 76.0 rect_min_size = Vector2( 19, 7 ) action = "" text = "del" - -[node name="Row2" type="HBoxContainer" parent="Control/VBox"] -margin_top = 11.0 -margin_right = 148.0 -margin_bottom = 18.0 - -[node name="Label" type="Label" parent="Control/VBox/Row2"] -margin_top = 1.0 -margin_right = 24.0 -margin_bottom = 6.0 -custom_fonts/font = SubResource( 1 ) -text = "lift" - -[node name="Spacer" type="Control" parent="Control/VBox/Row2"] -margin_left = 28.0 -margin_right = 68.0 -margin_bottom = 7.0 -size_flags_horizontal = 3 - -[node name="Key" parent="Control/VBox/Row2" instance=ExtResource( 2 )] -margin_left = 72.0 -margin_right = 79.0 -action = "" -text = "j" - -[node name="Key2" parent="Control/VBox/Row2" instance=ExtResource( 2 )] -margin_left = 83.0 -margin_right = 108.0 -rect_min_size = Vector2( 25, 7 ) -action = "" -text = "ctrl" - -[node name="Key3" parent="Control/VBox/Row2" instance=ExtResource( 2 )] -margin_left = 112.0 -margin_right = 119.0 -action = "" -text = "c" - -[node name="Key4" parent="Control/VBox/Row2" instance=ExtResource( 2 )] -margin_left = 123.0 -margin_right = 148.0 -rect_min_size = Vector2( 25, 7 ) -action = "" -text = "pgup" diff --git a/src/menu/options/OpenKeyMenu.gd b/src/menu/options/OpenKeyMenu.gd new file mode 100644 index 0000000..0bea7b8 --- /dev/null +++ b/src/menu/options/OpenKeyMenu.gd @@ -0,0 +1,6 @@ +extends CanvasItem + +func act(): + OptionsMenu.is_open = false + KeyMenu.open(true) + Audio.play("menu_pause", 0.9, 1.1) diff --git a/src/menu/options/OptionsMenu.tscn b/src/menu/options/OptionsMenu.tscn index 7395021..e360cae 100644 --- a/src/menu/options/OptionsMenu.tscn +++ b/src/menu/options/OptionsMenu.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=11 format=2] +[gd_scene load_steps=12 format=2] [ext_resource path="res://src/menu/options/OptionsMenu.gd" type="Script" id=1] [ext_resource path="res://src/menu/options/Volume.tscn" type="PackedScene" id=2] +[ext_resource path="res://src/menu/options/OpenKeyMenu.gd" type="Script" id=3] [ext_resource path="res://src/menu/Blink.gd" type="Script" id=4] [ext_resource path="res://media/audio/sfx/btn0.wav" type="AudioStream" id=5] [ext_resource path="res://media/font/m6x11.ttf" type="DynamicFontData" id=8] @@ -53,13 +54,38 @@ margin_top = 40.0 margin_right = 188.0 margin_bottom = 100.0 -[node name="Sounds" parent="Center/Control/MenuItems" instance=ExtResource( 2 )] +[node name="Keyboard" type="HBoxContainer" parent="Center/Control/MenuItems"] margin_right = 116.0 +margin_bottom = 8.0 +script = ExtResource( 3 ) -[node name="Music" parent="Center/Control/MenuItems" instance=ExtResource( 2 )] +[node name="Label" type="Label" parent="Center/Control/MenuItems/Keyboard"] +margin_right = 57.0 +margin_bottom = 8.0 +custom_fonts/font = ExtResource( 9 ) +text = "Keyboard Setup" + +[node name="Spacer" type="Control" parent="Center/Control/MenuItems/Keyboard"] +margin_left = 61.0 +margin_right = 104.0 +margin_bottom = 8.0 +size_flags_horizontal = 3 + +[node name="Spacer2" type="Control" parent="Center/Control/MenuItems/Keyboard"] +margin_left = 108.0 +margin_right = 116.0 +margin_bottom = 8.0 +rect_min_size = Vector2( 8, 0 ) + +[node name="Sounds" parent="Center/Control/MenuItems" instance=ExtResource( 2 )] margin_top = 12.0 margin_right = 116.0 margin_bottom = 20.0 + +[node name="Music" parent="Center/Control/MenuItems" instance=ExtResource( 2 )] +margin_top = 24.0 +margin_right = 116.0 +margin_bottom = 32.0 bus = 2 [node name="Label" parent="Center/Control/MenuItems/Music" index="0"] @@ -87,9 +113,9 @@ stream = ExtResource( 5 ) bus = "Music" [node name="Fullscreen" type="HBoxContainer" parent="Center/Control/MenuItems"] -margin_top = 24.0 +margin_top = 36.0 margin_right = 116.0 -margin_bottom = 32.0 +margin_bottom = 44.0 script = ExtResource( 20 ) [node name="Label" type="Label" parent="Center/Control/MenuItems/Fullscreen"] @@ -136,9 +162,9 @@ margin_bottom = 8.0 rect_min_size = Vector2( 8, 0 ) [node name="WindowSize" type="HBoxContainer" parent="Center/Control/MenuItems"] -margin_top = 36.0 +margin_top = 48.0 margin_right = 116.0 -margin_bottom = 44.0 +margin_bottom = 56.0 script = ExtResource( 21 ) [node name="Label" type="Label" parent="Center/Control/MenuItems/WindowSize"] @@ -168,9 +194,9 @@ text = "228 x 128" align = 1 [node name="TouchControls" type="HBoxContainer" parent="Center/Control/MenuItems"] -margin_top = 48.0 +margin_top = 60.0 margin_right = 116.0 -margin_bottom = 56.0 +margin_bottom = 68.0 script = ExtResource( 22 ) [node name="Label" type="Label" parent="Center/Control/MenuItems/TouchControls"]