Updated InventoryComponent and Shop

Fixed InventoryComponent to now work with singular items so you can purchase items from the shop!
This commit is contained in:
MH261677 2022-11-18 13:07:44 +00:00
parent 0c0876770b
commit 900feee5a9
9 changed files with 33 additions and 19 deletions

Binary file not shown.

BIN
Content/Blueprints/BP_Interaction.uasset (Stored with Git LFS)

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Content/Levels/MerchantPrototype.umap (Stored with Git LFS)

Binary file not shown.

View File

@ -25,30 +25,32 @@ void UInventoryComponent::BeginPlay()
for(auto & BaseItem : DefaultItems)
{
AddItem(BaseItem);
}
}
}
}
bool UInventoryComponent::AddItem(class UBaseItem* BaseItem)
{
//if the items is over the maxinventoryslots then it wont add the item
if (Items.Num() >= MaxItemSlots || !BaseItem)
{
UE_LOG(LogTemp, Display, TEXT("THERE ARE MORE ITEMS THAN THE INVENTORY SLOTS"));
return false;
}
BaseItem->StoredItems = this;
BaseItem->World = GetWorld();
Items.Add(BaseItem);
UE_LOG(LogTemp, Display, TEXT("ITEM HAS BEEN ADDED"));
//Update UI
OnInventoryUpdated.Broadcast();
return true;
}
bool UInventoryComponent::Remove(UBaseItem* BaseItem)
bool UInventoryComponent::Remove(class UBaseItem* BaseItem)
{
if(BaseItem)
{
UE_LOG(LogTemp, Display, TEXT("ItEM HAS BEEN REMOVED"));
BaseItem->StoredItems = nullptr;
BaseItem->World = nullptr;
Items.RemoveSingle(BaseItem);
@ -58,3 +60,8 @@ bool UInventoryComponent::Remove(UBaseItem* BaseItem)
return false;
}
UBaseItem* UInventoryComponent::GetItem(int32 Index)
{
return Items[Index];
}

View File

@ -36,6 +36,9 @@ public:
UPROPERTY(BlueprintAssignable, Category= "Inventory")
FOnInventoryUpdated OnInventoryUpdated; //This is our delegate
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category= "Items")
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category= "Items")
TArray<class UBaseItem*> Items; // The items currently in the inventory
UFUNCTION(BlueprintCallable, Category= "Inventory")
class UBaseItem* GetItem(int32 Index);
};

View File

@ -1,6 +1,8 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "TempCharacter.h"
#include "IDetailTreeNode.h"
#include "Blueprint/UserWidget.h"
#include "the_twilight_abyss/BaseItems/InventoryComponent.h"
#include "the_twilight_abyss/BaseItems/Items/BaseItem.h"
@ -82,9 +84,11 @@ void ATempCharacter::LineTraceLogic()
if(GoldBalance >= 100)
{
GoldBalance -= 100;
Inventory->AddItem(OutHit.GetActor()->FindComponentByClass<UInventoryComponent>()->GetItem(0));
//Inventory->AddItem(Cast<UBaseItem>(OutHit.GetActor()));
//Inventory->AddItem(OutHit.GetActor()->Get("HealingJelly"));
UE_LOG(LogTemp, Display, TEXT("Item Purchased"));
// UInventoryComponent* tempInventory = GetOwner()->FindComponentByClass<UInventoryComponent>();
// tempInventory->AddItem(ItemToBuy);
}
if(GoldBalance <= 0)
{

View File

@ -54,6 +54,6 @@ public:
UFUNCTION(BlueprintCallable, Category= "Items")
void BuyItem(class UBaseItem* BuyItem);
// UPROPERTY(EditAnywhere, Category= "Items")
// UBaseItem ItemToBuy;
UPROPERTY(EditAnywhere, Category= "Items")
UBaseItem* ItemToBuy;
};