diff --git a/lib/singleton_autoloads/PlayerInfo.gd b/lib/singleton_autoloads/PlayerInfo.gd index 83765a2..50c753f 100644 --- a/lib/singleton_autoloads/PlayerInfo.gd +++ b/lib/singleton_autoloads/PlayerInfo.gd @@ -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(): diff --git a/src/Interactables/ItemPickup.gd b/src/Interactables/ItemPickup.gd index 9c38c66..010bedc 100644 --- a/src/Interactables/ItemPickup.gd +++ b/src/Interactables/ItemPickup.gd @@ -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): diff --git a/src/actors/players/playerE/PlayerE.gd b/src/actors/players/playerE/PlayerE.gd index 370a277..cc67e85 100644 --- a/src/actors/players/playerE/PlayerE.gd +++ b/src/actors/players/playerE/PlayerE.gd @@ -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 diff --git a/src/classes/inventory_manager.gd b/src/classes/inventory_manager.gd index 6c263c7..f35c458 100644 --- a/src/classes/inventory_manager.gd +++ b/src/classes/inventory_manager.gd @@ -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: @@ -15,6 +20,14 @@ var _items :Dictionary # Called when the node enters the scene tree for the first time. 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): diff --git a/src/ui/HUD.gd b/src/ui/HUD.gd index 757c3bf..a31677e 100644 --- a/src/ui/HUD.gd +++ b/src/ui/HUD.gd @@ -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 diff --git a/src/ui/HUD.tscn b/src/ui/HUD.tscn index e261e20..fceaaf2 100644 --- a/src/ui/HUD.tscn +++ b/src/ui/HUD.tscn @@ -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"] diff --git a/src/ui/SelectedInventoryItems.gd b/src/ui/SelectedInventoryItems.gd new file mode 100644 index 0000000..87cbdff --- /dev/null +++ b/src/ui/SelectedInventoryItems.gd @@ -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 +