add left/right controls to inv ui
This commit is contained in:
parent
32be032c4a
commit
c56b89db84
4 changed files with 33 additions and 13 deletions
|
@ -16,7 +16,7 @@ anchor_bottom = 1.0
|
|||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_qw0r6")
|
||||
action = "inventory"
|
||||
action_name = &"inventory"
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="."]
|
||||
layout_mode = 1
|
||||
|
|
|
@ -4,13 +4,12 @@ signal pressed(toggle_state: bool)
|
|||
signal released(toggle_state: bool)
|
||||
|
||||
@export var toggle_state: bool
|
||||
|
||||
@export var action: String
|
||||
@export var action_name: StringName
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed(action):
|
||||
if event.is_action_pressed(action_name):
|
||||
self.toggle_state = !toggle_state
|
||||
pressed.emit(toggle_state)
|
||||
|
||||
if event.is_action_released(action):
|
||||
if event.is_action_released(action_name):
|
||||
released.emit(toggle_state)
|
||||
|
|
|
@ -5,3 +5,9 @@ class_name InventoryUI extends VBoxContainer
|
|||
|
||||
func _ready() -> void:
|
||||
item_list.add_items(inventory.items)
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed(PlayerInput.UIAction.Right):
|
||||
item_list.move_right()
|
||||
elif event.is_action_pressed(PlayerInput.UIAction.Left):
|
||||
item_list.move_left()
|
||||
|
|
|
@ -6,12 +6,27 @@ enum Device {
|
|||
Gamepad
|
||||
}
|
||||
|
||||
class Action:
|
||||
class GameAction:
|
||||
static var Run = 'run'
|
||||
static var Interact = 'interact'
|
||||
static var Ready = 'ready'
|
||||
static var Fire = 'fire'
|
||||
|
||||
class UIAction:
|
||||
static var Accept = 'ui_accept'
|
||||
static var Select = 'ui_select'
|
||||
static var Cancel = 'ui_cancel'
|
||||
static var FocusNext = 'ui_focus_next'
|
||||
static var FocusPrev = 'ui_focus_prev'
|
||||
static var Left = 'ui_left'
|
||||
static var Right = 'ui_right'
|
||||
static var Up = 'ui_up'
|
||||
static var Down = 'ui_down'
|
||||
static var PageUp = 'ui_page_up'
|
||||
static var PageDown = 'ui_page_down'
|
||||
static var Home = 'ui_home'
|
||||
static var End = 'ui_end'
|
||||
|
||||
signal walk
|
||||
signal run
|
||||
signal interact
|
||||
|
@ -82,7 +97,7 @@ var _analog_dir: Vector2:
|
|||
).normalized()
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
is_running = Input.is_action_pressed(Action.Run)
|
||||
is_running = Input.is_action_pressed(GameAction.Run)
|
||||
|
||||
func _get_device(event: InputEvent) -> Device:
|
||||
if event is InputEventMouse or event is InputEventKey:
|
||||
|
@ -95,22 +110,22 @@ func _get_device(event: InputEvent) -> Device:
|
|||
func _input(event: InputEvent) -> void:
|
||||
last_known_device = _get_device(event)
|
||||
|
||||
if event.is_action_pressed(Action.Interact):
|
||||
if event.is_action_pressed(GameAction.Interact):
|
||||
is_interacting = true
|
||||
|
||||
if event.is_action_released(Action.Interact):
|
||||
if event.is_action_released(GameAction.Interact):
|
||||
is_interacting = false
|
||||
|
||||
if event.is_action_pressed(Action.Ready):
|
||||
if event.is_action_pressed(GameAction.Ready):
|
||||
is_weapon_ready = true
|
||||
|
||||
if event.is_action_released(Action.Ready):
|
||||
if event.is_action_released(GameAction.Ready):
|
||||
is_weapon_ready = false
|
||||
|
||||
if event.is_action_pressed(Action.Fire):
|
||||
if event.is_action_pressed(GameAction.Fire):
|
||||
is_firing = true
|
||||
|
||||
if event.is_action_released(Action.Fire):
|
||||
if event.is_action_released(GameAction.Fire):
|
||||
is_firing = false
|
||||
|
||||
func next_velocity(speed: float, dir: Vector2 = movement_dir) -> Vector3:
|
||||
|
|
Loading…
Add table
Reference in a new issue