Godot 4.3
Problem! Custom cursor will not click options from OptionButton dropdown menu with joystick. Keyboard works, mouse works.
func _simulate_click_on_control():
var control_under_cursor := _get_control_under_cursor()
if control_under_cursor:
print("Klik na:", control_under_cursor.name)
if control_under_cursor is OptionButton:
control_under_cursor.show_popup()
return
if control_under_cursor is CheckBox:
control_under_cursor.button_pressed = not control_under_cursor\
.button_pressed
control_under_cursor.emit_signal("toggled", control_under_cursor\
.button_pressed)
return
if control_under_cursor is Button or control_under_cursor is TextureButton:
# Ako je dugme (uključujući TextureButton), direktno šaljemo pressed signal
control_under_cursor.emit_signal("pressed")
return
# Napravi klik event
var click_event := InputEventMouseButton.new()
click_event.position = control_under_cursor.get_global_transform().affine_inverse() * cursor_position
click_event.global_position = cursor_position
click_event.button_index = MOUSE_BUTTON_LEFT
click_event.pressed = true
click_event.button_mask = MOUSE_BUTTON_MASK_LEFT
click_event.double_click = false
# Šalji klik kroz gui_input
control_under_cursor.propagate_call("gui_input", [click_event])
# Odmah šalji release
click_event.pressed = false
click_event.button_mask = 0
control_under_cursor.propagate_call("gui_input", [click_event])
else:
print("Nema kontrole ispod kursora za klik.")
# Vrati kontrolu preko koje se nalazi kursor (za hover efekat)
func _get_control_under_cursor() -> Control:
var candidates: Array[Control] = []
for node in get_tree().get_nodes_in_group("ui"):
# Provera da li je node Control i da li je validan
if node is Control and is_instance_valid(node):
# Provera da li node postoji u sceni i da li je vidljiv
if node.is_visible_in_tree():
if node.mouse_filter != Control.MOUSE_FILTER_IGNORE:
if node.get_global_rect().has_point(cursor_position):
candidates.append(node)
if candidates.is_empty():
return null
# Sortiranje po z_index da uzmemo najviši element
candidates.sort_custom(func(a, b):
return a.z_index > b.z_index)
return candidates[0]