Added all BP Items in the game and updated scripts

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
This commit is contained in:
MH261677 2022-11-14 17:42:26 +00:00
parent 785974e169
commit a40aa57f70
10 changed files with 86 additions and 27 deletions

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:8e387511b72d482c0cef5dcaf48822ceba438b4bd0cc13ff7410220ca992f15c
size 6030

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:6d8d52b9430b52830e8488a07bdc388bb5a602828a0b898e727c18aeb583fffb
size 5894

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:302db81a27f3921406ca175911dd01315a52040b80af2d5515e150f169383463
size 5894

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:6b443f673bb208fa1d7dd5a10319aaf03d7173f4232adda4d9e692895c6c6ade
size 5894

View File

@ -2,6 +2,9 @@
#include "InventoryComponent.h" #include "InventoryComponent.h"
#include "Items/BaseItem.h"
// Sets default values for this component's properties // Sets default values for this component's properties
@ -11,7 +14,7 @@ UInventoryComponent::UInventoryComponent()
// off to improve performance if you don't need them. // off to improve performance if you don't need them.
PrimaryComponentTick.bCanEverTick = true; PrimaryComponentTick.bCanEverTick = true;
// ... MaxItemSlots = 10;
} }
@ -20,16 +23,39 @@ void UInventoryComponent::BeginPlay()
{ {
Super::BeginPlay(); Super::BeginPlay();
// ... for(auto & BaseItem : DefaultItems)
{
AddItem(BaseItem);
}
} }
bool UInventoryComponent::AddItem(class UBaseItem* BaseItem)
// Called every frame
void UInventoryComponent::TickComponent(float DeltaTime, ELevelTick TickType,FActorComponentTickFunction* ThisTickFunction)
{ {
Super::TickComponent(DeltaTime, TickType, ThisTickFunction); //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;
} }

View File

@ -6,6 +6,8 @@
#include "Components/ActorComponent.h" #include "Components/ActorComponent.h"
#include "InventoryComponent.generated.h" #include "InventoryComponent.generated.h"
//OUR DELEGATE IS CALLED FONINVENTORYUPDATED
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnInventoryUpdated);
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent)) UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class THE_TWILIGHT_ABYSS_API UInventoryComponent : public UActorComponent class THE_TWILIGHT_ABYSS_API UInventoryComponent : public UActorComponent
@ -21,6 +23,19 @@ protected:
virtual void BeginPlay() override; virtual void BeginPlay() override;
public: public:
// Called every frame bool AddItem(class UBaseItem* BaseItem); //adds the item to the player
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
bool Remove(class UBaseItem* BaseItem); //removes the item from the player
UPROPERTY(EditDefaultsOnly, Instanced)
TArray<class UBaseItem*> DefaultItems; //Items you start the game with IF YOU WANT YOU CAN JUST NOT USE THIS
UPROPERTY(EditDefaultsOnly, Category= "Inventory")
int32 MaxItemSlots;
UPROPERTY(BlueprintAssignable, Category= "Inventory")
FOnInventoryUpdated OnInventoryUpdated; //This is our delegate
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category= "Items")
TArray<class UBaseItem*> Items; // The items currently in the inventory
}; };

View File

@ -6,6 +6,7 @@
#include "UObject/Object.h" #include "UObject/Object.h"
#include "BaseItem.generated.h" #include "BaseItem.generated.h"
/** /**
* *
*/ */
@ -15,45 +16,50 @@ class THE_TWILIGHT_ABYSS_API UBaseItem : public UObject
GENERATED_BODY() GENERATED_BODY()
public: public:
UBaseItem(); UBaseItem();
virtual class UWorld* GetWorld() const { return World; };
UPROPERTY(Transient)
class UWorld* World;
//The text that will be displayed for using the item (Equip, Eat) //The text that will be displayed for using the item (Equip, Eat)
UPROPERTY(EditDefaultsOnly,BlueprintReadWrite, Category = "Item") UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item")
FText ItemUseAction; FText ItemUseAction;
//The actual mesh of the item //The actual mesh of the item
UPROPERTY(EditDefaultsOnly,BlueprintReadWrite, Category = "Item") UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item")
class UStaticMesh* ItemMesh; class UStaticMesh* ItemMesh;
//The picture of the item icon //The picture of the item icon
UPROPERTY(EditDefaultsOnly,BlueprintReadWrite, Category = "Item") UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item")
class UTexture2D* ItemIcon; class UTexture2D* ItemIcon;
//The name of the item //The name of the item
UPROPERTY(EditDefaultsOnly,BlueprintReadWrite, Category = "Item") UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item")
FText ItemDisplayName; FText ItemDisplayName;
//The description of the item //The description of the item
UPROPERTY(EditDefaultsOnly,BlueprintReadWrite, Category = "Item") UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item")
FText ItemDescription; FText ItemDescription;
//The cost of the item //The cost of the item
UPROPERTY(EditDefaultsOnly,BlueprintReadWrite, Category = "Item") UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Item")
int32 ItemCostPrice; int32 ItemCostPrice;
//ADD A HEALING ITEM VALUE? //ADD A HEALING ITEM VALUE?
//reference to the UInventoryComponent script //reference to the UInventoryComponent script
UPROPERTY() UPROPERTY()
class UInventoryComponent* StoredItems; class UInventoryComponent* StoredItems;
//The buy class to purchase the item //The buy class to purchase the item
virtual void Buy(class UItemPurchaseComponent* PurchaseItem) PURE_VIRTUAL(UBaseItem); // WILL SET THIS UP LATER virtual void Buy(class UItemPurchaseComponent* PurchaseItem) PURE_VIRTUAL(UBaseItem); // WILL SET THIS UP LATER
//The use Item class to use the item in the player Inventory //The use Item class to use the item in the player Inventory
virtual void Use(class ATempCharacter* Character) PURE_VIRTUAL(UBaseItem); virtual void Use(class ATempCharacter* Character) PURE_VIRTUAL(UBaseItem);
//This is the same as the use item class but its in BP instead //This is the same as the use item class but its in BP instead
UFUNCTION(BlueprintImplementableEvent) UFUNCTION(BlueprintImplementableEvent)
void OnUse (class ATempCharacter* Character); void OnUse(class ATempCharacter* Character);
}; };

View File

@ -1,12 +1,12 @@
// Fill out your copyright notice in the Description page of Project Settings. // Fill out your copyright notice in the Description page of Project Settings.
#include "Jelly1.h" #include "EatableItems.h"
#include "the_twilight_abyss/PlayerTemp/TempCharacter.h" #include "the_twilight_abyss/PlayerTemp/TempCharacter.h"
void UJelly1::Use(ATempCharacter* Character) void UEatableItems::Use(ATempCharacter* Character)
{ {
if(Character) if(Character)
{ {

View File

@ -4,13 +4,13 @@
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "BaseItem.h" #include "BaseItem.h"
#include "Jelly1.generated.h" #include "EatableItems.generated.h"
/** /**
* *
*/ */
UCLASS() UCLASS()
class THE_TWILIGHT_ABYSS_API UJelly1 : public UBaseItem class THE_TWILIGHT_ABYSS_API UEatableItems : public UBaseItem
{ {
GENERATED_BODY() GENERATED_BODY()

View File

@ -1,11 +1,9 @@
// Fill out your copyright notice in the Description page of Project Settings. // Fill out your copyright notice in the Description page of Project Settings.
#include "TempCharacter.h" #include "TempCharacter.h"
#include "UObject/SoftObjectPath.h"
#include "Dialogs/Dialogs.h"
#include "Engine/GameViewportClient.h"
#include "Blueprint/UserWidget.h" #include "Blueprint/UserWidget.h"
#include "../../../Plugins/Developer/RiderLink/Source/RD/thirdparty/clsocket/src/ActiveSocket.h" #include "../../../Plugins/Developer/RiderLink/Source/RD/thirdparty/clsocket/src/ActiveSocket.h"
#include "the_twilight_abyss/BaseItems/InventoryComponent.h"
#include "the_twilight_abyss/BaseItems/Items/BaseItem.h" #include "the_twilight_abyss/BaseItems/Items/BaseItem.h"
#include "the_twilight_abyss/MerchantInteraction/Interaction.h" #include "the_twilight_abyss/MerchantInteraction/Interaction.h"
@ -15,6 +13,8 @@ ATempCharacter::ATempCharacter()
{ {
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it. // Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true; PrimaryActorTick.bCanEverTick = true;
Inventory = CreateDefaultSubobject<UInventoryComponent>("Inventory");
Inventory->MaxItemSlots = 10;
} }
// Called when the game starts or when spawned // Called when the game starts or when spawned