Skip to content

Commit b2cfe93

Browse files
author
Roberto De Ioris
committed
preliminary support for animation editors
1 parent 61da86d commit b2cfe93

2 files changed

Lines changed: 34 additions & 6 deletions

File tree

Source/UnrealEnginePython/Private/Slate/UEPySlate.cpp

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
#if WITH_EDITOR
55
#include "LevelEditor.h"
66
#include "Editor/UnrealEd/Public/Toolkits/AssetEditorToolkit.h"
7+
#include "Editor/Persona/Public/PersonaModule.h"
8+
#include "Editor/AnimationEditor/Public/IAnimationEditorModule.h"
9+
#include "Editor/StaticMeshEditor/Public/StaticMeshEditorModule.h"
710
#endif
811

912
#include "Runtime/Slate/Public/Framework/Commands/UICommandList.h"
@@ -702,12 +705,37 @@ PyObject *py_unreal_engine_add_menu_extension(PyObject * self, PyObject * args)
702705
PyObject *py_callable;
703706

704707
char *hook = (char *)"WindowLayout";
708+
char *module = (char*)"LevelEditor";
705709

706-
if (!PyArg_ParseTuple(args, "sO|s:add_menu_extension", &command_name, &py_callable, &hook)) {
710+
if (!PyArg_ParseTuple(args, "sO|ss:add_menu_extension", &command_name, &py_callable, &hook, &module)) {
707711
return NULL;
708712
}
709713

710-
FLevelEditorModule &ExtensibleModule = FModuleManager::LoadModuleChecked<FLevelEditorModule>("LevelEditor");
714+
if (!FModuleManager::Get().ModuleExists(UTF8_TO_TCHAR(module)))
715+
return PyErr_Format(PyExc_Exception, "module %s does not exist", module);
716+
717+
// unfortunately we need to manually check for module names :(
718+
IHasMenuExtensibility *menu_extension_interface = nullptr;
719+
720+
if (!strcmp(module, (char *)"LevelEditor")) {
721+
FLevelEditorModule &Module = FModuleManager::LoadModuleChecked<FLevelEditorModule>(module);
722+
menu_extension_interface = (IHasMenuExtensibility *)&Module;
723+
}
724+
else if (!strcmp(module, (char *)"Persona")) {
725+
FPersonaModule &Module = FModuleManager::LoadModuleChecked<FPersonaModule>(module);
726+
menu_extension_interface = (IHasMenuExtensibility *)&Module;
727+
}
728+
else if (!strcmp(module, (char *)"AnimationEditor")) {
729+
IAnimationEditorModule &Module = FModuleManager::LoadModuleChecked<IAnimationEditorModule>(module);
730+
menu_extension_interface = (IHasMenuExtensibility *)&Module;
731+
}
732+
else if (!strcmp(module, (char *)"StaticMeshEditor")) {
733+
IStaticMeshEditorModule &Module = FModuleManager::LoadModuleChecked<IStaticMeshEditorModule>(module);
734+
menu_extension_interface = (IHasMenuExtensibility *)&Module;
735+
}
736+
737+
if (!menu_extension_interface)
738+
return PyErr_Format(PyExc_Exception, "module %s is not supported", module);
711739

712740
if (!PyCallable_Check(py_callable))
713741
return PyErr_Format(PyExc_Exception, "argument is not callable");
@@ -721,10 +749,9 @@ PyObject *py_unreal_engine_add_menu_extension(PyObject * self, PyObject * args)
721749
TSharedRef<FExtender> extender = MakeShareable(new FExtender());
722750
extender->AddMenuExtension(hook, EExtensionHook::After, commands->Get().GetCommands(), FMenuExtensionDelegate::CreateRaw(&commands->Get(), &FPythonSlateCommands::MenuBuilder));
723751

724-
ExtensibleModule.GetMenuExtensibilityManager()->AddExtender(extender);
752+
menu_extension_interface->GetMenuExtensibilityManager()->AddExtender(extender);
725753

726-
Py_INCREF(Py_None);
727-
return Py_None;
754+
Py_RETURN_NONE;
728755
}
729756

730757

Source/UnrealEnginePython/UnrealEnginePython.Build.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ public UnrealEnginePython(TargetInfo Target)
149149
"RawMesh",
150150
"DesktopWidgets",
151151
"EditorWidgets",
152-
"FBX"
152+
"FBX",
153+
"Persona"
153154
});
154155
}
155156

0 commit comments

Comments
 (0)