Pickup an intentory item. As well as inventory selection UI.

This commit is contained in:
Dustin 2025-04-06 13:45:47 -07:00
parent 8e8ec8e759
commit 2f6b085dec
7 changed files with 83 additions and 5 deletions

View File

@ -7,6 +7,7 @@ extends Node
var player_position: Vector2
var player_health: int
var player_stamina: int
var player_inventory: InventoryManager
# Called when the node enters the scene tree for the first time.
func _ready():

View File

@ -19,7 +19,8 @@ func _ready():
add_child(item_sprite)
item_sprite.play()
func trigger_interaction():
queue_free()
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):

View File

@ -6,13 +6,21 @@ export var player_number: int = 1
# var a = 2
# var b = "text"
onready var player_inventory :InventoryManager = InventoryManager.new()
#var mushroom :Item = preload("res://assets/items/doodad.tres")
# Called when the node enters the scene tree for the first time.
func _ready():
PlayerInfo.player_health = $Health_Component.health
PlayerInfo.player_inventory = player_inventory
# Set initial player position in world.
global_position = LevelInfo.player_start_position
# player_inventory.add_to_inventory(mushroom)
# player_inventory.select_primary(mushroom)
# Called every frame. 'delta' is the elapsed time since the previous frame.
@ -46,4 +54,8 @@ func touch_the_thing(the_thing: Interactable) -> bool:
transform.x.x = movement_component.LEFT
movement_state_machine.change_to_known_state('enter_right')
the_thing.trigger_interaction()
if the_thing is ItemPickup:
player_inventory.add_to_inventory(the_thing.item)
player_inventory.select_primary(the_thing.item)
the_thing.trigger_interaction()
return true

View File

@ -1,5 +1,10 @@
class_name InventoryManager
extends Resource
## Currently doing this in a weird way where the inventory items are the
## dictionary keys. This would make world inventory items ownable
## by the resourse itself. At least that's what I think. We'll see.
## I'm interested in an approach where the game world items aren't
## duplicated.
# Declare member variables here. Examples:
@ -16,6 +21,14 @@ var _items :Dictionary
func _ready():
pass # Replace with function body.
func select_primary(_item :Item) -> void:
if _items.has(_item):
primary_selection = _item
func select_secondary(_item :Item) -> void:
if _items.has(_item):
secondary_selection = _item
func add_to_inventory(_item :Item) -> int:
if _items.has(_item):
_items[_item] += 1

View File

@ -14,7 +14,11 @@ onready var DialogContainerText = $PanelContainer/HSplitContainer/Label
onready var DialogIndicator = $PanelContainer/Polygon2D
onready var HUD = $HealthBar
onready var health_bar = $HealthBar
## Cool I can bring this in with a ctrl drag
onready var selected_inventory_items = $"%SelectedInventoryItems"
var current_pane
@ -39,11 +43,11 @@ func _process(delta):
print("UI Switch detected")
current_pane = UiManager.current_pane
DialogContainer.visible = false
HUD.visible = false
health_bar.visible = false
match current_pane:
UiManager.UI_PANES.HUD:
print("Enable HUD")
HUD.visible = true
health_bar.visible = true
UiManager.UI_PANES.DIALOG:
print("Enable Dialog")
DialogContainerPortrait.texture = UiManager.dialog_portrait

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=8 format=2]
[gd_scene load_steps=9 format=2]
[ext_resource path="res://icon.png" type="Texture" id=1]
[ext_resource path="res://assets/Fonts/QuinqueFive.tres" type="DynamicFont" id=2]
@ -7,6 +7,7 @@
[ext_resource path="res://src/ui/HealthBar.gd" type="Script" id=5]
[ext_resource path="res://assets/UI/Healthbar-Indicator.png" type="Texture" id=6]
[ext_resource path="res://assets/UI/Staminabar-Indicator.png" type="Texture" id=7]
[ext_resource path="res://src/ui/SelectedInventoryItems.gd" type="Script" id=8]
[node name="HUD" type="CanvasLayer"]
pause_mode = 2
@ -96,3 +97,30 @@ margin_bottom = 40.0
margin_left = 13.0
margin_right = 40.0
margin_bottom = 40.0
[node name="SelectedInventoryItems" type="GridContainer" parent="."]
unique_name_in_owner = true
anchor_top = 1.0
anchor_bottom = 1.0
margin_left = 2.0
margin_top = -18.0
margin_right = 38.0
columns = 2
script = ExtResource( 8 )
[node name="Panel" type="Panel" parent="SelectedInventoryItems"]
margin_right = 16.0
margin_bottom = 18.0
size_flags_horizontal = 3
size_flags_vertical = 3
[node name="PrimaryItem" type="TextureRect" parent="SelectedInventoryItems/Panel"]
[node name="Panel2" type="Panel" parent="SelectedInventoryItems"]
margin_left = 20.0
margin_right = 36.0
margin_bottom = 18.0
size_flags_horizontal = 3
size_flags_vertical = 3
[node name="SecondaryItem" type="TextureRect" parent="SelectedInventoryItems/Panel2"]

View File

@ -0,0 +1,19 @@
extends GridContainer
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
onready var primary_item = $Panel/PrimaryItem
onready var secondary_item = $Panel2/SecondaryItem
# Called when the node enters the scene tree for the first time.
func _ready():
pass
#secondary_item.texture = PlayerInfo.player_inventory.secondary_selection.inventory_icon
func _process(delta):
if (PlayerInfo.player_inventory.primary_selection):
primary_item.texture = PlayerInfo.player_inventory.primary_selection.inventory_icon