Skip to content

Commit

Permalink
Inventory Item Datamodel
Browse files Browse the repository at this point in the history
  • Loading branch information
pavlicekdominik committed Oct 11, 2024
1 parent e8b23c3 commit aef60f8
Show file tree
Hide file tree
Showing 14 changed files with 245 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

#include "Definitions/MounteaInventoryItemBlueprint.h"

UMounteaInventoryItemBlueprint::UMounteaInventoryItemBlueprint()
#include "Definitions/MounteaItemAction.h"

UMounteaInventoryItemBlueprint::UMounteaInventoryItemBlueprint() : BlueprintGuid(FGuid::NewGuid())
{
}

void UMounteaInventoryItemBlueprint::SetItemActions(const TArray<TSubclassOf<UMounteaInventoryItemAction>>& NewActions)
{
for (const auto& newAction : NewActions)
{
if (newAction && !ItemActions.Contains(newAction))
ItemActions.Add(newAction);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// // All rights reserved Dominik Morse (Pavlicek) 2024


#include "Definitions/MounteaInventoryItemsLibrary.h"
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class MOUNTEAINVENTORYEQUIPMENT_API UMounteaEquipmentSlot : public UDataAsset
* It can be customized in the editor.
*/
UPROPERTY(SaveGame, Category="2. Read Only", VisibleAnywhere, BlueprintReadOnly)
FGuid SlotGuid = FGuid();;
FGuid SlotGuid = FGuid::NewGuid();

private:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,24 @@ class MOUNTEAINVENTORYEQUIPMENT_API UMounteaInventoryItemBlueprint : public UDat
protected:

/** Unique identifier for the item blueprint. Used to distinguish this blueprint from others. */
UPROPERTY(SaveGame, VisibleAnywhere, BlueprintReadOnly, Category="Required")
FGuid BlueprintGuid = FGuid();;
UPROPERTY(SaveGame, VisibleAnywhere, BlueprintReadOnly, Category="Required", meta=(NoResetToDefault))
FGuid BlueprintGuid;

/** Default gameplay tags associated with items created from this blueprint. */
UPROPERTY(SaveGame, EditDefaultsOnly, BlueprintReadOnly, Category="Required")
UPROPERTY(SaveGame, EditDefaultsOnly, BlueprintReadOnly, Category="Required", meta=(NoResetToDefault))
FGameplayTagContainer DefaultTags;

/** Primary data required for items created from this blueprint. */
UPROPERTY(SaveGame, EditDefaultsOnly, BlueprintReadOnly, Category="Required")
UPROPERTY(SaveGame, EditDefaultsOnly, BlueprintReadOnly, Category="Required", meta=(NoResetToDefault))
FMounteaInventoryItemRequiredData PrimaryData;

/** Optional secondary data for items created from this blueprint. */
UPROPERTY(SaveGame, EditDefaultsOnly, BlueprintReadOnly, Category="Optional")
UPROPERTY(SaveGame, EditDefaultsOnly, BlueprintReadOnly, Category="Optional", meta=(NoResetToDefault))
FMounteaInventoryItemOptionalData SecondaryData;

/** Set of actions associated with items created from this blueprint. */
UPROPERTY(SaveGame, EditDefaultsOnly, BlueprintReadOnly, Category="Optional")
TSet<TObjectPtr<UMounteaInventoryItemAction>> ItemActions;
UPROPERTY(SaveGame, EditDefaultsOnly, BlueprintReadOnly, Category="Optional", meta=(NoResetToDefault))
TSet<TSubclassOf<UMounteaInventoryItemAction>> ItemActions;

public:

Expand Down Expand Up @@ -118,20 +118,13 @@ class MOUNTEAINVENTORYEQUIPMENT_API UMounteaInventoryItemBlueprint : public UDat
* @return An array of pointers to the item actions.
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category="Mountea|Inventory&Equipment|ItemBlueprint", meta=(CustomTag="MounteaK2Getter"))
FORCEINLINE TArray<UMounteaInventoryItemAction*> GetItemActions() const { return ItemActions.Array(); }
FORCEINLINE TArray<TSubclassOf<UMounteaInventoryItemAction>> GetItemActions() const { return ItemActions.Array(); }

/**
* Sets the actions associated with items created from this blueprint.
*
* @param NewActions The new array of actions to assign.
*/
FORCEINLINE void SetItemActions(const TArray<UMounteaInventoryItemAction*>& NewActions)
{
for (const auto& newAction : NewActions)
{
if (newAction && !ItemActions.Contains(newAction))
ItemActions.Add(newAction);
}
}
void SetItemActions(const TArray<TSubclassOf<UMounteaInventoryItemAction>>& NewActions);
};

Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@ class MOUNTEAINVENTORYEQUIPMENT_API UMounteaInventoryItemCategory : public UData
*
* @return The EInventoryItemFlags representing the category's flags.
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category="Mountea|Inventory&Equipment|Category", meta=(CustomTag="MounteaK2Getter", Bitmask, BitmaskEnum="EInventoryItemFlags"))
UFUNCTION(BlueprintCallable, BlueprintPure, Category="Mountea|Inventory&Equipment|Category", meta=(CustomTag="MounteaK2Getter", Bitmask, BitmaskEnum="/Script/MounteaInventoryEquipment.EInventoryItemFlags"))
FORCEINLINE EInventoryItemFlags GetCategoryFlags() const { return static_cast<EInventoryItemFlags>(CategoryFlags); }

/**
* Sets the flags defining special properties or behaviors of the category.
*
* @param newFlags The new EInventoryItemFlags to assign to the category.
*/
UFUNCTION(BlueprintCallable, Category="Mountea|Inventory&Equipment|Category", meta=(CustomTag="MounteaK2Setter", Bitmask, BitmaskEnum="EInventoryItemFlags"))
UFUNCTION(BlueprintCallable, Category="Mountea|Inventory&Equipment|Category", meta=(CustomTag="MounteaK2Setter", Bitmask, BitmaskEnum="/Script/MounteaInventoryEquipment.EInventoryItemFlags"))
FORCEINLINE void SetCategoryFlags(EInventoryItemFlags newFlags) { CategoryFlags = static_cast<uint8>(newFlags); }

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// // All rights reserved Dominik Morse (Pavlicek) 2024

#pragma once

#include "CoreMinimal.h"
#include "Engine/DataAsset.h"
#include "MounteaInventoryItemsLibrary.generated.h"

/**
*
*/
UCLASS(BlueprintType, Blueprintable, EditInlineNew, ClassGroup="Mountea", DisplayName="Inventory Item Blueprints Library")
class MOUNTEAINVENTORYEQUIPMENT_API UMounteaInventoryItemsLibrary : public UDataAsset
{
GENERATED_BODY()

public:

protected:


};
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class MOUNTEAINVENTORYEQUIPMENT_API UMounteaInventoryItemAction : public UObject

/** Unique identifier for the action. Used to distinguish this action from others. */
UPROPERTY(SaveGame, VisibleAnywhere, BlueprintReadOnly, Category="Required", meta=(NoResetToDefault))
FGuid ActionGuid = FGuid();
FGuid ActionGuid = FGuid::NewGuid();

/** Gameplay tag associated with the action. Can be used for filtering or applying specific behaviors. */
UPROPERTY(SaveGame, EditDefaultsOnly, BlueprintReadOnly, Category="Required", meta=(NoResetToDefault))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
UENUM(BlueprintType, meta = (Bitflags, UseEnumValuesAsMaskValuesInEditor = "true"))
enum class EInventoryItemFlags : uint8
{
None = 0,
Tradeable = 1 << 0,
Stackable = 1 << 1,
Craftable = 1 << 2,
Dropable = 1 << 3,
Consumable = 1 << 4,
QuestItem = 1 << 5,
Expirable = 1 << 6,
Durable = 1 << 7
None = 0 UMETA(DisplayName="None"),
Tradeable = 1 << 0 UMETA(DisplayName="Tradeable"),
Stackable = 1 << 1 UMETA(DisplayName="Stackable"),
Craftable = 1 << 2 UMETA(DisplayName="Craftable"),
Dropable = 1 << 3 UMETA(DisplayName="Dropable"),
Consumable = 1 << 4 UMETA(DisplayName="Consumable"),
QuestItem = 1 << 5 UMETA(DisplayName="Quest Item"),
Expirable = 1 << 6 UMETA(DisplayName="Expirable"),
Durable = 1 << 7 UMETA(DisplayName="Durable")
};
ENUM_CLASS_FLAGS(EInventoryItemFlags)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ struct FMounteaInventoryItemRequiredData
UPROPERTY(Category="PrimaryData",EditAnywhere, BlueprintReadWrite, meta=(NoResetToDefault))
FSlateBrush ItemCover;

UPROPERTY(Category="PrimaryData",EditAnywhere, BlueprintReadWrite, meta=(NoResetToDefault, AllowedClasses="StaticMesh,SkeletalMesh"))
UPROPERTY(Category="PrimaryData",EditAnywhere, BlueprintReadWrite, meta=(NoResetToDefault, AllowedClasses="/Script/Engine.StaticMesh,/Script/Engine.SkeletalMesh"))
UStreamableRenderAsset* ItemMesh = nullptr;

public:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// All rights reserved Dominik Morse (Pavlicek) 2024

#include "FMounteaInventoryItemBlueprintAssetAction.h"

#include "Definitions/MounteaInventoryItemBlueprint.h"
#include "Helpers/FMounteaInventoryEquipmentEditorConsts.h"

#define LOCTEXT_NAMESPACE "FMounteaInventoryItemBlueprintAssetAction"

FMounteaInventoryItemBlueprintAssetAction::FMounteaInventoryItemBlueprintAssetAction()
{
}

FText FMounteaInventoryItemBlueprintAssetAction::GetName() const
{
return LOCTEXT("MounteaInventoryItemBlueprintAssetAction_Name", "Item Blueprint");
}

FColor FMounteaInventoryItemBlueprintAssetAction::GetTypeColor() const
{
return FColor::Yellow;
}

UClass* FMounteaInventoryItemBlueprintAssetAction::GetSupportedClass() const
{
return UMounteaInventoryItemBlueprint::StaticClass();
}

uint32 FMounteaInventoryItemBlueprintAssetAction::GetCategories()
{
if (FModuleManager::Get().IsModuleLoaded("AssetTools"))
{
return FAssetToolsModule::GetModule().Get().FindAdvancedAssetCategory(AdvancedMenuCategoryName);
}

return EAssetTypeCategories::Misc;
}

const TArray<FText>& FMounteaInventoryItemBlueprintAssetAction::GetSubMenus() const
{
static const TArray<FText> AssetTypeActionSubMenu
{
AdvancedMenuSubCategoryName_02
};
return AssetTypeActionSubMenu;
}

#undef LOCTEXT_NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// All rights reserved Dominik Morse (Pavlicek) 2024

#pragma once

#include "AssetTypeActions_Base.h"
#include "Utils/MounteaInventoryEquipmentEditorUtilities.h"

class FMounteaInventoryItemBlueprintAssetAction : public FAssetTypeActions_Base
{
public:

FMounteaInventoryItemBlueprintAssetAction();

virtual FText GetName() const override;
virtual FColor GetTypeColor() const override;
virtual UClass* GetSupportedClass() const override;
virtual uint32 GetCategories() override;

virtual const TArray<FText>& GetSubMenus() const override;

virtual bool CanFilter() override
{ return false; };

virtual void BuildBackendFilter(FARFilter& InFilter) override
{
FilterAddNativeParentClassPath(InFilter, GetSupportedClass());

// Add to filter all native children classes of our supported class
TArray<UClass*> NativeChildClasses;
TArray<UClass*> BlueprintChildClasses;
FMounteaInventoryEquipmentEditorUtilities::GetAllChildClassesOf(GetSupportedClass(), NativeChildClasses, BlueprintChildClasses);
for (const UClass* ChildNativeClass : NativeChildClasses)
{
FilterAddNativeParentClassPath(InFilter, ChildNativeClass);
}

InFilter.ClassPaths.Add(UBlueprint::StaticClass()->GetClassPathName());
InFilter.bRecursiveClasses = true;
};

static void FilterAddNativeParentClassPath(FARFilter& InFilter, const UClass* Class)
{
if (Class == nullptr)
{
return;
}

const FString Value = FString::Printf(
TEXT("%s'%s'"),
*UClass::StaticClass()->GetName(),
*Class->GetPathName()
);
InFilter.TagsAndValues.Add(FBlueprintTags::NativeParentClassPath, Value);
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// All rights reserved Dominik Morse (Pavlicek) 2024


#include "MounteaInventoryItemBlueprintFactory.h"

#include "Definitions/MounteaInventoryItemBlueprint.h"
#include "Kismet2/KismetEditorUtilities.h"
#include "Utils/MounteaInventoryEquipmentEditorUtilities.h"

UMounteaInventoryItemBlueprintFactory::UMounteaInventoryItemBlueprintFactory()
{
bCreateNew = true;
bEditAfterNew = true;

SupportedClass = UMounteaInventoryItemBlueprint::StaticClass();
}

UObject* UMounteaInventoryItemBlueprintFactory::FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn)
{
if (ParentClass == nullptr)
{
ParentClass = UMounteaInventoryItemBlueprint::StaticClass();
}

// Something is not right!
if (ParentClass == nullptr || !FKismetEditorUtilities::CanCreateBlueprintOfClass(ParentClass))
{
FMessageDialog::Open(EAppMsgType::Ok, FText::Format(NSLOCTEXT("UnrealEd", "CannotCreateBlueprintFromClass", "Cannot create a blueprint based on the class '{0}'."), FText::FromString(ParentClass->GetName())));
return nullptr;
}

return NewObject<UMounteaInventoryItemBlueprint>(InParent, ParentClass, Name, Flags, Context);
}

bool UMounteaInventoryItemBlueprintFactory::ConfigureProperties()
{
static const FText TitleText = FText::FromString(TEXT("Pick Parent Class for new Mountea Inventory Component"));
ParentClass = nullptr;

UClass* ChosenClass = nullptr;
const bool bPressedOk = FMounteaInventoryEquipmentEditorUtilities::PickChildrenOfClass(TitleText, ChosenClass, SupportedClass);
if (bPressedOk)
{
ParentClass = ChosenClass;
}

return bPressedOk;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// All rights reserved Dominik Morse (Pavlicek) 2024

#pragma once

#include "CoreMinimal.h"
#include "Factories/Factory.h"
#include "MounteaInventoryItemBlueprintFactory.generated.h"

class UMounteaInventoryItemBlueprint;

/**
*
*/
UCLASS()
class MOUNTEAINVENTORYEQUIPMENTEDITOR_API UMounteaInventoryItemBlueprintFactory : public UFactory
{
GENERATED_BODY()

public:

UMounteaInventoryItemBlueprintFactory();

virtual UObject* FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn) override;
virtual bool ConfigureProperties() override;

private:
// Holds the template of the class we are building
UPROPERTY()
TSubclassOf<UMounteaInventoryItemBlueprint> ParentClass;

};
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "AssetActions/FMounteaInventoryComponentAssetAction.h"
#include "AssetActions/FMounteaInventoryContentThemeAssetAction.h"
#include "AssetActions/FMounteaInventoryItemActionAssetAction.h"
#include "AssetActions/FMounteaInventoryItemBlueprintAssetAction.h"
#include "AssetActions/FMounteaInventoryItemConfigAssetAction.h"
#include "AssetActions/FMounteaInventoryRarityAssetAction.h"
#include "AssetActions/FMounteaInventoryThemeAssetAction.h"
Expand Down Expand Up @@ -70,7 +71,7 @@ void FMounteaInventoryEquipmentEditor::StartupModule()
RegisterAssetTypeAction(FAssetToolsModule::GetModule().Get(), MakeShared<FMounteaInventoryItemActionAssetAction>());
RegisterAssetTypeAction(FAssetToolsModule::GetModule().Get(), MakeShared<FMounteaInventoryContentThemeAssetAction>());
RegisterAssetTypeAction(FAssetToolsModule::GetModule().Get(), MakeShared<FMounteaInventoryContentThemeAssetAction>());

RegisterAssetTypeAction(FAssetToolsModule::GetModule().Get(), MakeShared<FMounteaInventoryItemBlueprintAssetAction>());
RegisterAssetTypeAction(FAssetToolsModule::GetModule().Get(), MakeShared<FCategoryThemeAssetActions>());
RegisterAssetTypeAction(FAssetToolsModule::GetModule().Get(), MakeShared<FTextThemeAssetActions>());
}
Expand Down

0 comments on commit aef60f8

Please sign in to comment.