basic loading of keyboard layout, including key width

This commit is contained in:
Crispy 2022-01-19 20:57:30 +01:00
parent 23b37778b1
commit 710b418970
7 changed files with 401 additions and 69 deletions

View file

@ -81,7 +81,7 @@ func update_tracker_id():
if _tracker_id == -1:
# could not find controller, fallback
print("Missing controller ", current_target, " ", target, " ", fallback, " - ", name)
# print("Missing controller ", current_target, " ", target, " ", fallback, " - ", name)
_tracker_id = 63 # highest tracker id (unused, at origin)

View file

@ -0,0 +1,12 @@
[gd_scene format=2]
[node name="Key" type="Button"]
margin_right = 128.0
margin_bottom = 128.0
rect_min_size = Vector2( 128, 128 )
[node name="Label" type="Label" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
align = 1
valign = 1

View file

@ -0,0 +1,8 @@
[gd_scene format=2]
[node name="KeyRow" type="HBoxContainer"]
margin_right = 230.0
margin_bottom = 128.0
__meta__ = {
"_edit_use_anchors_": false
}

View file

@ -4,8 +4,50 @@ const OVERLAY_PROPERTIES = {
"has_touch": true,
}
export var key_size := 128
export var key_row : PackedScene
export var key_button : PackedScene
var keymap := {}
func _ready():
pass
load_keys("res://overlay_resources/keyboard/layouts/layout_se.json")
func load_keys(fp: String):
var file = File.new()
file.open(fp, File.READ)
keymap = parse_json(file.get_as_text())
file.close()
apply_keys()
func apply_keys():
for row in keymap.rows:
var row_box = key_row.instance()
$PanelContainer/CenterContainer/VBoxContainer.add_child(row_box)
for key in row.keys:
var btn = key_button.instance()
if not key.has("display"):
key.display = key.keycode
btn.get_node("Label").text = key.display
btn.name = key.keycode
btn.rect_min_size.x = key_size
btn.rect_min_size.y = key_size
if key.has("width"):
btn.rect_min_size.x *= key.width
row_box.add_child(btn)
btn.connect("pressed", self, "key_pressed", [key.keycode])
#TODO gaps
func key_pressed(code, toggle=false):
GDVK.press(code)
func _on_KeyO_pressed():
@ -13,8 +55,10 @@ func _on_KeyO_pressed():
func _on_KeyE_pressed():
GDVK.press("E")
pass # Replace with function body.
GDVK.key_down("SHIFT")
GDVK.press("1")
GDVK.key_up("SHIFT")
func _on_KeyH_pressed():

View file

@ -0,0 +1,321 @@
{
"rows": [
{
"gap": 0.5,
"keys": [
{
"keycode": "ESCAPE",
"display": "Esc",
"gap": 1
},
{
"keycode": "F1",
"display": "F1"
},
{
"keycode": "F2",
"display": "F2"
},
{
"keycode": "F3",
"display": "F3"
},
{
"keycode": "F4",
"display": "F4",
"gap": 0.5
},
{
"keycode": "F5",
"display": "F5"
},
{
"keycode": "F6",
"display": "F6"
},
{
"keycode": "F7",
"display": "F7"
},
{
"keycode": "F8",
"display": "F8",
"gap": 0.5
},
{
"keycode": "F9",
"display": "F9"
},
{
"keycode": "F10",
"display": "F10"
},
{
"keycode": "F11",
"display": "F11"
},
{
"keycode": "F12",
"display": "F12",
"gap": 0.5
}
]
},
{
"gap": 0,
"keys": [
{
"keycode": "ASCIIGRAVE",
"display": "`"
},
{
"keycode": "1"
},
{
"keycode": "2"
},
{
"keycode": "3"
},
{
"keycode": "4"
},
{
"keycode": "5"
},
{
"keycode": "6"
},
{
"keycode": "7"
},
{
"keycode": "8"
},
{
"keycode": "9"
},
{
"keycode": "0"
},
{
"keycode": "PLUS",
"display": "+"
},
{
"keycode": "GRAVE",
"display": "`"
},
{
"keycode": "BACKSPACE",
"display": "<-",
"width": 2
}
]
},
{
"gap": 0,
"keys": [
{
"keycode": "TAB",
"display": "->",
"width": 1.5
},
{
"keycode": "Q"
},
{
"keycode": "W"
},
{
"keycode": "E"
},
{
"keycode": "R"
},
{
"keycode": "T"
},
{
"keycode": "Y"
},
{
"keycode": "U"
},
{
"keycode": "I"
},
{
"keycode": "O"
},
{
"keycode": "P"
},
{
"keycode": "ARING",
"display": "Å"
},
{
"keycode": "DIAERSIS",
"display": "^\n¨ ~"
},
{
"keycode": "ENTER",
"display": "Enter",
"width": 1.5
}
]
},
{
"gap": 0,
"keys": [
{
"keycode": "CAPSLOCK",
"display": "CAPS",
"width": 1.75
},
{
"keycode": "A"
},
{
"keycode": "S"
},
{
"keycode": "D"
},
{
"keycode": "F"
},
{
"keycode": "G"
},
{
"keycode": "H"
},
{
"keycode": "J"
},
{
"keycode": "K"
},
{
"keycode": "L"
},
{
"keycode": "ODIAERSIS",
"display": "Ö"
},
{
"keycode": "ADIAERSIS",
"display": "Ä"
},
{
"keycode": "APOSTROPHE",
"display": "*\n'"
},
{
"keycode": "ENTER",
"display": "Enter",
"width": 1.25
}
]
},
{
"gap": 0,
"keys": [
{
"keycode": "SHIFT",
"display": "^",
"width": 1.25
},
{
"keycode": "LESS",
"display": "> \n<|"
},
{
"keycode": "Z"
},
{
"keycode": "X"
},
{
"keycode": "C"
},
{
"keycode": "V"
},
{
"keycode": "B"
},
{
"keycode": "N"
},
{
"keycode": "M"
},
{
"keycode": "COMMA",
"display": ";\n,"
},
{
"keycode": "PERIOD",
"display": ":\n."
},
{
"keycode": "MINUS",
"display": "_\n-"
},
{
"keycode": "SHIFT",
"display": "SHIFT",
"width": 2.5
}
]
},
{
"gap": 0,
"keys": [
{
"keycode": "CONTROL",
"display": "Ctrl",
"width": 1.5
},
{
"keycode": "SUPER",
"display": "Super",
"width": 1.5
},
{
"keycode": "ALT",
"display": "Alt",
"width": 1.5
},
{
"keycode": "SPACE",
"display": "",
"width": 5.5
},
{
"keycode": "ALT",
"display": "Alt Gr(!)",
"width": 1.5
},
{
"keycode": "SUPER",
"display": "Super",
"width": 1.5
},
{
"keycode": "MENU",
"display": "Menu",
"width": 1.5
},
{
"keycode": "CONTROL",
"display": "Ctrl",
"width": 1.5
}
]
}
]
}

View file

@ -1,7 +1,9 @@
[gd_scene load_steps=3 format=2]
[gd_scene load_steps=5 format=2]
[ext_resource path="res://overlay_resources/keyboard/keyboard.theme" type="Theme" id=1]
[ext_resource path="res://overlay_resources/keyboard/keyboard_overlay.gd" type="Script" id=2]
[ext_resource path="res://overlay_resources/keyboard/KeyRow.tscn" type="PackedScene" id=3]
[ext_resource path="res://overlay_resources/keyboard/KeyBtn.tscn" type="PackedScene" id=4]
[node name="Overlay" type="Control"]
anchor_right = 1.0
@ -9,19 +11,14 @@ anchor_bottom = 1.0
theme = ExtResource( 1 )
script = ExtResource( 2 )
__meta__ = {
"_edit_lock_": true,
"_edit_use_anchors_": false
}
key_row = ExtResource( 3 )
key_button = ExtResource( 4 )
[node name="PanelContainer" type="PanelContainer" parent="."]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -123.0
margin_top = -103.5
margin_right = 123.0
margin_bottom = 103.5
anchor_right = 1.0
margin_bottom = 16.0
__meta__ = {
"_edit_use_anchors_": false
}
@ -29,59 +26,9 @@ __meta__ = {
[node name="CenterContainer" type="CenterContainer" parent="PanelContainer"]
margin_left = 8.0
margin_top = 8.0
margin_right = 400.0
margin_bottom = 268.0
margin_right = 2040.0
margin_bottom = 8.0
[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer"]
margin_left = 8.0
margin_top = 8.0
margin_right = 400.0
margin_bottom = 268.0
[node name="HBoxContainer" type="HBoxContainer" parent="PanelContainer/VBoxContainer"]
margin_right = 392.0
margin_bottom = 128.0
[node name="KeyH" type="Button" parent="PanelContainer/VBoxContainer/HBoxContainer"]
margin_right = 128.0
margin_bottom = 128.0
rect_min_size = Vector2( 128, 128 )
text = "H"
[node name="KeyE" type="Button" parent="PanelContainer/VBoxContainer/HBoxContainer"]
margin_left = 132.0
margin_right = 260.0
margin_bottom = 128.0
rect_min_size = Vector2( 128, 128 )
text = "E"
[node name="KeyO" type="Button" parent="PanelContainer/VBoxContainer/HBoxContainer"]
margin_left = 264.0
margin_right = 392.0
margin_bottom = 128.0
rect_min_size = Vector2( 128, 128 )
text = "O"
[node name="HBoxContainer2" type="HBoxContainer" parent="PanelContainer/VBoxContainer"]
margin_top = 132.0
margin_right = 392.0
margin_bottom = 260.0
[node name="KeyCaps" type="Button" parent="PanelContainer/VBoxContainer/HBoxContainer2"]
margin_right = 224.0
margin_bottom = 128.0
rect_min_size = Vector2( 224, 128 )
text = "CAPS"
[node name="KeyL" type="Button" parent="PanelContainer/VBoxContainer/HBoxContainer2"]
margin_left = 228.0
margin_right = 356.0
margin_bottom = 128.0
rect_min_size = Vector2( 128, 128 )
text = "L"
[connection signal="pressed" from="PanelContainer/VBoxContainer/HBoxContainer/KeyH" to="." method="_on_KeyH_pressed"]
[connection signal="pressed" from="PanelContainer/VBoxContainer/HBoxContainer/KeyE" to="." method="_on_KeyE_pressed"]
[connection signal="pressed" from="PanelContainer/VBoxContainer/HBoxContainer/KeyO" to="." method="_on_KeyO_pressed"]
[connection signal="pressed" from="PanelContainer/VBoxContainer/HBoxContainer2/KeyCaps" to="." method="_on_KeyCaps_pressed"]
[connection signal="pressed" from="PanelContainer/VBoxContainer/HBoxContainer2/KeyL" to="." method="_on_KeyL_pressed"]
[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer/CenterContainer"]
margin_left = 1016.0
margin_right = 1016.0