Files
ProjectEleri/Source/ProjectEleriEditor/Private/ProjectEleriEditorModule.cpp

104 lines
3.2 KiB
C++
Raw Normal View History

2026-07-11 10:43:52 +02:00
#include "ProjectEleriEditorModule.h"
2026-09-05 21:20:30 +02:00
#include "Framework/Docking/TabManager.h"
2026-07-11 10:43:52 +02:00
#include "Modules/ModuleManager.h"
#include "PropertyEditorModule.h"
2026-09-05 21:20:30 +02:00
#include "ToolMenus.h"
#include "Widgets/Docking/SDockTab.h"
2026-07-11 10:43:52 +02:00
#include "ItemDataAssetCustomization.h"
2026-09-05 21:20:30 +02:00
#include "ItemEditorWindow.h"
#define LOCTEXT_NAMESPACE "ProjectEleriEditorModule"
IMPLEMENT_GAME_MODULE(FProjectEleriEditorModule, ProjectEleriEditor);
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))
);
}
}
2026-07-11 10:43:52 +02:00
2026-09-05 21:20:30 +02:00
#undef LOCTEXT_NAMESPACE