New, subsystem style

This commit is contained in:
Lucas Peter 2024-09-18 12:25:01 +02:00
parent 1df4e9b848
commit 2d2f0192fa
No known key found for this signature in database
8 changed files with 51 additions and 266 deletions

View file

@ -17,7 +17,7 @@
{ {
"Name": "SkyPortal", "Name": "SkyPortal",
"Type": "Runtime", "Type": "Runtime",
"LoadingPhase": "Default" "LoadingPhase": "PostDefault"
} }
], ],
"IsExperimentalVersion": false, "IsExperimentalVersion": false,

View file

@ -1,13 +1,6 @@
// Copyright Epic Games, Inc. All Rights Reserved. // Copyright Epic Games, Inc. All Rights Reserved.
#include "SkyPortal.h" #include "SkyPortal.h"
#include "SkyPortalStyle.h"
#include "SkyPortalCommands.h"
#include "LevelEditor.h"
#include "Widgets/Docking/SDockTab.h"
#include "Widgets/Layout/SBox.h"
#include "Widgets/Text/STextBlock.h"
#include "ToolMenus.h"
//TODO: Need to make a raw input viewer //TODO: Need to make a raw input viewer
//maybe even a view of the different objects detected //maybe even a view of the different objects detected
@ -18,24 +11,8 @@ static const FName SkyPortalTabName("Portal Input Viewer");
void FSkyPortalModule::StartupModule() void FSkyPortalModule::StartupModule()
{ {
// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module // This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module
//SkyPortalSubsystem = GEngine->GetEngineSubsystem();
FSkyPortalStyle::Initialize();
FSkyPortalStyle::ReloadTextures();
FSkyPortalCommands::Register();
PluginCommands = MakeShareable(new FUICommandList);
PluginCommands->MapAction(
FSkyPortalCommands::Get().OpenPluginWindow,
FExecuteAction::CreateRaw(this, &FSkyPortalModule::PluginButtonClicked),
FCanExecuteAction());
UToolMenus::RegisterStartupCallback(FSimpleMulticastDelegate::FDelegate::CreateRaw(this, &FSkyPortalModule::RegisterMenus));
FGlobalTabmanager::Get()->RegisterNomadTabSpawner(SkyPortalTabName, FOnSpawnTab::CreateRaw(this, &FSkyPortalModule::OnSpawnPluginTab))
.SetDisplayName(LOCTEXT("FSkyPortalTabTitle", "SkyPortal"))
.SetMenuType(ETabSpawnerMenuType::Hidden);
} }
void FSkyPortalModule::ShutdownModule() void FSkyPortalModule::ShutdownModule()
@ -43,69 +20,10 @@ void FSkyPortalModule::ShutdownModule()
// This function may be called during shutdown to clean up your module. For modules that support dynamic reloading, // 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. // we call this function before unloading the module.
UToolMenus::UnRegisterStartupCallback(this);
UToolMenus::UnregisterOwner(this);
FSkyPortalStyle::Shutdown();
FSkyPortalCommands::Unregister();
FGlobalTabmanager::Get()->UnregisterNomadTabSpawner(SkyPortalTabName);
}
TSharedRef<SDockTab> FSkyPortalModule::OnSpawnPluginTab(const FSpawnTabArgs& SpawnTabArgs)
{
FText WidgetText = FText::Format(
LOCTEXT("WindowWidgetText", "Add code to {0} in {1} to override this window's contents"),
FText::FromString(TEXT("FSkyPortalModule::OnSpawnPluginTab")),
FText::FromString(TEXT("SkyPortal.cpp"))
);
return SNew(SDockTab)
.TabRole(ETabRole::NomadTab)
[
// Put your tab content here!
SNew(SBox)
.HAlign(HAlign_Center)
.VAlign(VAlign_Center)
[
SNew(STextBlock)
.Text(WidgetText)
]
];
}
void FSkyPortalModule::PluginButtonClicked()
{
FGlobalTabmanager::Get()->TryInvokeTab(SkyPortalTabName);
}
void FSkyPortalModule::RegisterMenus()
{
// Owner will be used for cleanup in call to UToolMenus::UnregisterOwner
FToolMenuOwnerScoped OwnerScoped(this);
{
UToolMenu* Menu = UToolMenus::Get()->ExtendMenu("LevelEditor.MainMenu.Window");
{
FToolMenuSection& Section = Menu->FindOrAddSection("WindowLayout");
Section.AddMenuEntryWithCommandList(FSkyPortalCommands::Get().OpenPluginWindow, PluginCommands);
}
}
{
UToolMenu* ToolbarMenu = UToolMenus::Get()->ExtendMenu("LevelEditor.LevelEditorToolBar");
{
FToolMenuSection& Section = ToolbarMenu->FindOrAddSection("Settings");
{
FToolMenuEntry& Entry = Section.AddEntry(FToolMenuEntry::InitToolBarButton(FSkyPortalCommands::Get().OpenPluginWindow));
Entry.SetCommandList(PluginCommands);
}
}
}
} }
#undef LOCTEXT_NAMESPACE #undef LOCTEXT_NAMESPACE
IMPLEMENT_MODULE(FSkyPortalModule, SkyPortal) IMPLEMENT_MODULE(FSkyPortalModule, SkyPortal)

View file

@ -1,12 +0,0 @@
// Copyright Epic Games, Inc. All Rights Reserved.
#include "SkyPortalCommands.h"
#define LOCTEXT_NAMESPACE "FSkyPortalModule"
void FSkyPortalCommands::RegisterCommands()
{
UI_COMMAND(OpenPluginWindow, "SkyPortal", "Bring up SkyPortal window", EUserInterfaceActionType::Button, FInputChord());
}
#undef LOCTEXT_NAMESPACE

View file

@ -1,60 +0,0 @@
// Copyright Epic Games, Inc. All Rights Reserved.
#include "SkyPortalStyle.h"
#include "Styling/SlateStyleRegistry.h"
#include "Framework/Application/SlateApplication.h"
#include "Slate/SlateGameResources.h"
#include "Interfaces/IPluginManager.h"
#include "Styling/SlateStyleMacros.h"
#define RootToContentDir Style->RootToContentDir
TSharedPtr<FSlateStyleSet> FSkyPortalStyle::StyleInstance = nullptr;
void FSkyPortalStyle::Initialize()
{
if (!StyleInstance.IsValid())
{
StyleInstance = Create();
FSlateStyleRegistry::RegisterSlateStyle(*StyleInstance);
}
}
void FSkyPortalStyle::Shutdown()
{
FSlateStyleRegistry::UnRegisterSlateStyle(*StyleInstance);
ensure(StyleInstance.IsUnique());
StyleInstance.Reset();
}
FName FSkyPortalStyle::GetStyleSetName()
{
static FName StyleSetName(TEXT("SkyPortalStyle"));
return StyleSetName;
}
const FVector2D Icon16x16(16.0f, 16.0f);
const FVector2D Icon20x20(20.0f, 20.0f);
TSharedRef< FSlateStyleSet > FSkyPortalStyle::Create()
{
TSharedRef< FSlateStyleSet > Style = MakeShareable(new FSlateStyleSet("SkyPortalStyle"));
Style->SetContentRoot(IPluginManager::Get().FindPlugin("SkyPortal")->GetBaseDir() / TEXT("Resources"));
Style->Set("SkyPortal.OpenPluginWindow", new IMAGE_BRUSH_SVG(TEXT("PlaceholderButtonIcon"), Icon20x20));
return Style;
}
void FSkyPortalStyle::ReloadTextures()
{
if (FSlateApplication::IsInitialized())
{
FSlateApplication::Get().GetRenderer()->ReloadTextureResources();
}
}
const ISlateStyle& FSkyPortalStyle::Get()
{
return *StyleInstance;
}

View file

@ -1,12 +1,11 @@
// Copyright Epic Games, Inc. All Rights Reserved. // Copyright Epic Games, Inc. All Rights Reserved.
// This plugin will try to make a complete plug n play subsystem for skylanders portals
#pragma once #pragma once
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "Modules/ModuleManager.h" #include "Modules/ModuleManager.h"
class FToolBarBuilder;
class FMenuBuilder;
class FSkyPortalModule : public IModuleInterface class FSkyPortalModule : public IModuleInterface
{ {
@ -15,16 +14,8 @@ public:
/** IModuleInterface implementation */ /** IModuleInterface implementation */
virtual void StartupModule() override; virtual void StartupModule() override;
virtual void ShutdownModule() override; virtual void ShutdownModule() override;
/** This function will be bound to Command (by default it will bring up plugin window) */
void PluginButtonClicked();
private:
void RegisterMenus();
TSharedRef<class SDockTab> OnSpawnPluginTab(const class FSpawnTabArgs& SpawnTabArgs);
private: private:
TSharedPtr<class FUICommandList> PluginCommands;
}; };

View file

@ -1,23 +0,0 @@
// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Framework/Commands/Commands.h"
#include "SkyPortalStyle.h"
class FSkyPortalCommands : public TCommands<FSkyPortalCommands>
{
public:
FSkyPortalCommands()
: TCommands<FSkyPortalCommands>(TEXT("SkyPortal"), NSLOCTEXT("Contexts", "SkyPortal", "SkyPortal Plugin"), NAME_None, FSkyPortalStyle::GetStyleSetName())
{
}
// TCommands<> interface
virtual void RegisterCommands() override;
public:
TSharedPtr< FUICommandInfo > OpenPluginWindow;
};

View file

@ -1,32 +0,0 @@
// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Styling/SlateStyle.h"
/** */
class FSkyPortalStyle
{
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;
};

View file

@ -4,55 +4,58 @@ using UnrealBuildTool;
public class SkyPortal : ModuleRules public class SkyPortal : ModuleRules
{ {
public SkyPortal(ReadOnlyTargetRules Target) : base(Target) public SkyPortal(ReadOnlyTargetRules Target) : base(Target)
{ {
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs; PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
PublicIncludePaths.AddRange( PublicIncludePaths.AddRange(
new string[] { new string[] {
// ... add public include paths required here ... // ... add public include paths required here ...
} }
); );
PrivateIncludePaths.AddRange( PrivateIncludePaths.AddRange(
new string[] { new string[] {
// ... add other private include paths required here ... // ... add other private include paths required here ...
} }
); );
PublicDependencyModuleNames.AddRange( PublicDependencyModuleNames.AddRange(
new string[] new string[]
{ {
"Core", "Core",
"CoreUObject",
"Engine",
// ... add other public dependencies that you statically link with here ... // ... add other public dependencies that you statically link with here ...
} }
); );
PrivateDependencyModuleNames.AddRange( PrivateDependencyModuleNames.AddRange(
new string[] new string[]
{ {
"Projects", "Projects",
"InputCore", "InputCore",
"EditorFramework", "EditorSubsystem",
"UnrealEd", "EditorFramework",
"ToolMenus", "UnrealEd",
"CoreUObject", "ToolMenus",
"Engine", "CoreUObject",
"Slate", "Engine",
"SlateCore", "Slate",
"SlateCore",
// ... add private dependencies that you statically link with here ... // ... add private dependencies that you statically link with here ...
} }
); );
DynamicallyLoadedModuleNames.AddRange( DynamicallyLoadedModuleNames.AddRange(
new string[] new string[]
{ {
// ... add any modules that your module loads dynamically here ... // ... add any modules that your module loads dynamically here ...
} }
); );
} }
} }