Add controller ui
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user