UI functionality and visual prototype
This commit is contained in:
		@@ -2,6 +2,7 @@
 | 
			
		||||
 | 
			
		||||
#include "AC_PlayerInventory.h"
 | 
			
		||||
#include "Engine/DataTable.h"
 | 
			
		||||
#include "AC_PlayerStats.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// Sets default values for this component's properties
 | 
			
		||||
@@ -11,6 +12,12 @@ UAC_PlayerInventory::UAC_PlayerInventory()
 | 
			
		||||
	// off to improve performance if you don't need them.
 | 
			
		||||
	PrimaryComponentTick.bCanEverTick = true;
 | 
			
		||||
 | 
			
		||||
	InventoryCapacityPerCategory.Add(EItemType::Weapon, 0);
 | 
			
		||||
	InventoryCapacityPerCategory.Add(EItemType::Armor, 0);
 | 
			
		||||
	InventoryCapacityPerCategory.Add(EItemType::Goods, 0);
 | 
			
		||||
	InventoryCapacityPerCategory.Add(EItemType::None, 0);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	// ...
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -22,6 +29,7 @@ void UAC_PlayerInventory::BeginPlay()
 | 
			
		||||
 | 
			
		||||
	InitializePlayerInventory();
 | 
			
		||||
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
	// ...
 | 
			
		||||
	
 | 
			
		||||
@@ -38,6 +46,7 @@ void UAC_PlayerInventory::TickComponent(float DeltaTime, ELevelTick TickType, FA
 | 
			
		||||
 | 
			
		||||
void UAC_PlayerInventory::InitializePlayerInventory()
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
	for (const FStartingItems& Item : StartingItems)
 | 
			
		||||
	{
 | 
			
		||||
		FString ContextString = TEXT("Initialize Player Inventory");
 | 
			
		||||
@@ -78,14 +87,37 @@ TArray<FBaseItemInfo> UAC_PlayerInventory::GetPlayerInventory()
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void UAC_PlayerInventory::RequestAddItem(FBaseItemInfo InItemInfo, int32 InItemQuantity)
 | 
			
		||||
void UAC_PlayerInventory::RequestAddItem(FBaseItemInfo InItemInfo, int32 InItemQuantity, AActor* ActorToDelete)
 | 
			
		||||
{
 | 
			
		||||
	for (int32 i = 0; i < InItemQuantity; i++)
 | 
			
		||||
	if (bUseRequiredLevel)
 | 
			
		||||
	{
 | 
			
		||||
		PlayerInventory.Add(InItemInfo);
 | 
			
		||||
		InventoryCurrentCapacity++;
 | 
			
		||||
	}
 | 
			
		||||
		//Using required level so perform checks
 | 
			
		||||
		UAC_PlayerStats* PlayerStatsComponent = GetOwner()->GetWorld()->GetFirstPlayerController()->GetPawn()->FindComponentByClass<UAC_PlayerStats>();
 | 
			
		||||
		if (InItemInfo.RequiredLevel <= GetOwner()->GetWorld()->GetFirstPlayerController()->GetPawn()->FindComponentByClass<UAC_PlayerStats>()->PlayerLevel)
 | 
			
		||||
		{
 | 
			
		||||
 | 
			
		||||
			for (int32 i = 0; i < InItemQuantity; i++)
 | 
			
		||||
			{
 | 
			
		||||
				PlayerInventory.Add(InItemInfo);
 | 
			
		||||
				InventoryCurrentCapacity++;
 | 
			
		||||
				ActorToDelete->Destroy();
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		else {
 | 
			
		||||
			UE_LOG(LogTemp, Warning, TEXT("Item Required Level is higher than Players current level"))
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	else {
 | 
			
		||||
		
 | 
			
		||||
		//Not using required level so just add item
 | 
			
		||||
 | 
			
		||||
		for (int32 i = 0; i < InItemQuantity; i++)
 | 
			
		||||
		{
 | 
			
		||||
			PlayerInventory.Add(InItemInfo);
 | 
			
		||||
			InventoryCurrentCapacity++;
 | 
			
		||||
			ActorToDelete->Destroy();
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TArray<FBaseItemInfo> UAC_PlayerInventory::GetAllInventoryItemsInCategory(EItemType InItemType)
 | 
			
		||||
 
 | 
			
		||||
@@ -52,9 +52,9 @@ void UBPFL_EpicInventory::RequestInteraction(AActor* InteractingActor)
 | 
			
		||||
				{
 | 
			
		||||
					FBaseItemInfo* LocItemInfo = DTRow.ItemDataTableAndRow.DataTable->FindRow<FBaseItemInfo>(DTRow.ItemDataTableAndRow.RowName, FString("Interaction Request"));
 | 
			
		||||
					int32 LocItemQuantity = DTRow.QuantityOfItem;
 | 
			
		||||
					PlayerInventoryComponent->RequestAddItem(*LocItemInfo, LocItemQuantity);
 | 
			
		||||
					PlayerInventoryComponent->RequestAddItem(*LocItemInfo, LocItemQuantity, InteractingActor);
 | 
			
		||||
					UE_LOG(LogTemp, Warning, TEXT("Attempted Add"));
 | 
			
		||||
					InteractingActor->Destroy();
 | 
			
		||||
					
 | 
			
		||||
 | 
			
		||||
				}
 | 
			
		||||
				break;
 | 
			
		||||
@@ -70,28 +70,28 @@ void UBPFL_EpicInventory::RequestInteraction(AActor* InteractingActor)
 | 
			
		||||
					if ((LocItemWeight + LocCurrentCarryWeight) >= LocMaxCarryWeight)
 | 
			
		||||
					{
 | 
			
		||||
						//Item will encumber player so trigger encumberance as well
 | 
			
		||||
						PlayerInventoryComponent->RequestAddItem(*LocItemInfo, LocItemQuantity);
 | 
			
		||||
						PlayerInventoryComponent->RequestAddItem(*LocItemInfo, LocItemQuantity, InteractingActor);
 | 
			
		||||
						PlayerStatsComponent->UpdateCurrentCarryWeight();
 | 
			
		||||
						UCharacterMovementComponent* MovementComponent = PlayerCharacter->GetCharacterMovement();
 | 
			
		||||
						MovementComponent->MaxWalkSpeed = 75.0f;
 | 
			
		||||
						InteractingActor->Destroy();
 | 
			
		||||
						
 | 
			
		||||
						UE_LOG(LogTemp, Warning, TEXT("Weight method used"));
 | 
			
		||||
 | 
			
		||||
					}
 | 
			
		||||
					else if ((LocItemWeight + LocCurrentCarryWeight) < LocMaxCarryWeight)
 | 
			
		||||
					{
 | 
			
		||||
						//Item will not encumber player so only add item and update weight
 | 
			
		||||
						PlayerInventoryComponent->RequestAddItem(*LocItemInfo, LocItemQuantity);
 | 
			
		||||
						PlayerInventoryComponent->RequestAddItem(*LocItemInfo, LocItemQuantity, InteractingActor);
 | 
			
		||||
						PlayerStatsComponent->UpdateCurrentCarryWeight();
 | 
			
		||||
						InteractingActor->Destroy();
 | 
			
		||||
						
 | 
			
		||||
						UE_LOG(LogTemp, Warning, TEXT("Weight method used"));
 | 
			
		||||
 | 
			
		||||
					}
 | 
			
		||||
					else {
 | 
			
		||||
						//Item will neither encumber or not encumber player somehow so add item and update weight
 | 
			
		||||
						PlayerInventoryComponent->RequestAddItem(*LocItemInfo, LocItemQuantity);
 | 
			
		||||
						PlayerInventoryComponent->RequestAddItem(*LocItemInfo, LocItemQuantity, InteractingActor);
 | 
			
		||||
						PlayerStatsComponent->UpdateCurrentCarryWeight();
 | 
			
		||||
						InteractingActor->Destroy();
 | 
			
		||||
						
 | 
			
		||||
						UE_LOG(LogTemp, Warning, TEXT("Weight method used"));
 | 
			
		||||
					}
 | 
			
		||||
 | 
			
		||||
@@ -113,15 +113,15 @@ void UBPFL_EpicInventory::RequestInteraction(AActor* InteractingActor)
 | 
			
		||||
					else if ((LocItemQuantity + LocCurrentItemCapacity) <= LocMaxItemCapacity)
 | 
			
		||||
					{
 | 
			
		||||
						//Would not go over max capacity so add item
 | 
			
		||||
						PlayerInventoryComponent->RequestAddItem(*LocItemInfo, LocItemQuantity);
 | 
			
		||||
						PlayerInventoryComponent->RequestAddItem(*LocItemInfo, LocItemQuantity, InteractingActor);
 | 
			
		||||
						UE_LOG(LogTemp, Warning, TEXT("Attempted Add"));
 | 
			
		||||
						InteractingActor->Destroy();
 | 
			
		||||
						
 | 
			
		||||
					}
 | 
			
		||||
					else {
 | 
			
		||||
						//Some weird edgcase where it would not exeed or be less than
 | 
			
		||||
						PlayerInventoryComponent->RequestAddItem(*LocItemInfo, LocItemQuantity);
 | 
			
		||||
						PlayerInventoryComponent->RequestAddItem(*LocItemInfo, LocItemQuantity, InteractingActor);
 | 
			
		||||
						UE_LOG(LogTemp, Warning, TEXT("Attempted Add"));
 | 
			
		||||
						InteractingActor->Destroy();
 | 
			
		||||
						
 | 
			
		||||
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
@@ -142,8 +142,8 @@ void UBPFL_EpicInventory::RequestInteraction(AActor* InteractingActor)
 | 
			
		||||
					else if ((LocItemQuantity + LocCategoryCurrentCapacity) <= *LocCategoryMaxCapacity)
 | 
			
		||||
					{
 | 
			
		||||
						//Item would not exceed category max so add and update capacity
 | 
			
		||||
						PlayerInventoryComponent->RequestAddItem(*LocItemInfo, LocItemQuantity);
 | 
			
		||||
						InteractingActor->Destroy();
 | 
			
		||||
						PlayerInventoryComponent->RequestAddItem(*LocItemInfo, LocItemQuantity, InteractingActor);
 | 
			
		||||
						
 | 
			
		||||
					}
 | 
			
		||||
 | 
			
		||||
				}
 | 
			
		||||
@@ -160,9 +160,9 @@ void UBPFL_EpicInventory::RequestInteraction(AActor* InteractingActor)
 | 
			
		||||
			{
 | 
			
		||||
				FBaseItemInfo* LocItemInfo = DTRow.ItemDataTableAndRow.DataTable->FindRow<FBaseItemInfo>(DTRow.ItemDataTableAndRow.RowName, FString("Interaction Request"));
 | 
			
		||||
				int32 LocItemQuantity = DTRow.QuantityOfItem;
 | 
			
		||||
				PlayerInventoryComponent->RequestAddItem(*LocItemInfo, LocItemQuantity);
 | 
			
		||||
				PlayerInventoryComponent->RequestAddItem(*LocItemInfo, LocItemQuantity, InteractingActor);
 | 
			
		||||
				UE_LOG(LogTemp, Warning, TEXT("Attempted Add"));
 | 
			
		||||
				InteractingActor->Destroy();
 | 
			
		||||
				
 | 
			
		||||
				
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
 
 | 
			
		||||
@@ -24,19 +24,22 @@ public:
 | 
			
		||||
	// Called every frame
 | 
			
		||||
	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
 | 
			
		||||
 | 
			
		||||
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Inventory Configuration")
 | 
			
		||||
	bool bUseRequiredLevel;
 | 
			
		||||
 | 
			
		||||
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Inventory Configuration")
 | 
			
		||||
	bool bUseInventoryCap;
 | 
			
		||||
 | 
			
		||||
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Inventory Configuration", meta = (EditCondition = "bUseInventoryCap", EditConditionHides, Tooltip = "Select the type of inventory cap. WEIGHT uses item weight, TOTAL uses total number of items, TOTAL PER CATEGORY uses a cap per category of inventory item"))
 | 
			
		||||
	EInventoryCapType InventoryCapType;
 | 
			
		||||
 | 
			
		||||
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Inventory Configuration", meta = (EditCondition = "InventoryCapType == EInventoryCapType::TotalItems", EditConditionHides))
 | 
			
		||||
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Inventory Configuration", meta = (EditCondition = "InventoryCapType == EInventoryCapType::TotalItems && bUseInventoryCap", EditConditionHides))
 | 
			
		||||
	int32 InventoryMaxCapacity = 100;
 | 
			
		||||
 | 
			
		||||
	UPROPERTY(BlueprintReadWrite)
 | 
			
		||||
	int32 InventoryCurrentCapacity = 0;
 | 
			
		||||
 | 
			
		||||
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Inventory Configuration", meta = (EditCondition = "InventoryCapType == EInventoryCapType::PerCat", EditConditionHides))
 | 
			
		||||
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Inventory Configuration", meta = (EditCondition = "InventoryCapType == EInventoryCapType::TotalItemsPerCategory && bUseInventoryCap", EditConditionHides))
 | 
			
		||||
	TMap<EItemType, int32> InventoryCapacityPerCategory;
 | 
			
		||||
 | 
			
		||||
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Inventory Starting Items")
 | 
			
		||||
@@ -50,7 +53,7 @@ public:
 | 
			
		||||
	TArray<FBaseItemInfo> GetPlayerInventory();
 | 
			
		||||
 | 
			
		||||
	UFUNCTION(BlueprintCallable)
 | 
			
		||||
	void RequestAddItem(FBaseItemInfo InItemInfo, int32 InItemQuantity);
 | 
			
		||||
	void RequestAddItem(FBaseItemInfo InItemInfo, int32 InItemQuantity, AActor* ActorToDelete);
 | 
			
		||||
 | 
			
		||||
	UFUNCTION(BlueprintCallable)
 | 
			
		||||
	TArray<FBaseItemInfo> GetAllInventoryItemsInCategory(EItemType InItemType);
 | 
			
		||||
 
 | 
			
		||||
@@ -31,6 +31,9 @@ public:
 | 
			
		||||
	UPROPERTY(BlueprintReadWrite, Category = "Current Player Stats")
 | 
			
		||||
	float CurrentHealth;
 | 
			
		||||
 | 
			
		||||
	UPROPERTY(BlueprintReadWrite, Category = "Current Player Stats")
 | 
			
		||||
	int32 PlayerLevel = 1;
 | 
			
		||||
 | 
			
		||||
	UPROPERTY(BlueprintReadWrite, Category = "Current Player Stats")
 | 
			
		||||
	float CurrentStamina;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -90,8 +90,8 @@ enum class EInventoryCapType : uint8
 | 
			
		||||
{
 | 
			
		||||
	None UMETA(DisplayName = "None"),
 | 
			
		||||
	Weight UMETA(DisplayName = "Weight"),
 | 
			
		||||
	TotalItems UMETA(DisplayName = "TotalItems"),
 | 
			
		||||
	TotalItemsPerCategory UMETA(DisplayName = "TotalItemsPerCategory")
 | 
			
		||||
	TotalItems UMETA(DisplayName = "Total Items"),
 | 
			
		||||
	TotalItemsPerCategory UMETA(DisplayName = "Total Items Per Category")
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user