From c56b89db845d97fa027e6e23feee5280de2b542a Mon Sep 17 00:00:00 2001 From: rowan Date: Thu, 12 Jun 2025 17:25:20 -0400 Subject: [PATCH] add left/right controls to inv ui --- godot/scenes/inventory.tscn | 2 +- godot/src/input_listener.gd | 7 +++---- godot/src/inventory_ui.gd | 6 ++++++ godot/src/player_input.gd | 31 +++++++++++++++++++++++-------- 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/godot/scenes/inventory.tscn b/godot/scenes/inventory.tscn index df731b5..5e66e32 100644 --- a/godot/scenes/inventory.tscn +++ b/godot/scenes/inventory.tscn @@ -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 diff --git a/godot/src/input_listener.gd b/godot/src/input_listener.gd index 6dcbbc9..2b49c25 100644 --- a/godot/src/input_listener.gd +++ b/godot/src/input_listener.gd @@ -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) diff --git a/godot/src/inventory_ui.gd b/godot/src/inventory_ui.gd index f8c85e0..2feeafa 100644 --- a/godot/src/inventory_ui.gd +++ b/godot/src/inventory_ui.gd @@ -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() diff --git a/godot/src/player_input.gd b/godot/src/player_input.gd index 393739a..5d19272 100644 --- a/godot/src/player_input.gd +++ b/godot/src/player_input.gd @@ -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: