finish basic layout generation
This commit is contained in:
parent
e1f6f673df
commit
82b4fc6d84
@ -14,7 +14,7 @@ main_label = NodePath("MainLabel")
|
||||
mesh = SubResource("BoxMesh_72e4x")
|
||||
|
||||
[node name="MainLabel" type="Label3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, -0.0669861, 0.075748, -0.0306985)
|
||||
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 0.076, 0)
|
||||
pixel_size = 0.0015
|
||||
shaded = true
|
||||
double_sided = false
|
||||
|
||||
@ -15,8 +15,14 @@ orientation = 1
|
||||
|
||||
[node name="Test" type="Node3D"]
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="."]
|
||||
[node name="OrthogonalCamera" type="Camera3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 4.76838e-07, 4.90848, -0.212414)
|
||||
projection = 1
|
||||
size = 2.895
|
||||
|
||||
[node name="PerspectiveCamera" type="Camera3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 0.48725, 0.873262, 0, -0.873262, 0.48725, 2.38419e-07, 2.79306, 0.864002)
|
||||
current = true
|
||||
|
||||
[node name="FloorMesh" type="MeshInstance3D" parent="."]
|
||||
mesh = SubResource("QuadMesh_ij1v8")
|
||||
|
||||
@ -33,7 +33,11 @@ func _unhandled_input(event: InputEvent) -> void:
|
||||
|
||||
var event_key := event as InputEventKey
|
||||
|
||||
if event_key.physical_keycode != props.physical_keycode:
|
||||
if (
|
||||
event_key.physical_keycode != props.physical_keycode
|
||||
or event_key.location != props.location
|
||||
):
|
||||
return
|
||||
|
||||
_is_pressed = event_key.is_pressed()
|
||||
# scale.z = 0.75 if _is_pressed else 1.0
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
class_name GameKeyboard extends Node3D
|
||||
|
||||
@export var _key_size: float = 0.25
|
||||
@export var _key_gap: float = 0.1
|
||||
@export var _key_gap: float = 0.05
|
||||
|
||||
@onready var _gap_to_size_ratio: float = _key_gap / _key_size
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@ -10,23 +12,28 @@ func _ready() -> void:
|
||||
|
||||
func _generate_keys() -> void:
|
||||
var layout_rows := LayoutAnsi.rows()
|
||||
|
||||
for row in layout_rows:
|
||||
_set_width_ratios_with_gaps(row)
|
||||
|
||||
var rows_amount := layout_rows.size()
|
||||
var row_width := (
|
||||
_get_row_width(layout_rows[0]) + (layout_rows[0].size() - 1) * _key_gap
|
||||
)
|
||||
|
||||
for i in range(rows_amount):
|
||||
var row := layout_rows[i] as Array[KeyProps]
|
||||
_generate_row(row as Array[KeyProps], i, rows_amount)
|
||||
_generate_row(row as Array[KeyProps], i, row_width, rows_amount)
|
||||
|
||||
|
||||
func _generate_row(row: Array[KeyProps], row_index: int, rows_amount: int) -> void:
|
||||
var keys_amount: int = row.size()
|
||||
var row_width := _get_row_width(row)
|
||||
|
||||
var offset_x: float = ((row_width - _key_size) + (keys_amount - 1) * _key_gap) / 2
|
||||
func _generate_row(
|
||||
row: Array[KeyProps], row_index: int, row_width: float, rows_amount: int
|
||||
) -> void:
|
||||
var offset_z: float = (
|
||||
((rows_amount - 1) * _key_size + (rows_amount - 1) * _key_gap) / 2
|
||||
)
|
||||
|
||||
var key_pos_x: float = -offset_x
|
||||
var key_pos_x: float = -row_width / 2 + _key_size / 2
|
||||
var key_pos_z: float = row_index * _key_size + row_index * _key_gap - offset_z
|
||||
|
||||
for key_props in row:
|
||||
@ -41,8 +48,16 @@ func _generate_row(row: Array[KeyProps], row_index: int, rows_amount: int) -> vo
|
||||
key_pos_x += _key_size * key_props.width_ratio + _key_gap
|
||||
|
||||
|
||||
func _set_width_ratios_with_gaps(row: Array[KeyProps]) -> void:
|
||||
for key_props in row:
|
||||
if key_props.width_ratio_init > 1:
|
||||
key_props.width_ratio += (
|
||||
_gap_to_size_ratio * (key_props.width_ratio_init - 1)
|
||||
)
|
||||
|
||||
|
||||
func _get_row_width(row: Array[KeyProps]) -> float:
|
||||
var width: float = 0
|
||||
for key_props in row:
|
||||
width += _key_size * key_props.width_ratio
|
||||
width += _key_size * key_props.width_ratio_init
|
||||
return width
|
||||
|
||||
@ -1,12 +1,23 @@
|
||||
class_name KeyProps
|
||||
|
||||
var physical_keycode: Key
|
||||
var location: KeyLocation
|
||||
var input_event: InputEventKey
|
||||
var width_ratio_init: float
|
||||
var width_ratio: float
|
||||
|
||||
|
||||
func _init(_physical_keycode: Key, _width_ratio: float = 1) -> void:
|
||||
func _init(
|
||||
_physical_keycode: Key,
|
||||
_width_ratio: float = 1,
|
||||
_location: KeyLocation = KEY_LOCATION_UNSPECIFIED
|
||||
) -> void:
|
||||
physical_keycode = _physical_keycode
|
||||
location = _location
|
||||
|
||||
input_event = InputEventKey.new()
|
||||
input_event.physical_keycode = physical_keycode
|
||||
width_ratio = _width_ratio
|
||||
input_event.location = _location
|
||||
|
||||
width_ratio_init = _width_ratio
|
||||
width_ratio = width_ratio_init
|
||||
|
||||
@ -18,8 +18,75 @@ static func rows() -> Array[Array]:
|
||||
KeyProps.new(KEY_0),
|
||||
KeyProps.new(KEY_MINUS),
|
||||
KeyProps.new(KEY_EQUAL),
|
||||
KeyProps.new(KEY_BACKSPACE, 2),
|
||||
KeyProps.new(KEY_BACKSPACE, 3.0 / 2.0),
|
||||
]
|
||||
as Array[KeyProps]
|
||||
)
|
||||
),
|
||||
(
|
||||
[
|
||||
KeyProps.new(KEY_TAB, 3.0 / 2.0),
|
||||
KeyProps.new(KEY_Q),
|
||||
KeyProps.new(KEY_W),
|
||||
KeyProps.new(KEY_E),
|
||||
KeyProps.new(KEY_R),
|
||||
KeyProps.new(KEY_T),
|
||||
KeyProps.new(KEY_Y),
|
||||
KeyProps.new(KEY_U),
|
||||
KeyProps.new(KEY_I),
|
||||
KeyProps.new(KEY_O),
|
||||
KeyProps.new(KEY_P),
|
||||
KeyProps.new(KEY_BRACKETLEFT),
|
||||
KeyProps.new(KEY_BRACKETRIGHT),
|
||||
KeyProps.new(KEY_BACKSLASH),
|
||||
]
|
||||
as Array[KeyProps]
|
||||
),
|
||||
(
|
||||
[
|
||||
KeyProps.new(KEY_CAPSLOCK, 7.0 / 4.0),
|
||||
KeyProps.new(KEY_A),
|
||||
KeyProps.new(KEY_S),
|
||||
KeyProps.new(KEY_D),
|
||||
KeyProps.new(KEY_F),
|
||||
KeyProps.new(KEY_G),
|
||||
KeyProps.new(KEY_H),
|
||||
KeyProps.new(KEY_J),
|
||||
KeyProps.new(KEY_K),
|
||||
KeyProps.new(KEY_L),
|
||||
KeyProps.new(KEY_SEMICOLON),
|
||||
KeyProps.new(KEY_APOSTROPHE),
|
||||
KeyProps.new(KEY_ENTER, 7.0 / 4.0),
|
||||
]
|
||||
as Array[KeyProps]
|
||||
),
|
||||
(
|
||||
[
|
||||
KeyProps.new(KEY_SHIFT, 9.0 / 4.0, KEY_LOCATION_LEFT),
|
||||
KeyProps.new(KEY_Z),
|
||||
KeyProps.new(KEY_X),
|
||||
KeyProps.new(KEY_C),
|
||||
KeyProps.new(KEY_V),
|
||||
KeyProps.new(KEY_B),
|
||||
KeyProps.new(KEY_N),
|
||||
KeyProps.new(KEY_M),
|
||||
KeyProps.new(KEY_COMMA),
|
||||
KeyProps.new(KEY_PERIOD),
|
||||
KeyProps.new(KEY_SLASH),
|
||||
KeyProps.new(KEY_SHIFT, 9.0 / 4.0, KEY_LOCATION_RIGHT),
|
||||
]
|
||||
as Array[KeyProps]
|
||||
),
|
||||
(
|
||||
[
|
||||
KeyProps.new(KEY_CTRL, 7.0 / 4.0, KEY_LOCATION_LEFT),
|
||||
KeyProps.new(KEY_META, 1, KEY_LOCATION_LEFT),
|
||||
KeyProps.new(KEY_ALT, 1, KEY_LOCATION_LEFT),
|
||||
KeyProps.new(KEY_SPACE, 6),
|
||||
KeyProps.new(KEY_ALT, 1, KEY_LOCATION_RIGHT),
|
||||
KeyProps.new(KEY_META, 1, KEY_LOCATION_RIGHT),
|
||||
KeyProps.new(KEY_MENU),
|
||||
KeyProps.new(KEY_CTRL, 7.0 / 4.0, KEY_LOCATION_RIGHT),
|
||||
]
|
||||
as Array[KeyProps]
|
||||
),
|
||||
]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user