forked from mbrlabs/Lorien
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* First work on keybindings settings - Add keybindings tab to settings dialog - Add basic list of actions and english translations for keybinding - Add non-functional UI elements as mock up * Add basic template parser * Start integrating the new StringTEmplating engine * Parser cleanup * Fixed warnings * Implement filters * Add test for template detection * Add keybindings string generation * Fix typos * Add docstrings, fix naming * Add templating to all translations * Fix templates againg after merge-conflict * Revert accidental commit of Main.tscn * PR change requests * Sort out GUI-event passing - Rewrote most event handling to use event-callbacks - This allows events to be intercepted in the _input method - I tried to rewrite everything so that input events are passed in _unhandled_input functions, bit was not able to do so for the ViewportContainer. Had to fallback on _gui_input instead which is good enough for my purpose. _unhandled_input really would be more desirable but requires a larger restructuring and putting all tools IN the viewport (I think). - There is one last use of _input but it does not handle events as the other old _event functions did: ColorPalettePicker still uses _input to decide when to close. It does not interfer with anything else though, so this should be okay. * Sort out GUI-event passing - Rewrote most event handling to use event-callbacks - This allows events to be intercepted in the _input method - I tried to rewrite everything so that input events are passed in _unhandled_input functions, bit was not able to do so for the ViewportContainer. Had to fallback on _gui_input instead which is good enough for my purpose. _unhandled_input really would be more desirable but requires a larger restructuring and putting all tools IN the viewport (I think). - There is one last use of _input but it does not handle events as the other old _event functions did: ColorPalettePicker still uses _input to decide when to close. It does not interfer with anything else though, so this should be okay. * Fix base-class function signature * Fix potential memory leak of StringTemplating * Implement removal of keybindings * Fix key-event processing * Basic working of keybinding editor - needs a lot of cleaning still * Change: Use _exact_ matching and allow key-repeatitions * Implement rebinds * Brigthen the popup borders a bit * Fix potential memory leak, less spammy print statements * Clean function signatures * Add back required function * Move around scripts to more apropriate locations * Implement workaround for keystroke detection * Use workaround in Main.gd as well * Fix: Use typed assignments * Collect translation strings and put them in the English translation file * Type annotations * Add trashcan to icons, revert red background * Code convention fixups * Fix: Remove message update as part of _process and modifier-key detection * Remove unused mask-var * Fix spacings, use existing delete.png
- Loading branch information
1 parent
9708ec0
commit d38b9aa
Showing
17 changed files
with
441 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
[gd_scene load_steps=4 format=2] | ||
|
||
[ext_resource path="res://UI/Components/KeyBindingsLineName.gd" type="Script" id=1] | ||
[ext_resource path="res://UI/Components/KeyBindingsLineBindings.gd" type="Script" id=2] | ||
[ext_resource path="res://UI/Components/KeyBindingsLineAddButton.gd" type="Script" id=3] | ||
|
||
[node name="KeyBindingsLine" type="GridContainer"] | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
columns = 3 | ||
__meta__ = { | ||
"_edit_use_anchors_": false | ||
} | ||
|
||
[node name="Name" type="Label" parent="."] | ||
margin_top = 3.0 | ||
margin_right = 38.0 | ||
margin_bottom = 17.0 | ||
text = "Name | ||
" | ||
valign = 1 | ||
max_lines_visible = 1 | ||
script = ExtResource( 1 ) | ||
|
||
[node name="Bindings" type="HBoxContainer" parent="."] | ||
margin_left = 42.0 | ||
margin_right = 42.0 | ||
margin_bottom = 20.0 | ||
script = ExtResource( 2 ) | ||
|
||
[node name="AddButton" type="Button" parent="."] | ||
margin_left = 46.0 | ||
margin_right = 66.0 | ||
margin_bottom = 20.0 | ||
text = "+" | ||
script = ExtResource( 3 ) | ||
|
||
[connection signal="pressed" from="AddButton" to="AddButton" method="_on_AddButton_pressed"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
extends Button | ||
|
||
# ------------------------------------------------------------------------------------------------- | ||
signal bind_new_key | ||
|
||
# ------------------------------------------------------------------------------------------------- | ||
func set_keybindings_data(_bindings_data: Dictionary) -> void: | ||
pass | ||
|
||
# ------------------------------------------------------------------------------------------------- | ||
func _on_AddButton_pressed() -> void: | ||
emit_signal("bind_new_key") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
extends HBoxContainer | ||
|
||
# ------------------------------------------------------------------------------------------------- | ||
signal modified_binding(bindings_data) | ||
|
||
# ------------------------------------------------------------------------------------------------- | ||
var _bindings_data := {} | ||
var _preloaded_image := preload("res://Assets/Icons/delete.png") | ||
|
||
# ------------------------------------------------------------------------------------------------- | ||
# Keybindings data: {"action": "str", "readable_name": "str", "events": [...]} | ||
func set_keybindings_data(bindings_data: Dictionary) -> void: | ||
for child in get_children(): | ||
remove_child(child) | ||
|
||
_bindings_data = bindings_data | ||
for event in bindings_data["events"]: | ||
if event is InputEventKey: | ||
var remove_button = Button.new() | ||
remove_button.text = OS.get_scancode_string(event.get_scancode_with_modifiers()) | ||
remove_button.icon = _preloaded_image | ||
|
||
remove_button.add_constant_override("hseparation", 6) | ||
|
||
remove_button.connect("pressed", self, "_remove_pressed", [event]) | ||
add_child(remove_button) | ||
|
||
# ------------------------------------------------------------------------------------------------- | ||
func _remove_pressed(event: InputEvent) -> void: | ||
_bindings_data["events"].erase(event) | ||
emit_signal("modified_binding", _bindings_data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
extends Label | ||
|
||
# ------------------------------------------------------------------------------------------------- | ||
signal modified_binding(bindings_data) | ||
|
||
# ------------------------------------------------------------------------------------------------- | ||
# Keybindings data: {"action": "str", "readable_name": "str", "events": [...]} | ||
func set_keybindings_data(_bindings_data: Dictionary) -> void: | ||
text = _bindings_data["readable_name"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
extends WindowDialog | ||
|
||
# ------------------------------------------------------------------------------------------------- | ||
const _MODIFIER_KEYS := [KEY_SUPER_L, KEY_SUPER_R, KEY_CONTROL, KEY_SHIFT, KEY_META, KEY_ALT] | ||
|
||
# ------------------------------------------------------------------------------------------------- | ||
export var action_name := "" | ||
export var readable_action_name := "" setget _set_readable_action_name | ||
|
||
onready var _confirm_rebind_dialog := $ConfirmRebind | ||
|
||
var _pending_bind_event = null | ||
|
||
# ------------------------------------------------------------------------------------------------- | ||
func _ready() -> void: | ||
_update_event_text() | ||
GlobalSignals.connect("language_changed", self, "_update_event_text") | ||
|
||
# ------------------------------------------------------------------------------------------------- | ||
func _set_readable_action_name(s: String): | ||
readable_action_name = s | ||
_update_event_text() | ||
|
||
# ------------------------------------------------------------------------------------------------- | ||
func _update_event_text() -> void: | ||
$VBoxContainer/EventText.text = tr( | ||
"KEYBINDING_DIALOG_BIND_ACTION" | ||
).format({"action": readable_action_name}) | ||
|
||
# ------------------------------------------------------------------------------------------------- | ||
func _action_for_event(event: InputEvent): | ||
for action in Utils.bindable_actions(): | ||
if InputMap.action_has_event(action, event): | ||
return action | ||
return null | ||
|
||
# ------------------------------------------------------------------------------------------------- | ||
func _input(event: InputEvent) -> void: | ||
if ! visible || _confirm_rebind_dialog.visible: | ||
return | ||
if event is InputEventKey && event.is_pressed(): | ||
get_tree().set_input_as_handled() | ||
|
||
if event.scancode in _MODIFIER_KEYS: | ||
return | ||
|
||
var event_type := InputEventKey.new() | ||
event_type.scancode = event.scancode | ||
event_type.alt = event.alt | ||
event_type.shift = event.shift | ||
event_type.control = event.control | ||
event_type.meta = event.meta | ||
event_type.command = event.command | ||
|
||
var _conflicting_action = _action_for_event(event_type) | ||
|
||
_pending_bind_event = event_type | ||
if _conflicting_action is String && _conflicting_action != action_name: | ||
_confirm_rebind_dialog.dialog_text = tr("KEYBINDING_DIALOG_REBIND_MESSAGE").format({ | ||
"event": OS.get_scancode_string(event_type.get_scancode_with_modifiers()), | ||
"action": Utils.translate_action(_conflicting_action) | ||
}) | ||
_confirm_rebind_dialog.popup_centered() | ||
else: | ||
_finish_rebind() | ||
|
||
# ------------------------------------------------------------------------------------------------- | ||
func _on_ConfirmRebind_confirmed() -> void: | ||
_finish_rebind() | ||
|
||
# ------------------------------------------------------------------------------------------------- | ||
func _finish_rebind() -> void: | ||
for action in Utils.bindable_actions(): | ||
if InputMap.action_has_event(action, _pending_bind_event): | ||
InputMap.action_erase_event(action, _pending_bind_event) | ||
InputMap.action_add_event(action_name, _pending_bind_event) | ||
visible = false |
Oops, something went wrong.