Arrange fleet abilities around fire stick
This commit is contained in:
parent
cb6b0b69c6
commit
9864e59efc
8 changed files with 156 additions and 7 deletions
49
ui/AbilityButtonLayout.gd
Normal file
49
ui/AbilityButtonLayout.gd
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
class_name AbilityButtonLayout
|
||||
extends Node
|
||||
|
||||
# Keeps the aimed fleet abilities close to the firing thumb. One ability sits
|
||||
# directly above the fire stick; multiple abilities fan through its upper-left
|
||||
# quadrant instead of becoming a detached horizontal toolbar.
|
||||
|
||||
@export var arc_radius: float = 280.0
|
||||
|
||||
@onready var fire_stick: Control = get_node("../UI/FireStick")
|
||||
@onready var buttons: Array = [
|
||||
get_node("../UI/DashButton"),
|
||||
get_node("../UI/GasBombButton"),
|
||||
get_node("../UI/LaserButton"),
|
||||
]
|
||||
|
||||
var visibility_signature: int = -1
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
get_viewport().size_changed.connect(_layout_visible_buttons)
|
||||
_layout_visible_buttons.call_deferred()
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
var signature: int = 0
|
||||
for i in range(buttons.size()):
|
||||
if buttons[i].visible:
|
||||
signature |= 1 << i
|
||||
if signature == visibility_signature:
|
||||
return
|
||||
visibility_signature = signature
|
||||
_layout_visible_buttons()
|
||||
|
||||
|
||||
func _layout_visible_buttons() -> void:
|
||||
var visible_buttons: Array = buttons.filter(func(button): return button.visible)
|
||||
if visible_buttons.is_empty():
|
||||
return
|
||||
var center: Vector2 = fire_stick.global_position + fire_stick.size * 0.5
|
||||
for i in range(visible_buttons.size()):
|
||||
# Screen coordinates grow downward: PI points left and 3*PI/2 points
|
||||
# upward, tracing exactly the useful quarter around a bottom-right stick.
|
||||
var weight: float = 1.0 if visible_buttons.size() == 1 \
|
||||
else float(i) / float(visible_buttons.size() - 1)
|
||||
var angle: float = lerpf(PI, PI * 1.5, weight)
|
||||
var button: Control = visible_buttons[i]
|
||||
button.global_position = center + Vector2.from_angle(angle) * arc_radius \
|
||||
- button.size * 0.5
|
||||
Loading…
Reference in a new issue