Skip to content

Commit

Permalink
Merge pull request #339 from Spartan322/fix/default-hotkey
Browse files Browse the repository at this point in the history
Fix default hotkeys being erroneously set
  • Loading branch information
Spartan322 authored Dec 29, 2024
2 parents 0a4e426 + 1a74b9c commit 7cbcc0e
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 28 deletions.
2 changes: 0 additions & 2 deletions game/src/Game/GameSession/GameSession.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ func _ready() -> void:
MusicConductor.generate_playlist()
MusicConductor.select_next_song()

Keychain.initialize_profiles()

func _process(_delta : float) -> void:
GameSingleton.update_clock()

Expand Down
27 changes: 27 additions & 0 deletions game/src/Game/Menu/OptionMenu/KeychainShortcutEdit.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
extends "res://addons/keychain/ShortcutEdit.gd"

func _ready() -> void:
# Setup Keychain for Hotkeys
for action : StringName in InputMap.get_actions():
if not Keychain.keep_binding_check.call(action):
continue
Keychain.actions[action] = Keychain.InputAction.new(
action.erase(0, "button_".length()).left(-"_hotkey".length()).capitalize(),
"Hotkeys")
var display_name : String = Keychain.actions[action].display_name
if display_name.begins_with("Mapmode"):
var mapmode_index := display_name.replace("Mapmode", "").to_int()
display_name = tr(GameSingleton.get_mapmode_localisation_key(mapmode_index))
if mapmode_index <= 10:
display_name = display_name\
.replace(" Mapmode", "")\
.replace("Mode de carte ", "")\
.replace("-Kartenmodus", "")\
.replace("Modo de mapa de ", "")\
.replace("Modo mapa de ", "")\
.replace("Modo mapa ", "")
display_name = tr("Mapmode %s") % display_name.capitalize()
Keychain.actions[action].display_name = display_name
Keychain.profiles[0].bindings[action] = InputMap.action_get_events(action)

super._ready()
7 changes: 7 additions & 0 deletions game/src/Game/Menu/OptionMenu/KeychainShortcutEdit.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[gd_scene load_steps=3 format=3 uid="uid://cka0tjqrek13"]

[ext_resource type="PackedScene" uid="uid://bq7ibhm0txl5p" path="res://addons/keychain/ShortcutEdit.tscn" id="1_47eix"]
[ext_resource type="Script" path="res://src/Game/Menu/OptionMenu/KeychainShortcutEdit.gd" id="2_gr2m0"]

[node name="ShortcutEdit" instance=ExtResource("1_47eix")]
script = ExtResource("2_gr2m0")
23 changes: 0 additions & 23 deletions game/src/Game/Menu/OptionMenu/OptionsMenu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,6 @@ func _ready() -> void:
_tab_container.set_tab_title(3, "OPTIONS_CONTROLS")
_tab_container.set_tab_title(4, "OPTIONS_OTHER")

# Setup Keychain for Hotkeys
for action : StringName in InputMap.get_actions():
if not Keychain.keep_binding_check.call(action):
continue
Keychain.actions[action] = Keychain.InputAction.new(
action.erase(0, "button_".length()).left(-"_hotkey".length()).capitalize(),
"Hotkeys")
var display_name : String = Keychain.actions[action].display_name
if display_name.begins_with("Mapmode"):
var mapmode_index := display_name.replace("Mapmode", "").to_int()
display_name = tr(GameSingleton.get_mapmode_localisation_key(mapmode_index))
if mapmode_index <= 10:
display_name = display_name\
.replace(" Mapmode", "")\
.replace("Mode de carte ", "")\
.replace("-Kartenmodus", "")\
.replace("Modo de mapa de ", "")\
.replace("Modo mapa de ", "")\
.replace("Modo mapa ", "")
display_name = tr("Mapmode %s") % display_name.capitalize()
Keychain.actions[action].display_name = display_name
Keychain.profiles[0].bindings[action] = InputMap.action_get_events(action)

# Prepare options menu before loading user settings
var tab_bar : TabBar = _tab_container.get_child(0, true)

Expand Down
11 changes: 8 additions & 3 deletions game/src/Game/Menu/OptionMenu/OptionsMenu.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
[ext_resource type="PackedScene" uid="uid://bq3awxxjn1tuw" path="res://src/Game/Menu/OptionMenu/VideoTab.tscn" id="2_ji8xr"]
[ext_resource type="PackedScene" uid="uid://cbtgwpx2wxi33" path="res://src/Game/Menu/OptionMenu/SoundTab.tscn" id="3_4w35t"]
[ext_resource type="PackedScene" uid="uid://duwjal7sd7p6w" path="res://src/Game/Menu/OptionMenu/GeneralTab.tscn" id="3_6gvf6"]
[ext_resource type="PackedScene" uid="uid://bq7ibhm0txl5p" path="res://addons/keychain/ShortcutEdit.tscn" id="4_vdhjp"]
[ext_resource type="PackedScene" uid="uid://dp2grvybtecqu" path="res://src/Game/Menu/OptionMenu/OtherTab.tscn" id="5_ahefp"]
[ext_resource type="PackedScene" uid="uid://cka0tjqrek13" path="res://src/Game/Menu/OptionMenu/KeychainShortcutEdit.tscn" id="6_f7qfn"]

[node name="OptionsMenu" type="PanelContainer" node_paths=PackedStringArray("_tab_container")]
editor_description = "UI-25"
Expand All @@ -28,26 +28,31 @@ theme_type_variation = &"TabMargin"
editor_description = "UI-45"
layout_mode = 2
tab_alignment = 1
current_tab = 0
use_hidden_tabs_for_min_size = true

[node name="General" parent="Margin/Tab" instance=ExtResource("3_6gvf6")]
layout_mode = 2
metadata/_tab_index = 0

[node name="Video" parent="Margin/Tab" instance=ExtResource("2_ji8xr")]
editor_description = "UI-46, UIFUN-43"
visible = false
layout_mode = 2
metadata/_tab_index = 1

[node name="Sound" parent="Margin/Tab" instance=ExtResource("3_4w35t")]
editor_description = "UI-47, UIFUN-44"
visible = false
layout_mode = 2
metadata/_tab_index = 2

[node name="Controls" parent="Margin/Tab" instance=ExtResource("4_vdhjp")]
[node name="Controls" parent="Margin/Tab" instance=ExtResource("6_f7qfn")]
editor_description = "SS-27, UI-49, UIFUN-46"
visible = false
layout_mode = 2
alignment = 1
metadata/_tab_index = 3

[node name="Other" parent="Margin/Tab" instance=ExtResource("5_ahefp")]
layout_mode = 2
metadata/_tab_index = 4

0 comments on commit 7cbcc0e

Please sign in to comment.