Files
UnrealEngineUWP/Engine/Source/Editor/UMGEditor/Private/UMGEditorModule.cpp
Nick Darnell 7f7c2d28b3 UMG - Still experimental but removing the experimental flag and always loading UMG.
[CL 2254931 by Nick Darnell in Main branch]
2014-08-13 14:04:16 -04:00

101 lines
3.7 KiB
C++

// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
#include "UMGEditorPrivatePCH.h"
#include "UMGEditorModule.h"
#include "ModuleManager.h"
#include "AssetToolsModule.h"
#include "AssetTypeActions_WidgetBlueprint.h"
#include "KismetCompilerModule.h"
#include "WidgetBlueprintCompiler.h"
#include "Editor/Sequencer/Public/ISequencerModule.h"
#include "Animation/MarginTrackEditor.h"
const FName UMGEditorAppIdentifier = FName(TEXT("UMGEditorApp"));
class FUMGEditorModule : public IUMGEditorModule
{
public:
/** Constructor, set up console commands and variables **/
FUMGEditorModule()
{
}
/** Called right after the module DLL has been loaded and the module object has been created */
virtual void StartupModule() override
{
FModuleManager::LoadModuleChecked<IUMGModule>("UMG");
MenuExtensibilityManager = MakeShareable(new FExtensibilityManager());
ToolBarExtensibilityManager = MakeShareable(new FExtensibilityManager());
// Register widget blueprint compiler we do this no matter what.
IKismetCompilerInterface& KismetCompilerModule = FModuleManager::LoadModuleChecked<IKismetCompilerInterface>("KismetCompiler");
FBlueprintCompileDelegate sd;
sd.BindRaw(this, &FUMGEditorModule::CompileWidgetBlueprint);
KismetCompilerModule.GetCompilers().Add(sd);
// Register asset types
IAssetTools& AssetTools = FModuleManager::LoadModuleChecked<FAssetToolsModule>("AssetTools").Get();
RegisterAssetTypeAction(AssetTools, MakeShareable(new FAssetTypeActions_WidgetBlueprint()));
// Register with the sequencer module that we provide auto-key handlers.
ISequencerModule& SequencerModule = FModuleManager::Get().LoadModuleChecked<ISequencerModule>("Sequencer");
SequencerModule.RegisterTrackEditor(FOnCreateTrackEditor::CreateStatic(&FMarginTrackEditor::CreateTrackEditor));
}
/** Called before the module is unloaded, right before the module object is destroyed. */
virtual void ShutdownModule() override
{
MenuExtensibilityManager.Reset();
ToolBarExtensibilityManager.Reset();
// Unregister all the asset types that we registered
if ( FModuleManager::Get().IsModuleLoaded("AssetTools") )
{
IAssetTools& AssetTools = FModuleManager::GetModuleChecked<FAssetToolsModule>("AssetTools").Get();
for ( int32 Index = 0; Index < CreatedAssetTypeActions.Num(); ++Index )
{
AssetTools.UnregisterAssetTypeActions(CreatedAssetTypeActions[Index].ToSharedRef());
}
}
CreatedAssetTypeActions.Empty();
}
FReply CompileWidgetBlueprint(UBlueprint* Blueprint, const FKismetCompilerOptions& CompileOptions, FCompilerResultsLog& Results, TArray<UObject*>* ObjLoaded)
{
if ( UWidgetBlueprint* WidgetBlueprint = Cast<UWidgetBlueprint>(Blueprint) )
{
FWidgetBlueprintCompiler Compiler(WidgetBlueprint, Results, CompileOptions, ObjLoaded);
Compiler.Compile();
check(Compiler.NewClass);
return FReply::Handled();
}
return FReply::Unhandled();
}
/** Gets the extensibility managers for outside entities to extend gui page editor's menus and toolbars */
virtual TSharedPtr<FExtensibilityManager> GetMenuExtensibilityManager() { return MenuExtensibilityManager; }
virtual TSharedPtr<FExtensibilityManager> GetToolBarExtensibilityManager() { return ToolBarExtensibilityManager; }
private:
void RegisterAssetTypeAction(IAssetTools& AssetTools, TSharedRef<IAssetTypeActions> Action)
{
AssetTools.RegisterAssetTypeActions(Action);
CreatedAssetTypeActions.Add(Action);
}
private:
TSharedPtr<FExtensibilityManager> MenuExtensibilityManager;
TSharedPtr<FExtensibilityManager> ToolBarExtensibilityManager;
/** All created asset type actions. Cached here so that we can unregister it during shutdown. */
TArray< TSharedPtr<IAssetTypeActions> > CreatedAssetTypeActions;
};
IMPLEMENT_MODULE(FUMGEditorModule, UMGEditor);