Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes input keycodes #105

Merged
merged 8 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class_name AudioOptionsMenu
extends Control

const SYSTEM_BUS_PREFIX : String = "System"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class_name InputOptionsMenu
extends Control

const ALREADY_ASSIGNED_TEXT : String = "%s already assigned to %s."
Expand All @@ -18,8 +19,10 @@ const KEY_DELETION_TEXT : String = "Are you sure you want to remove %s from %s?"
@export var add_button_texture : Texture2D
@export var remove_button_texture : Texture2D
@export_group("Built-in Actions")
## Shows action names starting with "ui_" that are typically Godot built-in.
## Shows Godot's built-in actions (action names starting with "ui_") in the tree.
@export var show_built_in_actions : bool = false
## Prevents assigning inputs that are already assigned to Godot's built-in actions (action names starting with "ui_"). Not recommended.
@export var catch_built_in_duplicate_inputs : bool = false
## Maps the names of built-in input actions to readable names for users.
@export var built_in_action_name_map : Dictionary = {
"ui_accept" : "Accept",
Expand Down Expand Up @@ -93,18 +96,18 @@ func _add_action_as_tree_item(readable_name : String, action_name : String, inpu
for input_event in input_events:
_add_input_event_as_tree_item(action_name, input_event, action_tree_item)

func _get_all_action_names() -> Array[StringName]:
func _get_all_action_names(include_built_in : bool = false) -> Array[StringName]:
var action_names : Array[StringName] = []
var full_action_name_map = action_name_map.duplicate()
if show_built_in_actions:
if include_built_in:
full_action_name_map.merge(built_in_action_name_map)
for action_name in full_action_name_map:
if action_name is String:
action_name = StringName(action_name)
if action_name is StringName:
action_names.append(action_name)
if show_all_actions:
var all_actions := AppSettings.get_action_names(show_built_in_actions)
var all_actions := AppSettings.get_action_names(include_built_in)
for action_name in all_actions:
if not action_name in action_names:
action_names.append(action_name)
Expand All @@ -122,7 +125,7 @@ func _get_action_readable_name(action_name : StringName) -> String:

func _build_ui_tree():
_start_tree()
var action_names : Array[StringName] = _get_all_action_names()
var action_names : Array[StringName] = _get_all_action_names(show_built_in_actions)
for action_name in action_names:
var input_events = InputMap.action_get_events(action_name)
if input_events.size() < 1:
Expand Down Expand Up @@ -153,7 +156,7 @@ func _remove_input_event_from_action(input_event : InputEvent, action_name : Str

func _build_assigned_input_events():
assigned_input_events.clear()
var action_names := _get_all_action_names()
var action_names := _get_all_action_names(show_built_in_actions and catch_built_in_duplicate_inputs)
for action_name in action_names:
var input_events = InputMap.action_get_events(action_name)
for input_event in input_events:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ grow_vertical = 2
theme_override_constants/margin_top = 24
theme_override_constants/margin_bottom = 24
script = ExtResource("1")
show_all_actions = true
add_button_texture = ExtResource("2_dw35t")
remove_button_texture = ExtResource("3_lngdd")

Expand Down Expand Up @@ -116,5 +115,4 @@ size = Vector2i(398, 100)
[connection signal="focus_entered" from="KeyAssignmentDialog/VBoxContainer/InputTextEdit" to="KeyAssignmentDialog" method="_on_text_edit_focus_entered"]
[connection signal="focus_exited" from="KeyAssignmentDialog/VBoxContainer/InputTextEdit" to="KeyAssignmentDialog" method="_on_input_text_edit_focus_exited"]
[connection signal="gui_input" from="KeyAssignmentDialog/VBoxContainer/InputTextEdit" to="KeyAssignmentDialog" method="_on_input_text_edit_gui_input"]
[connection signal="timeout" from="KeyAssignmentDialog/DelayTimer" to="." method="_on_delay_timer_timeout"]
[connection signal="confirmed" from="KeyDeletionDialog" to="." method="_on_key_deletion_dialog_confirmed"]
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class_name MasterOptionsMenu
extends Control

func _unhandled_input(event):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class_name MiniOptionsMenu
extends Control

@onready var mute_control = %MuteControl
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class_name VideoOptionsMenu
extends Control

func _preselect_resolution(window : Window):
Expand Down
8 changes: 7 additions & 1 deletion addons/maaacks_game_template/base/scripts/InputHelper.gd
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,11 @@ static func get_text(event : InputEvent) -> String:
full_string += " " + direction_string
return full_string
elif event is InputEventKey:
return OS.get_keycode_string(event.get_physical_keycode_with_modifiers())
var keycode : Key = event.get_physical_keycode()
if keycode:
keycode = event.get_physical_keycode_with_modifiers()
else:
keycode = event.get_keycode_with_modifiers()
keycode = DisplayServer.keyboard_get_keycode_from_physical(keycode)
return OS.get_keycode_string(keycode)
return event.as_text()
Original file line number Diff line number Diff line change
@@ -1 +1 @@
extends "res://addons/maaacks_game_template/base/scenes/Menus/OptionsMenu/Audio/AudioOptionsMenu.gd"
extends AudioOptionsMenu
Original file line number Diff line number Diff line change
@@ -1 +1 @@
extends "res://addons/maaacks_game_template/base/scenes/Menus/OptionsMenu/Input/InputOptionsMenu.gd"
extends InputOptionsMenu
Original file line number Diff line number Diff line change
@@ -1 +1 @@
extends "res://addons/maaacks_game_template/base/scenes/Menus/OptionsMenu/MasterOptionsMenu.gd"
extends MasterOptionsMenu
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

[node name="Controls" parent="TabContainer" index="1" instance=ExtResource("2_p458j")]
layout_mode = 2
show_all_actions = true

[node name="Audio" parent="TabContainer" index="2" instance=ExtResource("3_vs2ne")]
visible = false
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
extends "res://addons/maaacks_game_template/base/scenes/Menus/OptionsMenu/MiniOptionsMenu.gd"
extends MiniOptionsMenu
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extends "res://addons/maaacks_game_template/base/scenes/Menus/OptionsMenu/MiniOptionsMenu.gd"
extends MiniOptionsMenu

func _on_reset_game_control_reset_confirmed():
GameLevelLog.reset_game_data()
Original file line number Diff line number Diff line change
@@ -1 +1 @@
extends "res://addons/maaacks_game_template/base/scenes/Menus/OptionsMenu/Video/VideoOptionsMenu.gd"
extends VideoOptionsMenu
2 changes: 1 addition & 1 deletion scenes/Menus/OptionsMenu/Audio/AudioOptionsMenu.gd
Original file line number Diff line number Diff line change
@@ -1 +1 @@
extends "res://addons/maaacks_game_template/base/scenes/Menus/OptionsMenu/Audio/AudioOptionsMenu.gd"
extends AudioOptionsMenu
2 changes: 1 addition & 1 deletion scenes/Menus/OptionsMenu/Input/InputOptionsMenu.gd
Original file line number Diff line number Diff line change
@@ -1 +1 @@
extends "res://addons/maaacks_game_template/base/scenes/Menus/OptionsMenu/Input/InputOptionsMenu.gd"
extends InputOptionsMenu
2 changes: 1 addition & 1 deletion scenes/Menus/OptionsMenu/MasterOptionsMenu.gd
Original file line number Diff line number Diff line change
@@ -1 +1 @@
extends "res://addons/maaacks_game_template/base/scenes/Menus/OptionsMenu/MasterOptionsMenu.gd"
extends MasterOptionsMenu
11 changes: 6 additions & 5 deletions scenes/Menus/OptionsMenu/MasterOptionsMenuWithTabs.tscn
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
[gd_scene load_steps=6 format=3 uid="uid://cagfbg7m2undu"]

[ext_resource type="PackedScene" path="res://scenes/Menus/OptionsMenu/MasterOptionsMenu.tscn" id="1_poeal"]
[ext_resource type="PackedScene" path="res://scenes/Menus/OptionsMenu/Input/InputOptionsMenuWithMouseSensitivity.tscn" id="2_qmmtm"]
[ext_resource type="PackedScene" path="res://scenes/Menus/OptionsMenu/Audio/AudioOptionsMenu.tscn" id="3_g1i0l"]
[ext_resource type="PackedScene" path="res://scenes/Menus/OptionsMenu/Video/VideoOptionsMenuWithExtras.tscn" id="4_8mj1w"]
[ext_resource type="PackedScene" path="res://scenes/Menus/OptionsMenu/Game/GameOptionsMenu.tscn" id="5_277lf"]
[ext_resource type="PackedScene" uid="uid://d4gb821uhcxfi" path="res://scenes/Menus/OptionsMenu/MasterOptionsMenu.tscn" id="1_poeal"]
[ext_resource type="PackedScene" uid="uid://ckiogikpg1i3" path="res://scenes/Menus/OptionsMenu/Input/InputOptionsMenuWithMouseSensitivity.tscn" id="2_qmmtm"]
[ext_resource type="PackedScene" uid="uid://c8cehdleoso6q" path="res://scenes/Menus/OptionsMenu/Audio/AudioOptionsMenu.tscn" id="3_g1i0l"]
[ext_resource type="PackedScene" uid="uid://qn4a7owdi3mt" path="res://scenes/Menus/OptionsMenu/Video/VideoOptionsMenuWithExtras.tscn" id="4_8mj1w"]
[ext_resource type="PackedScene" uid="uid://hcqhf6rxq1e5" path="res://scenes/Menus/OptionsMenu/Game/GameOptionsMenu.tscn" id="5_277lf"]

[node name="MasterOptionsMenu" instance=ExtResource("1_poeal")]

[node name="Controls" parent="TabContainer" index="1" instance=ExtResource("2_qmmtm")]
layout_mode = 2
show_all_actions = true

[node name="Audio" parent="TabContainer" index="2" instance=ExtResource("3_g1i0l")]
visible = false
Expand Down
2 changes: 1 addition & 1 deletion scenes/Menus/OptionsMenu/MiniOptionsMenu.gd
Original file line number Diff line number Diff line change
@@ -1 +1 @@
extends "res://addons/maaacks_game_template/base/scenes/Menus/OptionsMenu/MiniOptionsMenu.gd"
extends MiniOptionsMenu
2 changes: 1 addition & 1 deletion scenes/Menus/OptionsMenu/MiniOptionsMenuWithReset.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extends "res://addons/maaacks_game_template/base/scenes/Menus/OptionsMenu/MiniOptionsMenu.gd"
extends MiniOptionsMenu

func _on_reset_game_control_reset_confirmed():
GameLevelLog.reset_game_data()
2 changes: 1 addition & 1 deletion scenes/Menus/OptionsMenu/Video/VideoOptionsMenu.gd
Original file line number Diff line number Diff line change
@@ -1 +1 @@
extends "res://addons/maaacks_game_template/base/scenes/Menus/OptionsMenu/Video/VideoOptionsMenu.gd"
extends VideoOptionsMenu