Minor Update - Reload Editor + Checkbox to activate auto save before restart - V0.1.0
This commit is contained in:
@@ -0,0 +1,185 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#include "ReloadEditor.h"
|
||||
#include "FileHelpers.h"
|
||||
#include "ReloadEditorStyle.h"
|
||||
#include "ReloadEditorCommands.h"
|
||||
#include "Misc/MessageDialog.h"
|
||||
#include "ToolMenus.h"
|
||||
#include "Widgets/SBoxPanel.h"
|
||||
#include "Widgets/Input/SButton.h"
|
||||
#include "Widgets/Input/SCheckBox.h"
|
||||
#include "Widgets/Text/STextBlock.h"
|
||||
#include "Widgets/Input/SMenuAnchor.h"
|
||||
#include "Widgets/Images/SImage.h"
|
||||
#include "Framework/Application/SlateApplication.h"
|
||||
|
||||
static const FName ReloadEditorTabName("ReloadEditor");
|
||||
|
||||
#define LOCTEXT_NAMESPACE "FReloadEditorModule"
|
||||
|
||||
void FReloadEditorModule::StartupModule()
|
||||
{
|
||||
FReloadEditorStyle::Initialize();
|
||||
FReloadEditorStyle::ReloadTextures();
|
||||
FReloadEditorCommands::Register();
|
||||
|
||||
PluginCommands = MakeShareable(new FUICommandList);
|
||||
|
||||
PluginCommands->MapAction(
|
||||
FReloadEditorCommands::Get().PluginAction,
|
||||
FExecuteAction::CreateRaw(this, &FReloadEditorModule::PluginButtonClicked),
|
||||
FCanExecuteAction()
|
||||
);
|
||||
|
||||
UToolMenus::RegisterStartupCallback(FSimpleMulticastDelegate::FDelegate::CreateRaw(this, &FReloadEditorModule::RegisterMenus));
|
||||
}
|
||||
|
||||
void FReloadEditorModule::ShutdownModule()
|
||||
{
|
||||
UToolMenus::UnRegisterStartupCallback(this);
|
||||
UToolMenus::UnregisterOwner(this);
|
||||
|
||||
FReloadEditorStyle::Shutdown();
|
||||
FReloadEditorCommands::Unregister();
|
||||
}
|
||||
|
||||
TSharedRef<SWidget> FReloadEditorModule::CreateReloadButton()
|
||||
{
|
||||
return SNew(SHorizontalBox)
|
||||
|
||||
+ SHorizontalBox::Slot()
|
||||
.AutoWidth()
|
||||
[
|
||||
SNew(SComboButton)
|
||||
.ButtonStyle(FAppStyle::Get(), "NoBorder")
|
||||
.HasDownArrow(false)
|
||||
.MenuPlacement(MenuPlacement_BelowRightAnchor)
|
||||
.ButtonContent()
|
||||
[
|
||||
SNew(SOverlay)
|
||||
+ SOverlay::Slot()
|
||||
[
|
||||
SNew(SBox)
|
||||
[
|
||||
SNew(SImage)
|
||||
.Image(FReloadEditorStyle::Get().GetBrush("ReloadEditor.Restart.Background"))
|
||||
]
|
||||
]
|
||||
+ SOverlay::Slot()
|
||||
[
|
||||
SNew(SBox)
|
||||
.Padding(FMargin(3.5f, 5, 3.5f, 5))
|
||||
[
|
||||
SNew(SImage)
|
||||
.Image(FReloadEditorStyle::Get().GetBrush("ReloadEditor.Restart"))
|
||||
.DesiredSizeOverride(FVector2D(20, 20))
|
||||
]
|
||||
]
|
||||
]
|
||||
.OnGetMenuContent_Lambda([this]() {
|
||||
PluginButtonClicked();
|
||||
return SNullWidget::NullWidget;
|
||||
})
|
||||
]
|
||||
|
||||
+ SHorizontalBox::Slot()
|
||||
.AutoWidth()
|
||||
.Padding(2, 0, 0, 0)
|
||||
[
|
||||
SNew(SComboButton)
|
||||
.ButtonStyle(FAppStyle::Get(), "NoBorder")
|
||||
.HasDownArrow(false)
|
||||
.MenuPlacement(MenuPlacement_BelowRightAnchor)
|
||||
.ButtonContent()
|
||||
[
|
||||
SNew(SOverlay)
|
||||
+ SOverlay::Slot()
|
||||
[
|
||||
SNew(SImage)
|
||||
.Image(FReloadEditorStyle::Get().GetBrush("ReloadEditor.ThreeDots.Background"))
|
||||
]
|
||||
+ SOverlay::Slot()
|
||||
[
|
||||
SNew(SBox)
|
||||
.Padding(FMargin(0.5f, 7, 0.5f, 7))
|
||||
[
|
||||
SNew(SImage)
|
||||
.Image(FReloadEditorStyle::Get().GetBrush("ReloadEditor.ThreeDots"))
|
||||
.DesiredSizeOverride(FVector2D(16, 16))
|
||||
]
|
||||
]
|
||||
]
|
||||
.OnGetMenuContent_Lambda([this]() {
|
||||
FMenuBuilder MenuBuilder(true, nullptr);
|
||||
MenuBuilder.AddMenuEntry(
|
||||
LOCTEXT("AutoSaveOption", "Sauvegarder automatiquement avant reload"),
|
||||
TAttribute<FText>(),
|
||||
FSlateIcon(),
|
||||
FUIAction(
|
||||
FExecuteAction::CreateLambda([this]() { bAutoSaveBeforeReload = !bAutoSaveBeforeReload; }),
|
||||
FCanExecuteAction(),
|
||||
FIsActionChecked::CreateLambda([this]() { return bAutoSaveBeforeReload; })
|
||||
),
|
||||
NAME_None,
|
||||
EUserInterfaceActionType::ToggleButton
|
||||
);
|
||||
return MenuBuilder.MakeWidget();
|
||||
})
|
||||
];
|
||||
}
|
||||
|
||||
void FReloadEditorModule::PluginButtonClicked()
|
||||
{
|
||||
if (bAutoSaveBeforeReload)
|
||||
{
|
||||
FEditorFileUtils::SaveDirtyPackages(true, true, true, false, false, false);
|
||||
}
|
||||
|
||||
TArray<UPackage*> DirtyPackages;
|
||||
FEditorFileUtils::GetDirtyPackages(DirtyPackages);
|
||||
|
||||
if (!bAutoSaveBeforeReload && DirtyPackages.Num() > 0)
|
||||
{
|
||||
if (FMessageDialog::Open(EAppMsgType::YesNo, FText::FromString(TEXT("Des fichiers non sauvegardés existent. Voulez-vous vraiment redémarrer ?"))) != EAppReturnType::Yes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
FString EditorExe = FPlatformProcess::ExecutablePath();
|
||||
FString ProjectFile = FPaths::GetProjectFilePath();
|
||||
FString CmdLine = FString::Printf(TEXT("\"%s\" %s"), *ProjectFile, FCommandLine::Get());
|
||||
|
||||
FPlatformProcess::CreateProc(*EditorExe, *CmdLine, true, false, false, nullptr, 0, nullptr, nullptr);
|
||||
FPlatformMisc::RequestExit(false);
|
||||
}
|
||||
|
||||
void FReloadEditorModule::RegisterMenus()
|
||||
{
|
||||
FToolMenuOwnerScoped OwnerScoped(this);
|
||||
|
||||
{
|
||||
UToolMenu* Menu = UToolMenus::Get()->ExtendMenu("LevelEditor.MainMenu.Window");
|
||||
FToolMenuSection& Section = Menu->FindOrAddSection("WindowLayout");
|
||||
Section.AddEntry(FToolMenuEntry::InitWidget(
|
||||
"ReloadEditorWidget",
|
||||
CreateReloadButton(),
|
||||
FText::FromString(TEXT("Redémarrer l'éditeur"))
|
||||
));
|
||||
}
|
||||
|
||||
{
|
||||
UToolMenu* ToolbarMenu = UToolMenus::Get()->ExtendMenu("LevelEditor.LevelEditorToolBar.PlayToolBar");
|
||||
FToolMenuSection& Section = ToolbarMenu->FindOrAddSection("PluginTools");
|
||||
Section.AddEntry(FToolMenuEntry::InitWidget(
|
||||
"ReloadEditorWidgetToolbar",
|
||||
CreateReloadButton(),
|
||||
FText::FromString(TEXT("Redémarrer l'éditeur"))
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
#undef LOCTEXT_NAMESPACE
|
||||
|
||||
IMPLEMENT_MODULE(FReloadEditorModule, ReloadEditor)
|
@@ -0,0 +1,12 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#include "ReloadEditorCommands.h"
|
||||
|
||||
#define LOCTEXT_NAMESPACE "FReloadEditorModule"
|
||||
|
||||
void FReloadEditorCommands::RegisterCommands()
|
||||
{
|
||||
UI_COMMAND(PluginAction, "ReloadEditor", "Execute ReloadEditor action", EUserInterfaceActionType::Button, FInputChord());
|
||||
}
|
||||
|
||||
#undef LOCTEXT_NAMESPACE
|
@@ -0,0 +1,86 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#include "ReloadEditorStyle.h"
|
||||
#include "ReloadEditor.h"
|
||||
#include "Framework/Application/SlateApplication.h"
|
||||
#include "Styling/SlateStyleRegistry.h"
|
||||
#include "Slate/SlateGameResources.h"
|
||||
#include "Interfaces/IPluginManager.h"
|
||||
#include "Styling/SlateStyleMacros.h"
|
||||
#include "Brushes/SlateRoundedBoxBrush.h"
|
||||
|
||||
#define RootToContentDir Style->RootToContentDir
|
||||
|
||||
TSharedPtr<FSlateStyleSet> FReloadEditorStyle::StyleInstance = nullptr;
|
||||
|
||||
void FReloadEditorStyle::Initialize()
|
||||
{
|
||||
if (!StyleInstance.IsValid())
|
||||
{
|
||||
StyleInstance = Create();
|
||||
FSlateStyleRegistry::RegisterSlateStyle(*StyleInstance);
|
||||
}
|
||||
}
|
||||
|
||||
void FReloadEditorStyle::Shutdown()
|
||||
{
|
||||
FSlateStyleRegistry::UnRegisterSlateStyle(*StyleInstance);
|
||||
ensure(StyleInstance.IsUnique());
|
||||
StyleInstance.Reset();
|
||||
}
|
||||
|
||||
FName FReloadEditorStyle::GetStyleSetName()
|
||||
{
|
||||
static FName StyleSetName(TEXT("ReloadEditorStyle"));
|
||||
return StyleSetName;
|
||||
}
|
||||
|
||||
const FVector2D Icon16x16(16.0f, 16.0f);
|
||||
const FVector2D Icon20x20(20.0f, 20.0f);
|
||||
|
||||
TSharedRef<FSlateStyleSet> FReloadEditorStyle::Create()
|
||||
{
|
||||
TSharedRef<FSlateStyleSet> Style = MakeShareable(new FSlateStyleSet(GetStyleSetName()));
|
||||
Style->SetContentRoot(IPluginManager::Get().FindPlugin("ReloadEditor")->GetBaseDir() / TEXT("Resources"));
|
||||
|
||||
Style->Set(
|
||||
TEXT("ReloadEditor.ThreeDots"),
|
||||
new IMAGE_BRUSH_SVG(TEXT("ThreeDots"), Icon20x20)
|
||||
);
|
||||
|
||||
Style->Set(
|
||||
TEXT("ReloadEditor.ThreeDots.Background"),
|
||||
new FSlateRoundedBoxBrush(
|
||||
FLinearColor(10.f/255.f, 10.f/255.f, 10.f/255.f, 1.f),
|
||||
FVector4 (0.f, 3.f, 3.f, 0.f)
|
||||
)
|
||||
);
|
||||
|
||||
Style->Set(
|
||||
TEXT("ReloadEditor.Restart"),
|
||||
new IMAGE_BRUSH_SVG(TEXT("Restart"), Icon20x20)
|
||||
);
|
||||
|
||||
Style->Set(
|
||||
TEXT("ReloadEditor.Restart.Background"),
|
||||
new FSlateRoundedBoxBrush(
|
||||
FLinearColor(10.f/255.f, 10.f/255.f, 10.f/255.f, 1.f),
|
||||
FVector4(3.f, 0.f, 0.f, 3.f)
|
||||
)
|
||||
);
|
||||
|
||||
return Style;
|
||||
}
|
||||
|
||||
void FReloadEditorStyle::ReloadTextures()
|
||||
{
|
||||
if (FSlateApplication::IsInitialized())
|
||||
{
|
||||
FSlateApplication::Get().GetRenderer()->ReloadTextureResources();
|
||||
}
|
||||
}
|
||||
|
||||
const ISlateStyle& FReloadEditorStyle::Get()
|
||||
{
|
||||
return *StyleInstance;
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Modules/ModuleManager.h"
|
||||
|
||||
class FToolBarBuilder;
|
||||
class FMenuBuilder;
|
||||
|
||||
class FReloadEditorModule : public IModuleInterface
|
||||
{
|
||||
public:
|
||||
|
||||
/** IModuleInterface implementation */
|
||||
virtual void StartupModule() override;
|
||||
virtual void ShutdownModule() override;
|
||||
|
||||
/** This function will be bound to Command. */
|
||||
void PluginButtonClicked();
|
||||
TSharedRef<SWidget> CreateReloadButton();
|
||||
|
||||
private:
|
||||
|
||||
void RegisterMenus();
|
||||
|
||||
public:
|
||||
|
||||
bool bAutoSaveBeforeReload = false;
|
||||
|
||||
private:
|
||||
TSharedPtr<class FUICommandList> PluginCommands;
|
||||
};
|
@@ -0,0 +1,23 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Framework/Commands/Commands.h"
|
||||
#include "ReloadEditorStyle.h"
|
||||
|
||||
class FReloadEditorCommands : public TCommands<FReloadEditorCommands>
|
||||
{
|
||||
public:
|
||||
|
||||
FReloadEditorCommands()
|
||||
: TCommands<FReloadEditorCommands>(TEXT("ReloadEditor"), NSLOCTEXT("Contexts", "ReloadEditor", "ReloadEditor Plugin"), NAME_None, FReloadEditorStyle::GetStyleSetName())
|
||||
{
|
||||
}
|
||||
|
||||
// TCommands<> interface
|
||||
virtual void RegisterCommands() override;
|
||||
|
||||
public:
|
||||
TSharedPtr< FUICommandInfo > PluginAction;
|
||||
};
|
@@ -0,0 +1,31 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Styling/SlateStyle.h"
|
||||
|
||||
class FReloadEditorStyle
|
||||
{
|
||||
public:
|
||||
|
||||
static void Initialize();
|
||||
|
||||
static void Shutdown();
|
||||
|
||||
/** reloads textures used by slate renderer */
|
||||
static void ReloadTextures();
|
||||
|
||||
/** @return The Slate style set for the Shooter game */
|
||||
static const ISlateStyle& Get();
|
||||
|
||||
static FName GetStyleSetName();
|
||||
|
||||
private:
|
||||
|
||||
static TSharedRef< class FSlateStyleSet > Create();
|
||||
|
||||
private:
|
||||
|
||||
static TSharedPtr< class FSlateStyleSet > StyleInstance;
|
||||
};
|
@@ -0,0 +1,58 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
using UnrealBuildTool;
|
||||
|
||||
public class ReloadEditor : ModuleRules
|
||||
{
|
||||
public ReloadEditor(ReadOnlyTargetRules Target) : base(Target)
|
||||
{
|
||||
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
|
||||
|
||||
PublicIncludePaths.AddRange(
|
||||
new string[] {
|
||||
// ... add public include paths required here ...
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
PrivateIncludePaths.AddRange(
|
||||
new string[] {
|
||||
// ... add other private include paths required here ...
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
PublicDependencyModuleNames.AddRange(
|
||||
new string[]
|
||||
{
|
||||
"Core",
|
||||
// ... add other public dependencies that you statically link with here ...
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
PrivateDependencyModuleNames.AddRange(
|
||||
new string[]
|
||||
{
|
||||
"Projects",
|
||||
"InputCore",
|
||||
"EditorFramework",
|
||||
"UnrealEd",
|
||||
"ToolMenus",
|
||||
"CoreUObject",
|
||||
"Engine",
|
||||
"Slate",
|
||||
"SlateCore",
|
||||
// ... add private dependencies that you statically link with here ...
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
DynamicallyLoadedModuleNames.AddRange(
|
||||
new string[]
|
||||
{
|
||||
// ... add any modules that your module loads dynamically here ...
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user