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 8dba239..ea6d917 100644 Binary files a/SwordNGun/Source/SwordNGunEditor/Private/States/SNGStateMachineFactory.cpp and b/SwordNGun/Source/SwordNGunEditor/Private/States/SNGStateMachineFactory.cpp differ diff --git a/SwordNGun/Source/SwordNGunEditor/Private/States/SNGStateMachineTypeActions.cpp b/SwordNGun/Source/SwordNGunEditor/Private/States/SNGStateMachineTypeActions.cpp index ee58c67..7240408 100644 Binary files a/SwordNGun/Source/SwordNGunEditor/Private/States/SNGStateMachineTypeActions.cpp and b/SwordNGun/Source/SwordNGunEditor/Private/States/SNGStateMachineTypeActions.cpp differ diff --git a/SwordNGun/Source/SwordNGunEditor/Public/States/IStateMachineEditor.h b/SwordNGun/Source/SwordNGunEditor/Public/States/IStateMachineEditor.h new file mode 100644 index 0000000..9cba31b --- /dev/null +++ b/SwordNGun/Source/SwordNGunEditor/Public/States/IStateMachineEditor.h @@ -0,0 +1,7 @@ +#pragma once + +class IStateMachineEditor : public FAssetEditorToolkit +{ +public: + +}; diff --git a/SwordNGun/Source/SwordNGunEditor/Public/States/SNGStateMachineEditor.h b/SwordNGun/Source/SwordNGunEditor/Public/States/SNGStateMachineEditor.h new file mode 100644 index 0000000..86a8a52 --- /dev/null +++ b/SwordNGun/Source/SwordNGunEditor/Public/States/SNGStateMachineEditor.h @@ -0,0 +1,43 @@ +// Project Sword & Gun Copyright © 2021 Kevin Poretti + +#pragma once + +#include "CoreMinimal.h" +#include "IStateMachineEditor.h" +#include "States/SNGStateMachine.h" +#include "Toolkits/SimpleAssetEditor.h" + +class FSNGStateMachineEditor : public IStateMachineEditor +{ +public: + /** IToolkit Interface */ + virtual void RegisterTabSpawners(const TSharedRef& 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 8e1cebe..f525470 100644 Binary files a/SwordNGun/Source/SwordNGunEditor/Public/States/SNGStateMachineFactory.h and b/SwordNGun/Source/SwordNGunEditor/Public/States/SNGStateMachineFactory.h differ diff --git a/SwordNGun/Source/SwordNGunEditor/Public/States/SNGStateMachineTypeActions.h b/SwordNGun/Source/SwordNGunEditor/Public/States/SNGStateMachineTypeActions.h index 0b5250c..6f5bea9 100644 Binary files a/SwordNGun/Source/SwordNGunEditor/Public/States/SNGStateMachineTypeActions.h and b/SwordNGun/Source/SwordNGunEditor/Public/States/SNGStateMachineTypeActions.h differ 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; };