aboutsummaryrefslogtreecommitdiff
path: root/Plugins/SimpleUGC/Source/SimpleUGCEditor/Private/SimpleUGCEditor.cpp
blob: ce43ddeebeb6d87662e92dd64360b62568d17791 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright Epic Games, Inc. All Rights Reserved.

#include "SimpleUGCEditor.h"
#include "SimpleUGCEditorStyle.h"
#include "SimpleUGCEditorCommands.h"
#include "SimpleUGCCreator.h"
#include "Misc/MessageDialog.h"
#include "Framework/MultiBox/MultiBoxBuilder.h"

#include "LevelEditor.h"

static const FName SimpleUGCEditorTabName("SimpleUGCEditor");

#define LOCTEXT_NAMESPACE "FSimpleUGCEditorModule"

void FSimpleUGCEditorModule::StartupModule()
{
	// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module

	UGCCreator = MakeShared<FSimpleUGCCreator>();
	UGCPackager = MakeShared<FSimpleUGCPackager>();

	FSimpleUGCEditorStyle::Initialize();
	FSimpleUGCEditorStyle::ReloadTextures();

	FSimpleUGCEditorCommands::Register();
	
	PluginCommands = MakeShareable(new FUICommandList);

	PluginCommands->MapAction(
		FSimpleUGCEditorCommands::Get().CreateUGCAction,
		FExecuteAction::CreateRaw(this, &FSimpleUGCEditorModule::CreateUGCButtonClicked),
		FCanExecuteAction()
	);

	FLevelEditorModule& LevelEditorModule = FModuleManager::LoadModuleChecked<FLevelEditorModule>("LevelEditor");
	// Add commands
	{
		FName MenuSection = "FileProject";
		FName ToolbarSection = "Misc";

		// Add creator button to the menu
		{
			TSharedPtr<FExtender> MenuExtender = MakeShareable(new FExtender());
			MenuExtender->AddMenuExtension(MenuSection, EExtensionHook::After, PluginCommands, FMenuExtensionDelegate::CreateRaw(this, &FSimpleUGCEditorModule::AddUGCCreatorMenuExtension));

			LevelEditorModule.GetMenuExtensibilityManager()->AddExtender(MenuExtender);
		}

		// Add creator button to the toolbar
		{
		TSharedPtr<FExtender> ToolbarExtender = MakeShareable(new FExtender);
			ToolbarExtender->AddToolBarExtension(ToolbarSection, EExtensionHook::After, PluginCommands, FToolBarExtensionDelegate::CreateRaw(this, &FSimpleUGCEditorModule::AddUGCCreatorToolbarExtension));

			LevelEditorModule.GetToolBarExtensibilityManager()->AddExtender(ToolbarExtender);
		}

		// Add packager button to the menu
		{
			TSharedPtr<FExtender> MenuExtender = MakeShareable(new FExtender());
			MenuExtender->AddMenuExtension(MenuSection, EExtensionHook::After, PluginCommands, FMenuExtensionDelegate::CreateRaw(this, &FSimpleUGCEditorModule::AddUGCPackagerMenuExtension));

			LevelEditorModule.GetMenuExtensibilityManager()->AddExtender(MenuExtender);
		}

		// Add packager button to the toolbar
		{
			TSharedPtr<FExtender> ToolbarExtender = MakeShareable(new FExtender);
			ToolbarExtender->AddToolBarExtension(ToolbarSection, EExtensionHook::After, PluginCommands, FToolBarExtensionDelegate::CreateRaw(this, &FSimpleUGCEditorModule::AddUGCPackagerToolbarExtension));

			LevelEditorModule.GetToolBarExtensibilityManager()->AddExtender(ToolbarExtender);
		}
	}
}

void FSimpleUGCEditorModule::ShutdownModule()
{
	// This function may be called during shutdown to clean up your module.  For modules that support dynamic reloading,
	// we call this function before unloading the module.
	FSimpleUGCEditorStyle::Shutdown();

	FSimpleUGCEditorCommands::Unregister();

}

void FSimpleUGCEditorModule::CreateUGCButtonClicked()
{
	if (UGCCreator.IsValid())
	{
		UGCCreator->OpenNewPluginWizard();
	}
}

void FSimpleUGCEditorModule::AddUGCCreatorMenuExtension(FMenuBuilder& Builder)
{
	Builder.AddMenuEntry(FSimpleUGCEditorCommands::Get().CreateUGCAction);
}

void FSimpleUGCEditorModule::AddUGCCreatorToolbarExtension(FToolBarBuilder& Builder)
{
	Builder.AddToolBarButton(FSimpleUGCEditorCommands::Get().CreateUGCAction);
}

void FSimpleUGCEditorModule::AddUGCPackagerMenuExtension(FMenuBuilder& Builder)
{
	FSimpleUGCPackager* Packager = UGCPackager.Get();

	Builder.AddSubMenu(LOCTEXT("PackageUGCMenu_Label", "Package UGC"),
		LOCTEXT("PackageUGCMenu_Tooltip", "Share and distribute UGC"),
		FNewMenuDelegate::CreateRaw(Packager, &FSimpleUGCPackager::GeneratePackagerMenuContent),
		false,
		FSlateIcon(FSimpleUGCEditorStyle::GetStyleSetName(), "SimpleUGCEditor.PackageUGCAction")
	);
}

void FSimpleUGCEditorModule::AddUGCPackagerToolbarExtension(FToolBarBuilder& Builder)
{
	FSimpleUGCPackager* Packager = UGCPackager.Get();

	Builder.AddComboButton(FUIAction(),
		FOnGetContent::CreateSP(Packager, &FSimpleUGCPackager::GeneratePackagerComboButtonContent),
		LOCTEXT("PackageUGC_Label", "Package UGC"),
		LOCTEXT("PackageUGC_Tooltip", "Share and distribute UGC"),
		FSlateIcon(FSimpleUGCEditorStyle::GetStyleSetName(), "SimpleUGCEditor.PackageUGCAction")
	);
}

#undef LOCTEXT_NAMESPACE
	
IMPLEMENT_MODULE(FSimpleUGCEditorModule, SimpleUGCEditor)