From b71b54537cadfdcae7be7d0e7da4438892a3ada2 Mon Sep 17 00:00:00 2001 From: Kevin Poretti Date: Sat, 2 Apr 2022 16:44:29 -0400 Subject: [PATCH] Implement asset editor interface so SNGStateMachine object can be created and edited --- .../States/ProtagStateMachine.uasset | 3 + .../SwordNGunEditor/ISNGModuleInterface.h | 5 ++ .../Private/States/IStateMachineEditor.cpp | 1 + .../Private/States/SNGStateMachineEditor.cpp | 68 ++++++++++++++++++ .../Private/States/SNGStateMachineFactory.cpp | Bin 1782 -> 1366 bytes .../States/SNGStateMachineTypeActions.cpp | Bin 1342 -> 2658 bytes .../Public/States/IStateMachineEditor.h | 7 ++ .../Public/States/SNGStateMachineEditor.h | 43 +++++++++++ .../Public/States/SNGStateMachineFactory.h | Bin 1358 -> 1154 bytes .../States/SNGStateMachineTypeActions.h | Bin 1306 -> 1526 bytes .../SwordNGunEditor/SwordNGunEditor.cpp | 25 +++++++ .../Source/SwordNGunEditor/SwordNGunEditor.h | 4 ++ 12 files changed, 156 insertions(+) create mode 100644 SwordNGun/Content/Characters/Protagonist/States/ProtagStateMachine.uasset create mode 100644 SwordNGun/Source/SwordNGunEditor/Private/States/IStateMachineEditor.cpp create mode 100644 SwordNGun/Source/SwordNGunEditor/Private/States/SNGStateMachineEditor.cpp create mode 100644 SwordNGun/Source/SwordNGunEditor/Public/States/IStateMachineEditor.h create mode 100644 SwordNGun/Source/SwordNGunEditor/Public/States/SNGStateMachineEditor.h diff --git a/SwordNGun/Content/Characters/Protagonist/States/ProtagStateMachine.uasset b/SwordNGun/Content/Characters/Protagonist/States/ProtagStateMachine.uasset new file mode 100644 index 0000000..efe21d2 --- /dev/null +++ b/SwordNGun/Content/Characters/Protagonist/States/ProtagStateMachine.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a99a09d03173adc4441e32998d7d01c3187b5ff5dd90345d78c2fc787ddc7a5c +size 1190 diff --git a/SwordNGun/Source/SwordNGunEditor/ISNGModuleInterface.h b/SwordNGun/Source/SwordNGunEditor/ISNGModuleInterface.h index c5a67ee..e1f169b 100644 --- a/SwordNGun/Source/SwordNGunEditor/ISNGModuleInterface.h +++ b/SwordNGun/Source/SwordNGunEditor/ISNGModuleInterface.h @@ -3,6 +3,7 @@ #pragma once #include "Modules/ModuleManager.h" +#include "Styling/SlateStyle.h" class ISNGModuleListenerInterface { @@ -14,10 +15,14 @@ public: class ISNGModuleInterface : public IModuleInterface { public: + /** IModuleInterface */ virtual void StartupModule() override; virtual void ShutdownModule() override; + virtual void AddModuleListeners() {}; + TSharedPtr StyleSet; + protected: TArray> ModuleListeners; }; diff --git a/SwordNGun/Source/SwordNGunEditor/Private/States/IStateMachineEditor.cpp b/SwordNGun/Source/SwordNGunEditor/Private/States/IStateMachineEditor.cpp new file mode 100644 index 0000000..130350b --- /dev/null +++ b/SwordNGun/Source/SwordNGunEditor/Private/States/IStateMachineEditor.cpp @@ -0,0 +1 @@ +#include "States/IStateMachineEditor.h" diff --git a/SwordNGun/Source/SwordNGunEditor/Private/States/SNGStateMachineEditor.cpp b/SwordNGun/Source/SwordNGunEditor/Private/States/SNGStateMachineEditor.cpp new file mode 100644 index 0000000..eb20db9 --- /dev/null +++ b/SwordNGun/Source/SwordNGunEditor/Private/States/SNGStateMachineEditor.cpp @@ -0,0 +1,68 @@ +#include "States/SNGStateMachineEditor.h" + +#define LOCTEXT_NAMESPACE "SNGStateMachineEditor" + +const FName SNGStateMachineEditorAppName = FName(TEXT("SNGStateMachineEditorAppName")); + +void FSNGStateMachineEditor::RegisterTabSpawners(const TSharedRef& InTabManager) +{ + /* + WorkspaceMenuCategory = TabManager->AddLocalWorkspaceMenuCategory(LOCTEXT("WorkspaceMenu_SNGStateMachineEditor", "SNG State Machine Editor")); + TSharedRef WorkspaceMenuCatRef = WorkspaceMenuCategory.ToSharedRef(); + FAssetEditorToolkit::RegisterTabSpawners(TabManager); + TabManager->RegisterTabSpawner(GraphCanvasTabId, ) + .SetDisplayName(LOCTEXT("GraphCanvasTab", "Graph")) + .SetGroup(WorkspaceMenuCategoryRef) + .SetIcon(FSlateIcon(FEditorStyle::GetStyleSetName(), "GraphEditor.EventGraph_16x")); + + TabManager->RegisterTabSpawner(PropertiesTabId, FOnSpawnTab::CreateSP(this, &FSoundSubmixEditor::SpawnTab_Properties)) + .SetDisplayName(LOCTEXT("PropertiesTab", "Details")) + .SetGroup(WorkspaceMenuCategoryRef) + .SetIcon(FSlateIcon(FEditorStyle::GetStyleSetName(), "LevelEditor.Tabs.Details"));\ + */ +} + +void FSNGStateMachineEditor::UnregisterTabSpawners(const TSharedRef& InTabManager) +{ + IStateMachineEditor::UnregisterTabSpawners(InTabManager); +} + +FText FSNGStateMachineEditor::GetBaseToolkitName() const +{ + return LOCTEXT("SNGStateMachineEditorAppLabel", "SNG State Machine Editor"); +} + +FText FSNGStateMachineEditor::GetToolkitName() const +{ + const bool bDirtyState = StateMachineEdited->GetOutermost()->IsDirty(); + + FFormatNamedArguments Args; + Args.Add(TEXT("StateMachineName", FText::FromString(StateMachineEdited->GetName()))); + Args.Add((TEXT("DirtyState")), bDirtyState ? FText::FromString("*") : FText::GetEmpty()); + return FText::Format(LOCTEXT("SNGStateMachineEditorToolkitName", "{StateMachineName}{DirtyState}"), Args); +} + +void FSNGStateMachineEditor::SaveAsset_Execute() +{ + FAssetEditorToolkit::SaveAsset_Execute(); +} + +void FSNGStateMachineEditor::SaveAssetAs_Execute() +{ + IStateMachineEditor::SaveAssetAs_Execute(); +} + +void FSNGStateMachineEditor::FocusWindow(UObject* ObjectToFocusOn) +{ + BringToolkitToFront(); + //JumpToObject +} + +void FSNGStateMachineEditor::InitStateMachineEditor(const EToolkitMode::Type Mode, + const TSharedPtr& InitToolkitHost, USNGStateMachine* StateMachine) +{ + StateMachineEdited = StateMachine; + FAssetEditorToolkit::InitAssetEditor(Mode, InitToolkitHost, SNGStateMachineEditorAppName, , true, true, StateMachine); +} + + diff --git a/SwordNGun/Source/SwordNGunEditor/Private/States/SNGStateMachineFactory.cpp b/SwordNGun/Source/SwordNGunEditor/Private/States/SNGStateMachineFactory.cpp index 8dba239f49089961919db7397b21e15a09356985..ea6d91739424f0cd4f6a38eca9bc631c47192d7a 100644 GIT binary patch delta 70 zcmeyydyQ*C$;67Bi9I@-Lm0(aOcWSu7!(+S7~B}*8A2F}7!n!s7>a>pGD8VNCPO}u Tm&lOApvhp(z{|kJPzxpjros;q delta 314 zcmcb{^^JEz$;5&JRY!(mAWUT_VF+QUWGDc#oEZ{x)J0mkSnYicp11DYQZFkl>{_9AE*lMGE0!YV1^8! iXem%U1Z35YdY!3kG+du~Z diff --git a/SwordNGun/Source/SwordNGunEditor/Private/States/SNGStateMachineTypeActions.cpp b/SwordNGun/Source/SwordNGunEditor/Private/States/SNGStateMachineTypeActions.cpp index ee58c6718dc4c2125b6abe14c005a9e562852f3f..724040832bd3ab28264421d4098948ae39c16656 100644 GIT binary patch literal 2658 zcmb_e+iuf95S>>e@eivYA-5_mg|`-hswyp2X&RA+K9|HP1~&~F(mcBH= zSAq|#;TSw#aDJ;9hRQx;xOF3E;5N0(@1M(-^6kNbig6XpSF7CGf0Xy18slESEpu1M z^9Q1tHMt zSe?ro>ByygewfhPQrEf6{>;8lWJguy!Mcr!cmsQ~*8+<%yqw|v5T8iC>12A3=LBnY zpmLd9>x!MWA7DMj6+Nu7BDU{chcpU4FW{4N-73eq-wA|9_VE{`;N=GOycHt8K!&UlPv|ms^BFpY?I26HQr#`wUFJWV zyFKGPvG?@En;=6f_%;4vRkP#fe*WJPd%~W1`7_*}`DBsmcJ& InTabManager) override; + virtual void UnregisterTabSpawners(const TSharedRef& InTabManager) override; + virtual FText GetBaseToolkitName() const override; + virtual FText GetToolkitName() const override; + virtual FName GetToolkitFName() const override { return FName(TEXT("SNGStateMachineEditor")); } + virtual FText GetToolkitToolTipText() const override; + virtual FLinearColor GetWorldCentricTabColorScale() const override; + virtual FString GetWorldCentricTabPrefix() const override; + + /** FAssetEditorToolkit interface */ + virtual FString GetDocumentationLink() const override; + virtual bool CanSaveAsset() const override { return true; } + virtual bool CanSaveAssetAs() const override { return true; } + virtual void SaveAsset_Execute() override; + virtual void SaveAssetAs_Execute() override; + + /** IAssetEditorInstance interface */ + virtual void FocusWindow(UObject* ObjectToFocusOn = nullptr) override; + + void InitStateMachineEditor(const EToolkitMode::Type Mode, const TSharedPtr& InitToolkitHost, USNGStateMachine* StateMachine); + +private: + /** State machien being edited */ + USNGStateMachine* StateMachineEdited; + + /** Graph Editor */ + TSharedPtr GraphEditorView; + + +}; diff --git a/SwordNGun/Source/SwordNGunEditor/Public/States/SNGStateMachineFactory.h b/SwordNGun/Source/SwordNGunEditor/Public/States/SNGStateMachineFactory.h index 8e1cebecf395c20200b34386ce3169ee157796e2..f52547015bd150bab53c1d49d944ab14d663544d 100644 GIT binary patch delta 43 zcmX@d)x7#}V9mhGz{LOn9i|JV delta 203 zcmZqTJjXR*#l~xTjFQ0&;SBx^K@2Voehlsmp+GX8!I2?=!E-YsQzcUBRASO^A11r=*Gfh2}Rk`S=+3WA-d5ONT2VrlJ9K#^g0 zhWY=^%)Rk$J}h&4nL%+iLG6+g diff --git a/SwordNGun/Source/SwordNGunEditor/SwordNGunEditor.cpp b/SwordNGun/Source/SwordNGunEditor/SwordNGunEditor.cpp index b2093bc..5f8c008 100644 --- a/SwordNGun/Source/SwordNGunEditor/SwordNGunEditor.cpp +++ b/SwordNGun/Source/SwordNGunEditor/SwordNGunEditor.cpp @@ -1,14 +1,39 @@ #include "SwordNGunEditor.h" +#include "AssetToolsModule.h" +#include "States/SNGStateMachineTypeActions.h" + IMPLEMENT_GAME_MODULE(FSwordNGunEditor, SwordNGunEditor) void FSwordNGunEditor::StartupModule() { + // register custom types + // add custom category + IAssetTools& AssetTools = FModuleManager::LoadModuleChecked("AssetTools").Get(); + // register custom asset with SwordNGun category + EAssetTypeCategories::Type SNGCategory = + AssetTools.RegisterAdvancedAssetCategory(FName(TEXT("SwordNGun")), FText::FromString("Sword N Gun")); + TSharedPtr Action = MakeShareable(new FSNGStateMachineTypeActions(SNGCategory)); + AssetTools.RegisterAssetTypeActions(Action.ToSharedRef()); + // save for later so it can be unregistered on shutdown + CreatedAssetTypeActions.Add(Action); + ISNGModuleInterface::StartupModule(); } void FSwordNGunEditor::ShutdownModule() { + // unregister all asset types created by this module + if(FModuleManager::Get().IsModuleLoaded("AssetTools")) + { + IAssetTools& AssetTools = FModuleManager::GetModuleChecked("AssetTools").Get(); + for(int32 i = 0; i < CreatedAssetTypeActions.Num(); i++) + { + AssetTools.UnregisterAssetTypeActions(CreatedAssetTypeActions[i].ToSharedRef()); + } + } + CreatedAssetTypeActions.Empty(); + ISNGModuleInterface::ShutdownModule(); } diff --git a/SwordNGun/Source/SwordNGunEditor/SwordNGunEditor.h b/SwordNGun/Source/SwordNGunEditor/SwordNGunEditor.h index 162d1f1..6dbde6f 100644 --- a/SwordNGun/Source/SwordNGunEditor/SwordNGunEditor.h +++ b/SwordNGun/Source/SwordNGunEditor/SwordNGunEditor.h @@ -1,4 +1,5 @@ #pragma once +#include "IAssetTypeActions.h" #include "ISNGModuleInterface.h" class FSwordNGunEditor : public ISNGModuleInterface @@ -19,4 +20,7 @@ public: { return FModuleManager::Get().IsModuleLoaded("SwordNGunEditor"); } + +private: + TArray> CreatedAssetTypeActions; };