Skip to content

Commit f58c07a

Browse files
author
Roberto De Ioris
committed
added support for regitering custom settings
1 parent 1c22936 commit f58c07a

File tree

6 files changed

+306
-3
lines changed

6 files changed

+306
-3
lines changed

Source/UnrealEnginePython/Private/UEPyEditor.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include "Editor/LandscapeEditor/Public/LandscapeEditorModule.h"
2626
#include "Editor/LandscapeEditor/Public/LandscapeFileFormatInterface.h"
2727

28+
#include "Developer/Settings/Public/ISettingsModule.h"
29+
2830

2931
PyObject *py_unreal_engine_editor_play_in_viewport(PyObject * self, PyObject * args)
3032
{
@@ -2197,5 +2199,67 @@ PyObject *py_unreal_engine_play_preview_sound(PyObject * self, PyObject * args)
21972199
Py_RETURN_NONE;
21982200
}
21992201

2202+
PyObject *py_unreal_engine_register_settings(PyObject * self, PyObject * args)
2203+
{
2204+
2205+
2206+
char *container_name;
2207+
char *category_name;
2208+
char *section_name;
2209+
char *display_name;
2210+
char *description;
2211+
PyObject *py_uobject;
2212+
2213+
if (!PyArg_ParseTuple(args, "sssssO:register_settings", &container_name, &category_name, &section_name, &display_name, &description, &py_uobject))
2214+
return nullptr;
2215+
2216+
UObject *u_object = ue_py_check_type<UObject>(py_uobject);
2217+
if (!u_object)
2218+
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
2219+
2220+
if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings"))
2221+
{
2222+
TSharedPtr<ISettingsSection> section = SettingsModule->RegisterSettings(UTF8_TO_TCHAR(container_name),
2223+
UTF8_TO_TCHAR(category_name),
2224+
UTF8_TO_TCHAR(section_name),
2225+
FText::FromString(UTF8_TO_TCHAR(display_name)),
2226+
FText::FromString(UTF8_TO_TCHAR(description)),
2227+
u_object);
2228+
2229+
if (!section.IsValid())
2230+
return PyErr_Format(PyExc_Exception, "unable to register settings");
2231+
}
2232+
else
2233+
{
2234+
return PyErr_Format(PyExc_Exception, "unable to find the Settings Module");
2235+
}
2236+
2237+
Py_RETURN_NONE;
2238+
}
2239+
2240+
PyObject *py_unreal_engine_unregister_settings(PyObject * self, PyObject * args)
2241+
{
2242+
2243+
2244+
char *container_name;
2245+
char *category_name;
2246+
char *section_name;
2247+
2248+
if (!PyArg_ParseTuple(args, "sss:unregister_settings", &container_name, &category_name, &section_name))
2249+
return nullptr;
2250+
2251+
if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings"))
2252+
{
2253+
SettingsModule->UnregisterSettings(UTF8_TO_TCHAR(container_name),
2254+
UTF8_TO_TCHAR(category_name),
2255+
UTF8_TO_TCHAR(section_name));
2256+
}
2257+
else
2258+
{
2259+
return PyErr_Format(PyExc_Exception, "unable to find the Settings Module");
2260+
}
2261+
2262+
Py_RETURN_NONE;
2263+
}
22002264
#endif
22012265

Source/UnrealEnginePython/Private/UEPyEditor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,7 @@ PyObject *py_unreal_engine_heightmap_expand(PyObject *, PyObject *);
108108
PyObject *py_unreal_engine_heightmap_import(PyObject *, PyObject *);
109109

110110
PyObject *py_unreal_engine_play_preview_sound(PyObject *, PyObject *);
111+
112+
PyObject *py_unreal_engine_register_settings(PyObject *, PyObject *);
113+
PyObject *py_unreal_engine_unregister_settings(PyObject *, PyObject *);
111114
#endif

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,9 @@ static PyMethodDef unreal_engine_methods[] = {
366366
{ "editor_get_pie_viewport_size", py_unreal_engine_editor_get_pie_viewport_size, METH_VARARGS, "" },
367367

368368
{ "editor_take_high_res_screen_shots", py_unreal_engine_editor_take_high_res_screen_shots, METH_VARARGS, "" },
369+
370+
{ "register_settings", py_unreal_engine_register_settings, METH_VARARGS, "" },
371+
{ "unregister_settings", py_unreal_engine_unregister_settings, METH_VARARGS, "" },
369372
#endif
370373

371374

@@ -424,6 +427,9 @@ static PyMethodDef ue_PyUObject_methods[] = {
424427

425428
{ "get_property", (PyCFunction)py_ue_get_property, METH_VARARGS, "" },
426429
{ "set_property", (PyCFunction)py_ue_set_property, METH_VARARGS, "" },
430+
{ "set_property_flags", (PyCFunction)py_ue_set_property_flags, METH_VARARGS, "" },
431+
{ "add_property_flags", (PyCFunction)py_ue_add_property_flags, METH_VARARGS, "" },
432+
{ "get_property_flags", (PyCFunction)py_ue_get_property_flags, METH_VARARGS, "" },
427433
{ "properties", (PyCFunction)py_ue_properties, METH_VARARGS, "" },
428434
{ "get_property_class", (PyCFunction)py_ue_get_property_class, METH_VARARGS, "" },
429435
{ "has_property", (PyCFunction)py_ue_has_property, METH_VARARGS, "" },
@@ -606,6 +612,13 @@ static PyMethodDef ue_PyUObject_methods[] = {
606612

607613
{ "get_class", (PyCFunction)py_ue_get_class, METH_VARARGS, "" },
608614
{ "class_generated_by", (PyCFunction)py_ue_class_generated_by, METH_VARARGS, "" },
615+
{ "class_get_flags", (PyCFunction)py_ue_class_get_flags, METH_VARARGS, "" },
616+
{ "class_set_flags", (PyCFunction)py_ue_class_set_flags, METH_VARARGS, "" },
617+
618+
#if WITH_EDITOR
619+
{ "class_get_config_name", (PyCFunction)py_ue_class_get_config_name, METH_VARARGS, "" },
620+
{ "class_set_config_name", (PyCFunction)py_ue_class_set_config_name, METH_VARARGS, "" },
621+
#endif
609622
{ "get_actor_components", (PyCFunction)py_ue_actor_components, METH_VARARGS, "" },
610623
{ "components", (PyCFunction)py_ue_actor_components, METH_VARARGS, "" },
611624
{ "get_components", (PyCFunction)py_ue_actor_components, METH_VARARGS, "" },
@@ -1921,6 +1934,19 @@ void unreal_engine_init_py_module()
19211934
PyDict_SetItemString(unreal_engine_dict, "IE_RELEASED", PyLong_FromLong(EInputEvent::IE_Released));
19221935
PyDict_SetItemString(unreal_engine_dict, "IE_REPEAT", PyLong_FromLong(EInputEvent::IE_Repeat));
19231936

1937+
// Classes
1938+
PyDict_SetItemString(unreal_engine_dict, "CLASS_CONFIG", PyLong_FromUnsignedLongLong((uint64)CLASS_Config));
1939+
PyDict_SetItemString(unreal_engine_dict, "CLASS_DEFAULT_CONFIG", PyLong_FromUnsignedLongLong((uint64)CLASS_DefaultConfig));
1940+
PyDict_SetItemString(unreal_engine_dict, "CLASS_ABSTRACT", PyLong_FromUnsignedLongLong((uint64)CLASS_Abstract));
1941+
PyDict_SetItemString(unreal_engine_dict, "CLASS_INTERFACE", PyLong_FromUnsignedLongLong((uint64)CLASS_Interface));
1942+
1943+
// Properties
1944+
PyDict_SetItemString(unreal_engine_dict, "CPF_CONFIG", PyLong_FromUnsignedLongLong((uint64)CPF_Config));
1945+
PyDict_SetItemString(unreal_engine_dict, "CPF_GLOBAL_CONFIG", PyLong_FromUnsignedLongLong((uint64)CPF_GlobalConfig));
1946+
PyDict_SetItemString(unreal_engine_dict, "CPF_EXPOSE_ON_SPAWN", PyLong_FromUnsignedLongLong((uint64)CPF_ExposeOnSpawn));
1947+
PyDict_SetItemString(unreal_engine_dict, "CPF_NET", PyLong_FromUnsignedLongLong((uint64)CPF_Net));
1948+
PyDict_SetItemString(unreal_engine_dict, "CPF_REP_NOTIFY", PyLong_FromUnsignedLongLong((uint64)CPF_RepNotify));
1949+
19241950
#if WITH_EDITOR
19251951
PyDict_SetItemString(unreal_engine_dict, "APP_MSG_TYPE_OK", PyLong_FromLong(EAppMsgType::Ok));
19261952
PyDict_SetItemString(unreal_engine_dict, "APP_MSG_TYPE_YES_NO", PyLong_FromLong(EAppMsgType::YesNo));
@@ -1997,7 +2023,7 @@ void unreal_engine_py_log_error()
19972023
if (zero)
19982024
{
19992025
msg = PyBytes_AsString(zero);
2000-
}
2026+
}
20012027
#else
20022028
msg = PyString_AsString(PyObject_Str(value));
20032029
#endif
@@ -2926,10 +2952,10 @@ PyObject *py_ue_ufunction_call(UFunction *u_function, UObject *u_obj, PyObject *
29262952
prop->ImportText(*default_key_value, prop->ContainerPtrToValuePtr<uint8>(buffer), PPF_None, NULL);
29272953
#else
29282954
prop->ImportText(*default_key_value, prop->ContainerPtrToValuePtr<uint8>(buffer), PPF_Localized, NULL);
2929-
#endif
2930-
}
29312955
#endif
29322956
}
2957+
#endif
2958+
}
29332959

29342960
Py_ssize_t tuple_len = PyTuple_Size(args);
29352961

Source/UnrealEnginePython/Private/UObject/UEPyObject.cpp

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,73 @@ PyObject *py_ue_class_generated_by(ue_PyUObject * self, PyObject * args)
4141
return (PyObject *)ret;
4242
}
4343

44+
PyObject *py_ue_class_get_flags(ue_PyUObject * self, PyObject * args)
45+
{
46+
47+
ue_py_check(self);
48+
49+
UClass *u_class = ue_py_check_type<UClass>(self);
50+
if (!u_class)
51+
return PyErr_Format(PyExc_Exception, "uobject is a not a UClass");
52+
53+
return PyLong_FromUnsignedLongLong((uint64)u_class->GetClassFlags());
54+
}
55+
56+
PyObject *py_ue_class_set_flags(ue_PyUObject * self, PyObject * args)
57+
{
58+
59+
ue_py_check(self);
60+
61+
uint64 flags;
62+
if (!PyArg_ParseTuple(args, "K:class_set_flags", &flags))
63+
{
64+
return nullptr;
65+
}
66+
67+
UClass *u_class = ue_py_check_type<UClass>(self);
68+
if (!u_class)
69+
return PyErr_Format(PyExc_Exception, "uobject is a not a UClass");
70+
71+
u_class->ClassFlags = (EClassFlags)flags;
72+
73+
Py_RETURN_NONE;
74+
}
75+
76+
#if WITH_EDITOR
77+
PyObject *py_ue_class_set_config_name(ue_PyUObject * self, PyObject * args)
78+
{
79+
80+
ue_py_check(self);
81+
82+
char *config_name;
83+
if (!PyArg_ParseTuple(args, "s:class_set_config_name", &config_name))
84+
{
85+
return nullptr;
86+
}
87+
88+
UClass *u_class = ue_py_check_type<UClass>(self);
89+
if (!u_class)
90+
return PyErr_Format(PyExc_Exception, "uobject is a not a UClass");
91+
92+
u_class->ClassConfigName = UTF8_TO_TCHAR(config_name);
93+
94+
Py_RETURN_NONE;
95+
}
96+
97+
PyObject *py_ue_class_get_config_name(ue_PyUObject * self, PyObject * args)
98+
{
99+
100+
ue_py_check(self);
101+
102+
103+
UClass *u_class = ue_py_check_type<UClass>(self);
104+
if (!u_class)
105+
return PyErr_Format(PyExc_Exception, "uobject is a not a UClass");
106+
107+
return PyUnicode_FromString(TCHAR_TO_UTF8(*u_class->ClassConfigName.ToString()));
108+
}
109+
#endif
110+
44111
PyObject *py_ue_get_property_struct(ue_PyUObject * self, PyObject * args)
45112
{
46113

@@ -573,6 +640,99 @@ PyObject *py_ue_set_property(ue_PyUObject *self, PyObject * args)
573640

574641
}
575642

643+
PyObject *py_ue_set_property_flags(ue_PyUObject *self, PyObject * args)
644+
{
645+
646+
ue_py_check(self);
647+
648+
char *property_name;
649+
uint64 flags;
650+
if (!PyArg_ParseTuple(args, "sK:set_property_flags", &property_name, &flags))
651+
{
652+
return NULL;
653+
}
654+
655+
UStruct *u_struct = nullptr;
656+
657+
if (self->ue_object->IsA<UStruct>())
658+
{
659+
u_struct = (UStruct *)self->ue_object;
660+
}
661+
else
662+
{
663+
u_struct = (UStruct *)self->ue_object->GetClass();
664+
}
665+
666+
UProperty *u_property = u_struct->FindPropertyByName(FName(UTF8_TO_TCHAR(property_name)));
667+
if (!u_property)
668+
return PyErr_Format(PyExc_Exception, "unable to find property %s", property_name);
669+
670+
671+
u_property->SetPropertyFlags(flags);
672+
Py_RETURN_NONE;
673+
}
674+
675+
PyObject *py_ue_add_property_flags(ue_PyUObject *self, PyObject * args)
676+
{
677+
678+
ue_py_check(self);
679+
680+
char *property_name;
681+
uint64 flags;
682+
if (!PyArg_ParseTuple(args, "sK:add_property_flags", &property_name, &flags))
683+
{
684+
return NULL;
685+
}
686+
687+
UStruct *u_struct = nullptr;
688+
689+
if (self->ue_object->IsA<UStruct>())
690+
{
691+
u_struct = (UStruct *)self->ue_object;
692+
}
693+
else
694+
{
695+
u_struct = (UStruct *)self->ue_object->GetClass();
696+
}
697+
698+
UProperty *u_property = u_struct->FindPropertyByName(FName(UTF8_TO_TCHAR(property_name)));
699+
if (!u_property)
700+
return PyErr_Format(PyExc_Exception, "unable to find property %s", property_name);
701+
702+
703+
u_property->SetPropertyFlags(u_property->GetPropertyFlags() | flags);
704+
Py_RETURN_NONE;
705+
}
706+
707+
PyObject *py_ue_get_property_flags(ue_PyUObject *self, PyObject * args)
708+
{
709+
710+
ue_py_check(self);
711+
712+
char *property_name;
713+
if (!PyArg_ParseTuple(args, "s:get_property_flags", &property_name))
714+
{
715+
return NULL;
716+
}
717+
718+
UStruct *u_struct = nullptr;
719+
720+
if (self->ue_object->IsA<UStruct>())
721+
{
722+
u_struct = (UStruct *)self->ue_object;
723+
}
724+
else
725+
{
726+
u_struct = (UStruct *)self->ue_object->GetClass();
727+
}
728+
729+
UProperty *u_property = u_struct->FindPropertyByName(FName(UTF8_TO_TCHAR(property_name)));
730+
if (!u_property)
731+
return PyErr_Format(PyExc_Exception, "unable to find property %s", property_name);
732+
733+
return PyLong_FromUnsignedLong(u_property->GetPropertyFlags());
734+
}
735+
576736
PyObject *py_ue_enum_values(ue_PyUObject *self, PyObject * args)
577737
{
578738
ue_py_check(self);

Source/UnrealEnginePython/Private/UObject/UEPyObject.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ PyObject *py_ue_set_name(ue_PyUObject *, PyObject * args);
1616
PyObject *py_ue_get_full_name(ue_PyUObject *, PyObject *);
1717
PyObject *py_ue_get_path_name(ue_PyUObject *, PyObject *);
1818
PyObject *py_ue_set_property(ue_PyUObject *, PyObject *);
19+
PyObject *py_ue_set_property_flags(ue_PyUObject *, PyObject *);
20+
PyObject *py_ue_add_property_flags(ue_PyUObject *, PyObject *);
21+
PyObject *py_ue_get_property_flags(ue_PyUObject *, PyObject *);
1922
PyObject *py_ue_get_property_struct(ue_PyUObject *, PyObject *);
2023
PyObject *py_ue_properties(ue_PyUObject *, PyObject *);
2124
PyObject *py_ue_call(ue_PyUObject *, PyObject *);
@@ -63,8 +66,13 @@ PyObject *py_ue_modify(ue_PyUObject *, PyObject *);
6366

6467
PyObject *py_ue_class_generated_by(ue_PyUObject *, PyObject *);
6568

69+
PyObject *py_ue_class_get_flags(ue_PyUObject *, PyObject *);
70+
PyObject *py_ue_class_set_flags(ue_PyUObject *, PyObject *);
71+
6672

6773
#if WITH_EDITOR
74+
PyObject *py_ue_class_get_config_name(ue_PyUObject *, PyObject *);
75+
PyObject *py_ue_class_set_config_name(ue_PyUObject *, PyObject *);
6876
PyObject *py_ue_save_package(ue_PyUObject *, PyObject *);
6977
PyObject *py_ue_duplicate(ue_PyUObject *, PyObject *);
7078
PyObject *py_ue_asset_can_reimport(ue_PyUObject *, PyObject *);

0 commit comments

Comments
 (0)