Skip to content

Commit 1475d32

Browse files
authored
Merge pull request getnamo#5 from 20tab/master
sync to master
2 parents 81b5571 + 7965e29 commit 1475d32

File tree

14 files changed

+454
-51
lines changed

14 files changed

+454
-51
lines changed

Source/UnrealEnginePython/Private/CollectionManager/UEPyICollectionManager.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ static PyObject *py_ue_icollection_manager_get_child_collection_names(PyObject *
5959
ICollectionManager &CollectionManager = FCollectionManagerModule::GetModule().Get();
6060
TArray<FName> names;
6161
CollectionManager.GetChildCollectionNames(FName(UTF8_TO_TCHAR(name)), (ECollectionShareType::Type)type, (ECollectionShareType::Type)child_type, names);
62-
for (FName name : names) {
63-
PyList_Append(py_list, PyUnicode_FromString(TCHAR_TO_UTF8(*name.ToString())));
62+
for (FName cname : names) {
63+
PyList_Append(py_list, PyUnicode_FromString(TCHAR_TO_UTF8(*cname.ToString())));
6464
}
6565
return py_list;
6666
}
@@ -463,7 +463,7 @@ static PyMethodDef ue_PyICollectionManager_methods[] = {
463463
{ "rename_collection", (PyCFunction)py_ue_icollection_manager_rename_collection, METH_VARARGS | METH_CLASS, "" },
464464
{ "add_to_collection", (PyCFunction)py_ue_icollection_manager_add_to_collection, METH_VARARGS | METH_CLASS, "" },
465465
{ "collection_exists", (PyCFunction)py_ue_icollection_manager_collection_exists, METH_VARARGS | METH_CLASS, "" },
466-
{ "create_unique_connection_name", (PyCFunction)py_ue_icollection_manager_create_unique_collection_name, METH_VARARGS | METH_CLASS, "" },
466+
{ "create_unique_collection_name", (PyCFunction)py_ue_icollection_manager_create_unique_collection_name, METH_VARARGS | METH_CLASS, "" },
467467
{ "destroy_collection", (PyCFunction)py_ue_icollection_manager_destroy_collection, METH_VARARGS | METH_CLASS, "" },
468468
{ "empty_collection", (PyCFunction)py_ue_icollection_manager_empty_collection, METH_VARARGS | METH_CLASS, "" },
469469
{ "get_dynamic_query_text", (PyCFunction)py_ue_icollection_manager_get_dynamic_query_text, METH_VARARGS | METH_CLASS, "" },

Source/UnrealEnginePython/Private/Slate/UEPySPythonWidget.h

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "UEPyFPaintContext.h"
88
#include "UEPyFCharacterEvent.h"
99
#include "UEPyFKeyEvent.h"
10+
#include "UEPyFPointerEvent.h"
1011

1112
extern PyTypeObject ue_PySPythonWidgetType;
1213

@@ -88,6 +89,127 @@ class SPythonWidget : public SCompoundWidget
8889
return FReply::Handled();
8990
}
9091

92+
virtual FReply OnMouseMove(const FGeometry & MyGeometry, const FPointerEvent & MyEvent) override
93+
{
94+
FScopePythonGIL gil;
95+
96+
if (!PyObject_HasAttrString(self, (char *)"on_mouse_move"))
97+
return FReply::Unhandled();
98+
99+
PyObject *py_callable_on_mouse_move = PyObject_GetAttrString(self, (char *)"on_mouse_move");
100+
if (!PyCallable_Check(py_callable_on_mouse_move))
101+
{
102+
UE_LOG(LogPython, Error, TEXT("on_mouse_move is not a callable"));
103+
return FReply::Unhandled();
104+
}
105+
106+
PyObject *ret = PyObject_CallFunction(py_callable_on_mouse_move, (char *)"OO", py_ue_new_fgeometry(MyGeometry), py_ue_new_fpointer_event(MyEvent));
107+
if (!ret)
108+
{
109+
unreal_engine_py_log_error();
110+
return FReply::Unhandled();
111+
}
112+
113+
if (ret == Py_False)
114+
{
115+
Py_DECREF(ret);
116+
return FReply::Unhandled();
117+
}
118+
Py_DECREF(ret);
119+
return FReply::Handled();
120+
}
121+
122+
virtual FReply OnMouseWheel(const FGeometry & MyGeometry, const FPointerEvent & MyEvent) override
123+
{
124+
FScopePythonGIL gil;
125+
126+
if (!PyObject_HasAttrString(self, (char *)"on_mouse_wheel"))
127+
return FReply::Unhandled();
128+
129+
PyObject *py_callable_on_mouse_wheel = PyObject_GetAttrString(self, (char *)"on_mouse_wheel");
130+
if (!PyCallable_Check(py_callable_on_mouse_wheel))
131+
{
132+
UE_LOG(LogPython, Error, TEXT("on_mouse_wheel is not a callable"));
133+
return FReply::Unhandled();
134+
}
135+
136+
PyObject *ret = PyObject_CallFunction(py_callable_on_mouse_wheel, (char *)"OO", py_ue_new_fgeometry(MyGeometry), py_ue_new_fpointer_event(MyEvent));
137+
if (!ret)
138+
{
139+
unreal_engine_py_log_error();
140+
return FReply::Unhandled();
141+
}
142+
143+
if (ret == Py_False)
144+
{
145+
Py_DECREF(ret);
146+
return FReply::Unhandled();
147+
}
148+
Py_DECREF(ret);
149+
return FReply::Handled();
150+
}
151+
152+
virtual FReply OnMouseButtonDown(const FGeometry & MyGeometry, const FPointerEvent & MyEvent) override
153+
{
154+
FScopePythonGIL gil;
155+
156+
if (!PyObject_HasAttrString(self, (char *)"on_mouse_button_down"))
157+
return FReply::Unhandled();
158+
159+
PyObject *py_callable_on_mouse_button_down = PyObject_GetAttrString(self, (char *)"on_mouse_button_down");
160+
if (!PyCallable_Check(py_callable_on_mouse_button_down))
161+
{
162+
UE_LOG(LogPython, Error, TEXT("on_mouse_button_down is not a callable"));
163+
return FReply::Unhandled();
164+
}
165+
166+
PyObject *ret = PyObject_CallFunction(py_callable_on_mouse_button_down, (char *)"OO", py_ue_new_fgeometry(MyGeometry), py_ue_new_fpointer_event(MyEvent));
167+
if (!ret)
168+
{
169+
unreal_engine_py_log_error();
170+
return FReply::Unhandled();
171+
}
172+
173+
if (ret == Py_False)
174+
{
175+
Py_DECREF(ret);
176+
return FReply::Unhandled();
177+
}
178+
Py_DECREF(ret);
179+
return FReply::Handled();
180+
}
181+
182+
virtual FReply OnMouseButtonUp(const FGeometry & MyGeometry, const FPointerEvent & MyEvent) override
183+
{
184+
FScopePythonGIL gil;
185+
186+
if (!PyObject_HasAttrString(self, (char *)"on_mouse_button_up"))
187+
return FReply::Unhandled();
188+
189+
PyObject *py_callable_on_mouse_button_up = PyObject_GetAttrString(self, (char *)"on_mouse_button_up");
190+
if (!PyCallable_Check(py_callable_on_mouse_button_up))
191+
{
192+
UE_LOG(LogPython, Error, TEXT("on_mouse_button_up is not a callable"));
193+
return FReply::Unhandled();
194+
}
195+
196+
PyObject *ret = PyObject_CallFunction(py_callable_on_mouse_button_up, (char *)"OO", py_ue_new_fgeometry(MyGeometry), py_ue_new_fpointer_event(MyEvent));
197+
if (!ret)
198+
{
199+
unreal_engine_py_log_error();
200+
return FReply::Unhandled();
201+
}
202+
203+
if (ret == Py_False)
204+
{
205+
Py_DECREF(ret);
206+
return FReply::Unhandled();
207+
}
208+
Py_DECREF(ret);
209+
return FReply::Handled();
210+
}
211+
212+
91213
virtual int32 OnPaint(const FPaintArgs & Args,
92214
const FGeometry & AllottedGeometry,
93215
const FSlateRect & MyClippingRect,

Source/UnrealEnginePython/Private/UEPyEditor.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2270,5 +2270,57 @@ PyObject *py_unreal_engine_all_viewport_clients(PyObject * self, PyObject * args
22702270
}
22712271
return py_list;
22722272
}
2273+
2274+
PyObject *py_unreal_engine_editor_sync_browser_to_assets(PyObject * self, PyObject * args)
2275+
{
2276+
PyObject *py_items;
2277+
PyObject *py_focus = nullptr;
2278+
2279+
if (!PyArg_ParseTuple(args, "O|O:sync_browser_to_assets", &py_items, &py_focus))
2280+
return nullptr;
2281+
2282+
PyObject *py_iter = PyObject_GetIter(py_items);
2283+
if (!py_iter)
2284+
{
2285+
return PyErr_Format(PyExc_Exception, "argument is not an iterable of UObject or FAssetData");
2286+
}
2287+
2288+
FContentBrowserModule& ContentBrowserModule = FModuleManager::Get().LoadModuleChecked<FContentBrowserModule>("ContentBrowser");
2289+
2290+
TArray<FAssetData> asset_data;
2291+
TArray<UObject *> uobjects;
2292+
2293+
while (PyObject *py_item = PyIter_Next(py_iter))
2294+
{
2295+
ue_PyFAssetData *py_data = py_ue_is_fassetdata(py_item);
2296+
if (py_data)
2297+
{
2298+
asset_data.Add(py_data->asset_data);
2299+
}
2300+
else
2301+
{
2302+
UObject *u_object = ue_py_check_type<UObject>(py_item);
2303+
if (!u_object)
2304+
{
2305+
return PyErr_Format(PyExc_Exception, "invalid item in iterable, must be UObject or FAssetData");
2306+
}
2307+
uobjects.Add(u_object);
2308+
}
2309+
}
2310+
2311+
if (asset_data.Num() > 0)
2312+
{
2313+
ContentBrowserModule.Get().SyncBrowserToAssets(asset_data, false, py_focus && PyObject_IsTrue(py_focus));
2314+
}
2315+
2316+
if (uobjects.Num() > 0)
2317+
{
2318+
ContentBrowserModule.Get().SyncBrowserToAssets(uobjects, false, py_focus && PyObject_IsTrue(py_focus));
2319+
}
2320+
2321+
Py_DECREF(py_iter);
2322+
2323+
Py_RETURN_NONE;
2324+
}
22732325
#endif
22742326

Source/UnrealEnginePython/Private/UEPyEditor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ PyObject *py_unreal_engine_transactions(PyObject *, PyObject *);
106106

107107
PyObject *py_unreal_engine_all_viewport_clients(PyObject *, PyObject *);
108108

109+
PyObject *py_unreal_engine_editor_sync_browser_to_assets(PyObject *, PyObject *);
110+
109111
PyObject *py_unreal_engine_heightmap_expand(PyObject *, PyObject *);
110112
PyObject *py_unreal_engine_heightmap_import(PyObject *, PyObject *);
111113

Source/UnrealEnginePython/Private/UEPyEngine.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,5 +1281,21 @@ PyObject *py_unreal_engine_copy_properties_for_unrelated_objects(PyObject * self
12811281
new_object,
12821282
params);
12831283

1284+
Py_RETURN_NONE;
1285+
}
1286+
1287+
PyObject *py_unreal_engine_set_random_seed(PyObject * self, PyObject * args)
1288+
{
1289+
int seed;
1290+
if (!PyArg_ParseTuple(args, "i:set_random_seed", &seed))
1291+
{
1292+
return nullptr;
1293+
}
1294+
1295+
// Thanks to Sven Mika (Ducandu GmbH) for spotting this
1296+
FMath::RandInit(seed);
1297+
FGenericPlatformMath::SRandInit(seed);
1298+
FGenericPlatformMath::RandInit(seed);
1299+
12841300
Py_RETURN_NONE;
12851301
}

Source/UnrealEnginePython/Private/UEPyEngine.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ PyObject *py_unreal_engine_get_forward_vector(PyObject *, PyObject *);
1313
PyObject *py_unreal_engine_get_right_vector(PyObject *, PyObject *);
1414
PyObject *py_unreal_engine_get_up_vector(PyObject *, PyObject *);
1515

16+
PyObject *py_unreal_engine_set_random_seed(PyObject *, PyObject *);
17+
1618
PyObject *py_unreal_engine_get_game_viewport_size(PyObject *, PyObject *);
1719
PyObject *py_unreal_engine_get_resolution(PyObject *, PyObject *);
1820

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ static PyMethodDef unreal_engine_methods[] = {
154154
{ "add_on_screen_debug_message", py_unreal_engine_add_on_screen_debug_message, METH_VARARGS, "" },
155155
{ "print_string", py_unreal_engine_print_string, METH_VARARGS, "" },
156156

157+
{ "set_random_seed", py_unreal_engine_set_random_seed, METH_VARARGS, "" },
158+
157159
{ "find_class", py_unreal_engine_find_class, METH_VARARGS, "" },
158160
{ "find_struct", py_unreal_engine_find_struct, METH_VARARGS, "" },
159161
{ "find_enum", py_unreal_engine_find_enum, METH_VARARGS, "" },
@@ -234,6 +236,8 @@ static PyMethodDef unreal_engine_methods[] = {
234236
{ "get_selected_assets", py_unreal_engine_get_selected_assets, METH_VARARGS, "" },
235237
{ "get_assets_by_class", py_unreal_engine_get_assets_by_class, METH_VARARGS, "" },
236238

239+
{ "sync_browser_to_assets", py_unreal_engine_editor_sync_browser_to_assets, METH_VARARGS, "" },
240+
237241
{ "get_asset_referencers", py_unreal_engine_get_asset_referencers, METH_VARARGS, "" },
238242
{ "get_asset_dependencies", py_unreal_engine_get_asset_dependencies, METH_VARARGS, "" },
239243

@@ -839,6 +843,7 @@ static PyMethodDef ue_PyUObject_methods[] = {
839843
{ "texture_get_width", (PyCFunction)py_ue_texture_get_width, METH_VARARGS, "" },
840844
{ "texture_get_height", (PyCFunction)py_ue_texture_get_height, METH_VARARGS, "" },
841845
{ "render_target_get_data", (PyCFunction)py_ue_render_target_get_data, METH_VARARGS, "" },
846+
{ "render_target_get_data_to_buffer", (PyCFunction)py_ue_render_target_get_data_to_buffer, METH_VARARGS, "" },
842847
{ "texture_update_resource", (PyCFunction)py_ue_texture_update_resource, METH_VARARGS, "" },
843848

844849
#if WITH_EDITOR

Source/UnrealEnginePython/Private/UObject/UEPyLandscape.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ PyObject *py_ue_landscape_import(ue_PyUObject *self, PyObject * args)
6363
int size_y = component_y * quads_per_component + 1;
6464

6565
if (heightmap_buffer.len < (Py_ssize_t)(size_x * size_y * sizeof(uint16)))
66-
return PyErr_Format(PyExc_Exception, "not enough heightmap data, expecting %d bytes", size_x * size_y * sizeof(uint16));
66+
return PyErr_Format(PyExc_Exception, "not enough heightmap data, expecting %lu bytes", size_x * size_y * sizeof(uint16));
6767

6868
uint16 *data = (uint16 *)heightmap_buffer.buf;
6969

0 commit comments

Comments
 (0)