From 4ee9f31c41d183119b218bac7eaa755443cd9afd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Vilas-B=C3=B4as?= Date: Tue, 21 Feb 2023 12:22:34 -0300 Subject: [PATCH] Add new properties to Elementus Item Data & Elementus Item Info (#33) --- ElementusInventory.uplugin | 4 +- .../ElementusInventory.Build.cs | 2 +- .../Actors/ElementusInventoryPackage.cpp | 2 +- .../ElementusInventoryFunctions.cpp | 26 +++- .../Management/ElementusInventoryData.h | 122 ++++++++++-------- .../Management/ElementusInventoryFunctions.h | 6 + .../Private/SElementusItemCreator.cpp | 35 +++-- 7 files changed, 122 insertions(+), 75 deletions(-) diff --git a/ElementusInventory.uplugin b/ElementusInventory.uplugin index 9f1d568..f763829 100644 --- a/ElementusInventory.uplugin +++ b/ElementusInventory.uplugin @@ -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", diff --git a/Source/ElementusInventory/ElementusInventory.Build.cs b/Source/ElementusInventory/ElementusInventory.Build.cs index 4adb2f9..1c2e1c8 100644 --- a/Source/ElementusInventory/ElementusInventory.Build.cs +++ b/Source/ElementusInventory/ElementusInventory.Build.cs @@ -25,4 +25,4 @@ public ElementusInventory(ReadOnlyTargetRules Target) : base(Target) "DeveloperSettings" }); } -} \ No newline at end of file +} diff --git a/Source/ElementusInventory/Private/Actors/ElementusInventoryPackage.cpp b/Source/ElementusInventory/Private/Actors/ElementusInventoryPackage.cpp index 754bf49..c2e600c 100644 --- a/Source/ElementusInventory/Private/Actors/ElementusInventoryPackage.cpp +++ b/Source/ElementusInventory/Private/Actors/ElementusInventoryPackage.cpp @@ -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()); } } diff --git a/Source/ElementusInventory/Private/Management/ElementusInventoryFunctions.cpp b/Source/ElementusInventory/Private/Management/ElementusInventoryFunctions.cpp index dd08fa8..e916c86 100644 --- a/Source/ElementusInventory/Private/Management/ElementusInventoryFunctions.cpp +++ b/Source/ElementusInventory/Private/Management/ElementusInventoryFunctions.cpp @@ -114,6 +114,30 @@ TArray UElementusInventoryFunctions::SearchElementusItemDat return Output; } +TMap UElementusInventoryFunctions::GetItemMetadatas(const FElementusItemInfo InItemInfo) +{ + TMap Output; + if (UElementusItemData* const Data = GetSingleItemDataById(InItemInfo.ItemId, TArray { "Custom" })) + { + Output = Data->Metadatas; + UnloadElementusItem(InItemInfo.ItemId); + } + + return Output; +} + +TMap UElementusInventoryFunctions::GetItemRelations(const FElementusItemInfo InItemInfo) +{ + TMap Output; + if (UElementusItemData* const Data = GetSingleItemDataById(InItemInfo.ItemId, TArray { "Custom" })) + { + Output = Data->Relations; + UnloadElementusItem(InItemInfo.ItemId); + } + + return Output; +} + TArray UElementusInventoryFunctions::LoadElementusItemDatas_Internal(UAssetManager* InAssetManager, const TArray& InIDs, const TArray& InBundles, const bool bAutoUnload) { TArray Output; @@ -193,8 +217,6 @@ TArray UElementusInventoryFunctions::LoadElementusItemDatas return Output; } - - TArray UElementusInventoryFunctions::LoadElementusItemDatas_Internal(UAssetManager* InAssetManager, const TArray& InIDs, const TArray& InBundles, const bool bAutoUnload) { const TArray PrimaryAssetIds(InIDs); diff --git a/Source/ElementusInventory/Public/Management/ElementusInventoryData.h b/Source/ElementusInventory/Public/Management/ElementusInventoryData.h index 960e584..478fe46 100644 --- a/Source/ElementusInventory/Public/Management/ElementusInventoryData.h +++ b/Source/ElementusInventory/Public/Management/ElementusInventoryData.h @@ -9,6 +9,8 @@ #include #include "ElementusInventoryData.generated.h" +class UTexture2D; + constexpr auto ElementusItemDataType = TEXT("ElementusInventory_ItemData"); UENUM(BlueprintType, Category = "Elementus Inventory | Enumerations") @@ -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 ItemObject; - - UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Elementus Inventory", meta = (AssetBundles = "SoftData")) - TSoftClassPtr 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 ItemIcon; - - UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Elementus Inventory", meta = (AssetBundles = "UI")) - TSoftObjectPtr ItemImage; -}; - USTRUCT(BlueprintType, Category = "Elementus Inventory | Structs") struct FPrimaryElementusItemId : public FPrimaryAssetId { @@ -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 Items; +}; + USTRUCT(BlueprintType, Category = "Elementus Inventory | Structs") struct FElementusItemInfo { @@ -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 @@ -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 ItemObject; + + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Elementus Inventory", meta = (AssetBundles = "SoftData")) + TSoftClassPtr 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 ItemIcon; + + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Elementus Inventory", meta = (AssetBundles = "UI")) + TSoftObjectPtr ItemImage; + + /* Allows to implement custom properties in this item data */ + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Elementus Inventory", meta = (DisplayName = "Custom Metadatas", AssetBundles = "Custom")) + TMap 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 Relations; +}; diff --git a/Source/ElementusInventory/Public/Management/ElementusInventoryFunctions.h b/Source/ElementusInventory/Public/Management/ElementusInventoryFunctions.h index 956dc0a..7bd73a1 100644 --- a/Source/ElementusInventory/Public/Management/ElementusInventoryFunctions.h +++ b/Source/ElementusInventory/Public/Management/ElementusInventoryFunctions.h @@ -104,6 +104,12 @@ class ELEMENTUSINVENTORY_API UElementusInventoryFunctions final : public UBluepr } } + UFUNCTION(BlueprintPure, Category = "Elementus Inventory") + static TMap GetItemMetadatas(const FElementusItemInfo InItemInfo); + + UFUNCTION(BlueprintPure, Category = "Elementus Inventory") + static TMap GetItemRelations(const FElementusItemInfo InItemInfo); + private: static TArray LoadElementusItemDatas_Internal(UAssetManager* InAssetManager, const TArray& InIDs, const TArray& InBundles, const bool bAutoUnload); static TArray LoadElementusItemDatas_Internal(UAssetManager* InAssetManager, const TArray& InIDs, const TArray& InBundles, const bool bAutoUnload); diff --git a/Source/ElementusInventoryEditor/Private/SElementusItemCreator.cpp b/Source/ElementusInventoryEditor/Private/SElementusItemCreator.cpp index 339563d..621f0ca 100644 --- a/Source/ElementusInventoryEditor/Private/SElementusItemCreator.cpp +++ b/Source/ElementusInventoryEditor/Private/SElementusItemCreator.cpp @@ -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& InStr, [[maybe_unused]] ESelectInfo::Type) - { - ItemType = ItemTypesArr.Find(InStr); - }))) + .OptionsSource(&ItemTypesArr) + .OnSelectionChanged_Lambda([this](const TSharedPtr& InStr, [[maybe_unused]] ESelectInfo::Type) + { + ItemType = ItemTypesArr.Find(InStr); + })) ] + SVerticalBox::Slot() .Padding(Slot_Padding) @@ -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) @@ -225,21 +225,20 @@ void SElementusItemCreator::Construct([[maybe_unused]] const FArguments&) [ SNew(STextComboBox) .OptionsSource(&AssetFoldersArr) - .OnSelectionChanged(STextComboBox::FOnTextSelectionChanged::CreateLambda( - [this](const TSharedPtr& InStr, [[maybe_unused]] ESelectInfo::Type) + .OnSelectionChanged_Lambda([this](const TSharedPtr& 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)