From 459925373ac2fd91e42dd0ab01fd687a43b5e7d3 Mon Sep 17 00:00:00 2001 From: lucoiso Date: Mon, 14 Aug 2023 19:18:17 +0100 Subject: [PATCH 1/7] add native function to sort inventory - override and implement in child classed --- ElementusInventory.uplugin | 4 ++-- .../Private/Components/ElementusInventoryComponent.cpp | 5 +++++ .../Public/Components/ElementusInventoryComponent.h | 3 +++ .../Private/SElementusDetailsPanel.h | 2 +- .../Private/SElementusItemCreator.cpp | 6 +++--- Source/ElementusInventoryEditor/Private/SElementusTable.cpp | 2 +- 6 files changed, 15 insertions(+), 7 deletions(-) diff --git a/ElementusInventory.uplugin b/ElementusInventory.uplugin index d8cc933..491c285 100644 --- a/ElementusInventory.uplugin +++ b/ElementusInventory.uplugin @@ -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", diff --git a/Source/ElementusInventory/Private/Components/ElementusInventoryComponent.cpp b/Source/ElementusInventory/Private/Components/ElementusInventoryComponent.cpp index 64a3b4f..3ef5a46 100644 --- a/Source/ElementusInventory/Private/Components/ElementusInventoryComponent.cpp +++ b/Source/ElementusInventory/Private/Components/ElementusInventoryComponent.cpp @@ -111,6 +111,11 @@ bool UElementusInventoryComponent::CanGiveItem(const FElementusItemInfo InItemIn return false; } +void UElementusInventoryComponent::SortInventory_Implementation() +{ + // Override this function to implement your own sorting algorithm +} + void UElementusInventoryComponent::BeginPlay() { Super::BeginPlay(); diff --git a/Source/ElementusInventory/Public/Components/ElementusInventoryComponent.h b/Source/ElementusInventory/Public/Components/ElementusInventoryComponent.h index 80e8be6..171ae57 100644 --- a/Source/ElementusInventory/Public/Components/ElementusInventoryComponent.h +++ b/Source/ElementusInventory/Public/Components/ElementusInventoryComponent.h @@ -169,6 +169,9 @@ class ELEMENTUSINVENTORY_API UElementusInventoryComponent : public UActorCompone UFUNCTION(Server, Reliable, BlueprintCallable, Category = "Elementus Inventory") void AddItems(const TArray& Items); + UFUNCTION(BlueprintNativeEvent, Category = "Elementus Inventory") + void SortInventory(); + protected: /* Items that this inventory have */ UPROPERTY(ReplicatedUsing = OnRep_ElementusItems, EditAnywhere, BlueprintReadOnly, Category = "Elementus Inventory", meta = (Getter = "GetItemsArray", ArrayClamp = "MaxNumItems")) diff --git a/Source/ElementusInventoryEditor/Private/SElementusDetailsPanel.h b/Source/ElementusInventoryEditor/Private/SElementusDetailsPanel.h index a060009..bef55ed 100644 --- a/Source/ElementusInventoryEditor/Private/SElementusDetailsPanel.h +++ b/Source/ElementusInventoryEditor/Private/SElementusDetailsPanel.h @@ -12,7 +12,7 @@ class SElementusDetailsPanel final : public IPropertyTypeCustomization public: static TSharedRef MakeInstance() { - return MakeShareable(new SElementusDetailsPanel()); + return MakeShared(); } protected: diff --git a/Source/ElementusInventoryEditor/Private/SElementusItemCreator.cpp b/Source/ElementusInventoryEditor/Private/SElementusItemCreator.cpp index b18e6c2..d9c6a84 100644 --- a/Source/ElementusInventoryEditor/Private/SElementusItemCreator.cpp +++ b/Source/ElementusInventoryEditor/Private/SElementusItemCreator.cpp @@ -24,7 +24,7 @@ void SElementusItemCreator::Construct([[maybe_unused]] const FArguments&) { constexpr float Slot_Padding = 1.f; - ImageIcon_ThumbnailPool = MakeShareable(new FAssetThumbnailPool(1024)); + ImageIcon_ThumbnailPool = MakeShared(1024); #if ENGINE_MAJOR_VERSION < 5 using FAppStyle = FEditorStyle; @@ -353,7 +353,7 @@ void SElementusItemCreator::UpdateFolders() { for (const FString& Path : Info.AssetScanPaths) { - AssetFoldersArr.Add(MakeShareable(new FString(Path))); + AssetFoldersArr.Add(MakeShared(Path)); } } } @@ -428,7 +428,7 @@ TArray> SElementusItemCreator::GetEnumValuesAsStringArray() TArray> EnumValues; for (uint32 iterator = 0; iterator < static_cast(EElementusItemType::MAX); iterator++) { - EnumValues.Add(MakeShareable(new FString(UElementusInventoryFunctions::ElementusItemEnumTypeToString(static_cast(iterator))))); + EnumValues.Add(MakeShared(UElementusInventoryFunctions::ElementusItemEnumTypeToString(static_cast(iterator)))); } return EnumValues; diff --git a/Source/ElementusInventoryEditor/Private/SElementusTable.cpp b/Source/ElementusInventoryEditor/Private/SElementusTable.cpp index e4f667d..1fd14df 100644 --- a/Source/ElementusInventoryEditor/Private/SElementusTable.cpp +++ b/Source/ElementusInventoryEditor/Private/SElementusTable.cpp @@ -222,7 +222,7 @@ void SElementusTable::UpdateItemList() for (const FPrimaryAssetId& Iterator : UElementusInventoryFunctions::GetAllElementusItemIds()) { - ItemArr.Add(MakeShareable(new FElementusItemRowData(Iterator))); + ItemArr.Add(MakeShared(Iterator)); } EdListView->RequestListRefresh(); From 21dcc48ed1ac1dfc6833bc590947febbe6298fd8 Mon Sep 17 00:00:00 2001 From: lucoiso Date: Tue, 15 Aug 2023 16:05:34 +0100 Subject: [PATCH 2/7] Slate Adjustments --- .../Private/ElementusInventoryEditor.cpp | 6 +++--- .../Private/SElementusItemCreator.cpp | 4 ++-- .../ElementusInventoryEditor/Private/SElementusSearch.cpp | 2 +- Source/ElementusInventoryEditor/Private/SElementusUtils.cpp | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Source/ElementusInventoryEditor/Private/ElementusInventoryEditor.cpp b/Source/ElementusInventoryEditor/Private/ElementusInventoryEditor.cpp index be2378f..1eb80fe 100644 --- a/Source/ElementusInventoryEditor/Private/ElementusInventoryEditor.cpp +++ b/Source/ElementusInventoryEditor/Private/ElementusInventoryEditor.cpp @@ -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")); } diff --git a/Source/ElementusInventoryEditor/Private/SElementusItemCreator.cpp b/Source/ElementusInventoryEditor/Private/SElementusItemCreator.cpp index d9c6a84..d9f2f53 100644 --- a/Source/ElementusInventoryEditor/Private/SElementusItemCreator.cpp +++ b/Source/ElementusInventoryEditor/Private/SElementusItemCreator.cpp @@ -313,7 +313,7 @@ void SElementusItemCreator::Construct([[maybe_unused]] const FArguments&) .AutoHeight() [ SNew(SButton) - .Text(FText::FromString("Create Item")) + .Text(FText::FromString(TEXT("Create Item"))) .OnClicked(this, &SElementusItemCreator::HandleCreateItemButtonClicked) .IsEnabled(this, &SElementusItemCreator::IsCreateEnabled) .ToolTip(ToolTip) @@ -368,7 +368,7 @@ FReply SElementusItemCreator::HandleCreateItemButtonClicked() const { if (AssetFolder.IsNone() || AssetName.IsNone()) { - FMessageDialog::Open(EAppMsgType::Ok, FText::FromString("Please enter the asset name and folder for the new item.")); + FMessageDialog::Open(EAppMsgType::Ok, FText::FromString(TEXT("Please enter the asset name and folder for the new item."))); return FReply::Handled(); } diff --git a/Source/ElementusInventoryEditor/Private/SElementusSearch.cpp b/Source/ElementusInventoryEditor/Private/SElementusSearch.cpp index 8de2e82..43f08bc 100644 --- a/Source/ElementusInventoryEditor/Private/SElementusSearch.cpp +++ b/Source/ElementusInventoryEditor/Private/SElementusSearch.cpp @@ -51,7 +51,7 @@ void SElementusSearch::Construct(const FArguments& InArgs) .Padding(Slot_Padding) [ SNew(STextBlock) - .Text(FText::FromString("Show only types:")) + .Text(FText::FromString(TEXT("Show only types:"))) .Font(AppStyle.GetFontStyle("NormalFontBold")) ] + SVerticalBox::Slot() diff --git a/Source/ElementusInventoryEditor/Private/SElementusUtils.cpp b/Source/ElementusInventoryEditor/Private/SElementusUtils.cpp index 81aa6a1..0c3c407 100644 --- a/Source/ElementusInventoryEditor/Private/SElementusUtils.cpp +++ b/Source/ElementusInventoryEditor/Private/SElementusUtils.cpp @@ -37,7 +37,7 @@ void SElementusUtils::Construct(const FArguments& InArgs) .Padding(Slot_Padding) [ SNew(STextBlock) - .Text(FText::FromString("Utils:")) + .Text(FText::FromString(TEXT("Utils:")) .Font(AppStyle.GetFontStyle("NormalFontBold")) ] + SVerticalBox::Slot() @@ -92,7 +92,7 @@ FReply SElementusUtils::OnButtonClicked(const uint32 ButtonId) const } else { - FMessageDialog::Open(EAppMsgType::Ok, FText::FromString("Work in Progress - ButtonId: " + FString::FromInt(ButtonId))); + FMessageDialog::Open(EAppMsgType::Ok, FText::FromString(TEXT("Work in Progress - ButtonId: ") + FString::FromInt(ButtonId))); } return FReply::Handled(); From 916bcf86473a86102ca4c1828b894a871067142a Mon Sep 17 00:00:00 2001 From: lucoiso Date: Tue, 15 Aug 2023 16:40:55 +0100 Subject: [PATCH 3/7] Slate Adjustments --- .../Private/SElementusFrame.cpp | 59 +- .../Private/SElementusFrame.h | 5 + .../Private/SElementusItemCreator.cpp | 553 +++++++++--------- .../Private/SElementusItemCreator.h | 17 +- .../Private/SElementusSearch.cpp | 155 ++--- .../Private/SElementusSearch.h | 6 +- .../Private/SElementusTable.cpp | 52 +- .../Private/SElementusTable.h | 12 +- .../Private/SElementusUtils.cpp | 58 +- .../Private/SElementusUtils.h | 8 +- 10 files changed, 482 insertions(+), 443 deletions(-) diff --git a/Source/ElementusInventoryEditor/Private/SElementusFrame.cpp b/Source/ElementusInventoryEditor/Private/SElementusFrame.cpp index fb31ef1..f58e931 100644 --- a/Source/ElementusInventoryEditor/Private/SElementusFrame.cpp +++ b/Source/ElementusInventoryEditor/Private/SElementusFrame.cpp @@ -10,38 +10,43 @@ void SElementusFrame::Construct([[maybe_unused]] const FArguments& InArgs) { - const TSharedRef Table = SNew(SElementusTable); - ChildSlot [ - SNew(SHorizontalBox) - + SHorizontalBox::Slot() - .AutoWidth() - .MaxWidth(300.f) + ConstructContent() + ]; +} + +TSharedRef SElementusFrame::ConstructContent() +{ + SAssignNew(Table, SElementusTable); + + return SNew(SHorizontalBox) + + SHorizontalBox::Slot() + .AutoWidth() + .MaxWidth(300.f) + [ + SNew(SScrollBox) + + SScrollBox::Slot() [ - SNew(SScrollBox) - + SScrollBox::Slot() + SNew(SVerticalBox) + + SVerticalBox::Slot() + .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() + .AutoHeight() + [ + SNew(SElementusUtils) + .TableSource(Table) ] ] - + SHorizontalBox::Slot() - .FillWidth(1.f) - [ - Table - ] + ] + + SHorizontalBox::Slot() + .FillWidth(1.f) + [ + Table.ToSharedRef() ]; } \ No newline at end of file diff --git a/Source/ElementusInventoryEditor/Private/SElementusFrame.h b/Source/ElementusInventoryEditor/Private/SElementusFrame.h index 2a12b47..d501b4f 100644 --- a/Source/ElementusInventoryEditor/Private/SElementusFrame.h +++ b/Source/ElementusInventoryEditor/Private/SElementusFrame.h @@ -16,4 +16,9 @@ class SElementusFrame final : public SCompoundWidget SLATE_END_ARGS() void Construct(const FArguments& InArgs); + +private: + TSharedRef ConstructContent(); + + TSharedPtr Table; }; diff --git a/Source/ElementusInventoryEditor/Private/SElementusItemCreator.cpp b/Source/ElementusInventoryEditor/Private/SElementusItemCreator.cpp index d9f2f53..b154d50 100644 --- a/Source/ElementusInventoryEditor/Private/SElementusItemCreator.cpp +++ b/Source/ElementusInventoryEditor/Private/SElementusItemCreator.cpp @@ -10,11 +10,12 @@ #include #include #include +#include #include #include #include #include -#include +#include #if ENGINE_MAJOR_VERSION >= 5 #include @@ -22,7 +23,18 @@ void SElementusItemCreator::Construct([[maybe_unused]] const FArguments&) { - constexpr float Slot_Padding = 1.f; + ItemTypesArr = GetEnumValuesAsStringArray(); + UpdateFolders(); + + ChildSlot + [ + ConstructContent() + ]; +} + +TSharedRef SElementusItemCreator::ConstructContent() +{ + constexpr float SlotPadding = 1.f; ImageIcon_ThumbnailPool = MakeShared(1024); @@ -30,18 +42,6 @@ void SElementusItemCreator::Construct([[maybe_unused]] const FArguments&) using FAppStyle = FEditorStyle; #endif - const ISlateStyle& AppStyle = FAppStyle::Get(); - - const auto CenterTextCreator_Lambda = [&AppStyle](const FString& InStr) -> const TSharedRef - { - return SNew(STextBlock) - .Text(FText::FromString(InStr)) - .TextStyle(AppStyle, "PropertyEditor.AssetClass") - .Font(AppStyle.GetFontStyle("PropertyWindow.NormalFont")) - .Justification(ETextJustify::Left) - .Margin(4.f); - }; - const auto ObjEntryBoxCreator_Lambda = [this](UClass* ObjClass, const int32 ObjId) -> const TSharedRef { return SNew(SObjectPropertyEntryBox) @@ -56,270 +56,289 @@ void SElementusItemCreator::Construct([[maybe_unused]] const FArguments&) .OnObjectChanged(this, &SElementusItemCreator::OnObjChanged, ObjId); }; - const auto ContentPairCreator_Lambda = [this, &AppStyle](const TSharedRef Content1, const TSharedRef Content2) -> const TSharedRef - { - return SNew(SBorder) - .BorderImage(AppStyle.GetBrush("ToolPanel.GroupBorder")) + return SNew(SScrollBox) + + SScrollBox::Slot() + [ + SNew(SGridPanel) + .FillColumn(1, 1.f) + + SGridPanel::Slot(0, 0) + .Padding(SlotPadding) + [ + SNew(STextBlock) + .Text(FText::FromString(TEXT("ID"))) + .TextStyle(FAppStyle::Get(), "PropertyEditor.AssetClass") + .Font(FAppStyle::Get().GetFontStyle("PropertyWindow.NormalFont")) + ] + + SGridPanel::Slot(1, 0) + .Padding(SlotPadding) + [ + SNew(SNumericEntryBox) + .AllowSpin(false) + .MinValue(1) + .Value_Lambda([this] { return ItemId; }) + .OnValueChanged_Lambda( + [this](const int32 InValue) + { + ItemId = InValue; + } + ) + ] + + SGridPanel::Slot(0, 1) + .Padding(SlotPadding) + [ + SNew(STextBlock) + .Text(FText::FromString(TEXT("Object"))) + .TextStyle(FAppStyle::Get(), "PropertyEditor.AssetClass") + .Font(FAppStyle::Get().GetFontStyle("PropertyWindow.NormalFont")) + ] + + SGridPanel::Slot(1, 1) + .Padding(Slot_Padding) + [ + ObjEntryBoxCreator_Lambda(UObject::StaticClass(), 0) + ] + + SGridPanel::Slot(0, 2) + .Padding(SlotPadding) + [ + SNew(STextBlock) + .Text(FText::FromString(TEXT("Class"))) + .TextStyle(FAppStyle::Get(), "PropertyEditor.AssetClass") + .Font(FAppStyle::Get().GetFontStyle("PropertyWindow.NormalFont")) + ] + + SGridPanel::Slot(1, 2) + .Padding(SlotPadding) + [ + SNew(SClassPropertyEntryBox) + .AllowAbstract(true) + .SelectedClass(this, &SElementusItemCreator::GetSelectedEntryClass) + .OnSetClass(this, &SElementusItemCreator::HandleNewEntryClassSelected) + ] + + SGridPanel::Slot(0, 3) + .Padding(SlotPadding) + [ + SNew(STextBlock) + .Text(FText::FromString(TEXT("Name"))) + .TextStyle(FAppStyle::Get(), "PropertyEditor.AssetClass") + .Font(FAppStyle::Get().GetFontStyle("PropertyWindow.NormalFont")) + ] + + SGridPanel::Slot(1, 3) + .Padding(SlotPadding) + [ + SNew(SEditableTextBox) + .OnTextChanged_Lambda( + [this](const FText& InText) + { + ItemName = *InText.ToString(); + } + ) + ] + + SGridPanel::Slot(0, 4) + .Padding(SlotPadding) + [ + SNew(STextBlock) + .Text(FText::FromString(TEXT("Description"))) + .TextStyle(FAppStyle::Get(), "PropertyEditor.AssetClass") + .Font(FAppStyle::Get().GetFontStyle("PropertyWindow.NormalFont")) + ] + + SGridPanel::Slot(1, 4) + .Padding(Slot_Padding) + [ + SNew(SMultiLineEditableTextBox) + .OnTextChanged_Lambda( + [this](const FText& InText) + { + ItemDescription = InText; + } + ) + ] + + SGridPanel::Slot(0, 5) + .Padding(SlotPadding) + [ + SNew(STextBlock) + .Text(FText::FromString(TEXT("Type"))) + .TextStyle(FAppStyle::Get(), "PropertyEditor.AssetClass") + .Font(FAppStyle::Get().GetFontStyle("PropertyWindow.NormalFont")) + ] + + SGridPanel::Slot(1, 5) + .Padding(SlotPadding) + [ + SNew(STextComboBox) + .OptionsSource(&ItemTypesArr) + .OnSelectionChanged_Lambda( + [this](const TSharedPtr& InStr, [[maybe_unused]] ESelectInfo::Type) + { + ItemType = ItemTypesArr.Find(InStr); + } + ) + ] + + SGridPanel::Slot(0, 6) + .Padding(SlotPadding) + [ + SNew(STextBlock) + .Text(FText::FromString(TEXT("Is Stackable"))) + .TextStyle(FAppStyle::Get(), "PropertyEditor.AssetClass") + .Font(FAppStyle::Get().GetFontStyle("PropertyWindow.NormalFont")) + ] + + SGridPanel::Slot(1, 6) + .Padding(SlotPadding) + [ + SNew(SCheckBox) + .IsChecked(ECheckBoxState::Checked) + .OnCheckStateChanged_Lambda( + [this](const ECheckBoxState InState) + { + bIsStackable = InState == ECheckBoxState::Checked; + } + ) + ] + + SGridPanel::Slot(0, 7) + .Padding(SlotPadding) + [ + SNew(STextBlock) + .Text(FText::FromString(TEXT("Value"))) + .TextStyle(FAppStyle::Get(), "PropertyEditor.AssetClass") + .Font(FAppStyle::Get().GetFontStyle("PropertyWindow.NormalFont")) + ] + + SGridPanel::Slot(1, 7) + .Padding(SlotPadding) + [ + SNew(SNumericEntryBox) + .AllowSpin(false) + .MinValue(0.0f) + .Value_Lambda([this] { return ItemValue; }) + .OnValueChanged_Lambda( + [this](const float InValue) + { + ItemValue = InValue; + } + ) + ] + + SGridPanel::Slot(0, 8) + .Padding(SlotPadding) + [ + SNew(STextBlock) + .Text(FText::FromString(TEXT("Weight"))) + .TextStyle(FAppStyle::Get(), "PropertyEditor.AssetClass") + .Font(FAppStyle::Get().GetFontStyle("PropertyWindow.NormalFont")) + ] + + SGridPanel::Slot(1, 8) + .Padding(SlotPadding) + [ + SNew(SNumericEntryBox) + .AllowSpin(false) + .MinValue(0.0f) + .Value_Lambda([this] { return ItemWeight; }) + .OnValueChanged_Lambda( + [this](const float InValue) + { + ItemWeight = InValue; + } + ) + ] + + SGridPanel::Slot(0, 9) + .Padding(SlotPadding) + [ + SNew(STextBlock) + .Text(FText::FromString(TEXT("Icon"))) + .TextStyle(FAppStyle::Get(), "PropertyEditor.AssetClass") + .Font(FAppStyle::Get().GetFontStyle("PropertyWindow.NormalFont")) + ] + + SGridPanel::Slot(1, 9) + .Padding(SlotPadding) + [ + ObjEntryBoxCreator_Lambda(UTexture2D::StaticClass(), 1) + ] + + SGridPanel::Slot(0, 10) + .Padding(SlotPadding) + [ + SNew(STextBlock) + .Text(FText::FromString(TEXT("Image"))) + .TextStyle(FAppStyle::Get(), "PropertyEditor.AssetClass") + .Font(FAppStyle::Get().GetFontStyle("PropertyWindow.NormalFont")) + ] + + SGridPanel::Slot(1, 10) + .Padding(SlotPadding) + [ + ObjEntryBoxCreator_Lambda(UTexture2D::StaticClass(), 2) + ] + + SGridPanel::Slot(0, 11) + .Padding(SlotPadding) + [ + SNew(STextBlock) + .Text(FText::FromString(TEXT("Asset Name"))) + .TextStyle(FAppStyle::Get(), "PropertyEditor.AssetClass") + .Font(FAppStyle::Get().GetFontStyle("PropertyWindow.NormalFont")) + ] + + SGridPanel::Slot(1, 11) + .Padding(SlotPadding) + [ + SNew(SEditableTextBox) + .OnTextChanged_Lambda( + [this](const FText& InText) + { + AssetName = *InText.ToString(); + } + ) + ] + + SGridPanel::Slot(0, 12) + .Padding(SlotPadding) + [ + SNew(STextBlock) + .Text(FText::FromString(TEXT("Asset Folder"))) + .TextStyle(FAppStyle::Get(), "PropertyEditor.AssetClass") + .Font(FAppStyle::Get().GetFontStyle("PropertyWindow.NormalFont")) + ] + + SGridPanel::Slot(1, 12) + .Padding(SlotPadding) [ SNew(SHorizontalBox) + SHorizontalBox::Slot() - .FillWidth(0.5f) - .HAlign(HAlign_Fill) - .VAlign(VAlign_Center) [ - Content1 + SNew(STextComboBox) + .OptionsSource(&AssetFoldersArr) + .OnSelectionChanged_Lambda( + [this](const TSharedPtr& InStr, [[maybe_unused]] ESelectInfo::Type) + { + AssetFolder = FName(*InStr.Get()); + } + ) ] + SHorizontalBox::Slot() - .FillWidth(0.5f) - .MaxWidth(250.f) - .HAlign(HAlign_Fill) - .VAlign(VAlign_Center) + .AutoWidth() [ - Content2 - ] - ]; - }; - - ItemTypesArr = GetEnumValuesAsStringArray(); - UpdateFolders(); - - const TSharedRef ToolTip = SNew(SToolTip) - .Text(FText::FromString(TEXT("Already exists a item with this Id."))) - .Visibility_Lambda( - [this]() -> EVisibility - { - return IsCreateEnabled() ? EVisibility::Collapsed : EVisibility::Visible; - } - ); - - ChildSlot - [ - SNew(SBorder) - [ - SNew(SScrollBox) - + SScrollBox::Slot() - [ - SNew(SVerticalBox) - + SVerticalBox::Slot() - .Padding(Slot_Padding) - .AutoHeight() - [ - ContentPairCreator_Lambda( - CenterTextCreator_Lambda("Item Id"), - SNew(SNumericEntryBox) - .AllowSpin(false) - .MinValue(1) - .Value_Lambda([this] { return ItemId; }) - .OnValueChanged_Lambda( - [this](const int32 InValue) - { - ItemId = InValue; - } - ) - ) - ] - + SVerticalBox::Slot() - .Padding(Slot_Padding) - .AutoHeight() - [ - ContentPairCreator_Lambda( - CenterTextCreator_Lambda("Item Object"), - ObjEntryBoxCreator_Lambda(UObject::StaticClass(), 0) - ) - ] - + SVerticalBox::Slot() - .Padding(Slot_Padding) - .AutoHeight() - [ - ContentPairCreator_Lambda( - CenterTextCreator_Lambda("Item Class"), - SNew(SClassPropertyEntryBox) - .AllowAbstract(true) - .SelectedClass(this, &SElementusItemCreator::GetSelectedEntryClass) - .OnSetClass(this, &SElementusItemCreator::HandleNewEntryClassSelected) - ) - ] - + SVerticalBox::Slot() - .Padding(Slot_Padding) - .AutoHeight() - [ - ContentPairCreator_Lambda( - CenterTextCreator_Lambda("Item Name"), - SNew(SEditableTextBox) - .OnTextChanged_Lambda( - [this](const FText& InText) - { - ItemName = *InText.ToString(); - } - ) - ) - ] - + SVerticalBox::Slot() - .Padding(Slot_Padding) - .AutoHeight() - [ - ContentPairCreator_Lambda( - CenterTextCreator_Lambda("Item Description"), - SNew(SMultiLineEditableTextBox) - .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_Lambda( - [this](const TSharedPtr& InStr, [[maybe_unused]] ESelectInfo::Type) - { - ItemType = ItemTypesArr.Find(InStr); - } - ) - ) - ] - + SVerticalBox::Slot() - .Padding(Slot_Padding) - .AutoHeight() - [ - ContentPairCreator_Lambda( - CenterTextCreator_Lambda("Is Stackable"), - SNew(SCheckBox) - .IsChecked(ECheckBoxState::Checked) - .OnCheckStateChanged_Lambda( - [this](const ECheckBoxState InState) - { - bIsStackable = InState == ECheckBoxState::Checked; - } - ) - ) - ] - + SVerticalBox::Slot() - .Padding(Slot_Padding) - .AutoHeight() - [ - ContentPairCreator_Lambda( - CenterTextCreator_Lambda("Item Value"), - SNew(SNumericEntryBox) - .AllowSpin(false) - .MinValue(0.0f) - .Value_Lambda([this] { return ItemValue; }) - .OnValueChanged_Lambda( - [this](const float InValue) - { - ItemValue = InValue; - } - ) - ) - ] - + SVerticalBox::Slot() - .Padding(Slot_Padding) - .AutoHeight() - [ - ContentPairCreator_Lambda( - CenterTextCreator_Lambda("Item Weight"), - SNew(SNumericEntryBox) - .AllowSpin(false) - .MinValue(0.0f) - .Value_Lambda([this] { return ItemWeight; }) - .OnValueChanged_Lambda( - [this](const float InValue) - { - ItemWeight = InValue; - } - ) - ) - ] - + SVerticalBox::Slot() - .Padding(Slot_Padding) - .AutoHeight() - [ - ContentPairCreator_Lambda( - CenterTextCreator_Lambda("Item Icon"), - ObjEntryBoxCreator_Lambda(UTexture2D::StaticClass(), 1) - ) - ] - + SVerticalBox::Slot() - .Padding(Slot_Padding) - .AutoHeight() - [ - ContentPairCreator_Lambda( - CenterTextCreator_Lambda("Item Image"), - ObjEntryBoxCreator_Lambda(UTexture2D::StaticClass(), 2) - ) - ] - + SVerticalBox::Slot() - .Padding(Slot_Padding) - .AutoHeight() - [ - ContentPairCreator_Lambda( - CenterTextCreator_Lambda("Asset Name"), - SNew(SEditableTextBox) - .OnTextChanged_Lambda( - [this](const FText& InText) - { - AssetName = *InText.ToString(); - } - ) - ) - ] - + SVerticalBox::Slot() - .Padding(Slot_Padding) - .AutoHeight() - [ - ContentPairCreator_Lambda( - CenterTextCreator_Lambda("Asset Folder"), - SNew(SHorizontalBox) - + SHorizontalBox::Slot() - [ - SNew(STextComboBox) - .OptionsSource(&AssetFoldersArr) - .OnSelectionChanged_Lambda( - [this](const TSharedPtr& InStr, [[maybe_unused]] ESelectInfo::Type) - { - AssetFolder = FName(*InStr.Get()); - } - ) - ] - + SHorizontalBox::Slot() - .AutoWidth() + SNew(SButton) + .OnClicked_Lambda( + [this]() -> FReply + { + UpdateFolders(); + return FReply::Handled(); + } + ) + .Content() [ - SNew(SButton) - .OnClicked_Lambda( - [this]() -> FReply - { - UpdateFolders(); - return FReply::Handled(); - } - ) - .Content() - [ - SNew(SImage) - .Image(AppStyle.GetBrush("Icons.Refresh")) - ] + SNew(SImage) + .Image(AppStyle.GetBrush("Icons.Refresh")) ] - ) - ] - + SVerticalBox::Slot() - .Padding(Slot_Padding * 2.f) - .HAlign(HAlign_Center) - .AutoHeight() - [ - SNew(SButton) - .Text(FText::FromString(TEXT("Create Item"))) - .OnClicked(this, &SElementusItemCreator::HandleCreateItemButtonClicked) - .IsEnabled(this, &SElementusItemCreator::IsCreateEnabled) - .ToolTip(ToolTip) - ] ] ] + + SGridPanel::Slot(1, 13) + .Padding(SlotPadding * 2.f) + .HAlign(HAlign_Left) + [ + SNew(SButton) + .Text(FText::FromString(TEXT("Create Item"))) + .OnClicked(this, &SElementusItemCreator::HandleCreateItemButtonClicked) + .IsEnabled(this, &SElementusItemCreator::IsCreateEnabled) + .ToolTip( + SNew(SToolTip) + .Text(FText::FromString(TEXT("Already exists a item with this Id."))) + .Visibility_Lambda( + [this]() -> EVisibility + { + return IsCreateEnabled() ? EVisibility::Collapsed : EVisibility::Visible; + } + ) + ) + ] ]; } diff --git a/Source/ElementusInventoryEditor/Private/SElementusItemCreator.h b/Source/ElementusInventoryEditor/Private/SElementusItemCreator.h index 1e261be..5c3fb17 100644 --- a/Source/ElementusInventoryEditor/Private/SElementusItemCreator.h +++ b/Source/ElementusInventoryEditor/Private/SElementusItemCreator.h @@ -17,12 +17,14 @@ class SElementusItemCreator final : public SCompoundWidget void Construct(const FArguments& InArgs); -protected: +private: + TSharedRef ConstructContent(); + FString GetObjPath(const int32 ObjId) const; - void OnObjChanged(const FAssetData& AssetData, const int32 ObjId); + void OnObjChanged(const struct FAssetData& AssetData, const int32 ObjId); - const UClass* GetSelectedEntryClass() const; - void HandleNewEntryClassSelected(const UClass* Class); + const class UClass* GetSelectedEntryClass() const; + void HandleNewEntryClassSelected(const class UClass* Class); void UpdateFolders(); @@ -31,16 +33,15 @@ class SElementusItemCreator final : public SCompoundWidget TArray> GetEnumValuesAsStringArray() const; -private: - TMap> ObjectMap; - TSharedPtr ImageIcon_ThumbnailPool; + TMap> ObjectMap; + TSharedPtr ImageIcon_ThumbnailPool; TArray> ItemTypesArr; TArray> AssetFoldersArr; FName AssetName; FName AssetFolder; int32 ItemId = 1; - TWeakObjectPtr ItemClass; + TWeakObjectPtr ItemClass; FName ItemName; FText ItemDescription; uint8 ItemType = 0; diff --git a/Source/ElementusInventoryEditor/Private/SElementusSearch.cpp b/Source/ElementusInventoryEditor/Private/SElementusSearch.cpp index 43f08bc..3bc4768 100644 --- a/Source/ElementusInventoryEditor/Private/SElementusSearch.cpp +++ b/Source/ElementusInventoryEditor/Private/SElementusSearch.cpp @@ -13,105 +13,108 @@ void SElementusSearch::Construct(const FArguments& InArgs) OnCheckStateChanged = InArgs._OnCheckboxStateChanged; OnTextChangedDelegate = InArgs._OnSearchTextChanged; + ChildSlot + [ + ConstructContent() + ]; +} + +TSharedRef SElementusSearch::ConstructContent() +{ #if ENGINE_MAJOR_VERSION < 5 using FAppStyle = FEditorStyle; #endif - const ISlateStyle& AppStyle = FAppStyle::Get(); + constexpr float SlotPadding = 4.f; - constexpr float CheckBox_Padding = 2.f; - constexpr float Slot_Padding = 4.f; - - const auto CheckBoxCreator_Lambda = [this, &CheckBox_Padding](const EElementusItemType& InType) -> const TSharedRef + const auto CheckBoxCreator_Lambda = [this](const EElementusItemType& InType) -> const TSharedRef { + constexpr float CheckBoxPadding = 2.f; const int32 Index = static_cast(InType); return SNew(SCheckBox) - .Padding(CheckBox_Padding) + .Padding(CheckBoxPadding) .OnCheckStateChanged(this, &SElementusSearch::TriggerOnCheckboxStateChanged, Index) .Content() [ SNew(STextBlock) .Text(FText::FromString(UElementusInventoryFunctions::ElementusItemEnumTypeToString(static_cast(Index)))) - .Margin(CheckBox_Padding) + .Margin(CheckBoxPadding) ]; }; - ChildSlot + return SNew(SVerticalBox) + + SVerticalBox::Slot() + .AutoHeight() [ - SNew(SVerticalBox) - + SVerticalBox::Slot() - .AutoHeight() + SNew(SSearchBox) + .OnTextChanged(this, &SElementusSearch::TriggerOnSearchTextChanged) + ] + + SVerticalBox::Slot() + .AutoHeight() + .Padding(SlotPadding) + [ + SNew(STextBlock) + .Text(FText::FromString(TEXT("Show types:"))) + .Font(FAppStyle::Get().GetFontStyle("NormalFontBold")) + ] + + SVerticalBox::Slot() + .AutoHeight() + .Padding(SlotPadding) + [ + SNew(SUniformGridPanel) + .SlotPadding(1.f) + + SUniformGridPanel::Slot(0, 0) [ - SNew(SSearchBox) - .OnTextChanged(this, &SElementusSearch::TriggerOnSearchTextChanged) + CheckBoxCreator_Lambda(EElementusItemType::Accessory) ] - + SVerticalBox::Slot() - .AutoHeight() - .Padding(Slot_Padding) + + SUniformGridPanel::Slot(1, 0) [ - SNew(STextBlock) - .Text(FText::FromString(TEXT("Show only types:"))) - .Font(AppStyle.GetFontStyle("NormalFontBold")) + CheckBoxCreator_Lambda(EElementusItemType::Armor) + ] + + SUniformGridPanel::Slot(0, 1) + [ + CheckBoxCreator_Lambda(EElementusItemType::Weapon) + ] + + SUniformGridPanel::Slot(1, 1) + [ + CheckBoxCreator_Lambda(EElementusItemType::Consumable) + ] + + SUniformGridPanel::Slot(0, 2) + [ + CheckBoxCreator_Lambda(EElementusItemType::Material) + ] + + SUniformGridPanel::Slot(1, 2) + [ + CheckBoxCreator_Lambda(EElementusItemType::Crafting) + ] + + SUniformGridPanel::Slot(0, 3) + [ + CheckBoxCreator_Lambda(EElementusItemType::Information) + ] + + SUniformGridPanel::Slot(1, 3) + [ + CheckBoxCreator_Lambda(EElementusItemType::Event) + ] + + SUniformGridPanel::Slot(0, 4) + [ + CheckBoxCreator_Lambda(EElementusItemType::Quest) + ] + + SUniformGridPanel::Slot(1, 4) + [ + CheckBoxCreator_Lambda(EElementusItemType::Junk) + ] + + SUniformGridPanel::Slot(0, 5) + [ + CheckBoxCreator_Lambda(EElementusItemType::Special) + ] + + SUniformGridPanel::Slot(1, 5) + [ + CheckBoxCreator_Lambda(EElementusItemType::Other) ] - + SVerticalBox::Slot() - .AutoHeight() - .Padding(Slot_Padding) + + SUniformGridPanel::Slot(0, 6) [ - SNew(SUniformGridPanel) - .SlotPadding(Slot_Padding / 4.f) - + SUniformGridPanel::Slot(0, 0) - [ - CheckBoxCreator_Lambda(EElementusItemType::Accessory) - ] - + SUniformGridPanel::Slot(1, 0) - [ - CheckBoxCreator_Lambda(EElementusItemType::Armor) - ] - + SUniformGridPanel::Slot(0, 1) - [ - CheckBoxCreator_Lambda(EElementusItemType::Weapon) - ] - + SUniformGridPanel::Slot(1, 1) - [ - CheckBoxCreator_Lambda(EElementusItemType::Consumable) - ] - + SUniformGridPanel::Slot(0, 2) - [ - CheckBoxCreator_Lambda(EElementusItemType::Material) - ] - + SUniformGridPanel::Slot(1, 2) - [ - CheckBoxCreator_Lambda(EElementusItemType::Crafting) - ] - + SUniformGridPanel::Slot(0, 3) - [ - CheckBoxCreator_Lambda(EElementusItemType::Information) - ] - + SUniformGridPanel::Slot(1, 3) - [ - CheckBoxCreator_Lambda(EElementusItemType::Event) - ] - + SUniformGridPanel::Slot(0, 4) - [ - CheckBoxCreator_Lambda(EElementusItemType::Quest) - ] - + SUniformGridPanel::Slot(1, 4) - [ - CheckBoxCreator_Lambda(EElementusItemType::Junk) - ] - + SUniformGridPanel::Slot(0, 5) - [ - CheckBoxCreator_Lambda(EElementusItemType::Special) - ] - + SUniformGridPanel::Slot(1, 5) - [ - CheckBoxCreator_Lambda(EElementusItemType::Other) - ] - + SUniformGridPanel::Slot(0, 6) - [ - CheckBoxCreator_Lambda(EElementusItemType::None) - ] + CheckBoxCreator_Lambda(EElementusItemType::None) ] ]; } diff --git a/Source/ElementusInventoryEditor/Private/SElementusSearch.h b/Source/ElementusInventoryEditor/Private/SElementusSearch.h index 02ec666..a92064d 100644 --- a/Source/ElementusInventoryEditor/Private/SElementusSearch.h +++ b/Source/ElementusInventoryEditor/Private/SElementusSearch.h @@ -16,7 +16,6 @@ class SElementusSearch final : public SCompoundWidget SLATE_USER_ARGS(SElementusSearch) { } - SLATE_EVENT(FOnElementusItemCheckStateChanged, OnCheckboxStateChanged) SLATE_EVENT(FOnTextChanged, OnSearchTextChanged) @@ -24,11 +23,12 @@ class SElementusSearch final : public SCompoundWidget void Construct(const FArguments& InArgs); -protected: +private: + TSharedRef ConstructContent(); + void TriggerOnCheckboxStateChanged(ECheckBoxState NewState, int32 InType) const; void TriggerOnSearchTextChanged(const FText& InText) const; -private: FOnElementusItemCheckStateChanged OnCheckStateChanged; FOnTextChanged OnTextChangedDelegate; }; diff --git a/Source/ElementusInventoryEditor/Private/SElementusTable.cpp b/Source/ElementusInventoryEditor/Private/SElementusTable.cpp index 1fd14df..f8e690a 100644 --- a/Source/ElementusInventoryEditor/Private/SElementusTable.cpp +++ b/Source/ElementusInventoryEditor/Private/SElementusTable.cpp @@ -24,7 +24,7 @@ class SElementusItemTableRow final : public SMultiColumnTableRow, HightlightTextSource) SLATE_END_ARGS() void Construct(const FArguments& InArgs, const TSharedRef& InOwnerTableView, const FElementusItemPtr InEntryItem) @@ -95,7 +95,7 @@ class SElementusItemTableRow final : public SMultiColumnTableRow HighlightText; }; void SElementusTable::Construct([[maybe_unused]] const FArguments&) @@ -121,20 +121,9 @@ void SElementusTable::Construct([[maybe_unused]] const FArguments&) HeaderRow->AddColumn(HeaderColumnCreator_Lambda(ColumnId_ValueLabel, "Value")); HeaderRow->AddColumn(HeaderColumnCreator_Lambda(ColumnId_WeightLabel, "Weight")); - EdListView = SNew(SListView) - .ListItemsSource(&ItemArr) - .SelectionMode(ESelectionMode::Multi) - .IsFocusable(true) - .OnGenerateRow(this, &SElementusTable::OnGenerateWidgetForList) - .HeaderRow(HeaderRow) - .OnMouseButtonDoubleClick(this, &SElementusTable::OnTableItemDoubleClicked); - ChildSlot [ - SNew(SBorder) - [ - EdListView.ToSharedRef() - ] + ConstructContent(HeaderRow.ToSharedRef()) ]; UAssetManager::CallOrRegister_OnCompletedInitialScan( @@ -147,11 +136,22 @@ void SElementusTable::Construct([[maybe_unused]] const FArguments&) ); } +TSharedRef SElementusTable::ConstructContent(const TSharedRef HeaderRow) +{ + return SAssignNew(EdListView, SListView) + .ListItemsSource(&ItemArr) + .SelectionMode(ESelectionMode::Multi) + .IsFocusable(true) + .OnGenerateRow(this, &SElementusTable::OnGenerateWidgetForList) + .HeaderRow(HeaderRow) + .OnMouseButtonDoubleClick(this, &SElementusTable::OnTableItemDoubleClicked); +} + TSharedRef SElementusTable::OnGenerateWidgetForList(const FElementusItemPtr InItem, const TSharedRef& OwnerTable) const { return SNew(SElementusItemTableRow, OwnerTable, InItem) .Visibility(this, &SElementusTable::GetIsVisible, InItem) - .HightlightTextSource(&SearchText); + .HightlightTextSource(SearchText); } void SElementusTable::OnTableItemDoubleClicked(const FElementusItemPtr ElementusItemRowData) const @@ -179,7 +179,7 @@ EVisibility SElementusTable::GetIsVisible(const FElementusItemPtr InItem) const || InItem->Class.ToString().Contains(InText, ESearchCase::IgnoreCase) || FString::SanitizeFloat(InItem->Value).Contains(InText, ESearchCase::IgnoreCase) || FString::SanitizeFloat(InItem->Weight).Contains(InText, ESearchCase::IgnoreCase); - }(SearchText.ToString()) + }(SearchText->ToString()) && (AllowedTypes.Contains(static_cast(InItem->Type)) || UElementusInventoryFunctions::HasEmptyParam(AllowedTypes))) { Output = EVisibility::Visible; @@ -194,7 +194,7 @@ EVisibility SElementusTable::GetIsVisible(const FElementusItemPtr InItem) const void SElementusTable::OnSearchTextModified(const FText& InText) { - SearchText = InText; + SearchText = MakeShared(InText); EdListView->RebuildList(); } @@ -243,7 +243,7 @@ void SElementusTable::OnColumnSort([[maybe_unused]] const EColumnSortPriority::T ColumnBeingSorted = ColumnName; CurrentSortMode = SortMode; - const auto CompareLambda = [&SortMode](const auto& Val1, const auto& Val2) -> bool + const auto Compare_Lambda = [&SortMode](const auto& Val1, const auto& Val2) -> bool { switch (SortMode) { @@ -261,21 +261,21 @@ void SElementusTable::OnColumnSort([[maybe_unused]] const EColumnSortPriority::T } }; - const auto Sort_Lambda = [&ColumnName, &CompareLambda](const FElementusItemPtr& Val1, const FElementusItemPtr& Val2) -> bool + const auto Sort_Lambda = [&ColumnName, &Compare_Lambda](const FElementusItemPtr& Val1, const FElementusItemPtr& Val2) -> bool { if (ColumnName == ColumnId_PrimaryIdLabel) { - return CompareLambda(Val1->PrimaryAssetId.ToString(), Val2->PrimaryAssetId.ToString()); + return Compare_Lambda(Val1->PrimaryAssetId.ToString(), Val2->PrimaryAssetId.ToString()); } if (ColumnName == ColumnId_ItemIdLabel) { - return CompareLambda(Val1->Id, Val2->Id); + return Compare_Lambda(Val1->Id, Val2->Id); } if (ColumnName == ColumnId_NameLabel) { - return CompareLambda(Val1->Name.ToString(), Val2->Name.ToString()); + return Compare_Lambda(Val1->Name.ToString(), Val2->Name.ToString()); } if (ColumnName == ColumnId_TypeLabel) @@ -285,22 +285,22 @@ void SElementusTable::OnColumnSort([[maybe_unused]] const EColumnSortPriority::T return *UElementusInventoryFunctions::ElementusItemEnumTypeToString(InType); }; - return CompareLambda(ItemTypeToString_Lambda(Val1->Type), ItemTypeToString_Lambda(Val2->Type)); + return Compare_Lambda(ItemTypeToString_Lambda(Val1->Type), ItemTypeToString_Lambda(Val2->Type)); } if (ColumnName == ColumnId_ClassLabel) { - return CompareLambda(Val1->Class.ToString(), Val2->Class.ToString()); + return Compare_Lambda(Val1->Class.ToString(), Val2->Class.ToString()); } if (ColumnName == ColumnId_ValueLabel) { - return CompareLambda(Val1->Value, Val2->Value); + return Compare_Lambda(Val1->Value, Val2->Value); } if (ColumnName == ColumnId_WeightLabel) { - return CompareLambda(Val1->Weight, Val2->Weight); + return Compare_Lambda(Val1->Weight, Val2->Weight); } return false; diff --git a/Source/ElementusInventoryEditor/Private/SElementusTable.h b/Source/ElementusInventoryEditor/Private/SElementusTable.h index b619a46..8d6b713 100644 --- a/Source/ElementusInventoryEditor/Private/SElementusTable.h +++ b/Source/ElementusInventoryEditor/Private/SElementusTable.h @@ -5,6 +5,7 @@ #pragma once #include +#include "Management/ElementusInventoryData.h" #include "Management/ElementusInventoryFunctions.h" struct FElementusItemRowData @@ -43,6 +44,9 @@ using FElementusItemPtr = TSharedPtr class SElementusTable final : public SCompoundWidget { + friend class SElementusFrame; + friend class SElementusUtils; + public: SLATE_USER_ARGS(SElementusTable) { @@ -52,10 +56,9 @@ class SElementusTable final : public SCompoundWidget void Construct(const FArguments& InArgs); - friend class SElementusFrame; - friend class SElementusUtils; +private: + TSharedRef ConstructContent(const TSharedRef HeaderRow); -protected: TSharedRef OnGenerateWidgetForList(const FElementusItemPtr InItem, const TSharedRef& OwnerTable) const; void OnTableItemDoubleClicked(FElementusItemPtr ElementusItemRowData) const; void OnColumnSort(EColumnSortPriority::Type SortPriority, const FName& ColumnName, EColumnSortMode::Type SortMode); @@ -66,10 +69,9 @@ class SElementusTable final : public SCompoundWidget void UpdateItemList(); TArray GetSelectedItems() const; -private: TArray ItemArr; TArray AllowedTypes; - FText SearchText; + TSharedPtr SearchText; FName ColumnBeingSorted = NAME_None; EColumnSortMode::Type CurrentSortMode = EColumnSortMode::None; diff --git a/Source/ElementusInventoryEditor/Private/SElementusUtils.cpp b/Source/ElementusInventoryEditor/Private/SElementusUtils.cpp index 0c3c407..a61b2fd 100644 --- a/Source/ElementusInventoryEditor/Private/SElementusUtils.cpp +++ b/Source/ElementusInventoryEditor/Private/SElementusUtils.cpp @@ -13,12 +13,19 @@ void SElementusUtils::Construct(const FArguments& InArgs) { TableSource = InArgs._TableSource; + ChildSlot + [ + ConstructContent() + ]; +} + +TSharedRef SElementusUtils::ConstructContent() +{ #if ENGINE_MAJOR_VERSION < 5 using FAppStyle = FEditorStyle; #endif - const ISlateStyle& AppStyle = FAppStyle::Get(); - constexpr float Slot_Padding = 2.f; + constexpr float SlotPadding = 2.f; const auto ButtonCreator_Lambda = [this](const FString& InStr, const FString& Tooltip, const uint32& ButtonId) -> TSharedRef { @@ -29,35 +36,32 @@ void SElementusUtils::Construct(const FArguments& InArgs) .OnClicked(this, &SElementusUtils::OnButtonClicked, ButtonId); }; - ChildSlot + return SNew(SVerticalBox) + + SVerticalBox::Slot() + .AutoHeight() + .Padding(SlotPadding) + [ + SNew(STextBlock) + .Text(FText::FromString(TEXT("Utils:"))) + .Font(FAppStyle::Get().GetFontStyle("NormalFontBold")) + ] + + SVerticalBox::Slot() + .AutoHeight() + .Padding(SlotPadding) [ - SNew(SVerticalBox) - + SVerticalBox::Slot() - .AutoHeight() - .Padding(Slot_Padding) + SNew(SUniformGridPanel) + .SlotPadding(SlotPadding / 2.f) + + SUniformGridPanel::Slot(0, 0) + [ + ButtonCreator_Lambda("Create Item", "Open the item creator window", 0) + ] + + SUniformGridPanel::Slot(1, 0) [ - SNew(STextBlock) - .Text(FText::FromString(TEXT("Utils:")) - .Font(AppStyle.GetFontStyle("NormalFontBold")) + ButtonCreator_Lambda("Delete Items", "Delete the selected items", 1) ] - + SVerticalBox::Slot() - .AutoHeight() - .Padding(Slot_Padding) + + SUniformGridPanel::Slot(0, 1) [ - SNew(SUniformGridPanel) - .SlotPadding(Slot_Padding / 2.f) - + SUniformGridPanel::Slot(0, 0) - [ - ButtonCreator_Lambda("Create Item", "Open the item creator window", 0) - ] - + SUniformGridPanel::Slot(1, 0) - [ - ButtonCreator_Lambda("Delete Items", "Delete the selected items", 1) - ] - + SUniformGridPanel::Slot(0, 1) - [ - ButtonCreator_Lambda("Update Table", "Update the items table", 2) - ] + ButtonCreator_Lambda("Update Table", "Update the items table", 2) ] ]; } diff --git a/Source/ElementusInventoryEditor/Private/SElementusUtils.h b/Source/ElementusInventoryEditor/Private/SElementusUtils.h index 3744500..73bdb81 100644 --- a/Source/ElementusInventoryEditor/Private/SElementusUtils.h +++ b/Source/ElementusInventoryEditor/Private/SElementusUtils.h @@ -15,14 +15,14 @@ class SElementusUtils final : public SCompoundWidget { } - SLATE_ARGUMENT(SElementusTable*, TableSource) + SLATE_ARGUMENT(TSharedPtr, TableSource) SLATE_END_ARGS() void Construct(const FArguments& InArgs); -protected: +private: + TSharedRef ConstructContent(); FReply OnButtonClicked(const uint32 ButtonId) const; -private: - SElementusTable* TableSource = nullptr; + TSharedPtr TableSource; }; From 7e723148bac2a0912a89709702e3ad18a55b6484 Mon Sep 17 00:00:00 2001 From: lucoiso Date: Tue, 15 Aug 2023 16:41:28 +0100 Subject: [PATCH 4/7] fix --- .../Private/SElementusItemCreator.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/ElementusInventoryEditor/Private/SElementusItemCreator.cpp b/Source/ElementusInventoryEditor/Private/SElementusItemCreator.cpp index b154d50..976625b 100644 --- a/Source/ElementusInventoryEditor/Private/SElementusItemCreator.cpp +++ b/Source/ElementusInventoryEditor/Private/SElementusItemCreator.cpp @@ -92,7 +92,7 @@ TSharedRef SElementusItemCreator::ConstructContent() .Font(FAppStyle::Get().GetFontStyle("PropertyWindow.NormalFont")) ] + SGridPanel::Slot(1, 1) - .Padding(Slot_Padding) + .Padding(SlotPadding) [ ObjEntryBoxCreator_Lambda(UObject::StaticClass(), 0) ] @@ -140,7 +140,7 @@ TSharedRef SElementusItemCreator::ConstructContent() .Font(FAppStyle::Get().GetFontStyle("PropertyWindow.NormalFont")) ] + SGridPanel::Slot(1, 4) - .Padding(Slot_Padding) + .Padding(SlotPadding) [ SNew(SMultiLineEditableTextBox) .OnTextChanged_Lambda( @@ -316,7 +316,7 @@ TSharedRef SElementusItemCreator::ConstructContent() .Content() [ SNew(SImage) - .Image(AppStyle.GetBrush("Icons.Refresh")) + .Image(FAppStyle::Get().GetBrush("Icons.Refresh")) ] ] ] From 445b79f92869f0915538ea029a9c025c1b0ca7a4 Mon Sep 17 00:00:00 2001 From: lucoiso Date: Tue, 15 Aug 2023 16:44:35 +0100 Subject: [PATCH 5/7] fix size --- .../Private/SElementusItemCreator.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Source/ElementusInventoryEditor/Private/SElementusItemCreator.cpp b/Source/ElementusInventoryEditor/Private/SElementusItemCreator.cpp index 976625b..90574c7 100644 --- a/Source/ElementusInventoryEditor/Private/SElementusItemCreator.cpp +++ b/Source/ElementusInventoryEditor/Private/SElementusItemCreator.cpp @@ -34,7 +34,7 @@ void SElementusItemCreator::Construct([[maybe_unused]] const FArguments&) TSharedRef SElementusItemCreator::ConstructContent() { - constexpr float SlotPadding = 1.f; + constexpr float SlotPadding = 4.f; ImageIcon_ThumbnailPool = MakeShared(1024); @@ -60,7 +60,8 @@ TSharedRef SElementusItemCreator::ConstructContent() + SScrollBox::Slot() [ SNew(SGridPanel) - .FillColumn(1, 1.f) + .FillColumn(0, 0.3f) + .FillColumn(1, 0.7f) + SGridPanel::Slot(0, 0) .Padding(SlotPadding) [ From f4a10a035079bac56da5cd6d8659379a961884d3 Mon Sep 17 00:00:00 2001 From: lucoiso Date: Tue, 15 Aug 2023 16:53:01 +0100 Subject: [PATCH 6/7] Fix crashes --- Source/ElementusInventoryEditor/Private/SElementusFrame.cpp | 4 ++++ Source/ElementusInventoryEditor/Private/SElementusTable.cpp | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Source/ElementusInventoryEditor/Private/SElementusFrame.cpp b/Source/ElementusInventoryEditor/Private/SElementusFrame.cpp index f58e931..90cb476 100644 --- a/Source/ElementusInventoryEditor/Private/SElementusFrame.cpp +++ b/Source/ElementusInventoryEditor/Private/SElementusFrame.cpp @@ -18,6 +18,8 @@ void SElementusFrame::Construct([[maybe_unused]] const FArguments& InArgs) TSharedRef SElementusFrame::ConstructContent() { + constexpr float SlotPadding = 4.f; + SAssignNew(Table, SElementusTable); return SNew(SHorizontalBox) @@ -30,6 +32,7 @@ TSharedRef SElementusFrame::ConstructContent() [ SNew(SVerticalBox) + SVerticalBox::Slot() + .Padding(SlotPadding) .AutoHeight() [ SNew(SElementusSearch) @@ -37,6 +40,7 @@ TSharedRef SElementusFrame::ConstructContent() .OnCheckboxStateChanged(Table.ToSharedRef(), &SElementusTable::OnSearchTypeModified) ] + SVerticalBox::Slot() + .Padding(SlotPadding) .AutoHeight() [ SNew(SElementusUtils) diff --git a/Source/ElementusInventoryEditor/Private/SElementusTable.cpp b/Source/ElementusInventoryEditor/Private/SElementusTable.cpp index f8e690a..bdb5fdc 100644 --- a/Source/ElementusInventoryEditor/Private/SElementusTable.cpp +++ b/Source/ElementusInventoryEditor/Private/SElementusTable.cpp @@ -39,7 +39,7 @@ class SElementusItemTableRow final : public SMultiColumnTableRow GenerateWidgetForColumn(const FName& ColumnName) override { const FSlateFontInfo CellFont = FCoreStyle::GetDefaultFontStyle("Regular", 10); - const FMargin CellMargin = FMargin(4.f); + const FMargin CellMargin(4.f); const auto TextBlockCreator_Lambda = [this, &CellFont, &CellMargin](const FText& InText) -> TSharedRef { @@ -47,7 +47,7 @@ class SElementusItemTableRow final : public SMultiColumnTableRowClass.ToString().Contains(InText, ESearchCase::IgnoreCase) || FString::SanitizeFloat(InItem->Value).Contains(InText, ESearchCase::IgnoreCase) || FString::SanitizeFloat(InItem->Weight).Contains(InText, ESearchCase::IgnoreCase); - }(SearchText->ToString()) + }(SearchText.IsValid() ? SearchText->ToString() : FString()) && (AllowedTypes.Contains(static_cast(InItem->Type)) || UElementusInventoryFunctions::HasEmptyParam(AllowedTypes))) { Output = EVisibility::Visible; From b54f8c392747c7ba9b762ac0dc2f7fd036d34bb5 Mon Sep 17 00:00:00 2001 From: lucoiso Date: Tue, 15 Aug 2023 19:47:07 +0100 Subject: [PATCH 7/7] Implement inventory sorting --- .../ElementusInventoryComponent.cpp | 192 +++++++++++++++++- .../Components/ElementusInventoryComponent.h | 26 ++- .../Management/ElementusInventoryData.h | 10 + .../Private/SElementusItemCreator.cpp | 4 +- 4 files changed, 226 insertions(+), 6 deletions(-) diff --git a/Source/ElementusInventory/Private/Components/ElementusInventoryComponent.cpp b/Source/ElementusInventory/Private/Components/ElementusInventoryComponent.cpp index 3ef5a46..5e18c85 100644 --- a/Source/ElementusInventory/Private/Components/ElementusInventoryComponent.cpp +++ b/Source/ElementusInventory/Private/Components/ElementusInventoryComponent.cpp @@ -111,9 +111,197 @@ bool UElementusInventoryComponent::CanGiveItem(const FElementusItemInfo InItemIn return false; } -void UElementusInventoryComponent::SortInventory_Implementation() +void UElementusInventoryComponent::SortInventory(const EElementusInventorySortingMode Mode, const EElementusInventorySortingOrientation Orientation) { - // Override this function to implement your own sorting algorithm + 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() diff --git a/Source/ElementusInventory/Public/Components/ElementusInventoryComponent.h b/Source/ElementusInventory/Public/Components/ElementusInventoryComponent.h index 171ae57..8435e9f 100644 --- a/Source/ElementusInventory/Public/Components/ElementusInventoryComponent.h +++ b/Source/ElementusInventory/Public/Components/ElementusInventoryComponent.h @@ -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 { @@ -169,8 +191,8 @@ class ELEMENTUSINVENTORY_API UElementusInventoryComponent : public UActorCompone UFUNCTION(Server, Reliable, BlueprintCallable, Category = "Elementus Inventory") void AddItems(const TArray& Items); - UFUNCTION(BlueprintNativeEvent, Category = "Elementus Inventory") - void SortInventory(); + UFUNCTION(BlueprintCallable, Category = "Elementus Inventory") + void SortInventory(const EElementusInventorySortingMode Mode, const EElementusInventorySortingOrientation Orientation); protected: /* Items that this inventory have */ diff --git a/Source/ElementusInventory/Public/Management/ElementusInventoryData.h b/Source/ElementusInventory/Public/Management/ElementusInventoryData.h index fa7ba33..f324e4b 100644 --- a/Source/ElementusInventory/Public/Management/ElementusInventoryData.h +++ b/Source/ElementusInventory/Public/Management/ElementusInventoryData.h @@ -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") diff --git a/Source/ElementusInventoryEditor/Private/SElementusItemCreator.cpp b/Source/ElementusInventoryEditor/Private/SElementusItemCreator.cpp index 90574c7..8cbf9b9 100644 --- a/Source/ElementusInventoryEditor/Private/SElementusItemCreator.cpp +++ b/Source/ElementusInventoryEditor/Private/SElementusItemCreator.cpp @@ -36,13 +36,13 @@ TSharedRef SElementusItemCreator::ConstructContent() { constexpr float SlotPadding = 4.f; - ImageIcon_ThumbnailPool = MakeShared(1024); + ImageIcon_ThumbnailPool = MakeShared(1024u); #if ENGINE_MAJOR_VERSION < 5 using FAppStyle = FEditorStyle; #endif - const auto ObjEntryBoxCreator_Lambda = [this](UClass* ObjClass, const int32 ObjId) -> const TSharedRef + const auto ObjEntryBoxCreator_Lambda = [this](UClass* const ObjClass, const int32 ObjId) -> const TSharedRef { return SNew(SObjectPropertyEntryBox) .IsEnabled(true)