Item editor implementation
This commit is contained in:
116
Source/ProjectEleriEditor/Public/ItemEditorWindow.h
Normal file
116
Source/ProjectEleriEditor/Public/ItemEditorWindow.h
Normal file
@@ -0,0 +1,116 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "AssetRegistry/AssetData.h"
|
||||
#include "Types/SlateEnums.h"
|
||||
#include "Widgets/SCompoundWidget.h"
|
||||
#include "Widgets/Views/SListView.h"
|
||||
|
||||
class IDetailsView;
|
||||
class ITableRow;
|
||||
class SSearchBox;
|
||||
class STableViewBase;
|
||||
class STextBlock;
|
||||
class UItemDataAsset;
|
||||
struct FPropertyChangedEvent;
|
||||
|
||||
/** One row shown in the item list of the editor window. */
|
||||
struct FItemListEntry
|
||||
{
|
||||
/** Registry data of the data asset (never loads the asset on its own). */
|
||||
FAssetData AssetData;
|
||||
|
||||
/** Human readable item name (FText source), used as the row label and for sorting. */
|
||||
FString ItemName;
|
||||
|
||||
/** Underlying value of the ItemCategory enum (e.g. Category::Plant), INDEX_NONE if unknown. */
|
||||
int32 CategoryValue = INDEX_NONE;
|
||||
|
||||
/** Lower-cased text used for filtering (name + category + asset + package path). */
|
||||
FString SearchText;
|
||||
};
|
||||
|
||||
/**
|
||||
* Editor tool window that lets the user type an item name, pick the matching
|
||||
* ItemDataAsset and edit its properties directly on the asset.
|
||||
*/
|
||||
class SItemEditorWindow : public SCompoundWidget
|
||||
{
|
||||
public:
|
||||
SLATE_BEGIN_ARGS(SItemEditorWindow) {}
|
||||
SLATE_END_ARGS()
|
||||
|
||||
void Construct(const FArguments& InArgs);
|
||||
virtual ~SItemEditorWindow();
|
||||
|
||||
/** Re-queries the Asset Registry for every UItemDataAsset in the project. */
|
||||
void RefreshAssetList();
|
||||
|
||||
private:
|
||||
using FItemEntry = TSharedPtr<FItemListEntry>;
|
||||
|
||||
// Slate callbacks
|
||||
TSharedRef<ITableRow> OnGenerateRow(FItemEntry InItem, const TSharedRef<STableViewBase>& InOwnerTable);
|
||||
void OnSearchTextChanged(const FText& InText);
|
||||
void OnSearchTextCommitted(const FText& InText, ETextCommit::Type InCommitType);
|
||||
void OnItemSelectionChanged(FItemEntry InItem, ESelectInfo::Type InSelectInfo);
|
||||
void OnItemDoubleClicked(FItemEntry InItem);
|
||||
void OnAssetPropertyChanged(const FPropertyChangedEvent& InEvent);
|
||||
|
||||
// Toolbar / button handlers
|
||||
FReply OnRefreshClicked();
|
||||
FReply OnSaveClicked();
|
||||
FReply OnOpenAssetEditorClicked();
|
||||
FReply OnFindInContentBrowserClicked();
|
||||
void OnAutoSaveCheckChanged(ECheckBoxState InState);
|
||||
|
||||
// Category filter
|
||||
void InitCategoryFilter();
|
||||
TSharedRef<SWidget> MakeCategoryFilterWidget();
|
||||
TSharedRef<SWidget> MakeCategoryCheckBox(int32 InCategoryValue, const FText& InLabel);
|
||||
ECheckBoxState IsCategoryChecked(int32 InCategoryValue) const;
|
||||
void OnCategoryToggled(int32 InCategoryValue, ECheckBoxState InState);
|
||||
|
||||
// Helpers
|
||||
void ApplyFilter();
|
||||
void SelectFirstVisibleItem();
|
||||
FItemEntry FindEntryForAsset(const UItemDataAsset* InAsset);
|
||||
UItemDataAsset* LoadAssetForEntry(FItemEntry InItem);
|
||||
UItemDataAsset* GetCurrentAsset() const;
|
||||
void UpdateEntryFromLoadedAsset(FItemEntry InEntry, const UItemDataAsset* InAsset);
|
||||
void SaveCurrentAsset();
|
||||
void SetStatusMessage(const FString& InMessage, bool bIsError = false);
|
||||
void OpenInAssetEditor(UItemDataAsset* InAsset);
|
||||
void ShowInContentBrowser(UItemDataAsset* InAsset);
|
||||
|
||||
FText GetSelectionStatusText() const;
|
||||
|
||||
static FString GetEntryDisplayName(const FItemListEntry& InEntry);
|
||||
static FString BuildEntrySearchText(const FItemListEntry& InEntry);
|
||||
static FString GetTaggedItemName(const FAssetData& InAsset);
|
||||
|
||||
/** All data assets of type UItemDataAsset found in the project (registry only). */
|
||||
TArray<TSharedPtr<FItemListEntry>> ItemEntries;
|
||||
|
||||
/** Subset of ItemEntries currently visible after applying the search filter. */
|
||||
TArray<FItemEntry> FilteredItems;
|
||||
|
||||
/** Ordered category values offered as filter chips (underlying Category enum values). */
|
||||
TArray<int32> CategoryFilterValues;
|
||||
|
||||
/** ItemCategory values that should be shown in the list; empty means show every category. */
|
||||
TSet<int32> SelectedCategoryValues;
|
||||
|
||||
/** The data asset currently being edited. */
|
||||
TWeakObjectPtr<UItemDataAsset> CurrentAsset;
|
||||
|
||||
TSharedPtr<SSearchBox> SearchBox;
|
||||
TSharedPtr<SListView<FItemEntry>> ListView;
|
||||
TSharedPtr<IDetailsView> DetailsView;
|
||||
TSharedPtr<STextBlock> StatusText;
|
||||
|
||||
FText SearchFilterText;
|
||||
bool bAutoSaveOnChange = false;
|
||||
};
|
||||
@@ -1,10 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Modules/ModuleInterface.h"
|
||||
#include "Modules/ModuleManager.h"
|
||||
|
||||
class FProjectEleriEditorModule : public IModuleInterface
|
||||
{
|
||||
public:
|
||||
virtual void StartupModule() override;
|
||||
virtual void ShutdownModule() override;
|
||||
};
|
||||
public:
|
||||
virtual void StartupModule() override;
|
||||
virtual void ShutdownModule() override;
|
||||
|
||||
/** Opens (or focuses) the Item Editor window. */
|
||||
void OpenItemEditorTab();
|
||||
|
||||
private:
|
||||
void RegisterMenus();
|
||||
|
||||
/** Tab id of the Item Editor window. */
|
||||
static const FName ItemEditorTabName;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user