promiscuity/game/scenes/Interaction/RadialCommandMenu.gd
null ffee63dc57
All checks were successful
Deploy Promiscuity Auth API / deploy (push) Successful in 1m0s
Deploy Promiscuity Character API / deploy (push) Successful in 1m1s
Deploy Promiscuity Crafting API / deploy (push) Successful in 1m0s
Deploy Promiscuity Inventory API / deploy (push) Successful in 1m0s
Deploy Promiscuity Locations API / deploy (push) Successful in 1m0s
Deploy Promiscuity Mail API / deploy (push) Successful in 1m1s
Deploy Promiscuity World API / deploy (push) Successful in 1m1s
k8s smoke test / test (push) Successful in 21s
feat: change camera rotation to be always active when mouse is captured
2026-05-12 17:19:34 -05:00

61 lines
1.7 KiB
GDScript

extends Control
@export var radius: float = 150.0
@export var transition_speed: float = 0.2
func _ready():
hide() # Start hidden
_arrange_buttons()
func _input(event):
if event.is_action_pressed("OpenRadialCommandMenu"): # Map 'Q' to "open_menu" in Input Map
_toggle_menu()
func _toggle_menu():
visible = !visible
if visible:
# Center the menu on the mouse or screen
global_position = get_viewport().get_mouse_position()
_animate_menu(true)
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
else:
_animate_menu(false)
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _arrange_buttons():
var buttons = get_children().filter(func(child): return child is Control)
var count = buttons.size()
if count == 0:
return
for i in range(count):
# Calculate the angle for each button in radians
var angle = i * (2 * PI / count)
# Standard circle math: x = cos(a) * r, y = sin(a) * r
var target_pos = Vector2(cos(angle), sin(angle)) * radius
# Offset by button size to keep them centered
buttons[i].position = target_pos - (buttons[i].size / 2)
func _animate_menu(opening: bool):
var tween = create_tween().set_parallel(true)
for button in get_children().filter(func(child): return child is Control):
var final_scale = Vector2.ONE if opening else Vector2.ZERO
tween.tween_property(button, "scale", final_scale, transition_speed).from(Vector2.ZERO if opening else Vector2.ONE)
func _on_btn_follow_pressed() -> void:
print("Follow command pressed")
_toggle_menu() # Closes the menu after clicking
func _on_btn_go_to_pressed() -> void:
print("Go to command pressed")
_toggle_menu() # Closes the menu after clicking
func _on_btn_attack_pressed() -> void:
print("Attack command pressed")
_toggle_menu() # Closes the menu after clicking