You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
#lockdown Nick.Penwarden #rb none ========================== MAJOR FEATURES + CHANGES ========================== Change 3209340 on 2016/11/23 by Ben.Marsh Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h. Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms. * Every header now includes everything it needs to compile. * There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first. * There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h. * Every .cpp file includes its matching .h file first. * This helps validate that each header is including everything it needs to compile. * No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more. * You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there. * There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible. * No engine code explicitly includes a precompiled header any more. * We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies. * PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files. Tool used to generate this transform is at Engine\Source\Programs\IncludeTool. [CL 3209342 by Ben Marsh in Main branch]
302 lines
8.4 KiB
C++
302 lines
8.4 KiB
C++
// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "Modules/ModuleManager.h"
|
|
#include "UObject/UObjectHash.h"
|
|
#include "UObject/UObjectIterator.h"
|
|
#include "Widgets/DeclarativeSyntaxSupport.h"
|
|
#include "ISettingsContainer.h"
|
|
#include "ISettingsEditorModel.h"
|
|
#include "Models/SettingsEditorModel.h"
|
|
#include "Widgets/SWidget.h"
|
|
#include "Framework/Notifications/NotificationManager.h"
|
|
#include "Widgets/Notifications/SNotificationList.h"
|
|
#include "Widgets/SSettingsEditor.h"
|
|
|
|
#include "ISettingsEditorModule.h"
|
|
#include "ISettingsModule.h"
|
|
#include "Engine/DeveloperSettings.h"
|
|
|
|
#define LOCTEXT_NAMESPACE "SSettingsEditor"
|
|
|
|
/** Holds auto discovered settings information so that they can be unloaded automatically when refreshing. */
|
|
struct FRegisteredSettings
|
|
{
|
|
FName ContainerName;
|
|
FName CategoryName;
|
|
FName SectionName;
|
|
};
|
|
|
|
|
|
/** Manages the notification for when the application needs to be restarted due to a settings change */
|
|
class FApplicationRestartRequiredNotification
|
|
{
|
|
public:
|
|
void SetOnRestartApplicationCallback( FSimpleDelegate InRestartApplicationDelegate )
|
|
{
|
|
RestartApplicationDelegate = InRestartApplicationDelegate;
|
|
}
|
|
|
|
void OnRestartRequired()
|
|
{
|
|
TSharedPtr<SNotificationItem> NotificationPin = NotificationPtr.Pin();
|
|
if (NotificationPin.IsValid() || !RestartApplicationDelegate.IsBound())
|
|
{
|
|
return;
|
|
}
|
|
|
|
FNotificationInfo Info( LOCTEXT("RestartRequiredTitle", "Restart required to apply new settings") );
|
|
|
|
// Add the buttons with text, tooltip and callback
|
|
Info.ButtonDetails.Add(FNotificationButtonInfo(
|
|
LOCTEXT("RestartNow", "Restart Now"),
|
|
LOCTEXT("RestartNowToolTip", "Restart now to finish applying your new settings."),
|
|
FSimpleDelegate::CreateRaw(this, &FApplicationRestartRequiredNotification::OnRestartClicked))
|
|
);
|
|
Info.ButtonDetails.Add(FNotificationButtonInfo(
|
|
LOCTEXT("RestartLater", "Restart Later"),
|
|
LOCTEXT("RestartLaterToolTip", "Dismiss this notificaton without restarting. Some new settings will not be applied."),
|
|
FSimpleDelegate::CreateRaw(this, &FApplicationRestartRequiredNotification::OnDismissClicked))
|
|
);
|
|
|
|
// We will be keeping track of this ourselves
|
|
Info.bFireAndForget = false;
|
|
|
|
// Set the width so that the notification doesn't resize as its text changes
|
|
Info.WidthOverride = 300.0f;
|
|
|
|
Info.bUseLargeFont = false;
|
|
Info.bUseThrobber = false;
|
|
Info.bUseSuccessFailIcons = false;
|
|
|
|
// Launch notification
|
|
NotificationPtr = FSlateNotificationManager::Get().AddNotification(Info);
|
|
NotificationPin = NotificationPtr.Pin();
|
|
|
|
if (NotificationPin.IsValid())
|
|
{
|
|
NotificationPin->SetCompletionState(SNotificationItem::CS_Pending);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
void OnRestartClicked()
|
|
{
|
|
TSharedPtr<SNotificationItem> NotificationPin = NotificationPtr.Pin();
|
|
if (NotificationPin.IsValid())
|
|
{
|
|
NotificationPin->SetText(LOCTEXT("RestartingNow", "Restarting..."));
|
|
NotificationPin->SetCompletionState(SNotificationItem::CS_Success);
|
|
NotificationPin->ExpireAndFadeout();
|
|
NotificationPtr.Reset();
|
|
}
|
|
|
|
RestartApplicationDelegate.ExecuteIfBound();
|
|
}
|
|
|
|
void OnDismissClicked()
|
|
{
|
|
TSharedPtr<SNotificationItem> NotificationPin = NotificationPtr.Pin();
|
|
if (NotificationPin.IsValid())
|
|
{
|
|
NotificationPin->SetText(LOCTEXT("RestartDismissed", "Restart Dismissed..."));
|
|
NotificationPin->SetCompletionState(SNotificationItem::CS_None);
|
|
NotificationPin->ExpireAndFadeout();
|
|
NotificationPtr.Reset();
|
|
}
|
|
}
|
|
|
|
/** Used to reference to the active restart notification */
|
|
TWeakPtr<SNotificationItem> NotificationPtr;
|
|
|
|
/** Used to actually restart the application */
|
|
FSimpleDelegate RestartApplicationDelegate;
|
|
};
|
|
|
|
|
|
/**
|
|
* Implements the SettingsEditor module.
|
|
*/
|
|
class FSettingsEditorModule
|
|
: public ISettingsEditorModule
|
|
{
|
|
public:
|
|
|
|
FSettingsEditorModule()
|
|
: bAreSettingsStale(true)
|
|
{
|
|
}
|
|
|
|
// IModuleInterface interface
|
|
|
|
virtual void StartupModule() override
|
|
{
|
|
FModuleManager::Get().OnModulesChanged().AddRaw(this, &FSettingsEditorModule::ModulesChangesCallback);
|
|
}
|
|
|
|
virtual void ShutdownModule() override
|
|
{
|
|
ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings");
|
|
|
|
if ( SettingsModule != nullptr )
|
|
{
|
|
UnregisterAutoDiscoveredSettings(*SettingsModule);
|
|
}
|
|
|
|
FModuleManager::Get().OnModulesChanged().RemoveAll(this);
|
|
}
|
|
|
|
// ISettingsEditorModule interface
|
|
|
|
virtual TSharedRef<SWidget> CreateEditor( const TSharedRef<ISettingsEditorModel>& Model ) override
|
|
{
|
|
UpdateSettings(true);
|
|
|
|
TSharedRef<SWidget> Editor = SNew(SSettingsEditor, Model)
|
|
.OnApplicationRestartRequired(FSimpleDelegate::CreateRaw(this, &FSettingsEditorModule::OnApplicationRestartRequired));
|
|
|
|
ClearStaleEditorWidgets();
|
|
EditorWidgets.Add(Editor);
|
|
|
|
return Editor;
|
|
}
|
|
|
|
virtual ISettingsEditorModelRef CreateModel( const TSharedRef<ISettingsContainer>& SettingsContainer ) override
|
|
{
|
|
return MakeShareable(new FSettingsEditorModel(SettingsContainer));
|
|
}
|
|
|
|
virtual void OnApplicationRestartRequired() override
|
|
{
|
|
ApplicationRestartRequiredNotification.OnRestartRequired();
|
|
}
|
|
|
|
virtual void SetRestartApplicationCallback( FSimpleDelegate InRestartApplicationDelegate ) override
|
|
{
|
|
ApplicationRestartRequiredNotification.SetOnRestartApplicationCallback(InRestartApplicationDelegate);
|
|
}
|
|
|
|
private:
|
|
|
|
void ModulesChangesCallback(FName ModuleName, EModuleChangeReason ReasonForChange)
|
|
{
|
|
ClearStaleEditorWidgets();
|
|
bAreSettingsStale = true;
|
|
UpdateSettings();
|
|
}
|
|
|
|
void UpdateSettings(bool bForce = false)
|
|
{
|
|
if ( ( AnyActiveSettingsEditor() || bForce ) && bAreSettingsStale )
|
|
{
|
|
bAreSettingsStale = false;
|
|
|
|
ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings");
|
|
|
|
if ( SettingsModule != nullptr )
|
|
{
|
|
UnregisterAutoDiscoveredSettings(*SettingsModule);
|
|
RegisterAutoDiscoveredSettings(*SettingsModule);
|
|
}
|
|
}
|
|
}
|
|
|
|
void ClearStaleEditorWidgets()
|
|
{
|
|
for ( int32 i = 0; i < EditorWidgets.Num(); i++ )
|
|
{
|
|
if ( !EditorWidgets[i].IsValid() )
|
|
{
|
|
EditorWidgets.RemoveAtSwap(i);
|
|
i--;
|
|
}
|
|
}
|
|
}
|
|
|
|
bool AnyActiveSettingsEditor()
|
|
{
|
|
return EditorWidgets.Num() > 0;
|
|
}
|
|
|
|
private:
|
|
|
|
void RegisterAutoDiscoveredSettings(ISettingsModule& SettingsModule)
|
|
{
|
|
// Find game object
|
|
for ( TObjectIterator<UDeveloperSettings> SettingsIt(RF_NoFlags); SettingsIt; ++SettingsIt )
|
|
{
|
|
if ( UDeveloperSettings* Settings = *SettingsIt )
|
|
{
|
|
// Only Add the CDO of any UDeveloperSettings objects.
|
|
if ( Settings->HasAnyFlags(RF_ClassDefaultObject) && !Settings->GetClass()->HasAnyCastFlag(CLASS_Deprecated) )
|
|
{
|
|
// Ignore the setting if it's specifically the UDeveloperSettings or other abstract settings classes
|
|
if ( Settings->GetClass()->HasAnyClassFlags(CLASS_Abstract) )
|
|
{
|
|
continue;
|
|
}
|
|
|
|
FRegisteredSettings Registered;
|
|
Registered.ContainerName = Settings->GetContainerName();
|
|
Registered.CategoryName = Settings->GetCategoryName();
|
|
Registered.SectionName = Settings->GetSectionName();
|
|
|
|
TSharedPtr<SWidget> CustomWidget = Settings->GetCustomSettingsWidget();
|
|
if ( CustomWidget.IsValid() )
|
|
{
|
|
// Add Settings
|
|
SettingsModule.RegisterSettings(Registered.ContainerName, Registered.CategoryName, Registered.SectionName,
|
|
Settings->GetSectionText(),
|
|
Settings->GetSectionDescription(),
|
|
CustomWidget.ToSharedRef()
|
|
);
|
|
}
|
|
else
|
|
{
|
|
// Add Settings
|
|
SettingsModule.RegisterSettings(Registered.ContainerName, Registered.CategoryName, Registered.SectionName,
|
|
Settings->GetSectionText(),
|
|
Settings->GetSectionDescription(),
|
|
Settings
|
|
);
|
|
}
|
|
|
|
AutoDiscoveredSettings.Add(Registered);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void UnregisterAutoDiscoveredSettings(ISettingsModule& SettingsModule)
|
|
{
|
|
// Unregister any auto discovers settings.
|
|
for ( const FRegisteredSettings& Settings : AutoDiscoveredSettings )
|
|
{
|
|
SettingsModule.UnregisterSettings(Settings.ContainerName, Settings.CategoryName, Settings.SectionName);
|
|
}
|
|
|
|
AutoDiscoveredSettings.Reset();
|
|
}
|
|
|
|
private:
|
|
|
|
FApplicationRestartRequiredNotification ApplicationRestartRequiredNotification;
|
|
|
|
/** The list of auto discovered settings that need to be unregistered. */
|
|
TArray<FRegisteredSettings> AutoDiscoveredSettings;
|
|
|
|
/** Living editor widgets that have been handed out. */
|
|
TArray< TWeakPtr<SWidget> > EditorWidgets;
|
|
|
|
/** Flag if the settings are stale currently and need to be refreshed. */
|
|
bool bAreSettingsStale;
|
|
};
|
|
|
|
|
|
IMPLEMENT_MODULE(FSettingsEditorModule, SettingsEditor);
|
|
|
|
|
|
#undef LOCTEXT_NAMESPACE
|