Skip to content

Commit 437ae3b

Browse files
author
ikrima
committed
Merge commit '551c3d08cf58a19790759e5fb14e2fdc453628c0' into bebylon
2 parents 596986a + 551c3d0 commit 437ae3b

File tree

15 files changed

+246
-34
lines changed

15 files changed

+246
-34
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ The currently supported Unreal Engine versions are 4.12, 4.13, 4.14, 4.15, 4.16,
2828

2929
We support official python.org releases as well as IntelPython and Anaconda distributions.
3030

31-
Note: this plugin has nothing to do with the experimental 'PythonScriptPlugin' included in Unreal Engine >= 4.19. This plugin aims at full integration with engine and editor (included the Slate api), as well as support for the vast majority of python features like asyncio, coroutines, generators, threads and third party modules.
31+
Note: this plugin has nothing to do with the experimental 'PythonScriptPlugin' included in Unreal Engine >= 4.19. We aim at full integration with engine and editor (included the Slate api), as well as support for the vast majority of python features like asyncio, coroutines, generators, threads and third party modules.
3232

3333
# Binary installation on Windows (64 bit)
3434

Source/PythonEditor/Private/SPythonEditableText.cpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ void SPythonEditableText::Construct(const FArguments& InArgs)
2020
.OnCursorMoved(this, &SPythonEditableText::OnCursorMoved)
2121
);
2222
OnExecuted = InArgs._OnExecuted;
23+
CurrentScale = 1;
2324
}
2425

2526
FReply SPythonEditableText::OnKeyChar(const FGeometry& MyGeometry, const FCharacterEvent& InCharacterEvent)
@@ -71,17 +72,41 @@ FReply SPythonEditableText::OnKeyChar(const FGeometry& MyGeometry, const FCharac
7172
return Reply;
7273
}
7374

75+
FReply SPythonEditableText::OnMouseWheel(const FGeometry& MyGeometry, const FPointerEvent& InPointerEvent)
76+
{
77+
if (FSlateApplication::Get().GetModifierKeys().IsControlDown())
78+
{
79+
if (InPointerEvent.GetWheelDelta() > 0)
80+
{
81+
CurrentScale += 0.1;
82+
}
83+
else if (InPointerEvent.GetWheelDelta() < 0)
84+
{
85+
CurrentScale -= 0.1;
86+
}
87+
88+
if (CurrentScale < 1)
89+
CurrentScale = 1;
90+
SetRenderTransform(FSlateRenderTransform(CurrentScale));
91+
return FReply::Handled();
92+
}
93+
return SMultiLineEditableText::OnMouseWheel(MyGeometry, InPointerEvent);
94+
}
95+
7496
FReply SPythonEditableText::OnKeyDown(const FGeometry& MyGeometry, const FKeyEvent& InKeyEvent)
7597
{
7698
FReply Reply = FReply::Unhandled();
77-
if (InKeyEvent.GetKeyCode() == 9) {
99+
if (InKeyEvent.GetKeyCode() == 9)
100+
{
78101
Reply = FReply::Handled();
79102
}
80-
else if (InKeyEvent.IsControlDown() && InKeyEvent.GetKeyCode() == 13) {
103+
else if (InKeyEvent.IsControlDown() && InKeyEvent.GetKeyCode() == 13)
104+
{
81105
Reply = FReply::Handled();
82106
OnExecuted.Execute();
83107
}
84-
else {
108+
else
109+
{
85110
Reply = SMultiLineEditableText::OnKeyDown(MyGeometry, InKeyEvent);
86111
}
87112

Source/PythonEditor/Private/SPythonEditableText.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,12 @@ class SPythonEditableText : public SMultiLineEditableText
3939
private:
4040
virtual FReply OnKeyChar(const FGeometry& MyGeometry,const FCharacterEvent& InCharacterEvent) override;
4141
virtual FReply OnKeyDown(const FGeometry& MyGeometry, const FKeyEvent& InKeyEvent) override;
42+
virtual FReply OnMouseWheel(const FGeometry& MyGeometry, const FPointerEvent& InPointerEvent) override;
4243

4344
FOnExecuted OnExecuted;
4445

46+
float CurrentScale;
47+
4548
int32 CurrentLine;
4649
int32 CurrentColumn;
4750
};

Source/PythonEditor/Private/SPythonEditor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ FText SPythonEditor::GetLineAndColumn() const
144144
int32 Column;
145145
PythonEditableText->GetLineAndColumn(Line, Column);
146146

147-
FString LineAndColumn = FString::Printf(TEXT("Line: %d Column: %d"), Line, Column);
147+
FString LineAndColumn = FString::Printf(TEXT("Line: %d Column: %d"), Line + 1, Column);
148148

149149
return FText::FromString(LineAndColumn);
150150
}

Source/UnrealEnginePython/Private/Blueprint/UEPyEdGraph.cpp

Lines changed: 129 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "Runtime/Engine/Classes/EdGraph/EdGraph.h"
66
#include "Editor/BlueprintGraph/Classes/K2Node_CallFunction.h"
7+
#include "Editor/BlueprintGraph/Classes/K2Node_DynamicCast.h"
78
#include "Editor/BlueprintGraph/Classes/EdGraphSchema_K2.h"
89
#include "Editor/BlueprintGraph/Classes/K2Node_CustomEvent.h"
910
#include "Editor/BlueprintGraph/Classes/K2Node_VariableGet.h"
@@ -290,56 +291,56 @@ PyObject *py_ue_graph_add_node(ue_PyUObject * self, PyObject * args)
290291
PyObject *py_node_class;
291292
int x = 0;
292293
int y = 0;
293-
PyObject *py_data = nullptr;
294+
294295
char *metadata = nullptr;
296+
PyObject *py_data = nullptr;
297+
295298
if (!PyArg_ParseTuple(args, "O|iisO:graph_add_node", &py_node_class, &x, &y, &metadata, &py_data))
296299
{
297-
return NULL;
300+
return nullptr;
298301
}
299302

300-
if (!self->ue_object->IsA<UEdGraph>())
301-
{
303+
UEdGraph *graph = ue_py_check_type<UEdGraph>(self);
304+
if (!graph)
302305
return PyErr_Format(PyExc_Exception, "uobject is not a UEdGraph");
303-
}
304306

305-
UEdGraph *graph = (UEdGraph *)self->ue_object;
306-
307-
if (!ue_is_pyuobject(py_node_class))
308-
{
307+
UObject *u_obj = ue_py_check_type<UObject>(py_node_class);
308+
if (!u_obj)
309309
return PyErr_Format(PyExc_Exception, "argument is not a UObject");
310-
}
311310

312311
UEdGraphNode *node = nullptr;
313312

314-
ue_PyUObject *py_obj = (ue_PyUObject *)py_node_class;
315-
if (py_obj->ue_object->IsA<UClass>())
313+
if (UClass *u_class = Cast<UClass>(u_obj))
316314
{
317-
UClass *u_class = (UClass *)py_obj->ue_object;
318315
if (!u_class->IsChildOf<UEdGraphNode>())
319316
{
320317
return PyErr_Format(PyExc_Exception, "argument is not a child of UEdGraphNode");
321318
}
322-
node = (UEdGraphNode *)NewObject<UObject>(graph, u_class);
319+
node = NewObject<UEdGraphNode>(graph, u_class);
323320
node->PostLoad();
324321
}
325-
else if (py_obj->ue_object->IsA<UEdGraphNode>())
322+
else
326323
{
327-
node = (UEdGraphNode *)py_obj->ue_object;
328-
if (node->GetOuter() != graph)
324+
node = Cast<UEdGraphNode>(u_obj);
325+
if (node)
329326
{
330-
node->Rename(*node->GetName(), graph);
327+
if (node->GetOuter() != graph)
328+
329+
node->Rename(*node->GetName(), graph);
331330
}
332331
}
333332

334333
if (!node)
335-
{
336334
return PyErr_Format(PyExc_Exception, "argument is not a supported type");
337-
}
335+
338336

339337
node->CreateNewGuid();
340338
node->PostPlacedNewNode();
341339
node->SetFlags(RF_Transactional);
342-
node->AllocateDefaultPins();
340+
if (node->Pins.Num() == 0)
341+
{
342+
node->AllocateDefaultPins();
343+
}
343344
node->NodePosX = x;
344345
node->NodePosY = y;
345346

@@ -380,6 +381,60 @@ PyObject *py_ue_graph_add_node(ue_PyUObject * self, PyObject * args)
380381
Py_RETURN_UOBJECT(node);
381382
}
382383

384+
PyObject *py_ue_graph_add_node_dynamic_cast(ue_PyUObject * self, PyObject * args)
385+
{
386+
387+
ue_py_check(self);
388+
389+
PyObject *py_node_class;
390+
int x = 0;
391+
int y = 0;
392+
393+
char *metadata = nullptr;
394+
PyObject *py_data = nullptr;
395+
396+
if(!PyArg_ParseTuple(args, "O|iis:graph_add_node_dynamic_cast", &py_node_class, &x, &y, &metadata))
397+
{
398+
return nullptr;
399+
}
400+
401+
UEdGraph *graph = ue_py_check_type<UEdGraph>(self);
402+
if(!graph)
403+
return PyErr_Format(PyExc_Exception, "uobject is not a UEdGraph");
404+
405+
UClass *u_class = ue_py_check_type<UClass>(py_node_class);
406+
if(!u_class)
407+
return PyErr_Format(PyExc_Exception, "argument is not a UClass");
408+
409+
UK2Node_DynamicCast *node = NewObject<UK2Node_DynamicCast>(graph);
410+
node->TargetType = u_class;
411+
node->SetPurity(false);
412+
node->AllocateDefaultPins();
413+
414+
node->CreateNewGuid();
415+
node->PostPlacedNewNode();
416+
node->SetFlags(RF_Transactional);
417+
node->NodePosX = x;
418+
node->NodePosY = y;
419+
420+
if(metadata == nullptr || strlen(metadata) == 0)
421+
{
422+
UEdGraphSchema_K2::SetNodeMetaData(node, FNodeMetadata::DefaultGraphNode);
423+
}
424+
else
425+
{
426+
UEdGraphSchema_K2::SetNodeMetaData(node, FName(UTF8_TO_TCHAR(metadata)));
427+
}
428+
graph->AddNode(node);
429+
430+
if(UBlueprint *bp = Cast<UBlueprint>(node->GetGraph()->GetOuter()))
431+
{
432+
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(bp);
433+
}
434+
435+
Py_RETURN_UOBJECT(node);
436+
}
437+
383438
PyObject *py_ue_node_pins(ue_PyUObject * self, PyObject * args)
384439
{
385440

@@ -582,4 +637,57 @@ PyObject *py_ue_node_create_pin(ue_PyUObject * self, PyObject * args)
582637
Py_INCREF(ret);
583638
return ret;
584639
}
640+
641+
642+
PyObject *py_ue_node_pin_type_changed(ue_PyUObject * self, PyObject * args)
643+
{
644+
645+
ue_py_check(self);
646+
647+
PyObject *py_pin;
648+
if (!PyArg_ParseTuple(args, "O:node_pin_type_changed", &py_pin))
649+
{
650+
return nullptr;
651+
}
652+
653+
UEdGraphNode *node = ue_py_check_type<UEdGraphNode>(self);
654+
if (!node)
655+
return PyErr_Format(PyExc_Exception, "uobject is not a UEdGraphNode");
656+
657+
ue_PyEdGraphPin *pin = py_ue_is_edgraphpin(py_pin);
658+
if (!pin)
659+
return PyErr_Format(PyExc_Exception, "argument is not a EdGraphPin");
660+
661+
node->PinTypeChanged(pin->pin);
662+
663+
Py_RETURN_NONE;
664+
}
665+
666+
PyObject *py_ue_node_pin_default_value_changed(ue_PyUObject * self, PyObject * args)
667+
{
668+
669+
ue_py_check(self);
670+
671+
PyObject *py_pin;
672+
if (!PyArg_ParseTuple(args, "O:node_pin_default_value_changed", &py_pin))
673+
{
674+
return nullptr;
675+
}
676+
677+
UEdGraphNode *node = ue_py_check_type<UEdGraphNode>(self);
678+
if (!node)
679+
return PyErr_Format(PyExc_Exception, "uobject is not a UEdGraphNode");
680+
681+
ue_PyEdGraphPin *pin = py_ue_is_edgraphpin(py_pin);
682+
if (!pin)
683+
return PyErr_Format(PyExc_Exception, "argument is not a EdGraphPin");
684+
685+
node->PinDefaultValueChanged(pin->pin);
686+
687+
Py_RETURN_NONE;
688+
}
689+
690+
691+
692+
585693
#endif

Source/UnrealEnginePython/Private/Blueprint/UEPyEdGraph.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ PyObject *py_ue_graph_add_node_custom_event(ue_PyUObject *, PyObject *);
1313
PyObject *py_ue_graph_add_node_variable_get(ue_PyUObject *, PyObject *);
1414
PyObject *py_ue_graph_add_node_variable_set(ue_PyUObject *, PyObject *);
1515
PyObject *py_ue_graph_add_node(ue_PyUObject *, PyObject *);
16+
PyObject *py_ue_graph_add_node_dynamic_cast(ue_PyUObject *, PyObject *);
1617
PyObject *py_ue_graph_add_node_event(ue_PyUObject *, PyObject *);
1718

1819
PyObject *py_ue_graph_get_good_place_for_new_node(ue_PyUObject *, PyObject *);
@@ -21,6 +22,9 @@ PyObject *py_ue_node_pins(ue_PyUObject *, PyObject *);
2122
PyObject *py_ue_node_find_pin(ue_PyUObject *, PyObject *);
2223
PyObject *py_ue_node_create_pin(ue_PyUObject *, PyObject *);
2324

25+
PyObject *py_ue_node_pin_type_changed(ue_PyUObject *, PyObject *);
26+
PyObject *py_ue_node_pin_default_value_changed(ue_PyUObject *, PyObject *);
27+
2428
PyObject *py_ue_node_function_entry_set_pure(ue_PyUObject *, PyObject *);
2529

2630
PyObject *py_ue_node_get_title(ue_PyUObject *, PyObject *);

Source/UnrealEnginePython/Private/Blueprint/UEPyEdGraphPin.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,25 @@ static int py_ue_edgraphpin_set_default_value(ue_PyEdGraphPin *self, PyObject *v
134134
return -1;
135135
}
136136

137+
static PyObject *py_ue_edgraphpin_get_default_text_value(ue_PyEdGraphPin *self, void *closure)
138+
{
139+
return PyUnicode_FromString(TCHAR_TO_UTF8(*(self->pin->DefaultTextValue.ToString())));
140+
}
141+
142+
static int py_ue_edgraphpin_set_default_text_value(ue_PyEdGraphPin *self, PyObject *value, void *closure)
143+
{
144+
if (value && PyUnicode_Check(value))
145+
{
146+
char *str = PyUnicode_AsUTF8(value);
147+
self->pin->DefaultTextValue = FText::FromString(UTF8_TO_TCHAR(str));
148+
return 0;
149+
}
150+
PyErr_SetString(PyExc_TypeError, "value is not a string");
151+
return -1;
152+
}
153+
154+
155+
137156
static PyObject *py_ue_edgraphpin_get_default_object(ue_PyEdGraphPin *self, void *closure)
138157
{
139158
UObject *u_object = self->pin->DefaultObject;
@@ -161,6 +180,7 @@ static PyGetSetDef ue_PyEdGraphPin_getseters[] = {
161180
{ (char*)"category", (getter)py_ue_edgraphpin_get_category, NULL, (char *)"", NULL },
162181
{ (char*)"sub_category", (getter)py_ue_edgraphpin_get_sub_category, NULL, (char *)"", NULL },
163182
{ (char*)"default_value", (getter)py_ue_edgraphpin_get_default_value, (setter)py_ue_edgraphpin_set_default_value, (char *)"", NULL },
183+
{ (char*)"default_text_value", (getter)py_ue_edgraphpin_get_default_text_value, (setter)py_ue_edgraphpin_set_default_text_value, (char *)"", NULL },
164184
{ (char*)"default_object", (getter)py_ue_edgraphpin_get_default_object, (setter)py_ue_edgraphpin_set_default_object, (char *)"", NULL },
165185
{ NULL } /* Sentinel */
166186
};
@@ -234,4 +254,4 @@ ue_PyEdGraphPin *py_ue_is_edgraphpin(PyObject *obj)
234254
return (ue_PyEdGraphPin *)obj;
235255
}
236256

237-
#endif
257+
#endif

0 commit comments

Comments
 (0)