a40aa57f70
All Items are added in BP with the values they are meant to have. Starting to now actually implement them into the inventory UI and creating the Inventory UI
62 lines
1.2 KiB
C++
62 lines
1.2 KiB
C++
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
#include "InventoryComponent.h"
|
|
#include "Items/BaseItem.h"
|
|
|
|
|
|
|
|
|
|
// Sets default values for this component's properties
|
|
UInventoryComponent::UInventoryComponent()
|
|
{
|
|
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
|
|
// off to improve performance if you don't need them.
|
|
PrimaryComponentTick.bCanEverTick = true;
|
|
|
|
MaxItemSlots = 10;
|
|
}
|
|
|
|
|
|
// Called when the game starts
|
|
void UInventoryComponent::BeginPlay()
|
|
{
|
|
Super::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)
|
|
{
|
|
return false;
|
|
}
|
|
BaseItem->StoredItems = this;
|
|
BaseItem->World = GetWorld();
|
|
Items.Add(BaseItem);
|
|
|
|
//Update UI
|
|
OnInventoryUpdated.Broadcast();
|
|
|
|
return true;
|
|
}
|
|
|
|
bool UInventoryComponent::Remove(UBaseItem* BaseItem)
|
|
{
|
|
if(BaseItem)
|
|
{
|
|
BaseItem->StoredItems = nullptr;
|
|
BaseItem->World = nullptr;
|
|
Items.RemoveSingle(BaseItem);
|
|
OnInventoryUpdated.Broadcast(); // Updates UI
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|