move input events to game key class
This commit is contained in:
parent
ed197efcd2
commit
ac773de0a1
@ -11,21 +11,33 @@ static var _scene := preload("res://scenes/game_key.tscn")
|
||||
|
||||
var props: KeyProps
|
||||
var keyboard: GameKeyboard
|
||||
var input_event_init: InputEventKey
|
||||
|
||||
var _is_pressed: bool
|
||||
|
||||
var _input_event_main: InputEventKey
|
||||
var _input_event_shift: InputEventKey
|
||||
var _input_event_alt: InputEventKey
|
||||
var _input_event_alt_shift: InputEventKey
|
||||
|
||||
@onready var _default_position: Vector3 = position
|
||||
|
||||
|
||||
static func instantiate_with_props(
|
||||
_props: KeyProps, _keyboard: GameKeyboard
|
||||
) -> GameKey:
|
||||
var input_event := InputEventKey.new()
|
||||
input_event.physical_keycode = _props.physical_keycode
|
||||
input_event.location = _props.location
|
||||
|
||||
var node := _scene.instantiate() as GameKey
|
||||
node.keyboard = _keyboard
|
||||
node.props = _props
|
||||
node.name = node.name + " " + _props.input_event_init.as_text_physical_keycode()
|
||||
node.input_event_init = input_event
|
||||
node.name = node.name + " " + node.input_event_init.as_text_physical_keycode()
|
||||
if _props.location != KEY_LOCATION_UNSPECIFIED:
|
||||
node.name += " " + _props.input_event_init.as_text_location()
|
||||
node.name += " " + node.input_event_init.as_text_location()
|
||||
|
||||
return node
|
||||
|
||||
|
||||
@ -55,18 +67,19 @@ func _unhandled_input(event: InputEvent) -> void:
|
||||
if keyboard.configuring and _is_pressed:
|
||||
if not keyboard.alt_layout:
|
||||
if not event_key.shift_pressed:
|
||||
props.input_event_main = event_key
|
||||
_input_event_main = event_key
|
||||
else:
|
||||
props.input_event_shift = event_key
|
||||
_input_event_shift = event_key
|
||||
else:
|
||||
if not event_key.shift_pressed:
|
||||
props.input_event_alt = event_key
|
||||
_input_event_alt = event_key
|
||||
else:
|
||||
props.input_event_alt_shift = event_key
|
||||
_input_event_alt_shift = event_key
|
||||
|
||||
_set_labels()
|
||||
|
||||
func _clear_labels()->void:
|
||||
|
||||
func _clear_labels() -> void:
|
||||
_upper_left_label.text = ""
|
||||
_upper_right_label.text = ""
|
||||
_lower_left_label.text = ""
|
||||
@ -78,21 +91,17 @@ func _set_labels() -> void:
|
||||
_clear_labels()
|
||||
|
||||
var main_char := (
|
||||
char(props.input_event_main.unicode).to_upper()
|
||||
if props.input_event_main
|
||||
else ""
|
||||
char(_input_event_main.unicode).to_upper() if _input_event_main else ""
|
||||
)
|
||||
var shift_char := (
|
||||
char(props.input_event_shift.unicode).to_upper()
|
||||
if props.input_event_shift
|
||||
else ""
|
||||
char(_input_event_shift.unicode).to_upper() if _input_event_shift else ""
|
||||
)
|
||||
var alt_char := (
|
||||
char(props.input_event_alt.unicode).to_upper() if props.input_event_alt else ""
|
||||
char(_input_event_alt.unicode).to_upper() if _input_event_alt else ""
|
||||
)
|
||||
var alt_shift_char := (
|
||||
char(props.input_event_alt_shift.unicode).to_upper()
|
||||
if props.input_event_alt_shift
|
||||
char(_input_event_alt_shift.unicode).to_upper()
|
||||
if _input_event_alt_shift
|
||||
else ""
|
||||
)
|
||||
|
||||
@ -100,7 +109,7 @@ func _set_labels() -> void:
|
||||
props.physical_keycode == KEY_SPACE
|
||||
or (!main_char and !shift_char and !alt_char and !alt_shift_char)
|
||||
):
|
||||
_center_label.text = props.input_event_init.as_text_physical_keycode()
|
||||
_center_label.text = input_event_init.as_text_physical_keycode()
|
||||
return
|
||||
|
||||
if (main_char and not shift_char) or main_char == shift_char:
|
||||
@ -110,6 +119,9 @@ func _set_labels() -> void:
|
||||
_upper_left_label.text = shift_char
|
||||
_lower_left_label.text = main_char
|
||||
|
||||
if (not main_char and shift_char) and main_char != shift_char:
|
||||
_upper_left_label.text = shift_char
|
||||
|
||||
if alt_char and alt_char != main_char:
|
||||
_lower_right_label.text = alt_char
|
||||
|
||||
|
||||
@ -3,12 +3,6 @@ class_name KeyProps
|
||||
var physical_keycode: Key
|
||||
var location: KeyLocation
|
||||
|
||||
var input_event_init: InputEventKey
|
||||
var input_event_main: InputEventKey
|
||||
var input_event_shift: InputEventKey
|
||||
var input_event_alt: InputEventKey
|
||||
var input_event_alt_shift: InputEventKey
|
||||
|
||||
var width_ratio_init: float
|
||||
var width_ratio: float
|
||||
|
||||
@ -21,9 +15,5 @@ func _init(
|
||||
physical_keycode = _physical_keycode
|
||||
location = _location
|
||||
|
||||
input_event_init = InputEventKey.new()
|
||||
input_event_init.physical_keycode = physical_keycode
|
||||
input_event_init.location = _location
|
||||
|
||||
width_ratio_init = _width_ratio
|
||||
width_ratio = width_ratio_init
|
||||
|
||||
Loading…
Reference in New Issue
Block a user