From b7a583ab27981e7acb995b2b034160fa9a039449 Mon Sep 17 00:00:00 2001 From: Ji Yoon Rhee Date: Wed, 27 Dec 2023 20:29:00 +0900 Subject: [PATCH] some more progress to inventory system --- .../Source/hwanyoung2/HYInteractableActor.cpp | 5 +++++ .../Source/hwanyoung2/HYInteractableActor.h | 9 +++++++++ .../hwanyoung2/HYPlayerCharacController.cpp | 19 +++++++++++++++++++ .../hwanyoung2/HYPlayerCharacController.h | 2 ++ .../Source/hwanyoung2/InventoryItem.cpp | 3 +++ 5 files changed, 38 insertions(+) diff --git a/hwanyoung2/Source/hwanyoung2/HYInteractableActor.cpp b/hwanyoung2/Source/hwanyoung2/HYInteractableActor.cpp index 3ca13aa0..647ccfbe 100644 --- a/hwanyoung2/Source/hwanyoung2/HYInteractableActor.cpp +++ b/hwanyoung2/Source/hwanyoung2/HYInteractableActor.cpp @@ -19,6 +19,11 @@ void AHYInteractableActor::Interact_Implementation(APlayerController* Controller { } +FString AHYInteractableActor::GetInteractText() const +{ + return FString(); +} + // Called when the game starts or when spawned void AHYInteractableActor::BeginPlay() { diff --git a/hwanyoung2/Source/hwanyoung2/HYInteractableActor.h b/hwanyoung2/Source/hwanyoung2/HYInteractableActor.h index d7a0df35..c1643ed6 100644 --- a/hwanyoung2/Source/hwanyoung2/HYInteractableActor.h +++ b/hwanyoung2/Source/hwanyoung2/HYInteractableActor.h @@ -20,6 +20,15 @@ public: void Interact(APlayerController* Controller); virtual void Interact_Implementation(APlayerController* Controller); + UPROPERTY(EditDefaultsOnly) + FString Name; + + UPROPERTY(EditDefaultsOnly) + FString Action; + + UFUNCTION(Blueprintcallable, Category = "Pickup") + FString GetInteractText() const; + protected: // Called when the game starts or when spawned virtual void BeginPlay() override; diff --git a/hwanyoung2/Source/hwanyoung2/HYPlayerCharacController.cpp b/hwanyoung2/Source/hwanyoung2/HYPlayerCharacController.cpp index 28729cb7..478710a6 100644 --- a/hwanyoung2/Source/hwanyoung2/HYPlayerCharacController.cpp +++ b/hwanyoung2/Source/hwanyoung2/HYPlayerCharacController.cpp @@ -2,6 +2,8 @@ #include "HYPlayerCharacController.h" +#include "HYGameStateBase.h" +#include "hwanyoung2Character.h" AHYPlayerCharacController::AHYPlayerCharacController() { @@ -27,16 +29,33 @@ int32 AHYPlayerCharacController::GetInventoryWeight() bool AHYPlayerCharacController::AddItemToInventoryByID(FName ID) { + AHYGameStateBase* gameState = Cast(GetWorld()->GetGameState()); + UDataTable* itemDB = gameState->GetItemDatabase(); + FInventoryItem* itemToAdd = itemDB->FindRow(ID, ""); + + if (itemToAdd) { + if (Inventory.Num() < InventorySlotLimit && + GetInventoryWeight() + itemToAdd->ItemWeight <= InventoryWeightLimit) { + Inventory.Add(*itemToAdd); + ReloadInventory(); + return true; + } + } return false; } void AHYPlayerCharacController::Interact() { + if (CurrentInteractable) CurrentInteractable->Interact(this); } void AHYPlayerCharacController::SetupInputComponent() { Super::SetupInputComponent(); + + InputComponent->BindAction( + "Interact", IE_Pressed, this, + &AHYPlayerCharacController::Interact); } void AHYPlayerCharacController::OnPossess(APawn* InPawn) diff --git a/hwanyoung2/Source/hwanyoung2/HYPlayerCharacController.h b/hwanyoung2/Source/hwanyoung2/HYPlayerCharacController.h index 9878492d..0f461a20 100644 --- a/hwanyoung2/Source/hwanyoung2/HYPlayerCharacController.h +++ b/hwanyoung2/Source/hwanyoung2/HYPlayerCharacController.h @@ -19,8 +19,10 @@ class HWANYOUNG2_API AHYPlayerCharacController : public APlayerController public: #pragma region inventory + //setting up the controller inventory AHYPlayerCharacController(); + UFUNCTION(BlueprintImplementableEvent) void ReloadInventory(); diff --git a/hwanyoung2/Source/hwanyoung2/InventoryItem.cpp b/hwanyoung2/Source/hwanyoung2/InventoryItem.cpp index 72b1dfbe..0548a054 100644 --- a/hwanyoung2/Source/hwanyoung2/InventoryItem.cpp +++ b/hwanyoung2/Source/hwanyoung2/InventoryItem.cpp @@ -5,4 +5,7 @@ FInventoryItem::FInventoryItem() { + this->ItemName = FText::FromString("No Name"); + this->ItemWeight = 1; + this->ItemDescription = FText::FromString("No Description"); }