Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
Add new properties to Elementus Item Data & Elementus Item Info (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucoiso authored Feb 21, 2023
1 parent 572fc77 commit 4ee9f31
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 75 deletions.
4 changes: 2 additions & 2 deletions ElementusInventory.uplugin
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"FileVersion": 3,
"Version": 3,
"VersionName": "1.1.5",
"Version": 4,
"VersionName": "1.1.6",
"FriendlyName": "Elementus Inventory",
"Description": "Plugin that provides a Data-Driven Inventory & Items system based on FPrimaryAssetIds and the Asset Manager.",
"Category": "Game Features",
Expand Down
2 changes: 1 addition & 1 deletion Source/ElementusInventory/ElementusInventory.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ public ElementusInventory(ReadOnlyTargetRules Target) : base(Target)
"DeveloperSettings"
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,6 @@ void AElementusInventoryPackage::BeginPackageDestruction_Implementation()
}
else
{
UE_LOG(LogElementusInventory, Warning, TEXT("ElementusInventory - %s: Package %s was not destroyed because the " "option 'bDestroyWhenInventoryIsEmpty' was disabled"), *FString(__func__), *GetName());
UE_LOG(LogElementusInventory_Internal, Warning, TEXT("ElementusInventory - %s: Package %s was not destroyed because the " "option 'bDestroyWhenInventoryIsEmpty' was disabled"), *FString(__func__), *GetName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,30 @@ TArray<UElementusItemData*> UElementusInventoryFunctions::SearchElementusItemDat
return Output;
}

TMap<FGameplayTag, FName> UElementusInventoryFunctions::GetItemMetadatas(const FElementusItemInfo InItemInfo)
{
TMap<FGameplayTag, FName> Output;
if (UElementusItemData* const Data = GetSingleItemDataById(InItemInfo.ItemId, TArray<FName> { "Custom" }))
{
Output = Data->Metadatas;
UnloadElementusItem(InItemInfo.ItemId);
}

return Output;
}

TMap<FGameplayTag, FPrimaryElementusItemIdContainer> UElementusInventoryFunctions::GetItemRelations(const FElementusItemInfo InItemInfo)
{
TMap<FGameplayTag, FPrimaryElementusItemIdContainer> Output;
if (UElementusItemData* const Data = GetSingleItemDataById(InItemInfo.ItemId, TArray<FName> { "Custom" }))
{
Output = Data->Relations;
UnloadElementusItem(InItemInfo.ItemId);
}

return Output;
}

TArray<UElementusItemData*> UElementusInventoryFunctions::LoadElementusItemDatas_Internal(UAssetManager* InAssetManager, const TArray<FPrimaryAssetId>& InIDs, const TArray<FName>& InBundles, const bool bAutoUnload)
{
TArray<UElementusItemData*> Output;
Expand Down Expand Up @@ -193,8 +217,6 @@ TArray<UElementusItemData*> UElementusInventoryFunctions::LoadElementusItemDatas
return Output;
}



TArray<UElementusItemData*> UElementusInventoryFunctions::LoadElementusItemDatas_Internal(UAssetManager* InAssetManager, const TArray<FPrimaryElementusItemId>& InIDs, const TArray<FName>& InBundles, const bool bAutoUnload)
{
const TArray<FPrimaryAssetId> PrimaryAssetIds(InIDs);
Expand Down
122 changes: 71 additions & 51 deletions Source/ElementusInventory/Public/Management/ElementusInventoryData.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <Engine/DataAsset.h>
#include "ElementusInventoryData.generated.h"

class UTexture2D;

constexpr auto ElementusItemDataType = TEXT("ElementusInventory_ItemData");

UENUM(BlueprintType, Category = "Elementus Inventory | Enumerations")
Expand All @@ -31,55 +33,6 @@ enum class EElementusItemType : uint8
MAX
};

class UTexture2D;

UCLASS(NotBlueprintable, NotPlaceable, Category = "Elementus Inventory | Classes | Data")
class ELEMENTUSINVENTORY_API UElementusItemData final : public UPrimaryDataAsset
{
GENERATED_BODY()

public:
explicit UElementusItemData(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get());

FORCEINLINE virtual FPrimaryAssetId GetPrimaryAssetId() const override
{
return FPrimaryAssetId(TEXT("ElementusInventory_ItemData"), *("Item_" + FString::FromInt(ItemId)));
}

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Elementus Inventory", meta = (AssetBundles = "Data"))
int32 ItemId;

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Elementus Inventory", meta = (AssetBundles = "SoftData"))
TSoftObjectPtr<UObject> ItemObject;

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Elementus Inventory", meta = (AssetBundles = "SoftData"))
TSoftClassPtr<UObject> ItemClass;

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Elementus Inventory", meta = (AssetBundles = "Data"))
FName ItemName;

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Elementus Inventory", meta = (AssetBundles = "Data", MultiLine = "true"))
FText ItemDescription;

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Elementus Inventory", meta = (AssetBundles = "Data"))
EElementusItemType ItemType;

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Elementus Inventory", meta = (AssetBundles = "Data"))
bool bIsStackable = true;

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Elementus Inventory", meta = (AssetBundles = "Data"))
float ItemValue;

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Elementus Inventory", meta = (UIMin = 0, ClampMin = 0, AssetBundles = "Data"))
float ItemWeight;

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Elementus Inventory", meta = (AssetBundles = "UI"))
TSoftObjectPtr<UTexture2D> ItemIcon;

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Elementus Inventory", meta = (AssetBundles = "UI"))
TSoftObjectPtr<UTexture2D> ItemImage;
};

USTRUCT(BlueprintType, Category = "Elementus Inventory | Structs")
struct FPrimaryElementusItemId : public FPrimaryAssetId
{
Expand All @@ -98,6 +51,15 @@ struct FPrimaryElementusItemId : public FPrimaryAssetId
}
};

USTRUCT(BlueprintType, Category = "Elementus Inventory | Structs")
struct FPrimaryElementusItemIdContainer
{
GENERATED_BODY()

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Elementus Inventory")
TArray<FPrimaryElementusItemId> Items;
};

USTRUCT(BlueprintType, Category = "Elementus Inventory | Structs")
struct FElementusItemInfo
{
Expand All @@ -121,12 +83,12 @@ struct FElementusItemInfo

bool operator==(const FElementusItemInfo& Other) const
{
return ItemId == Other.ItemId && Tags == Other.Tags;
return ItemId == Other.ItemId && Tags == Other.Tags && Level == Other.Level;
}

bool operator!=(const FElementusItemInfo& Other) const
{
return !(ItemId == Other.ItemId && Tags == Other.Tags);
return !(*this == Other);
}

bool operator<(const FElementusItemInfo& Other) const
Expand All @@ -137,9 +99,67 @@ struct FElementusItemInfo
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Elementus Inventory")
FPrimaryElementusItemId ItemId;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Elementus Inventory")
int32 Level = 1;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Elementus Inventory")
int32 Quantity = 1;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Elementus Inventory")
FGameplayTagContainer Tags;
};

UCLASS(NotBlueprintable, NotPlaceable, Category = "Elementus Inventory | Classes | Data")
class ELEMENTUSINVENTORY_API UElementusItemData final : public UPrimaryDataAsset
{
GENERATED_BODY()

public:
explicit UElementusItemData(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get());

FORCEINLINE virtual FPrimaryAssetId GetPrimaryAssetId() const override
{
return FPrimaryAssetId(TEXT("ElementusInventory_ItemData"), *("Item_" + FString::FromInt(ItemId)));
}

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Elementus Inventory", meta = (AssetBundles = "Data"))
int32 ItemId;

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Elementus Inventory", meta = (AssetBundles = "SoftData"))
TSoftObjectPtr<UObject> ItemObject;

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Elementus Inventory", meta = (AssetBundles = "SoftData"))
TSoftClassPtr<UObject> ItemClass;

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Elementus Inventory", meta = (AssetBundles = "Data"))
FName ItemName;

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Elementus Inventory", meta = (AssetBundles = "Data", MultiLine = "true"))
FText ItemDescription;

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Elementus Inventory", meta = (AssetBundles = "Data"))
EElementusItemType ItemType;

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Elementus Inventory", meta = (AssetBundles = "Data"))
bool bIsStackable = true;

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Elementus Inventory", meta = (UIMin = 0, ClampMin = 0, AssetBundles = "Data"))
float ItemValue;

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Elementus Inventory", meta = (UIMin = 0, ClampMin = 0, AssetBundles = "Data"))
float ItemWeight;

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Elementus Inventory", meta = (AssetBundles = "UI"))
TSoftObjectPtr<UTexture2D> ItemIcon;

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Elementus Inventory", meta = (AssetBundles = "UI"))
TSoftObjectPtr<UTexture2D> ItemImage;

/* Allows to implement custom properties in this item data */
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Elementus Inventory", meta = (DisplayName = "Custom Metadatas", AssetBundles = "Custom"))
TMap<FGameplayTag, FName> Metadatas;

/* Map containing a tag as key and a ID container as value to add relations to other items such as crafting requirements, etc. */
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Elementus Inventory", meta = (DisplayName = "Item Relations", AssetBundles = "Custom"))
TMap<FGameplayTag, FPrimaryElementusItemIdContainer> Relations;
};
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ class ELEMENTUSINVENTORY_API UElementusInventoryFunctions final : public UBluepr
}
}

UFUNCTION(BlueprintPure, Category = "Elementus Inventory")
static TMap<FGameplayTag, FName> GetItemMetadatas(const FElementusItemInfo InItemInfo);

UFUNCTION(BlueprintPure, Category = "Elementus Inventory")
static TMap<FGameplayTag, FPrimaryElementusItemIdContainer> GetItemRelations(const FElementusItemInfo InItemInfo);

private:
static TArray<UElementusItemData*> LoadElementusItemDatas_Internal(UAssetManager* InAssetManager, const TArray<FPrimaryAssetId>& InIDs, const TArray<FName>& InBundles, const bool bAutoUnload);
static TArray<UElementusItemData*> LoadElementusItemDatas_Internal(UAssetManager* InAssetManager, const TArray<FPrimaryElementusItemId>& InIDs, const TArray<FName>& InBundles, const bool bAutoUnload);
Expand Down
35 changes: 17 additions & 18 deletions Source/ElementusInventoryEditor/Private/SElementusItemCreator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,31 +131,31 @@ void SElementusItemCreator::Construct([[maybe_unused]] const FArguments&)
.AutoHeight()
[
ContentPairCreator_Lambda(CenterTextCreator_Lambda("Item Name"), SNew(SEditableTextBox)
.OnTextChanged(FOnTextChanged::CreateLambda([this](const FText& InText)
.OnTextChanged_Lambda([this](const FText& InText)
{
ItemName = *InText.ToString();
})))
}))
]
+ SVerticalBox::Slot()
.Padding(Slot_Padding)
.AutoHeight()
[
ContentPairCreator_Lambda(CenterTextCreator_Lambda("Item Description"), SNew(SMultiLineEditableTextBox)
.OnTextChanged(FOnTextChanged::CreateLambda([this](const FText& InText)
.OnTextChanged_Lambda([this](const FText& InText)
{
ItemDescription = InText;
})))
}))
]
+ SVerticalBox::Slot()
.Padding(Slot_Padding)
.AutoHeight()
[
ContentPairCreator_Lambda(CenterTextCreator_Lambda("Item Type"), SNew(STextComboBox)
.OptionsSource(&ItemTypesArr)
.OnSelectionChanged(STextComboBox::FOnTextSelectionChanged::CreateLambda([this](const TSharedPtr<FString>& InStr, [[maybe_unused]] ESelectInfo::Type)
{
ItemType = ItemTypesArr.Find(InStr);
})))
.OptionsSource(&ItemTypesArr)
.OnSelectionChanged_Lambda([this](const TSharedPtr<FString>& InStr, [[maybe_unused]] ESelectInfo::Type)
{
ItemType = ItemTypesArr.Find(InStr);
}))
]
+ SVerticalBox::Slot()
.Padding(Slot_Padding)
Expand Down Expand Up @@ -211,10 +211,10 @@ void SElementusItemCreator::Construct([[maybe_unused]] const FArguments&)
.AutoHeight()
[
ContentPairCreator_Lambda(CenterTextCreator_Lambda("Asset Name"), SNew(SEditableTextBox)
.OnTextChanged(FOnTextChanged::CreateLambda([this](const FText& InText)
{
AssetName = *InText.ToString();
})))
.OnTextChanged_Lambda([this](const FText& InText)
{
AssetName = *InText.ToString();
}))
]
+ SVerticalBox::Slot()
.Padding(Slot_Padding)
Expand All @@ -225,21 +225,20 @@ void SElementusItemCreator::Construct([[maybe_unused]] const FArguments&)
[
SNew(STextComboBox)
.OptionsSource(&AssetFoldersArr)
.OnSelectionChanged(STextComboBox::FOnTextSelectionChanged::CreateLambda(
[this](const TSharedPtr<FString>& InStr, [[maybe_unused]] ESelectInfo::Type)
.OnSelectionChanged_Lambda([this](const TSharedPtr<FString>& InStr, [[maybe_unused]] ESelectInfo::Type)
{
AssetFolder = FName(*InStr.Get());
}))
})
]
+ SHorizontalBox::Slot()
.AutoWidth()
[
SNew(SButton)
.OnClicked(FOnClicked::CreateLambda([this]() -> FReply
.OnClicked_Lambda([this]() -> FReply
{
UpdateFolders();
return FReply::Handled();
}))
})
.Content()
[
SNew(SImage)
Expand Down

0 comments on commit 4ee9f31

Please sign in to comment.