Implement keybindings.

This commit is contained in:
Relintai 2020-07-31 01:15:13 +02:00
parent 39f80386e8
commit c9d53f5801
20 changed files with 587 additions and 20 deletions

8
game/InputMapEditor.tscn Normal file
View File

@ -0,0 +1,8 @@
[gd_scene format=2]
[node name="InputMapEditor" type="InputMapEditor"]
anchor_right = 1.0
anchor_bottom = 1.0
__meta__ = {
"_edit_use_anchors_": false
}

View File

@ -345,6 +345,266 @@ move_right={
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"unicode":0,"echo":false,"script":null)
]
}
actionbar_2_0={
"deadzone": 0.5,
"events": [ ]
}
actionbar_2_1={
"deadzone": 0.5,
"events": [ ]
}
actionbar_2_2={
"deadzone": 0.5,
"events": [ ]
}
actionbar_2_3={
"deadzone": 0.5,
"events": [ ]
}
actionbar_2_4={
"deadzone": 0.5,
"events": [ ]
}
actionbar_2_5={
"deadzone": 0.5,
"events": [ ]
}
actionbar_2_6={
"deadzone": 0.5,
"events": [ ]
}
actionbar_2_7={
"deadzone": 0.5,
"events": [ ]
}
actionbar_2_8={
"deadzone": 0.5,
"events": [ ]
}
actionbar_2_9={
"deadzone": 0.5,
"events": [ ]
}
actionbar_2_10={
"deadzone": 0.5,
"events": [ ]
}
actionbar_2_11={
"deadzone": 0.5,
"events": [ ]
}
actionbar_2_12={
"deadzone": 0.5,
"events": [ ]
}
actionbar_3_0={
"deadzone": 0.5,
"events": [ ]
}
actionbar_3_1={
"deadzone": 0.5,
"events": [ ]
}
actionbar_3_2={
"deadzone": 0.5,
"events": [ ]
}
actionbar_3_3={
"deadzone": 0.5,
"events": [ ]
}
actionbar_3_4={
"deadzone": 0.5,
"events": [ ]
}
actionbar_3_5={
"deadzone": 0.5,
"events": [ ]
}
actionbar_3_6={
"deadzone": 0.5,
"events": [ ]
}
actionbar_3_7={
"deadzone": 0.5,
"events": [ ]
}
actionbar_3_8={
"deadzone": 0.5,
"events": [ ]
}
actionbar_3_9={
"deadzone": 0.5,
"events": [ ]
}
actionbar_3_10={
"deadzone": 0.5,
"events": [ ]
}
actionbar_3_11={
"deadzone": 0.5,
"events": [ ]
}
actionbar_3_12={
"deadzone": 0.5,
"events": [ ]
}
actionbar_4_0={
"deadzone": 0.5,
"events": [ ]
}
actionbar_4_1={
"deadzone": 0.5,
"events": [ ]
}
actionbar_4_2={
"deadzone": 0.5,
"events": [ ]
}
actionbar_4_3={
"deadzone": 0.5,
"events": [ ]
}
actionbar_4_4={
"deadzone": 0.5,
"events": [ ]
}
actionbar_4_5={
"deadzone": 0.5,
"events": [ ]
}
actionbar_4_6={
"deadzone": 0.5,
"events": [ ]
}
actionbar_4_7={
"deadzone": 0.5,
"events": [ ]
}
actionbar_4_8={
"deadzone": 0.5,
"events": [ ]
}
actionbar_4_9={
"deadzone": 0.5,
"events": [ ]
}
actionbar_4_10={
"deadzone": 0.5,
"events": [ ]
}
actionbar_4_11={
"deadzone": 0.5,
"events": [ ]
}
actionbar_4_12={
"deadzone": 0.5,
"events": [ ]
}
actionbar_5_0={
"deadzone": 0.5,
"events": [ ]
}
actionbar_5_1={
"deadzone": 0.5,
"events": [ ]
}
actionbar_5_2={
"deadzone": 0.5,
"events": [ ]
}
actionbar_5_3={
"deadzone": 0.5,
"events": [ ]
}
actionbar_5_4={
"deadzone": 0.5,
"events": [ ]
}
actionbar_5_5={
"deadzone": 0.5,
"events": [ ]
}
actionbar_5_6={
"deadzone": 0.5,
"events": [ ]
}
actionbar_5_7={
"deadzone": 0.5,
"events": [ ]
}
actionbar_5_8={
"deadzone": 0.5,
"events": [ ]
}
actionbar_5_9={
"deadzone": 0.5,
"events": [ ]
}
actionbar_5_10={
"deadzone": 0.5,
"events": [ ]
}
actionbar_5_11={
"deadzone": 0.5,
"events": [ ]
}
actionbar_5_12={
"deadzone": 0.5,
"events": [ ]
}
actionbar_6_0={
"deadzone": 0.5,
"events": [ ]
}
actionbar_6_1={
"deadzone": 0.5,
"events": [ ]
}
actionbar_6_2={
"deadzone": 0.5,
"events": [ ]
}
actionbar_6_3={
"deadzone": 0.5,
"events": [ ]
}
actionbar_6_4={
"deadzone": 0.5,
"events": [ ]
}
actionbar_6_5={
"deadzone": 0.5,
"events": [ ]
}
actionbar_6_6={
"deadzone": 0.5,
"events": [ ]
}
actionbar_6_7={
"deadzone": 0.5,
"events": [ ]
}
actionbar_6_8={
"deadzone": 0.5,
"events": [ ]
}
actionbar_6_9={
"deadzone": 0.5,
"events": [ ]
}
actionbar_6_10={
"deadzone": 0.5,
"events": [ ]
}
actionbar_6_11={
"deadzone": 0.5,
"events": [ ]
}
actionbar_6_12={
"deadzone": 0.5,
"events": [ ]
}
[layer_names]

View File

@ -53,6 +53,8 @@ func _ready() -> void:
keybind_text = get_node(keybind_text_path) as Label
button.connect("pressed", self, "_on_button_pressed")
ProfileManager.connect("keybinds_changed", self, "on_keybinds_changed")
func _exit_tree():
if icon_rect.texture != null:
@ -116,8 +118,28 @@ func set_button_entry(action_bar_button_entry: ActionBarButtonEntry, p_player: E
if not InputMap.has_action(action_name):
InputMap.add_action(action_name)
on_keybinds_changed()
iea.action = action_name
iea.pressed = true
var sc : ShortCut = ShortCut.new()
sc.shortcut = iea
shortcut = sc
setup_icon()
func on_keybinds_changed():
var action_name : String = "actionbar_" + str(button_entry.action_bar_id) + "_" + str(button_entry.slot_id)
keybind_text.text = ""
if not InputMap.has_action(action_name):
return
var action_list : Array = InputMap.get_action_list(action_name)
keybind_text.text = ""
for action in action_list:
if action is InputEventKey:
var s : String = ""
@ -141,14 +163,6 @@ func set_button_entry(action_bar_button_entry: ActionBarButtonEntry, p_player: E
keybind_text.text = s
iea.action = action_name
iea.pressed = true
var sc : ShortCut = ShortCut.new()
sc.shortcut = iea
shortcut = sc
setup_icon()
func setup_icon() -> void:
if (button_entry.type == ActionBarButtonEntry.ACTION_BAR_BUTTON_ENTRY_TYPE_NONE):
if icon_rect.texture != null:

View File

@ -0,0 +1 @@
<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="m7 1v6h-6v2h6v6h2v-6h6v-2h-6v-6z" fill="#e0e0e0"/></svg>

After

Width:  |  Height:  |  Size: 149 B

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/icon_add.svg-8d234c23ab44bacb67bdfe3f0ee81a47.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://ui/icons/icon_add.svg"
dest_files=[ "res://.import/icon_add.svg-8d234c23ab44bacb67bdfe3f0ee81a47.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=1
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=false
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

View File

@ -0,0 +1 @@
<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="m7 1c-.554 0-1 .446-1 1v2h4v-2c0-.554-.446-1-1-1zm-1 4v7l2 3 2-3v-7zm1 1h1v5h-1z" fill="#e0e0e0"/></svg>

After

Width:  |  Height:  |  Size: 197 B

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/icon_edit.svg-1aba0748a13b323d6887f1edfd72e194.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://ui/icons/icon_edit.svg"
dest_files=[ "res://.import/icon_edit.svg-1aba0748a13b323d6887f1edfd72e194.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=1
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=false
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

View File

@ -0,0 +1 @@
<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><g transform="translate(0 -1036.4)"><path d="m27 1038.4h7v14h-7z" fill="#fff" fill-opacity=".99608"/><g fill="#e0e0e0"><path d="m3 1a2 2 0 0 0 -2 2v10a2 2 0 0 0 2 2h12v-14zm4 2h2a1 1 0 0 1 1 1v2h2a1 1 0 0 1 1 1v2a1 1 0 0 1 -1 1h-2v2a1 1 0 0 1 -1 1h-2a1 1 0 0 1 -1-1v-2h-2a1 1 0 0 1 -1-1v-2a1 1 0 0 1 1-1h2v-2a1 1 0 0 1 1-1z" fill-opacity=".99608" transform="translate(0 1036.4)"/><circle cx="8" cy="1044.4" r="1"/></g></g></svg>

After

Width:  |  Height:  |  Size: 512 B

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/icon_joy_axis.svg-df8e548a1140e7ce99b04939b395b138.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://ui/icons/icon_joy_axis.svg"
dest_files=[ "res://.import/icon_joy_axis.svg-df8e548a1140e7ce99b04939b395b138.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=1
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=false
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

View File

@ -0,0 +1 @@
<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><g fill-opacity=".99608" transform="translate(0 -1036.4)"><path d="m27 1038.4h7v14h-7z" fill="#fff"/><path d="m1 1v14h12c1.1046 0 2-.8954 2-2v-10c0-1.1046-.89543-2-2-2zm7 1a2 2 0 0 1 2 2 2 2 0 0 1 -2 2 2 2 0 0 1 -2-2 2 2 0 0 1 2-2zm-4 4a2 2 0 0 1 2 2 2 2 0 0 1 -2 2 2 2 0 0 1 -2-2 2 2 0 0 1 2-2zm8 0a2 2 0 0 1 2 2 2 2 0 0 1 -2 2 2 2 0 0 1 -2-2 2 2 0 0 1 2-2zm-4 4a2 2 0 0 1 2 2 2 2 0 0 1 -2 2 2 2 0 0 1 -2-2 2 2 0 0 1 2-2z" fill="#e0e0e0" transform="translate(0 1036.4)"/></g></svg>

After

Width:  |  Height:  |  Size: 566 B

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/icon_joy_button.svg-90efe2841da127b700c9fe4f1211a539.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://ui/icons/icon_joy_button.svg"
dest_files=[ "res://.import/icon_joy_button.svg-90efe2841da127b700c9fe4f1211a539.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=1
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=false
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

View File

@ -0,0 +1 @@
<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><g fill-opacity=".99608" transform="translate(0 -1036.4)"><path d="m4 2a1 1 0 0 0 -1 1v9.084a1 .91667 0 0 0 1 .91602h8a1 .91667 0 0 0 1-.91602v-9.084a1 1 0 0 0 -1-1zm-3 2v9a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-9h-1v9a.99998.99998 0 0 1 -1 1h-10a1 1 0 0 1 -1-1v-9zm4 0h2v3l2-3h2l-2 3 2 4h-2l-2-4v4h-2z" fill="#e0e0e0" transform="translate(0 1036.4)"/><path d="m27 1038.4h7v14h-7z" fill="#fff"/></g></svg>

After

Width:  |  Height:  |  Size: 482 B

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/icon_keyboard.svg-48afc1010696d26403af4139c2b28ebf.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://ui/icons/icon_keyboard.svg"
dest_files=[ "res://.import/icon_keyboard.svg-48afc1010696d26403af4139c2b28ebf.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=1
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=false
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

View File

@ -0,0 +1 @@
<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="m7 1.1016a5 5 0 0 0 -4 4.8984h4zm2 .0039063v4.8945h4a5 5 0 0 0 -4-4.8945zm-6 6.8945v2a5 5 0 0 0 5 5 5 5 0 0 0 5-5v-2z" fill="#e0e0e0"/></svg>

After

Width:  |  Height:  |  Size: 234 B

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/icon_mouse.svg-92245f2e2690694f01e281113add7d2d.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://ui/icons/icon_mouse.svg"
dest_files=[ "res://.import/icon_mouse.svg-92245f2e2690694f01e281113add7d2d.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=1
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=false
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

View File

@ -0,0 +1 @@
<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="m5 1v1h-4v2h14v-2h-4v-1zm-3 4v8a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2v-8zm1 2h2v6h-2zm4 0h2v6h-2zm4 0h2v6h-2z" fill="#e0e0e0" fill-opacity=".99608"/></svg>

After

Width:  |  Height:  |  Size: 240 B

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/icon_remove.svg-997114201fcc93bffd099fce5ecc1ae7.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://ui/icons/icon_remove.svg"
dest_files=[ "res://.import/icon_remove.svg-997114201fcc93bffd099fce5ecc1ae7.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=1
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=false
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

View File

@ -24,6 +24,24 @@ export(PackedScene) var keybind_category_scene : PackedScene
export(NodePath) var content_container_path : NodePath
var _player : Entity
func set_player(player : Entity):
if _player:
_player.disconnect("centity_data_changed", self, "on_data_changed")
_player = player
on_data_changed(_player.getc_entity_data())
_player.connect("centity_data_changed", self, "on_data_changed")
func on_data_changed(data):
if data:
ProfileManager.on_keybinds_changed(data.get_path())
InputMap.load_from_globals()
# Note for the reader:
#
@ -127,3 +145,12 @@ func a_ready():
# Do not start processing input until a button is pressed
set_process_input(false)
func close():
InputMap.load_from_globals()
if _player:
ProfileManager.on_keybinds_changed(_player.getc_entity_data().get_path())
hide()

View File

@ -1,8 +1,15 @@
[gd_scene load_steps=4 format=2]
[gd_scene load_steps=11 format=2]
[ext_resource path="res://ui/keybinds/Keybinds.gd" type="Script" id=1]
[ext_resource path="res://ui/theme/ui_theme.tres" type="Theme" id=2]
[ext_resource path="res://ui/keybinds/KeybindCategory.tscn" type="PackedScene" id=3]
[ext_resource path="res://ui/icons/icon_mouse.svg" type="Texture" id=4]
[ext_resource path="res://ui/icons/icon_joy_axis.svg" type="Texture" id=5]
[ext_resource path="res://ui/icons/icon_keyboard.svg" type="Texture" id=6]
[ext_resource path="res://ui/icons/icon_edit.svg" type="Texture" id=7]
[ext_resource path="res://ui/icons/icon_add.svg" type="Texture" id=8]
[ext_resource path="res://ui/icons/icon_remove.svg" type="Texture" id=9]
[ext_resource path="res://ui/icons/icon_joy_button.svg" type="Texture" id=10]
[node name="KeybindWindow" type="PanelContainer"]
anchor_right = 1.0
@ -13,7 +20,6 @@ __meta__ = {
"_edit_use_anchors_": false
}
keybind_category_scene = ExtResource( 3 )
content_container_path = NodePath("VBoxContainer/ScrollContainer/Content")
[node name="VBoxContainer" type="VBoxContainer" parent="."]
margin_left = 4.0
@ -27,7 +33,7 @@ margin_bottom = 30.0
[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer"]
margin_top = 7.0
margin_right = 968.0
margin_right = 972.0
margin_bottom = 22.0
size_flags_horizontal = 3
text = "Keybinds"
@ -39,17 +45,19 @@ margin_bottom = 30.0
rect_min_size = Vector2( 40, 30 )
text = "X"
[node name="ScrollContainer" type="ScrollContainer" parent="VBoxContainer"]
[node name="InputMapEditor" type="InputMapEditor" parent="VBoxContainer"]
margin_top = 38.0
margin_right = 1016.0
margin_bottom = 554.0
size_flags_horizontal = 3
size_flags_vertical = 3
scroll_horizontal_enabled = false
[node name="Content" type="VBoxContainer" parent="VBoxContainer/ScrollContainer"]
margin_right = 1016.0
size_flags_horizontal = 3
add_texture = ExtResource( 8 )
remove_texture = ExtResource( 9 )
edit_texture = ExtResource( 7 )
keyboard_texture = ExtResource( 6 )
joybutton_texture = ExtResource( 10 )
joyaxis_texture = ExtResource( 5 )
mouse_texture = ExtResource( 4 )
[node name="HBoxContainer2" type="HBoxContainer" parent="VBoxContainer"]
margin_top = 562.0
@ -58,8 +66,8 @@ margin_bottom = 592.0
alignment = 2
[node name="Button" type="Button" parent="VBoxContainer/HBoxContainer2"]
margin_left = 848.0
margin_right = 928.0
margin_left = 852.0
margin_right = 932.0
margin_bottom = 30.0
rect_min_size = Vector2( 80, 30 )
text = "Cancel"
@ -71,3 +79,6 @@ margin_bottom = 30.0
rect_min_size = Vector2( 80, 30 )
text = "OK"
[connection signal="pressed" from="VBoxContainer/HBoxContainer/Button" to="." method="hide"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer2/Button" to="." method="hide"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer2/Button2" to="." method="close"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer2/Button2" to="VBoxContainer/InputMapEditor" method="queue_save"]

View File

@ -44,7 +44,7 @@ script = ExtResource( 1 )
__meta__ = {
"_edit_lock_": true
}
child_controls = [ NodePath("Unitframes"), NodePath("Actionbars"), NodePath("Windows/SpellBookWindow"), NodePath("Buttons"), NodePath("Castbar"), NodePath("AuraFrame"), NodePath("Windows/Inventory"), NodePath("Windows/LootWindow"), NodePath("Windows/TalentWindow"), NodePath("Windows/CraftingWindow") ]
child_controls = [ NodePath("Unitframes"), NodePath("Actionbars"), NodePath("Windows/SpellBookWindow"), NodePath("Buttons"), NodePath("Castbar"), NodePath("AuraFrame"), NodePath("Windows/Inventory"), NodePath("Windows/LootWindow"), NodePath("Windows/TalentWindow"), NodePath("Windows/CraftingWindow"), NodePath("IngameMenu/KeybindWindow") ]
[node name="TouchTargetControls" type="MarginContainer" parent="GUI"]
visible = false
@ -460,3 +460,5 @@ visible = false
[connection signal="toggled" from="GUI/Buttons/TalentButton" to="GUI/Windows/TalentWindow" method="_on_TalentButton_toggled"]
[connection signal="toggled" from="GUI/Buttons/CraftingButton" to="GUI/Windows/CraftingWindow" method="_on_CraftingButton_toggled"]
[connection signal="pressed" from="GUI/Buttons/Menu" to="GUI/IngameMenu" method="show"]
[editable path="GUI/IngameMenu"]