Add controller ui

This commit is contained in:
2026-06-11 20:19:15 -05:00
parent 619bf09ab9
commit 456ea1e07e
6 changed files with 98 additions and 17 deletions
+22 -13
View File
@@ -15,24 +15,33 @@ enum Action {
signal action(action:Action)
func _ready() -> void:
btnAttack.pressed.connect(func():
action.emit(Action.ATTACK)
)
btnMagic.pressed.connect(func():
action.emit(Action.MAGIC)
)
btnItem.pressed.connect(func():
action.emit(Action.ITEM)
)
btnBack.pressed.connect(func():
action.emit(Action.BACK)
)
btnAttack.pressed.connect(func(): action.emit(Action.ATTACK))
btnMagic.pressed.connect(func(): action.emit(Action.MAGIC))
btnItem.pressed.connect(func(): action.emit(Action.ITEM))
btnBack.pressed.connect(func(): action.emit(Action.BACK))
self.visible = false
func _unhandled_input(event:InputEvent) -> void:
if !visible:
return
if event.is_action_pressed("ui_cancel"):
action.emit(Action.BACK)
get_viewport().set_input_as_handled()
func getAction(fighter:BattleFighter) -> Action:
btnAttack.disabled = fighter.movePrimary == null || !fighter.movePrimary.canFighterUse(fighter)
btnMagic.disabled = fighter.movesMagical.size() == 0
btnItem.disabled = false # TODO: check if items available?
btnItem.disabled = false
# Focus the first available button so the controller can navigate immediately.
if !btnAttack.disabled:
btnAttack.grab_focus()
elif !btnMagic.disabled:
btnMagic.grab_focus()
elif !btnItem.disabled:
btnItem.grab_focus()
else:
btnBack.grab_focus()
var act = await action
return act