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

Commit

Permalink
Merge pull request #47 from lucoiso/development
Browse files Browse the repository at this point in the history
Elementus Inventory v1.1.9
  • Loading branch information
lucoiso authored Aug 15, 2023
2 parents 310e70c + 647f4f3 commit 78d99f6
Show file tree
Hide file tree
Showing 16 changed files with 730 additions and 458 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": 6,
"VersionName": "1.1.8",
"Version": 7,
"VersionName": "1.1.9",
"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
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,199 @@ bool UElementusInventoryComponent::CanGiveItem(const FElementusItemInfo InItemIn
return false;
}

void UElementusInventoryComponent::SortInventory(const EElementusInventorySortingMode Mode, const EElementusInventorySortingOrientation Orientation)
{
const auto SortByOrientation = [Orientation](const auto A, const auto B) {
switch (Orientation)
{
case EElementusInventorySortingOrientation::Ascending:
return A < B;

case EElementusInventorySortingOrientation::Descending:
return A > B;

default:
return false;
}

return false;
};

switch (Mode)
{
case EElementusInventorySortingMode::ID:
ElementusItems.Sort(
[SortByOrientation](const FElementusItemInfo& A, const FElementusItemInfo& B)
{
return UElementusInventoryFunctions::IsItemValid(A) && SortByOrientation(A.ItemId, B.ItemId);
}
);
break;

case EElementusInventorySortingMode::Name:
ElementusItems.Sort(
[SortByOrientation](const FElementusItemInfo& A, const FElementusItemInfo& B)
{
if (!UElementusInventoryFunctions::IsItemValid(A))
{
return false;
}

if (const UElementusItemData* const ItemDataA = UElementusInventoryFunctions::GetSingleItemDataById(A.ItemId, { "Data" }))
{
if (const UElementusItemData* const ItemDataB = UElementusInventoryFunctions::GetSingleItemDataById(B.ItemId, { "Data" }))
{
return SortByOrientation(ItemDataA->ItemName, ItemDataB->ItemName);
}
}

return false;
}
);
break;

case EElementusInventorySortingMode::Type:
ElementusItems.Sort(
[SortByOrientation](const FElementusItemInfo& A, const FElementusItemInfo& B)
{
if (!UElementusInventoryFunctions::IsItemValid(A))
{
return false;
}

if (const UElementusItemData* const ItemDataA = UElementusInventoryFunctions::GetSingleItemDataById(A.ItemId, { "Data" }))
{
if (const UElementusItemData* const ItemDataB = UElementusInventoryFunctions::GetSingleItemDataById(B.ItemId, { "Data" }))
{
return SortByOrientation(ItemDataA->ItemType, ItemDataB->ItemType);
}
}

return false;
}
);
break;

case EElementusInventorySortingMode::IndividualValue:
ElementusItems.Sort(
[SortByOrientation](const FElementusItemInfo& A, const FElementusItemInfo& B)
{
if (!UElementusInventoryFunctions::IsItemValid(A))
{
return false;
}

if (const UElementusItemData* const ItemDataA = UElementusInventoryFunctions::GetSingleItemDataById(A.ItemId, { "Data" }))
{
if (const UElementusItemData* const ItemDataB = UElementusInventoryFunctions::GetSingleItemDataById(B.ItemId, { "Data" }))
{
return SortByOrientation(ItemDataA->ItemValue, ItemDataB->ItemValue);
}
}

return false;
}
);
break;

case EElementusInventorySortingMode::StackValue:
ElementusItems.Sort(
[SortByOrientation](const FElementusItemInfo& A, const FElementusItemInfo& B)
{
if (!UElementusInventoryFunctions::IsItemValid(A))
{
return false;
}

if (const UElementusItemData* const ItemDataA = UElementusInventoryFunctions::GetSingleItemDataById(A.ItemId, { "Data" }))
{
if (const UElementusItemData* const ItemDataB = UElementusInventoryFunctions::GetSingleItemDataById(B.ItemId, { "Data" }))
{
return SortByOrientation(ItemDataA->ItemValue * A.Quantity, ItemDataB->ItemValue * B.Quantity);
}
}

return false;
}
);
break;

case EElementusInventorySortingMode::IndividualWeight:
ElementusItems.Sort(
[SortByOrientation](const FElementusItemInfo& A, const FElementusItemInfo& B)
{
if (!UElementusInventoryFunctions::IsItemValid(A))
{
return false;
}

if (const UElementusItemData* const ItemDataA = UElementusInventoryFunctions::GetSingleItemDataById(A.ItemId, { "Data" }))
{
if (const UElementusItemData* const ItemDataB = UElementusInventoryFunctions::GetSingleItemDataById(B.ItemId, { "Data" }))
{
return SortByOrientation(ItemDataA->ItemWeight, ItemDataB->ItemWeight);
}
}

return false;
}
);
break;

case EElementusInventorySortingMode::StackWeight:
ElementusItems.Sort(
[SortByOrientation](const FElementusItemInfo& A, const FElementusItemInfo& B)
{
if (!UElementusInventoryFunctions::IsItemValid(A))
{
return false;
}

if (const UElementusItemData* const ItemDataA = UElementusInventoryFunctions::GetSingleItemDataById(A.ItemId, { "Data" }))
{
if (const UElementusItemData* const ItemDataB = UElementusInventoryFunctions::GetSingleItemDataById(B.ItemId, { "Data" }))
{
return SortByOrientation(ItemDataA->ItemWeight * A.Quantity, ItemDataB->ItemWeight * B.Quantity);
}
}

return false;
}
);
break;

case EElementusInventorySortingMode::Quantity:
ElementusItems.Sort(
[SortByOrientation](const FElementusItemInfo& A, const FElementusItemInfo& B)
{
return UElementusInventoryFunctions::IsItemValid(A) && SortByOrientation(A.Quantity, B.Quantity);
}
);
break;

case EElementusInventorySortingMode::Level:
ElementusItems.Sort(
[SortByOrientation](const FElementusItemInfo& A, const FElementusItemInfo& B)
{
return UElementusInventoryFunctions::IsItemValid(A) && SortByOrientation(A.Level, B.Level);
}
);
break;

case EElementusInventorySortingMode::Tags:
ElementusItems.Sort(
[SortByOrientation](const FElementusItemInfo& A, const FElementusItemInfo& B)
{
return UElementusInventoryFunctions::IsItemValid(A) && SortByOrientation(A.Tags.Num(), B.Tags.Num());
}
);
break;

default:
break;
}
}

void UElementusInventoryComponent::BeginPlay()
{
Super::BeginPlay();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,28 @@ enum class EElementusInventoryUpdateOperation : uint8
Remove
};

UENUM(Category = "Elementus Inventory | Enumerations")
enum class EElementusInventorySortingMode : uint8
{
ID,
Name,
Type,
IndividualValue,
StackValue,
IndividualWeight,
StackWeight,
Quantity,
Level,
Tags
};

UENUM(Category = "Elementus Inventory | Enumerations")
enum class EElementusInventorySortingOrientation : uint8
{
Ascending,
Descending
};

USTRUCT(Category = "Elementus Inventory | Structures")
struct FItemModifierData
{
Expand Down Expand Up @@ -169,6 +191,9 @@ class ELEMENTUSINVENTORY_API UElementusInventoryComponent : public UActorCompone
UFUNCTION(Server, Reliable, BlueprintCallable, Category = "Elementus Inventory")
void AddItems(const TArray<FElementusItemInfo>& Items);

UFUNCTION(BlueprintCallable, Category = "Elementus Inventory")
void SortInventory(const EElementusInventorySortingMode Mode, const EElementusInventorySortingOrientation Orientation);

protected:
/* Items that this inventory have */
UPROPERTY(ReplicatedUsing = OnRep_ElementusItems, EditAnywhere, BlueprintReadOnly, Category = "Elementus Inventory", meta = (Getter = "GetItemsArray", ArrayClamp = "MaxNumItems"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ struct FPrimaryElementusItemId : public FPrimaryAssetId
explicit FPrimaryElementusItemId(const FString& TypeAndName) : Super(TypeAndName)
{
}

bool operator>(const FPrimaryElementusItemId& Other) const
{
return ToString() > Other.ToString();
}

bool operator<(const FPrimaryElementusItemId& Other) const
{
return ToString() < Other.ToString();
}
};

USTRUCT(BlueprintType, Category = "Elementus Inventory | Structs")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ void FElementusInventoryEditorModule::RegisterMenus()
const auto EditorTabSpawnerDelegate = FOnSpawnTab::CreateRaw(this, &FElementusInventoryEditorModule::OnSpawnTab, ElementusEditorTabId);

FGlobalTabmanager::Get()->RegisterNomadTabSpawner(ElementusEditorTabId, EditorTabSpawnerDelegate)
.SetDisplayName(FText::FromString("Elementus Inventory Management"))
.SetTooltipText(FText::FromString("Open Elementus Inventory Window"))
.SetDisplayName(FText::FromString(TEXT("Elementus Inventory Management")))
.SetTooltipText(FText::FromString(TEXT("Open Elementus Inventory Window")))
.SetGroup(Menu.ToSharedRef())
.SetIcon(FSlateIcon(AppStyleName, "Icons.Package"));

const auto ItemCreatorTabSpawnerDelegate = FOnSpawnTab::CreateRaw(this, &FElementusInventoryEditorModule::OnSpawnTab, ItemCreatorTabId);

FGlobalTabmanager::Get()->RegisterNomadTabSpawner(ItemCreatorTabId, ItemCreatorTabSpawnerDelegate)
.SetDisplayName(FText::FromString("Elementus Item Creator"))
.SetDisplayName(FText::FromString(TEXT("Elementus Item Creator")))
.SetGroup(Menu.ToSharedRef())
.SetIcon(FSlateIcon(AppStyleName, "Icons.PlusCircle"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class SElementusDetailsPanel final : public IPropertyTypeCustomization
public:
static TSharedRef<IPropertyTypeCustomization> MakeInstance()
{
return MakeShareable(new SElementusDetailsPanel());
return MakeShared<SElementusDetailsPanel>();
}

protected:
Expand Down
63 changes: 36 additions & 27 deletions Source/ElementusInventoryEditor/Private/SElementusFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,47 @@

void SElementusFrame::Construct([[maybe_unused]] const FArguments& InArgs)
{
const TSharedRef<SElementusTable> Table = SNew(SElementusTable);

ChildSlot
[
SNew(SHorizontalBox)
+ SHorizontalBox::Slot()
.AutoWidth()
.MaxWidth(300.f)
ConstructContent()
];
}

TSharedRef<SWidget> SElementusFrame::ConstructContent()
{
constexpr float SlotPadding = 4.f;

SAssignNew(Table, SElementusTable);

return SNew(SHorizontalBox)
+ SHorizontalBox::Slot()
.AutoWidth()
.MaxWidth(300.f)
[
SNew(SScrollBox)
+ SScrollBox::Slot()
[
SNew(SScrollBox)
+ SScrollBox::Slot()
SNew(SVerticalBox)
+ SVerticalBox::Slot()
.Padding(SlotPadding)
.AutoHeight()
[
SNew(SVerticalBox)
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(SElementusSearch)
.OnSearchTextChanged(Table, &SElementusTable::OnSearchTextModified)
.OnCheckboxStateChanged(Table, &SElementusTable::OnSearchTypeModified)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(SElementusUtils)
.TableSource(&Table.Get())
]
SNew(SElementusSearch)
.OnSearchTextChanged(Table.ToSharedRef(), &SElementusTable::OnSearchTextModified)
.OnCheckboxStateChanged(Table.ToSharedRef(), &SElementusTable::OnSearchTypeModified)
]
+ SVerticalBox::Slot()
.Padding(SlotPadding)
.AutoHeight()
[
SNew(SElementusUtils)
.TableSource(Table)
]
]
+ SHorizontalBox::Slot()
.FillWidth(1.f)
[
Table
]
]
+ SHorizontalBox::Slot()
.FillWidth(1.f)
[
Table.ToSharedRef()
];
}
5 changes: 5 additions & 0 deletions Source/ElementusInventoryEditor/Private/SElementusFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ class SElementusFrame final : public SCompoundWidget
SLATE_END_ARGS()

void Construct(const FArguments& InArgs);

private:
TSharedRef<SWidget> ConstructContent();

TSharedPtr<class SElementusTable> Table;
};
Loading

0 comments on commit 78d99f6

Please sign in to comment.