Files
Plugin/Source/SenseGloveEditor/Private/SGEditor/SGSocketsEditor.cpp
T

292 lines
9.2 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/SGSocketsEditor.h"
#include "Framework/MultiBox/MultiBoxExtender.h"
#include "ISkeletonEditorModule.h"
#include "Modules/ModuleManager.h"
// #include "SGEditor/SGAssetTypeActions_Skeleton.h"
#include "SGEditor/SGPluginStyle.h"
#include "SGEditor/SGSocketsEditorCommands.h"
#define LOCTEXT_NAMESPACE "SocketsEditor"
struct FSGSocketsEditor::FImpl
{
/************************
* Member variables
************************/
// TSharedPtr<FSGAssetTypeActions_Skeleton> AssetActions;
TSharedPtr<FSGSocketsEditorCommands> EditorCommands;
TSharedPtr<FExtender> MenuExtender;
TSharedPtr<FExtender> ToolbarExtender;
/************************
* Owner object
************************/
FSGSocketsEditor* Owner;
/************************
* Constructor / Destructor
************************/
explicit FImpl(FSGSocketsEditor* InOwner);
~FImpl();
/************************
* Default copy constructor & copy assignment operator
************************/
FImpl(const FImpl& Rhs) = default;
FImpl& operator=(const FImpl& Rhs) = default;
};
TSharedRef<FSGSocketsEditor> FSGSocketsEditor::GetInstance()
{
static TSharedPtr<FSGSocketsEditor> Instance{MakeShared<FSGSocketsEditor>()};
return Instance.ToSharedRef();
}
FSGSocketsEditor::FSGSocketsEditor()
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
{
}
FSGSocketsEditor::~FSGSocketsEditor() = default;
void FSGSocketsEditor::Initialize() const
{
//RegisterAssetTypeActions();
RegisterCommands();
ExtendMenu();
ExtendToolbar();
}
void FSGSocketsEditor::Deinitialize() const
{
UnregisterCommands();
}
void FSGSocketsEditor::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 FSGSocketsEditor::RegisterCommands() const
{
if (Pimpl->EditorCommands.IsValid())
{
Pimpl->EditorCommands.Reset();
}
Pimpl->EditorCommands = MakeShared<FSGSocketsEditorCommands>();
Pimpl->EditorCommands->RegisterCommands();
}
void FSGSocketsEditor::UnregisterCommands() const
{
if (!Pimpl->EditorCommands.IsValid())
{
return;
}
Pimpl->EditorCommands->Unregister();
}
void FSGSocketsEditor::ExtendMenu() const
{
if (Pimpl->MenuExtender.IsValid())
{
Pimpl->MenuExtender.Reset();
}
Pimpl->MenuExtender = MakeShared<FExtender>();
ISkeletonEditorModule& SkeletalMeshEditorModule{
FModuleManager::LoadModuleChecked<ISkeletonEditorModule>("SkeletalMeshEditor")
};
ISkeletonEditorModule& SkeletonEditorModule{
FModuleManager::LoadModuleChecked<ISkeletonEditorModule>("SkeletonEditor")
};
const TSharedPtr<FExtensibilityManager> SkeletalMeshExtensibilityManager{
SkeletalMeshEditorModule.GetMenuExtensibilityManager()
};
const TSharedPtr<FExtensibilityManager> SkeletonExtensibilityManager{
SkeletonEditorModule.GetMenuExtensibilityManager()
};
if (!ensureAlwaysMsgf(SkeletonExtensibilityManager.IsValid(),
TEXT("Invalid SkeletonExtensibilityManager!")))
{
return;
}
if (!ensureAlwaysMsgf(SkeletalMeshExtensibilityManager.IsValid(),
TEXT("Invalid SkeletalMeshExtensibilityManager!")))
{
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->SenseGloveAddSockets,
NAME_None,
LOCTEXT("SenseGloveAddSocketsLabel", "Add SenseGlove Sockets"),
LOCTEXT(
"SenseGloveAddSocketsToolTip", "Adds and sets up the SenseGlove grab and touch sockets"),
FSGPluginStyle::GetStyleSetIcon(),
NAME_None);
MenuBuilder.AddMenuEntry(
Pimpl->EditorCommands->SenseGloveClearExistingSockets,
NAME_None,
LOCTEXT("SenseGloveClearExistingSocketsLabel", "Clear Existing Sockets"),
LOCTEXT(
"SenseGloveClearSocketsToolTip", "Clears all sockets; SenseGlove or otherwise"),
FSlateIcon{FSGPluginStyle::GetStyleSetIcon()},
NAME_None);
}
MenuBuilder.EndSection();
}));
SkeletalMeshExtensibilityManager->AddExtender(Pimpl->MenuExtender);
SkeletonExtensibilityManager->AddExtender(Pimpl->MenuExtender);
}
void FSGSocketsEditor::ExtendToolbar() const
{
if (Pimpl->ToolbarExtender.IsValid())
{
Pimpl->ToolbarExtender.Reset();
}
Pimpl->ToolbarExtender = MakeShared<FExtender>();
ISkeletonEditorModule& SkeletalMeshEditorModule{
FModuleManager::LoadModuleChecked<ISkeletonEditorModule>("SkeletalMeshEditor")
};
ISkeletonEditorModule& SkeletonEditorModule{
FModuleManager::LoadModuleChecked<ISkeletonEditorModule>("SkeletonEditor")
};
const TSharedPtr<FExtensibilityManager> SkeletalMeshExtensibilityManager{
SkeletalMeshEditorModule.GetToolBarExtensibilityManager()
};
const TSharedPtr<FExtensibilityManager> SkeletonExtensibilityManager{
SkeletonEditorModule.GetToolBarExtensibilityManager()
};
if (!ensureAlwaysMsgf(SkeletonExtensibilityManager.IsValid(),
TEXT("Invalid SkeletonExtensibilityManager!")))
{
return;
}
if (!ensureAlwaysMsgf(SkeletalMeshExtensibilityManager.IsValid(),
TEXT("Invalid SkeletalMeshExtensibilityManager!")))
{
return;
}
Pimpl->ToolbarExtender->AddToolBarExtension(
FName{TEXT("SkeletalMesh")},
EExtensionHook::After,
Pimpl->EditorCommands->CommandList,
FToolBarExtensionDelegate::CreateLambda([&](FToolBarBuilder& ToolbarBuilder)-> void
{
ToolbarBuilder.BeginSection(FName{TEXT("SenseGlove")});
{
ToolbarBuilder.AddToolBarButton(
Pimpl->EditorCommands->SenseGloveAddSockets,
NAME_None,
LOCTEXT("SenseGloveAddSocketsLabel", "Add SenseGlove Sockets"),
LOCTEXT(
"SenseGloveAddSocketsToolTip", "Adds and sets up the SenseGlove grab and touch sockets"),
FSGPluginStyle::GetStyleSetIcon(),
NAME_None,
FNewMenuDelegate{}
);
ToolbarBuilder.AddToolBarButton(
Pimpl->EditorCommands->SenseGloveClearExistingSockets,
NAME_None,
LOCTEXT("SenseGloveClearExistingSocketsLabel", "Clear Existing Sockets"),
LOCTEXT(
"SenseGloveClearSocketsToolTip", "Clears all sockets; SenseGlove or otherwise"),
FSGPluginStyle::GetStyleSetIcon(),
NAME_None,
FNewMenuDelegate{}
);
}
ToolbarBuilder.EndSection();
}));
SkeletalMeshExtensibilityManager->AddExtender(Pimpl->ToolbarExtender);
SkeletonExtensibilityManager->AddExtender(Pimpl->ToolbarExtender);
}
FSGSocketsEditor::FImpl::FImpl(FSGSocketsEditor* InOwner)
: Owner(InOwner)
{
}
FSGSocketsEditor::FImpl::~FImpl() = default;
void FSGSocketsEditor::FImplDeleter::operator()(const FImpl* P) const
{
delete P;
}
#undef LOCTEXT_NAMESPACE