fix keypress, keydown, keyup events crashing
This commit is contained in:
@@ -380,6 +380,33 @@ func _on_gui_input_mouse_universal(event: InputEvent, signal_node: Node) -> void
|
|||||||
var mouse_info = _get_element_relative_mouse_position(mouse_event, subscription.element_id)
|
var mouse_info = _get_element_relative_mouse_position(mouse_event, subscription.element_id)
|
||||||
_execute_lua_callback(subscription, [mouse_info])
|
_execute_lua_callback(subscription, [mouse_info])
|
||||||
|
|
||||||
|
func _on_gui_input_keys_universal(event: InputEvent, signal_node: Node) -> void:
|
||||||
|
if event is InputEventKey:
|
||||||
|
var key_event = event as InputEventKey
|
||||||
|
for subscription_id in event_subscriptions:
|
||||||
|
var subscription = event_subscriptions[subscription_id]
|
||||||
|
if subscription.connected_node == signal_node and subscription.connected_signal == "gui_input_keys":
|
||||||
|
var should_trigger = false
|
||||||
|
match subscription.event_name:
|
||||||
|
"keydown":
|
||||||
|
should_trigger = key_event.pressed
|
||||||
|
"keyup":
|
||||||
|
should_trigger = not key_event.pressed
|
||||||
|
"keypress":
|
||||||
|
should_trigger = key_event.pressed
|
||||||
|
|
||||||
|
if should_trigger:
|
||||||
|
var key_info = {
|
||||||
|
"key": OS.get_keycode_string(key_event.keycode),
|
||||||
|
"keycode": key_event.keycode,
|
||||||
|
"ctrl": key_event.ctrl_pressed,
|
||||||
|
"shift": key_event.shift_pressed,
|
||||||
|
"alt": key_event.alt_pressed,
|
||||||
|
"meta": key_event.meta_pressed,
|
||||||
|
"echo": key_event.echo
|
||||||
|
}
|
||||||
|
_execute_lua_callback(subscription, [key_info])
|
||||||
|
|
||||||
# Event callback handlers
|
# Event callback handlers
|
||||||
func _on_gui_input_mousemove(event: InputEvent, subscription: EventSubscription) -> void:
|
func _on_gui_input_mousemove(event: InputEvent, subscription: EventSubscription) -> void:
|
||||||
if not event_subscriptions.has(subscription.id):
|
if not event_subscriptions.has(subscription.id):
|
||||||
|
|||||||
@@ -86,6 +86,21 @@ static func connect_element_event(signal_node: Node, event_name: String, subscri
|
|||||||
subscription.connected_signal = "focus_exited"
|
subscription.connected_signal = "focus_exited"
|
||||||
subscription.connected_node = signal_node
|
subscription.connected_node = signal_node
|
||||||
return true
|
return true
|
||||||
|
"keydown", "keypress", "keyup":
|
||||||
|
if signal_node is Control:
|
||||||
|
var already_connected = false
|
||||||
|
for existing_id in subscription.lua_api.event_subscriptions:
|
||||||
|
var existing_sub = subscription.lua_api.event_subscriptions[existing_id]
|
||||||
|
if existing_sub.connected_node == signal_node and existing_sub.connected_signal == "gui_input_keys":
|
||||||
|
already_connected = true
|
||||||
|
break
|
||||||
|
|
||||||
|
if not already_connected:
|
||||||
|
signal_node.gui_input.connect(subscription.lua_api._on_gui_input_keys_universal.bind(signal_node))
|
||||||
|
|
||||||
|
subscription.connected_signal = "gui_input_keys"
|
||||||
|
subscription.connected_node = signal_node
|
||||||
|
return true
|
||||||
"change":
|
"change":
|
||||||
# Check for DateButton first before generic button signals
|
# Check for DateButton first before generic button signals
|
||||||
if is_date_button(signal_node):
|
if is_date_button(signal_node):
|
||||||
@@ -246,6 +261,9 @@ static func disconnect_subscription(subscription, lua_api) -> void:
|
|||||||
"gui_input_focus":
|
"gui_input_focus":
|
||||||
if target_node.has_signal("gui_input"):
|
if target_node.has_signal("gui_input"):
|
||||||
target_node.gui_input.disconnect(lua_api._on_focus_gui_input.bind(subscription))
|
target_node.gui_input.disconnect(lua_api._on_focus_gui_input.bind(subscription))
|
||||||
|
"gui_input_keys":
|
||||||
|
if target_node.has_signal("gui_input"):
|
||||||
|
target_node.gui_input.disconnect(lua_api._on_gui_input_keys_universal.bind(target_node))
|
||||||
"mouse_entered":
|
"mouse_entered":
|
||||||
if target_node.has_signal("mouse_entered"):
|
if target_node.has_signal("mouse_entered"):
|
||||||
# Check if this is a body event or element event
|
# Check if this is a body event or element event
|
||||||
|
|||||||
Reference in New Issue
Block a user