Skip to content

Commit

Permalink
Merge pull request #5 from 20tab/master
Browse files Browse the repository at this point in the history
sync to master
  • Loading branch information
getnamo committed Dec 19, 2017
2 parents 81b5571 + 7965e29 commit 1475d32
Show file tree
Hide file tree
Showing 14 changed files with 454 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ static PyObject *py_ue_icollection_manager_get_child_collection_names(PyObject *
ICollectionManager &CollectionManager = FCollectionManagerModule::GetModule().Get();
TArray<FName> names;
CollectionManager.GetChildCollectionNames(FName(UTF8_TO_TCHAR(name)), (ECollectionShareType::Type)type, (ECollectionShareType::Type)child_type, names);
for (FName name : names) {
PyList_Append(py_list, PyUnicode_FromString(TCHAR_TO_UTF8(*name.ToString())));
for (FName cname : names) {
PyList_Append(py_list, PyUnicode_FromString(TCHAR_TO_UTF8(*cname.ToString())));
}
return py_list;
}
Expand Down Expand Up @@ -463,7 +463,7 @@ static PyMethodDef ue_PyICollectionManager_methods[] = {
{ "rename_collection", (PyCFunction)py_ue_icollection_manager_rename_collection, METH_VARARGS | METH_CLASS, "" },
{ "add_to_collection", (PyCFunction)py_ue_icollection_manager_add_to_collection, METH_VARARGS | METH_CLASS, "" },
{ "collection_exists", (PyCFunction)py_ue_icollection_manager_collection_exists, METH_VARARGS | METH_CLASS, "" },
{ "create_unique_connection_name", (PyCFunction)py_ue_icollection_manager_create_unique_collection_name, METH_VARARGS | METH_CLASS, "" },
{ "create_unique_collection_name", (PyCFunction)py_ue_icollection_manager_create_unique_collection_name, METH_VARARGS | METH_CLASS, "" },
{ "destroy_collection", (PyCFunction)py_ue_icollection_manager_destroy_collection, METH_VARARGS | METH_CLASS, "" },
{ "empty_collection", (PyCFunction)py_ue_icollection_manager_empty_collection, METH_VARARGS | METH_CLASS, "" },
{ "get_dynamic_query_text", (PyCFunction)py_ue_icollection_manager_get_dynamic_query_text, METH_VARARGS | METH_CLASS, "" },
Expand Down
122 changes: 122 additions & 0 deletions Source/UnrealEnginePython/Private/Slate/UEPySPythonWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "UEPyFPaintContext.h"
#include "UEPyFCharacterEvent.h"
#include "UEPyFKeyEvent.h"
#include "UEPyFPointerEvent.h"

extern PyTypeObject ue_PySPythonWidgetType;

Expand Down Expand Up @@ -88,6 +89,127 @@ class SPythonWidget : public SCompoundWidget
return FReply::Handled();
}

virtual FReply OnMouseMove(const FGeometry & MyGeometry, const FPointerEvent & MyEvent) override
{
FScopePythonGIL gil;

if (!PyObject_HasAttrString(self, (char *)"on_mouse_move"))
return FReply::Unhandled();

PyObject *py_callable_on_mouse_move = PyObject_GetAttrString(self, (char *)"on_mouse_move");
if (!PyCallable_Check(py_callable_on_mouse_move))
{
UE_LOG(LogPython, Error, TEXT("on_mouse_move is not a callable"));
return FReply::Unhandled();
}

PyObject *ret = PyObject_CallFunction(py_callable_on_mouse_move, (char *)"OO", py_ue_new_fgeometry(MyGeometry), py_ue_new_fpointer_event(MyEvent));
if (!ret)
{
unreal_engine_py_log_error();
return FReply::Unhandled();
}

if (ret == Py_False)
{
Py_DECREF(ret);
return FReply::Unhandled();
}
Py_DECREF(ret);
return FReply::Handled();
}

virtual FReply OnMouseWheel(const FGeometry & MyGeometry, const FPointerEvent & MyEvent) override
{
FScopePythonGIL gil;

if (!PyObject_HasAttrString(self, (char *)"on_mouse_wheel"))
return FReply::Unhandled();

PyObject *py_callable_on_mouse_wheel = PyObject_GetAttrString(self, (char *)"on_mouse_wheel");
if (!PyCallable_Check(py_callable_on_mouse_wheel))
{
UE_LOG(LogPython, Error, TEXT("on_mouse_wheel is not a callable"));
return FReply::Unhandled();
}

PyObject *ret = PyObject_CallFunction(py_callable_on_mouse_wheel, (char *)"OO", py_ue_new_fgeometry(MyGeometry), py_ue_new_fpointer_event(MyEvent));
if (!ret)
{
unreal_engine_py_log_error();
return FReply::Unhandled();
}

if (ret == Py_False)
{
Py_DECREF(ret);
return FReply::Unhandled();
}
Py_DECREF(ret);
return FReply::Handled();
}

virtual FReply OnMouseButtonDown(const FGeometry & MyGeometry, const FPointerEvent & MyEvent) override
{
FScopePythonGIL gil;

if (!PyObject_HasAttrString(self, (char *)"on_mouse_button_down"))
return FReply::Unhandled();

PyObject *py_callable_on_mouse_button_down = PyObject_GetAttrString(self, (char *)"on_mouse_button_down");
if (!PyCallable_Check(py_callable_on_mouse_button_down))
{
UE_LOG(LogPython, Error, TEXT("on_mouse_button_down is not a callable"));
return FReply::Unhandled();
}

PyObject *ret = PyObject_CallFunction(py_callable_on_mouse_button_down, (char *)"OO", py_ue_new_fgeometry(MyGeometry), py_ue_new_fpointer_event(MyEvent));
if (!ret)
{
unreal_engine_py_log_error();
return FReply::Unhandled();
}

if (ret == Py_False)
{
Py_DECREF(ret);
return FReply::Unhandled();
}
Py_DECREF(ret);
return FReply::Handled();
}

virtual FReply OnMouseButtonUp(const FGeometry & MyGeometry, const FPointerEvent & MyEvent) override
{
FScopePythonGIL gil;

if (!PyObject_HasAttrString(self, (char *)"on_mouse_button_up"))
return FReply::Unhandled();

PyObject *py_callable_on_mouse_button_up = PyObject_GetAttrString(self, (char *)"on_mouse_button_up");
if (!PyCallable_Check(py_callable_on_mouse_button_up))
{
UE_LOG(LogPython, Error, TEXT("on_mouse_button_up is not a callable"));
return FReply::Unhandled();
}

PyObject *ret = PyObject_CallFunction(py_callable_on_mouse_button_up, (char *)"OO", py_ue_new_fgeometry(MyGeometry), py_ue_new_fpointer_event(MyEvent));
if (!ret)
{
unreal_engine_py_log_error();
return FReply::Unhandled();
}

if (ret == Py_False)
{
Py_DECREF(ret);
return FReply::Unhandled();
}
Py_DECREF(ret);
return FReply::Handled();
}


virtual int32 OnPaint(const FPaintArgs & Args,
const FGeometry & AllottedGeometry,
const FSlateRect & MyClippingRect,
Expand Down
52 changes: 52 additions & 0 deletions Source/UnrealEnginePython/Private/UEPyEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2270,5 +2270,57 @@ PyObject *py_unreal_engine_all_viewport_clients(PyObject * self, PyObject * args
}
return py_list;
}

PyObject *py_unreal_engine_editor_sync_browser_to_assets(PyObject * self, PyObject * args)
{
PyObject *py_items;
PyObject *py_focus = nullptr;

if (!PyArg_ParseTuple(args, "O|O:sync_browser_to_assets", &py_items, &py_focus))
return nullptr;

PyObject *py_iter = PyObject_GetIter(py_items);
if (!py_iter)
{
return PyErr_Format(PyExc_Exception, "argument is not an iterable of UObject or FAssetData");
}

FContentBrowserModule& ContentBrowserModule = FModuleManager::Get().LoadModuleChecked<FContentBrowserModule>("ContentBrowser");

TArray<FAssetData> asset_data;
TArray<UObject *> uobjects;

while (PyObject *py_item = PyIter_Next(py_iter))
{
ue_PyFAssetData *py_data = py_ue_is_fassetdata(py_item);
if (py_data)
{
asset_data.Add(py_data->asset_data);
}
else
{
UObject *u_object = ue_py_check_type<UObject>(py_item);
if (!u_object)
{
return PyErr_Format(PyExc_Exception, "invalid item in iterable, must be UObject or FAssetData");
}
uobjects.Add(u_object);
}
}

if (asset_data.Num() > 0)
{
ContentBrowserModule.Get().SyncBrowserToAssets(asset_data, false, py_focus && PyObject_IsTrue(py_focus));
}

if (uobjects.Num() > 0)
{
ContentBrowserModule.Get().SyncBrowserToAssets(uobjects, false, py_focus && PyObject_IsTrue(py_focus));
}

Py_DECREF(py_iter);

Py_RETURN_NONE;
}
#endif

2 changes: 2 additions & 0 deletions Source/UnrealEnginePython/Private/UEPyEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ PyObject *py_unreal_engine_transactions(PyObject *, PyObject *);

PyObject *py_unreal_engine_all_viewport_clients(PyObject *, PyObject *);

PyObject *py_unreal_engine_editor_sync_browser_to_assets(PyObject *, PyObject *);

PyObject *py_unreal_engine_heightmap_expand(PyObject *, PyObject *);
PyObject *py_unreal_engine_heightmap_import(PyObject *, PyObject *);

Expand Down
16 changes: 16 additions & 0 deletions Source/UnrealEnginePython/Private/UEPyEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1281,5 +1281,21 @@ PyObject *py_unreal_engine_copy_properties_for_unrelated_objects(PyObject * self
new_object,
params);

Py_RETURN_NONE;
}

PyObject *py_unreal_engine_set_random_seed(PyObject * self, PyObject * args)
{
int seed;
if (!PyArg_ParseTuple(args, "i:set_random_seed", &seed))
{
return nullptr;
}

// Thanks to Sven Mika (Ducandu GmbH) for spotting this
FMath::RandInit(seed);
FGenericPlatformMath::SRandInit(seed);
FGenericPlatformMath::RandInit(seed);

Py_RETURN_NONE;
}
2 changes: 2 additions & 0 deletions Source/UnrealEnginePython/Private/UEPyEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ PyObject *py_unreal_engine_get_forward_vector(PyObject *, PyObject *);
PyObject *py_unreal_engine_get_right_vector(PyObject *, PyObject *);
PyObject *py_unreal_engine_get_up_vector(PyObject *, PyObject *);

PyObject *py_unreal_engine_set_random_seed(PyObject *, PyObject *);

PyObject *py_unreal_engine_get_game_viewport_size(PyObject *, PyObject *);
PyObject *py_unreal_engine_get_resolution(PyObject *, PyObject *);

Expand Down
5 changes: 5 additions & 0 deletions Source/UnrealEnginePython/Private/UEPyModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ static PyMethodDef unreal_engine_methods[] = {
{ "add_on_screen_debug_message", py_unreal_engine_add_on_screen_debug_message, METH_VARARGS, "" },
{ "print_string", py_unreal_engine_print_string, METH_VARARGS, "" },

{ "set_random_seed", py_unreal_engine_set_random_seed, METH_VARARGS, "" },

{ "find_class", py_unreal_engine_find_class, METH_VARARGS, "" },
{ "find_struct", py_unreal_engine_find_struct, METH_VARARGS, "" },
{ "find_enum", py_unreal_engine_find_enum, METH_VARARGS, "" },
Expand Down Expand Up @@ -234,6 +236,8 @@ static PyMethodDef unreal_engine_methods[] = {
{ "get_selected_assets", py_unreal_engine_get_selected_assets, METH_VARARGS, "" },
{ "get_assets_by_class", py_unreal_engine_get_assets_by_class, METH_VARARGS, "" },

{ "sync_browser_to_assets", py_unreal_engine_editor_sync_browser_to_assets, METH_VARARGS, "" },

{ "get_asset_referencers", py_unreal_engine_get_asset_referencers, METH_VARARGS, "" },
{ "get_asset_dependencies", py_unreal_engine_get_asset_dependencies, METH_VARARGS, "" },

Expand Down Expand Up @@ -839,6 +843,7 @@ static PyMethodDef ue_PyUObject_methods[] = {
{ "texture_get_width", (PyCFunction)py_ue_texture_get_width, METH_VARARGS, "" },
{ "texture_get_height", (PyCFunction)py_ue_texture_get_height, METH_VARARGS, "" },
{ "render_target_get_data", (PyCFunction)py_ue_render_target_get_data, METH_VARARGS, "" },
{ "render_target_get_data_to_buffer", (PyCFunction)py_ue_render_target_get_data_to_buffer, METH_VARARGS, "" },
{ "texture_update_resource", (PyCFunction)py_ue_texture_update_resource, METH_VARARGS, "" },

#if WITH_EDITOR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ PyObject *py_ue_landscape_import(ue_PyUObject *self, PyObject * args)
int size_y = component_y * quads_per_component + 1;

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

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

Expand Down

0 comments on commit 1475d32

Please sign in to comment.