Add controller ui
This commit is contained in:
@@ -15,24 +15,33 @@ enum Action {
|
|||||||
signal action(action:Action)
|
signal action(action:Action)
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
btnAttack.pressed.connect(func():
|
btnAttack.pressed.connect(func(): action.emit(Action.ATTACK))
|
||||||
action.emit(Action.ATTACK)
|
btnMagic.pressed.connect(func(): action.emit(Action.MAGIC))
|
||||||
)
|
btnItem.pressed.connect(func(): action.emit(Action.ITEM))
|
||||||
btnMagic.pressed.connect(func():
|
btnBack.pressed.connect(func(): action.emit(Action.BACK))
|
||||||
action.emit(Action.MAGIC)
|
|
||||||
)
|
|
||||||
btnItem.pressed.connect(func():
|
|
||||||
action.emit(Action.ITEM)
|
|
||||||
)
|
|
||||||
btnBack.pressed.connect(func():
|
|
||||||
action.emit(Action.BACK)
|
|
||||||
)
|
|
||||||
self.visible = false
|
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:
|
func getAction(fighter:BattleFighter) -> Action:
|
||||||
btnAttack.disabled = fighter.movePrimary == null || !fighter.movePrimary.canFighterUse(fighter)
|
btnAttack.disabled = fighter.movePrimary == null || !fighter.movePrimary.canFighterUse(fighter)
|
||||||
btnMagic.disabled = fighter.movesMagical.size() == 0
|
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
|
var act = await action
|
||||||
return act
|
return act
|
||||||
|
|||||||
@@ -138,6 +138,47 @@ camera_orbit_down={
|
|||||||
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":1.0,"script":null)
|
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":1.0,"script":null)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
ui_accept={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194309,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||||
|
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":32,"physical_keycode":0,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null)
|
||||||
|
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
ui_cancel={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194305,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||||
|
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":1,"pressure":0.0,"pressed":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
ui_up={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194320,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||||
|
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":11,"pressure":0.0,"pressed":false,"script":null)
|
||||||
|
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":-1.0,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
ui_down={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194322,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||||
|
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":12,"pressure":0.0,"pressed":false,"script":null)
|
||||||
|
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":1.0,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
ui_left={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194319,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||||
|
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":13,"pressure":0.0,"pressed":false,"script":null)
|
||||||
|
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":-1.0,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
ui_right={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194321,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||||
|
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":14,"pressure":0.0,"pressed":false,"script":null)
|
||||||
|
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":1.0,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
[internationalization]
|
[internationalization]
|
||||||
|
|
||||||
|
|||||||
+17
-1
@@ -8,11 +8,27 @@ class_name MainMenu extends Control
|
|||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
btnNewGame.pressed.connect(onNewGamePressed)
|
btnNewGame.pressed.connect(onNewGamePressed)
|
||||||
btnSettings.pressed.connect(onSettingsPressed)
|
btnSettings.pressed.connect(onSettingsPressed)
|
||||||
|
settingsMenu.opened.connect(_onSettingsOpened)
|
||||||
|
settingsMenu.closed.connect(_onSettingsClosed)
|
||||||
|
btnNewGame.grab_focus()
|
||||||
|
|
||||||
|
func _onSettingsOpened() -> void:
|
||||||
|
# Move focus into the settings panel so the controller can navigate it.
|
||||||
|
# The SettingsMenu grabs its own internal focus via _notification.
|
||||||
|
pass
|
||||||
|
|
||||||
|
func _onSettingsClosed() -> void:
|
||||||
|
btnSettings.grab_focus()
|
||||||
|
|
||||||
|
func _unhandled_input(event:InputEvent) -> void:
|
||||||
|
if event.is_action_pressed("ui_cancel"):
|
||||||
|
if settingsMenu.isOpen:
|
||||||
|
settingsMenu.close()
|
||||||
|
get_viewport().set_input_as_handled()
|
||||||
|
|
||||||
func onNewGamePressed() -> void:
|
func onNewGamePressed() -> void:
|
||||||
SCENE.setScene(SceneSingleton.SceneType.OVERWORLD)
|
SCENE.setScene(SceneSingleton.SceneType.OVERWORLD)
|
||||||
OVERWORLD.mapChange(newGameScene, "PlayerSpawnPoint")
|
OVERWORLD.mapChange(newGameScene, "PlayerSpawnPoint")
|
||||||
|
|
||||||
func onSettingsPressed() -> void:
|
func onSettingsPressed() -> void:
|
||||||
print("Settings button pressed")
|
|
||||||
settingsMenu.isOpen = true
|
settingsMenu.isOpen = true
|
||||||
|
|||||||
@@ -4,11 +4,12 @@ func _ready() -> void:
|
|||||||
visible = false
|
visible = false
|
||||||
$HBoxContainer/ItemList.item_selected.connect(onItemSelected)
|
$HBoxContainer/ItemList.item_selected.connect(onItemSelected)
|
||||||
|
|
||||||
func open():
|
func open() -> void:
|
||||||
visible = true
|
visible = true
|
||||||
$HBoxContainer/ItemList.clear()
|
$HBoxContainer/ItemList.clear()
|
||||||
|
$HBoxContainer/ItemList.grab_focus()
|
||||||
|
|
||||||
func close():
|
func close() -> void:
|
||||||
visible = false
|
visible = false
|
||||||
|
|
||||||
func isOpen() -> bool:
|
func isOpen() -> bool:
|
||||||
|
|||||||
@@ -17,3 +17,14 @@ func close() -> void:
|
|||||||
visible = false
|
visible = false
|
||||||
MAIN.close()
|
MAIN.close()
|
||||||
SETTINGS.close()
|
SETTINGS.close()
|
||||||
|
|
||||||
|
func _unhandled_input(event:InputEvent) -> void:
|
||||||
|
if !visible:
|
||||||
|
return
|
||||||
|
if event.is_action_pressed("ui_cancel"):
|
||||||
|
if SETTINGS.isOpen():
|
||||||
|
SETTINGS.close()
|
||||||
|
MAIN.open()
|
||||||
|
else:
|
||||||
|
close()
|
||||||
|
get_viewport().set_input_as_handled()
|
||||||
|
|||||||
@@ -7,9 +7,12 @@ func _ready() -> void:
|
|||||||
tabs.tab_changed.connect(onTabChanged)
|
tabs.tab_changed.connect(onTabChanged)
|
||||||
onTabChanged(tabs.current_tab)
|
onTabChanged(tabs.current_tab)
|
||||||
|
|
||||||
|
func _notification(what:int) -> void:
|
||||||
|
if what == NOTIFICATION_VISIBILITY_CHANGED and visible:
|
||||||
|
tabs.grab_focus()
|
||||||
|
|
||||||
func onTabChanged(tabIndex:int) -> void:
|
func onTabChanged(tabIndex:int) -> void:
|
||||||
for control in tabControls:
|
for control in tabControls:
|
||||||
control.visible = false
|
control.visible = false
|
||||||
|
|
||||||
if tabIndex >= 0 and tabIndex < tabControls.size():
|
if tabIndex >= 0 and tabIndex < tabControls.size():
|
||||||
tabControls[tabIndex].visible = true
|
tabControls[tabIndex].visible = true
|
||||||
|
|||||||
Reference in New Issue
Block a user