From 9135caabbec4792c04a0389cff32e6188bfd230c Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Sun, 29 May 2022 12:51:56 +0300 Subject: [PATCH] Update Keychain --- addons/README.md | 4 +- addons/keychain/ShortcutProfile.gd | 7 ++++ addons/keychain/ShortcutSelectorDialog.gd | 45 ++++++++++++++--------- 3 files changed, 36 insertions(+), 20 deletions(-) diff --git a/addons/README.md b/addons/README.md index 6d72730b1..f552897c5 100644 --- a/addons/README.md +++ b/addons/README.md @@ -3,13 +3,13 @@ ## Keychain - Upstream: https://github.com/Orama-Interactive/Keychain -- Version: Based on git commit 29e80383e46acb5478696d40990bc3624a6920c4 with slight modifications in Keychain.gd and ShortcutEdit.tscn. +- Version: Based on git commit 22539c2b9b9e781c0cd54f32d92c77b6f36837e0 with slight modifications in Keychain.gd and ShortcutEdit.tscn. - License: [MIT](https://github.com/Orama-Interactive/Keychain/blob/main/LICENSE) ## gdgifexporter - Upstream: https://github.com/jegor377/godot-gdgifexporter -- Version: git (b6a6628dc253acb5c2955bc9ca5c8eaa2eaf2e1a, 2021) +- Version: custom - License: [MIT](https://github.com/jegor377/godot-gdgifexporter/blob/master/LICENSE) Files extracted from source: diff --git a/addons/keychain/ShortcutProfile.gd b/addons/keychain/ShortcutProfile.gd index af9d583c2..a3bf00802 100644 --- a/addons/keychain/ShortcutProfile.gd +++ b/addons/keychain/ShortcutProfile.gd @@ -11,9 +11,14 @@ func _init() -> void: func fill_bindings() -> void: + var unnecessary_actions = bindings.duplicate() # Checks if the profile has any unused actions for action in InputMap.get_actions(): if not action in bindings: bindings[action] = InputMap.get_action_list(action) + unnecessary_actions.erase(action) + for action in unnecessary_actions: + bindings.erase(action) + save() func change_action(action: String) -> void: @@ -24,6 +29,8 @@ func change_action(action: String) -> void: func save() -> bool: + if !customizable: + return false var err := ResourceSaver.save(resource_path, self) if err != OK: print("Error saving shortcut profile %s. Error code: %s" % [resource_path, err]) diff --git a/addons/keychain/ShortcutSelectorDialog.gd b/addons/keychain/ShortcutSelectorDialog.gd index 3e4e2d0cc..be1bbb069 100644 --- a/addons/keychain/ShortcutSelectorDialog.gd +++ b/addons/keychain/ShortcutSelectorDialog.gd @@ -97,14 +97,9 @@ func _set_shortcut(action: String, old_event: InputEvent, new_event: InputEvent) if metadata is InputEvent: if input_to_replace.shortcut_match(metadata): var map_action: String = tree_item.get_parent().get_metadata(0) - if map_action in Keychain.actions: - # If it's local, check if it's the same group, otherwise ignore - if !Keychain.actions[map_action].global: - if Keychain.actions[map_action].group != group: - tree_item = _get_next_tree_item(tree_item) - continue - tree_item.free() - break + if map_action == action_to_replace: + tree_item.free() + break tree_item = _get_next_tree_item(tree_item) @@ -138,14 +133,16 @@ func _find_matching_event_in_map(action: String, event: InputEvent) -> Array: if Keychain.ignore_ui_actions and map_action.begins_with("ui_"): continue for map_event in InputMap.get_action_list(map_action): - if event.shortcut_match(map_event): - if map_action in Keychain.actions: - # If it's local, check if it's the same group, otherwise ignore - if !Keychain.actions[map_action].global: - if Keychain.actions[map_action].group != group: - continue + if !event.shortcut_match(map_event): + continue - return [map_action, map_event] + if map_action in Keychain.actions: + # If it's local, check if it's the same group, otherwise ignore + if !Keychain.actions[action].global or !Keychain.actions[map_action].global: + if Keychain.actions[map_action].group != group: + continue + + return [map_action, map_event] return [] @@ -158,10 +155,22 @@ func _on_ShortcutSelectorDialog_about_to_show() -> void: yield(get_tree(), "idle_frame") entered_shortcut.grab_focus() else: - if !listened_input: + var metadata = root.currently_editing_tree_item.get_metadata(0) + if metadata is InputEvent: # Editing an input event + var index := 0 + if metadata is InputEventMouseButton: + index = metadata.button_index - 1 + elif metadata is InputEventJoypadButton: + index = metadata.button_index + elif metadata is InputEventJoypadMotion: + index = metadata.axis * 2 + index += round(metadata.axis_value) / 2.0 + 0.5 + option_button.select(index) + _on_OptionButton_item_selected(index) + + elif metadata is String: # Adding a new input event to an action + option_button.select(0) _on_OptionButton_item_selected(0) - else: - _show_assigned_state(listened_input) func _on_ShortcutSelectorDialog_popup_hide() -> void: