Improve Android controller support

This commit is contained in:
Alexander Sellite 2026-08-03 09:31:13 -04:00
parent b47f131797
commit 9c89116713
16 changed files with 647 additions and 31 deletions

View file

@ -13,10 +13,12 @@ const SECTOR_COUNT: int = 8
const SIT_SECTOR: int = 0
const RING_RADIUS: float = 172.0
const BUBBLE_SIZE: Vector2 = Vector2(92.0, 88.0)
const CONTROLLER_SELECTION_DEADZONE: float = 0.35
var _buttons: Array[BubbleButton] = []
var _is_open: bool = false
var _selected_sector: int = SIT_SECTOR
var _controller_selection_mode: bool = false
func _ready() -> void:
@ -42,7 +44,7 @@ func handle_input(event: InputEvent, can_open: bool) -> bool:
if event.is_pressed():
if _is_open or not can_open:
return _is_open
open_menu()
open_menu(event is InputEventJoypadButton)
return true
if not _is_open:
return false
@ -53,9 +55,10 @@ func handle_input(event: InputEvent, can_open: bool) -> bool:
return true
func open_menu() -> void:
func open_menu(controller_selection: bool = false) -> void:
_is_open = true
_selected_sector = SIT_SECTOR
_controller_selection_mode = controller_selection
visible = true
_layout_bubbles()
_apply_selection_styles()
@ -74,7 +77,7 @@ func _process(_delta: float) -> void:
if not _is_open:
return
_layout_bubbles()
_update_mouse_selection()
_update_selection()
func _layout_bubbles() -> void:
@ -88,10 +91,27 @@ func _layout_bubbles() -> void:
bubble.pivot_offset = BUBBLE_SIZE * 0.5
func _update_selection() -> void:
var stick: Vector2 = Vector2(
Input.get_joy_axis(0, JOY_AXIS_RIGHT_X),
Input.get_joy_axis(0, JOY_AXIS_RIGHT_Y),
)
if stick.length() >= CONTROLLER_SELECTION_DEADZONE:
_select_sector_from_offset(stick)
return
if _controller_selection_mode:
return
_update_mouse_selection()
func _update_mouse_selection() -> void:
var offset: Vector2 = get_local_mouse_position() - size * 0.5
if offset.length() < 24.0:
return
_select_sector_from_offset(offset)
func _select_sector_from_offset(offset: Vector2) -> void:
var angle: float = fposmod(offset.angle() + PI * 0.5 + PI / 8.0, TAU)
var sector: int = int(floor(angle / (TAU / float(SECTOR_COUNT))))
if sector == _selected_sector: