File size: 10,470 Bytes
7fd553e | 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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | // Copyright Epic Games, Inc. All Rights Reserved.
#include "LyraEditor.h"
#include "AbilitySystemGlobals.h"
#include "DataValidationModule.h"
#include "Development/LyraDeveloperSettings.h"
#include "Editor/UnrealEdEngine.h"
#include "Engine/GameInstance.h"
#include "Framework/Application/SlateApplication.h"
#include "Framework/MultiBox/MultiBoxBuilder.h"
#include "GameEditorStyle.h"
#include "GameModes/LyraExperienceManager.h"
#include "GameplayAbilitiesEditorModule.h"
#include "GameplayCueInterface.h"
#include "GameplayCueNotify_Burst.h"
#include "GameplayCueNotify_BurstLatent.h"
#include "GameplayCueNotify_Looping.h"
#include "Private/AssetTypeActions_LyraContextEffectsLibrary.h"
#include "ToolMenu.h"
#include "ToolMenus.h"
#include "UObject/UObjectIterator.h"
#include "UnrealEdGlobals.h"
#include "Validation/EditorValidator.h"
class SWidget;
#define LOCTEXT_NAMESPACE "LyraEditor"
DEFINE_LOG_CATEGORY(LogLyraEditor);
// This function tells the GameplayCue editor what classes to expose when creating new notifies.
static void GetGameplayCueDefaultClasses(TArray<UClass*>& Classes)
{
Classes.Empty();
Classes.Add(UGameplayCueNotify_Burst::StaticClass());
Classes.Add(AGameplayCueNotify_BurstLatent::StaticClass());
Classes.Add(AGameplayCueNotify_Looping::StaticClass());
}
// This function tells the GameplayCue editor what classes to search for GameplayCue events.
static void GetGameplayCueInterfaceClasses(TArray<UClass*>& Classes)
{
Classes.Empty();
for (UClass* Class : TObjectRange<UClass>())
{
if (Class->IsChildOf<AActor>() && Class->ImplementsInterface(UGameplayCueInterface::StaticClass()))
{
Classes.Add(Class);
}
}
}
// This function tells the GameplayCue editor where to create the GameplayCue notifies based on their tag.
static FString GetGameplayCuePath(FString GameplayCueTag)
{
FString Path = FString(TEXT("/Game"));
//@TODO: Try plugins (e.g., GameplayCue.ShooterGame.Foo should be in ShooterCore or something)
// Default path to the first entry in the UAbilitySystemGlobals::GameplayCueNotifyPaths.
if (IGameplayAbilitiesModule::IsAvailable())
{
IGameplayAbilitiesModule& GameplayAbilitiesModule = IGameplayAbilitiesModule::Get();
if (GameplayAbilitiesModule.IsAbilitySystemGlobalsAvailable())
{
UAbilitySystemGlobals* AbilitySystemGlobals = GameplayAbilitiesModule.GetAbilitySystemGlobals();
check(AbilitySystemGlobals);
TArray<FString> GetGameplayCueNotifyPaths = AbilitySystemGlobals->GetGameplayCueNotifyPaths();
if (GetGameplayCueNotifyPaths.Num() > 0)
{
Path = GetGameplayCueNotifyPaths[0];
}
}
}
GameplayCueTag.RemoveFromStart(TEXT("GameplayCue."));
FString NewDefaultPathName = FString::Printf(TEXT("%s/GCN_%s"), *Path, *GameplayCueTag);
return NewDefaultPathName;
}
static bool HasPlayWorld()
{
return GEditor->PlayWorld != nullptr;
}
static bool HasNoPlayWorld()
{
return !HasPlayWorld();
}
static bool HasPlayWorldAndRunning()
{
return HasPlayWorld() && !GUnrealEd->PlayWorld->bDebugPauseExecution;
}
static void OpenCommonMap_Clicked(const FString MapPath)
{
if (ensure(MapPath.Len()))
{
GEditor->GetEditorSubsystem<UAssetEditorSubsystem>()->OpenEditorForAsset(MapPath);
}
}
static bool CanShowCommonMaps()
{
return HasNoPlayWorld() && !GetDefault<ULyraDeveloperSettings>()->CommonEditorMaps.IsEmpty();
}
static TSharedRef<SWidget> GetCommonMapsDropdown()
{
FMenuBuilder MenuBuilder(true, nullptr);
for (const FSoftObjectPath& Path : GetDefault<ULyraDeveloperSettings>()->CommonEditorMaps)
{
if (!Path.IsValid())
{
continue;
}
const FText DisplayName = FText::FromString(Path.GetAssetName());
MenuBuilder.AddMenuEntry(
DisplayName,
LOCTEXT("CommonPathDescription", "Opens this map in the editor"),
FSlateIcon(),
FUIAction(
FExecuteAction::CreateStatic(&OpenCommonMap_Clicked, Path.ToString()),
FCanExecuteAction::CreateStatic(&HasNoPlayWorld),
FIsActionChecked(),
FIsActionButtonVisible::CreateStatic(&HasNoPlayWorld)
)
);
}
return MenuBuilder.MakeWidget();
}
static void CheckGameContent_Clicked()
{
UEditorValidator::ValidateCheckedOutContent(/*bInteractive=*/true, EDataValidationUsecase::Manual);
}
static void RegisterGameEditorMenus()
{
UToolMenu* Menu = UToolMenus::Get()->ExtendMenu("LevelEditor.LevelEditorToolBar.PlayToolBar");
FToolMenuSection& Section = Menu->AddSection("PlayGameExtensions", TAttribute<FText>(), FToolMenuInsert("Play", EToolMenuInsertType::After));
// Uncomment this to add a custom toolbar that is displayed during PIE
// Useful for making easy access to changing game state artificially, adding cheats, etc
// FToolMenuEntry BlueprintEntry = FToolMenuEntry::InitComboButton(
// "OpenGameMenu",
// FUIAction(
// FExecuteAction(),
// FCanExecuteAction::CreateStatic(&HasPlayWorld),
// FIsActionChecked(),
// FIsActionButtonVisible::CreateStatic(&HasPlayWorld)),
// FOnGetContent::CreateStatic(&YourCustomMenu),
// LOCTEXT("GameOptions_Label", "Game Options"),
// LOCTEXT("GameOptions_ToolTip", "Game Options"),
// FSlateIcon(FAppStyle::GetAppStyleSetName(), "LevelEditor.OpenLevelBlueprint")
// );
// BlueprintEntry.StyleNameOverride = "CalloutToolbar";
// Section.AddEntry(BlueprintEntry);
FToolMenuEntry CheckContentEntry = FToolMenuEntry::InitToolBarButton(
"CheckContent",
FUIAction(
FExecuteAction::CreateStatic(&CheckGameContent_Clicked),
FCanExecuteAction::CreateStatic(&HasNoPlayWorld),
FIsActionChecked(),
FIsActionButtonVisible::CreateStatic(&HasNoPlayWorld)),
LOCTEXT("CheckContentButton", "Check Content"),
LOCTEXT("CheckContentDescription", "Runs the Content Validation job on all checked out assets to look for warnings and errors"),
FSlateIcon(FGameEditorStyle::GetStyleSetName(), "GameEditor.CheckContent")
);
CheckContentEntry.StyleNameOverride = "CalloutToolbar";
Section.AddEntry(CheckContentEntry);
FToolMenuEntry CommonMapEntry = FToolMenuEntry::InitComboButton(
"CommonMapOptions",
FUIAction(
FExecuteAction(),
FCanExecuteAction::CreateStatic(&HasNoPlayWorld),
FIsActionChecked(),
FIsActionButtonVisible::CreateStatic(&CanShowCommonMaps)),
FOnGetContent::CreateStatic(&GetCommonMapsDropdown),
LOCTEXT("CommonMaps_Label", "Common Maps"),
LOCTEXT("CommonMaps_ToolTip", "Some commonly desired maps while using the editor"),
FSlateIcon(FAppStyle::GetAppStyleSetName(), "Icons.Level")
);
CommonMapEntry.StyleNameOverride = "CalloutToolbar";
Section.AddEntry(CommonMapEntry);
}
/**
* FLyraEditorModule
*/
class FLyraEditorModule : public FDefaultGameModuleImpl
{
typedef FLyraEditorModule ThisClass;
virtual void StartupModule() override
{
FGameEditorStyle::Initialize();
if (!IsRunningGame())
{
FModuleManager::Get().OnModulesChanged().AddRaw(this, &FLyraEditorModule::ModulesChangedCallback);
BindGameplayAbilitiesEditorDelegates();
if (FSlateApplication::IsInitialized())
{
ToolMenusHandle = UToolMenus::RegisterStartupCallback(FSimpleMulticastDelegate::FDelegate::CreateStatic(&RegisterGameEditorMenus));
}
FEditorDelegates::BeginPIE.AddRaw(this, &ThisClass::OnBeginPIE);
FEditorDelegates::EndPIE.AddRaw(this, &ThisClass::OnEndPIE);
}
// Register the Context Effects Library asset type actions.
{
IAssetTools& AssetTools = FModuleManager::LoadModuleChecked<FAssetToolsModule>("AssetTools").Get();
TSharedRef<FAssetTypeActions_LyraContextEffectsLibrary> AssetAction = MakeShared<FAssetTypeActions_LyraContextEffectsLibrary>();
LyraContextEffectsLibraryAssetAction = AssetAction;
AssetTools.RegisterAssetTypeActions(AssetAction);
}
}
void OnBeginPIE(bool bIsSimulating)
{
ULyraExperienceManager* ExperienceManager = GEngine->GetEngineSubsystem<ULyraExperienceManager>();
check(ExperienceManager);
ExperienceManager->OnPlayInEditorBegun();
}
void OnEndPIE(bool bIsSimulating)
{
}
virtual void ShutdownModule() override
{
// Unregister the Context Effects Library asset type actions.
{
FAssetToolsModule* AssetToolsModule = FModuleManager::GetModulePtr<FAssetToolsModule>("AssetTools");
TSharedPtr<IAssetTypeActions> AssetAction = LyraContextEffectsLibraryAssetAction.Pin();
if (AssetToolsModule && AssetAction)
{
AssetToolsModule->Get().UnregisterAssetTypeActions(AssetAction.ToSharedRef());
}
}
FEditorDelegates::BeginPIE.RemoveAll(this);
FEditorDelegates::EndPIE.RemoveAll(this);
// Undo UToolMenus
if (UObjectInitialized() && ToolMenusHandle.IsValid())
{
UToolMenus::UnRegisterStartupCallback(ToolMenusHandle);
}
UnbindGameplayAbilitiesEditorDelegates();
FModuleManager::Get().OnModulesChanged().RemoveAll(this);
FGameEditorStyle::Shutdown();
}
protected:
static void BindGameplayAbilitiesEditorDelegates()
{
IGameplayAbilitiesEditorModule& GameplayAbilitiesEditorModule = IGameplayAbilitiesEditorModule::Get();
GameplayAbilitiesEditorModule.GetGameplayCueNotifyClassesDelegate().BindStatic(&GetGameplayCueDefaultClasses);
GameplayAbilitiesEditorModule.GetGameplayCueInterfaceClassesDelegate().BindStatic(&GetGameplayCueInterfaceClasses);
GameplayAbilitiesEditorModule.GetGameplayCueNotifyPathDelegate().BindStatic(&GetGameplayCuePath);
}
static void UnbindGameplayAbilitiesEditorDelegates()
{
if (IGameplayAbilitiesEditorModule::IsAvailable())
{
IGameplayAbilitiesEditorModule& GameplayAbilitiesEditorModule = IGameplayAbilitiesEditorModule::Get();
GameplayAbilitiesEditorModule.GetGameplayCueNotifyClassesDelegate().Unbind();
GameplayAbilitiesEditorModule.GetGameplayCueInterfaceClassesDelegate().Unbind();
GameplayAbilitiesEditorModule.GetGameplayCueNotifyPathDelegate().Unbind();
}
}
void ModulesChangedCallback(FName ModuleThatChanged, EModuleChangeReason ReasonForChange)
{
if ((ReasonForChange == EModuleChangeReason::ModuleLoaded) && (ModuleThatChanged.ToString() == TEXT("GameplayAbilitiesEditor")))
{
BindGameplayAbilitiesEditorDelegates();
}
}
private:
TWeakPtr<IAssetTypeActions> LyraContextEffectsLibraryAssetAction;
FDelegateHandle ToolMenusHandle;
};
IMPLEMENT_MODULE(FLyraEditorModule, LyraEditor);
#undef LOCTEXT_NAMESPACE
|