239 lines
7.1 KiB
C++
239 lines
7.1 KiB
C++
/**
|
|
* @file
|
|
*
|
|
* @author Mamadou Babaei <mamadou@senseglove.com>
|
|
*
|
|
* @section LICENSE
|
|
*
|
|
* (The MIT License)
|
|
*
|
|
* Copyright (c) 2020 - 2024 SenseGlove
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
* copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
* SOFTWARE.
|
|
*
|
|
* @section DESCRIPTION
|
|
*
|
|
*
|
|
*/
|
|
|
|
|
|
#include "SGEditor/SGSkeletonEditor.h"
|
|
|
|
#include "Framework/MultiBox/MultiBoxExtender.h"
|
|
#include "ISkeletonEditor.h"
|
|
#include "ISkeletonEditorModule.h"
|
|
#include "Modules/ModuleManager.h"
|
|
|
|
#include "SGEditor/SGAssetTypeActions_Skeleton.h"
|
|
#include "SGEditor/SGPluginStyle.h"
|
|
#include "SGEditor/SGSkeletonEditorCommands.h"
|
|
|
|
#define LOCTEXT_NAMESPACE "SkeletonEditor"
|
|
|
|
struct FSGSkeletonEditor::FImpl
|
|
{
|
|
/************************
|
|
* Member variables
|
|
************************/
|
|
|
|
TSharedPtr<FSGAssetTypeActions_Skeleton> AssetActions;
|
|
TSharedPtr<FSGSkeletonEditorCommands> EditorCommands;
|
|
TSharedPtr<FExtender> MenuExtender;
|
|
TSharedPtr<FExtender> ToolbarExtender;
|
|
|
|
/************************
|
|
* Owner object
|
|
************************/
|
|
|
|
FSGSkeletonEditor* Owner;
|
|
|
|
/************************
|
|
* Constructor / Destructor
|
|
************************/
|
|
|
|
explicit FImpl(FSGSkeletonEditor* InOwner);
|
|
~FImpl();
|
|
|
|
/************************
|
|
* Default copy constructor & copy assignment operator
|
|
************************/
|
|
|
|
FImpl(const FImpl& Rhs) = default;
|
|
FImpl& operator=(const FImpl& Rhs) = default;
|
|
};
|
|
|
|
TSharedRef<FSGSkeletonEditor> FSGSkeletonEditor::GetInstance()
|
|
{
|
|
static TSharedPtr<FSGSkeletonEditor> Instance{MakeShared<FSGSkeletonEditor>()};
|
|
return Instance.ToSharedRef();
|
|
}
|
|
|
|
FSGSkeletonEditor::FSGSkeletonEditor()
|
|
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
|
|
{
|
|
}
|
|
|
|
FSGSkeletonEditor::~FSGSkeletonEditor() = default;
|
|
|
|
void FSGSkeletonEditor::Initialize() const
|
|
{
|
|
//RegisterAssetTypeActions();
|
|
RegisterCommands();
|
|
ExtendMenu();
|
|
ExtendToolbar();
|
|
}
|
|
|
|
void FSGSkeletonEditor::Deinitialize() const
|
|
{
|
|
UnregisterCommands();
|
|
}
|
|
|
|
void FSGSkeletonEditor::RegisterAssetTypeActions() const
|
|
{
|
|
if (Pimpl->AssetActions.IsValid())
|
|
{
|
|
Pimpl->AssetActions.Reset();
|
|
}
|
|
Pimpl->AssetActions = MakeShared<FSGAssetTypeActions_Skeleton>();
|
|
|
|
IAssetTools& AssetTools = FModuleManager::LoadModuleChecked<FAssetToolsModule>("AssetTools").Get();
|
|
|
|
AssetTools.RegisterAssetTypeActions(Pimpl->AssetActions.ToSharedRef());
|
|
}
|
|
|
|
void FSGSkeletonEditor::RegisterCommands() const
|
|
{
|
|
if (Pimpl->EditorCommands.IsValid())
|
|
{
|
|
Pimpl->EditorCommands.Reset();
|
|
}
|
|
Pimpl->EditorCommands = MakeShared<FSGSkeletonEditorCommands>();
|
|
Pimpl->EditorCommands->RegisterCommands();
|
|
}
|
|
|
|
void FSGSkeletonEditor::UnregisterCommands() const
|
|
{
|
|
if (!Pimpl->EditorCommands.IsValid())
|
|
{
|
|
return;
|
|
}
|
|
Pimpl->EditorCommands->Unregister();
|
|
}
|
|
|
|
void FSGSkeletonEditor::ExtendMenu() const
|
|
{
|
|
if (Pimpl->MenuExtender.IsValid())
|
|
{
|
|
Pimpl->MenuExtender.Reset();
|
|
}
|
|
Pimpl->MenuExtender = MakeShared<FExtender>();
|
|
|
|
ISkeletonEditorModule& SkeletonEditorModule{
|
|
FModuleManager::LoadModuleChecked<ISkeletonEditorModule>("SkeletonEditor")
|
|
};
|
|
const TSharedPtr<FExtensibilityManager> ExtensibilityManager{
|
|
SkeletonEditorModule.GetMenuExtensibilityManager()
|
|
};
|
|
|
|
if (!ensureAlwaysMsgf(ExtensibilityManager.IsValid(), TEXT("Invalid ExtensibilityManager!")))
|
|
{
|
|
return;
|
|
}
|
|
|
|
Pimpl->MenuExtender->AddMenuExtension(
|
|
FName{TEXT("AssetEditorActions")},
|
|
EExtensionHook::After,
|
|
Pimpl->EditorCommands->CommandList,
|
|
FMenuExtensionDelegate::CreateLambda([&](FMenuBuilder MenuBuilder)-> void
|
|
{
|
|
MenuBuilder.BeginSection(FName{TEXT("SenseGlove")}, LOCTEXT("SenseGloveHeading", "SenseGlove"));
|
|
{
|
|
MenuBuilder.AddMenuEntry(
|
|
Pimpl->EditorCommands->AddSenseGloveSockets,
|
|
NAME_None,
|
|
LOCTEXT("AddSenseGloveSocketsLabel", "Add SenseGlove Sockets"),
|
|
LOCTEXT(
|
|
"AddSenseGloveSocketsToolTip", "Adds and sets up the SenseGlove grab and touch sockets"),
|
|
FSGPluginStyle::GetStyleSetIcon(),
|
|
NAME_None);
|
|
}
|
|
MenuBuilder.EndSection();
|
|
}));
|
|
|
|
ExtensibilityManager->AddExtender(Pimpl->MenuExtender);
|
|
}
|
|
|
|
void FSGSkeletonEditor::ExtendToolbar() const
|
|
{
|
|
if (Pimpl->ToolbarExtender.IsValid())
|
|
{
|
|
Pimpl->ToolbarExtender.Reset();
|
|
}
|
|
Pimpl->ToolbarExtender = MakeShared<FExtender>();
|
|
|
|
ISkeletonEditorModule& SkeletonEditorModule{
|
|
FModuleManager::LoadModuleChecked<ISkeletonEditorModule>("SkeletonEditor")
|
|
};
|
|
const TSharedPtr<FExtensibilityManager> ExtensibilityManager{
|
|
SkeletonEditorModule.GetToolBarExtensibilityManager()
|
|
};
|
|
|
|
if (!ensureAlwaysMsgf(ExtensibilityManager.IsValid(), TEXT("Invalid ExtensibilityManager!")))
|
|
{
|
|
return;
|
|
}
|
|
|
|
Pimpl->ToolbarExtender->AddToolBarExtension(
|
|
FName{TEXT("Skeleton")},
|
|
EExtensionHook::After,
|
|
Pimpl->EditorCommands->CommandList,
|
|
FToolBarExtensionDelegate::CreateLambda([&](FToolBarBuilder& ToolbarBuilder)-> void
|
|
{
|
|
ToolbarBuilder.BeginSection(FName{TEXT("SenseGlove")});
|
|
{
|
|
ToolbarBuilder.AddToolBarButton(
|
|
Pimpl->EditorCommands->AddSenseGloveSockets,
|
|
NAME_None,
|
|
LOCTEXT("AddSenseGloveSocketsLabel", "Add SenseGlove Sockets"),
|
|
LOCTEXT(
|
|
"AddSenseGloveSocketsToolTip", "Adds and sets up the SenseGlove grab and touch sockets"),
|
|
FSGPluginStyle::GetStyleSetIcon(),
|
|
NAME_None,
|
|
FNewMenuDelegate{}
|
|
);
|
|
}
|
|
ToolbarBuilder.EndSection();
|
|
}));
|
|
|
|
ExtensibilityManager->AddExtender(Pimpl->ToolbarExtender);
|
|
}
|
|
|
|
FSGSkeletonEditor::FImpl::FImpl(FSGSkeletonEditor* InOwner)
|
|
: Owner(InOwner)
|
|
{
|
|
}
|
|
|
|
FSGSkeletonEditor::FImpl::~FImpl() = default;
|
|
|
|
void FSGSkeletonEditor::FImplDeleter::operator()(const FImpl* P) const
|
|
{
|
|
delete P;
|
|
}
|
|
|
|
#undef LOCTEXT_NAMESPACE |