From 2d2f0192fa65396cf33d22e60f89e20107b23447 Mon Sep 17 00:00:00 2001 From: Lucas Peter Date: Wed, 18 Sep 2024 12:25:01 +0200 Subject: [PATCH] New, subsystem style --- SkyPortal.uplugin | 2 +- Source/SkyPortal/Private/SkyPortal.cpp | 88 +------------------ .../SkyPortal/Private/SkyPortalCommands.cpp | 12 --- Source/SkyPortal/Private/SkyPortalStyle.cpp | 60 ------------- Source/SkyPortal/Public/SkyPortal.h | 15 +--- Source/SkyPortal/Public/SkyPortalCommands.h | 23 ----- Source/SkyPortal/Public/SkyPortalStyle.h | 32 ------- Source/SkyPortal/SkyPortal.Build.cs | 85 +++++++++--------- 8 files changed, 51 insertions(+), 266 deletions(-) delete mode 100644 Source/SkyPortal/Private/SkyPortalCommands.cpp delete mode 100644 Source/SkyPortal/Private/SkyPortalStyle.cpp delete mode 100644 Source/SkyPortal/Public/SkyPortalCommands.h delete mode 100644 Source/SkyPortal/Public/SkyPortalStyle.h diff --git a/SkyPortal.uplugin b/SkyPortal.uplugin index 00ac1d6..c1c8075 100644 --- a/SkyPortal.uplugin +++ b/SkyPortal.uplugin @@ -17,7 +17,7 @@ { "Name": "SkyPortal", "Type": "Runtime", - "LoadingPhase": "Default" + "LoadingPhase": "PostDefault" } ], "IsExperimentalVersion": false, diff --git a/Source/SkyPortal/Private/SkyPortal.cpp b/Source/SkyPortal/Private/SkyPortal.cpp index 21631a2..b4e6ecd 100644 --- a/Source/SkyPortal/Private/SkyPortal.cpp +++ b/Source/SkyPortal/Private/SkyPortal.cpp @@ -1,13 +1,6 @@ // Copyright Epic Games, Inc. All Rights Reserved. #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 //maybe even a view of the different objects detected @@ -18,24 +11,8 @@ static const FName SkyPortalTabName("Portal Input Viewer"); 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 - - FSkyPortalStyle::Initialize(); - FSkyPortalStyle::ReloadTextures(); + //SkyPortalSubsystem = GEngine->GetEngineSubsystem(); - 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() @@ -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, // we call this function before unloading the module. - UToolMenus::UnRegisterStartupCallback(this); - UToolMenus::UnregisterOwner(this); - - FSkyPortalStyle::Shutdown(); - - FSkyPortalCommands::Unregister(); - - FGlobalTabmanager::Get()->UnregisterNomadTabSpawner(SkyPortalTabName); -} - -TSharedRef 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 - + IMPLEMENT_MODULE(FSkyPortalModule, SkyPortal) + diff --git a/Source/SkyPortal/Private/SkyPortalCommands.cpp b/Source/SkyPortal/Private/SkyPortalCommands.cpp deleted file mode 100644 index e9fc874..0000000 --- a/Source/SkyPortal/Private/SkyPortalCommands.cpp +++ /dev/null @@ -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 diff --git a/Source/SkyPortal/Private/SkyPortalStyle.cpp b/Source/SkyPortal/Private/SkyPortalStyle.cpp deleted file mode 100644 index 095d525..0000000 --- a/Source/SkyPortal/Private/SkyPortalStyle.cpp +++ /dev/null @@ -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 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; -} diff --git a/Source/SkyPortal/Public/SkyPortal.h b/Source/SkyPortal/Public/SkyPortal.h index 9405618..e04c5d8 100644 --- a/Source/SkyPortal/Public/SkyPortal.h +++ b/Source/SkyPortal/Public/SkyPortal.h @@ -1,12 +1,11 @@ // Copyright Epic Games, Inc. All Rights Reserved. +// This plugin will try to make a complete plug n play subsystem for skylanders portals #pragma once #include "CoreMinimal.h" #include "Modules/ModuleManager.h" -class FToolBarBuilder; -class FMenuBuilder; class FSkyPortalModule : public IModuleInterface { @@ -15,16 +14,8 @@ public: /** IModuleInterface implementation */ virtual void StartupModule() 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 OnSpawnPluginTab(const class FSpawnTabArgs& SpawnTabArgs); private: - TSharedPtr PluginCommands; + }; + diff --git a/Source/SkyPortal/Public/SkyPortalCommands.h b/Source/SkyPortal/Public/SkyPortalCommands.h deleted file mode 100644 index 4d054c3..0000000 --- a/Source/SkyPortal/Public/SkyPortalCommands.h +++ /dev/null @@ -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 -{ -public: - - FSkyPortalCommands() - : TCommands(TEXT("SkyPortal"), NSLOCTEXT("Contexts", "SkyPortal", "SkyPortal Plugin"), NAME_None, FSkyPortalStyle::GetStyleSetName()) - { - } - - // TCommands<> interface - virtual void RegisterCommands() override; - -public: - TSharedPtr< FUICommandInfo > OpenPluginWindow; -}; diff --git a/Source/SkyPortal/Public/SkyPortalStyle.h b/Source/SkyPortal/Public/SkyPortalStyle.h deleted file mode 100644 index 52e3194..0000000 --- a/Source/SkyPortal/Public/SkyPortalStyle.h +++ /dev/null @@ -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; -}; diff --git a/Source/SkyPortal/SkyPortal.Build.cs b/Source/SkyPortal/SkyPortal.Build.cs index 84a0dce..5c96679 100644 --- a/Source/SkyPortal/SkyPortal.Build.cs +++ b/Source/SkyPortal/SkyPortal.Build.cs @@ -4,55 +4,58 @@ using UnrealBuildTool; public class SkyPortal : ModuleRules { - public SkyPortal(ReadOnlyTargetRules Target) : base(Target) - { - PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs; - - PublicIncludePaths.AddRange( - new string[] { + public SkyPortal(ReadOnlyTargetRules Target) : base(Target) + { + PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs; + + PublicIncludePaths.AddRange( + new string[] { // ... add public include paths required here ... } - ); - - - PrivateIncludePaths.AddRange( - new string[] { + ); + + + PrivateIncludePaths.AddRange( + new string[] { // ... add other private include paths required here ... } - ); - - - PublicDependencyModuleNames.AddRange( - new string[] - { - "Core", + ); + + + PublicDependencyModuleNames.AddRange( + new string[] + { + "Core", + "CoreUObject", + "Engine", // ... add other public dependencies that you statically link with here ... } - ); - - - PrivateDependencyModuleNames.AddRange( - new string[] - { - "Projects", - "InputCore", - "EditorFramework", - "UnrealEd", - "ToolMenus", - "CoreUObject", - "Engine", - "Slate", - "SlateCore", + ); + + + PrivateDependencyModuleNames.AddRange( + new string[] + { + "Projects", + "InputCore", + "EditorSubsystem", + "EditorFramework", + "UnrealEd", + "ToolMenus", + "CoreUObject", + "Engine", + "Slate", + "SlateCore", // ... add private dependencies that you statically link with here ... } - ); - - - DynamicallyLoadedModuleNames.AddRange( - new string[] - { + ); + + + DynamicallyLoadedModuleNames.AddRange( + new string[] + { // ... add any modules that your module loads dynamically here ... } - ); - } + ); + } }