Item editor implementation
This commit is contained in:
@@ -1,23 +1,103 @@
|
||||
#include "ProjectEleriEditorModule.h"
|
||||
|
||||
#include "Framework/Docking/TabManager.h"
|
||||
#include "Modules/ModuleManager.h"
|
||||
#include "PropertyEditorModule.h"
|
||||
#include "ToolMenus.h"
|
||||
#include "Widgets/Docking/SDockTab.h"
|
||||
|
||||
#include "ItemDataAssetCustomization.h"
|
||||
#include "ItemEditorWindow.h"
|
||||
|
||||
IMPLEMENT_GAME_MODULE(FProjectEleriEditorModule, ProjectEleriEditor);
|
||||
#define LOCTEXT_NAMESPACE "ProjectEleriEditorModule"
|
||||
|
||||
void FProjectEleriEditorModule::StartupModule()
|
||||
{
|
||||
FPropertyEditorModule& PropEd = FModuleManager::LoadModuleChecked<FPropertyEditorModule>("PropertyEditor");
|
||||
PropEd.RegisterCustomClassLayout(
|
||||
TEXT("ItemDataAsset"), // UCLASS name
|
||||
FOnGetDetailCustomizationInstance::CreateStatic(&FItemDataAssetCustomization::MakeInstance)
|
||||
);
|
||||
}
|
||||
IMPLEMENT_GAME_MODULE(FProjectEleriEditorModule, ProjectEleriEditor);
|
||||
|
||||
void FProjectEleriEditorModule::ShutdownModule()
|
||||
{
|
||||
if (FModuleManager::Get().IsModuleLoaded("PropertyEditor")) {
|
||||
FPropertyEditorModule& PropEd = FModuleManager::GetModuleChecked<FPropertyEditorModule>("PropertyEditor");
|
||||
PropEd.UnregisterCustomClassLayout(TEXT("ItemDataAsset"));
|
||||
}
|
||||
}
|
||||
const FName FProjectEleriEditorModule::ItemEditorTabName(TEXT("ProjectEleriItemEditor"));
|
||||
|
||||
void FProjectEleriEditorModule::StartupModule()
|
||||
{
|
||||
// Details customization for the item data asset (property map generation widget).
|
||||
FPropertyEditorModule& PropEd = FModuleManager::LoadModuleChecked<FPropertyEditorModule>("PropertyEditor");
|
||||
PropEd.RegisterCustomClassLayout(
|
||||
TEXT("ItemDataAsset"),
|
||||
FOnGetDetailCustomizationInstance::CreateStatic(&FItemDataAssetCustomization::MakeInstance)
|
||||
);
|
||||
|
||||
// Register the Item Editor as a docking tab.
|
||||
if (FGlobalTabmanager::Get()->HasTabSpawner(ItemEditorTabName))
|
||||
{
|
||||
FGlobalTabmanager::Get()->UnregisterNomadTabSpawner(ItemEditorTabName);
|
||||
}
|
||||
|
||||
FGlobalTabmanager::Get()->RegisterNomadTabSpawner(
|
||||
ItemEditorTabName,
|
||||
FOnSpawnTab::CreateLambda([](const FSpawnTabArgs& Args)
|
||||
{
|
||||
return SNew(SDockTab)
|
||||
.TabRole(ETabRole::NomadTab)
|
||||
.Label(LOCTEXT("ItemEditorTabLabel", "Item Editor"))
|
||||
.ToolTipText(LOCTEXT("ItemEditorTabTooltip", "Search items by name and edit their data assets"))
|
||||
[
|
||||
SNew(SItemEditorWindow)
|
||||
];
|
||||
}))
|
||||
.SetDisplayName(LOCTEXT("ItemEditorDisplayName", "Item Editor"))
|
||||
.SetMenuType(ETabSpawnerMenuType::Hidden);
|
||||
|
||||
// Add a menu entry to open the window. Menus might not be ready yet during startup.
|
||||
if (UToolMenus::IsToolMenuUIEnabled())
|
||||
{
|
||||
RegisterMenus();
|
||||
}
|
||||
else
|
||||
{
|
||||
UToolMenus::RegisterStartupCallback(
|
||||
FSimpleMulticastDelegate::FDelegate::CreateRaw(this, &FProjectEleriEditorModule::RegisterMenus));
|
||||
}
|
||||
}
|
||||
|
||||
void FProjectEleriEditorModule::ShutdownModule()
|
||||
{
|
||||
if (FModuleManager::Get().IsModuleLoaded("PropertyEditor"))
|
||||
{
|
||||
FPropertyEditorModule& PropEd = FModuleManager::GetModuleChecked<FPropertyEditorModule>("PropertyEditor");
|
||||
PropEd.UnregisterCustomClassLayout(TEXT("ItemDataAsset"));
|
||||
}
|
||||
|
||||
if (FGlobalTabmanager::Get()->HasTabSpawner(ItemEditorTabName))
|
||||
{
|
||||
FGlobalTabmanager::Get()->UnregisterNomadTabSpawner(ItemEditorTabName);
|
||||
}
|
||||
|
||||
UToolMenus::UnregisterOwner(this);
|
||||
}
|
||||
|
||||
void FProjectEleriEditorModule::OpenItemEditorTab()
|
||||
{
|
||||
FGlobalTabmanager::Get()->TryInvokeTab(ItemEditorTabName);
|
||||
}
|
||||
|
||||
void FProjectEleriEditorModule::RegisterMenus()
|
||||
{
|
||||
FToolMenuOwnerScoped OwnerScoped(this);
|
||||
|
||||
if (UToolMenu* WindowMenu = UToolMenus::Get()->ExtendMenu("LevelEditor.MainMenu.Window"))
|
||||
{
|
||||
FToolMenuSection& Section = WindowMenu->AddSection(
|
||||
TEXT("ItemEditor"),
|
||||
LOCTEXT("ItemEditorSectionLabel", "Eleri Tools"),
|
||||
FToolMenuInsert(NAME_None, EToolMenuInsertType::First)
|
||||
);
|
||||
|
||||
Section.AddMenuEntry(
|
||||
TEXT("OpenItemEditor"),
|
||||
LOCTEXT("ItemEditorMenuLabel", "Item Editor"),
|
||||
LOCTEXT("ItemEditorMenuTooltip", "Open a window to search items by name and edit their data assets."),
|
||||
FSlateIcon(),
|
||||
FUIAction(FExecuteAction::CreateRaw(this, &FProjectEleriEditorModule::OpenItemEditorTab))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#undef LOCTEXT_NAMESPACE
|
||||
|
||||
Reference in New Issue
Block a user