|
4 | 4 |
|
5 | 5 | #include "Runtime/Engine/Classes/EdGraph/EdGraph.h" |
6 | 6 | #include "Editor/BlueprintGraph/Classes/K2Node_CallFunction.h" |
| 7 | +#include "Editor/BlueprintGraph/Classes/K2Node_DynamicCast.h" |
7 | 8 | #include "Editor/BlueprintGraph/Classes/EdGraphSchema_K2.h" |
8 | 9 | #include "Editor/BlueprintGraph/Classes/K2Node_CustomEvent.h" |
9 | 10 | #include "Editor/BlueprintGraph/Classes/K2Node_VariableGet.h" |
@@ -290,56 +291,56 @@ PyObject *py_ue_graph_add_node(ue_PyUObject * self, PyObject * args) |
290 | 291 | PyObject *py_node_class; |
291 | 292 | int x = 0; |
292 | 293 | int y = 0; |
293 | | - PyObject *py_data = nullptr; |
| 294 | + |
294 | 295 | char *metadata = nullptr; |
| 296 | + PyObject *py_data = nullptr; |
| 297 | + |
295 | 298 | if (!PyArg_ParseTuple(args, "O|iisO:graph_add_node", &py_node_class, &x, &y, &metadata, &py_data)) |
296 | 299 | { |
297 | | - return NULL; |
| 300 | + return nullptr; |
298 | 301 | } |
299 | 302 |
|
300 | | - if (!self->ue_object->IsA<UEdGraph>()) |
301 | | - { |
| 303 | + UEdGraph *graph = ue_py_check_type<UEdGraph>(self); |
| 304 | + if (!graph) |
302 | 305 | return PyErr_Format(PyExc_Exception, "uobject is not a UEdGraph"); |
303 | | - } |
304 | 306 |
|
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) |
309 | 309 | return PyErr_Format(PyExc_Exception, "argument is not a UObject"); |
310 | | - } |
311 | 310 |
|
312 | 311 | UEdGraphNode *node = nullptr; |
313 | 312 |
|
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)) |
316 | 314 | { |
317 | | - UClass *u_class = (UClass *)py_obj->ue_object; |
318 | 315 | if (!u_class->IsChildOf<UEdGraphNode>()) |
319 | 316 | { |
320 | 317 | return PyErr_Format(PyExc_Exception, "argument is not a child of UEdGraphNode"); |
321 | 318 | } |
322 | | - node = (UEdGraphNode *)NewObject<UObject>(graph, u_class); |
| 319 | + node = NewObject<UEdGraphNode>(graph, u_class); |
323 | 320 | node->PostLoad(); |
324 | 321 | } |
325 | | - else if (py_obj->ue_object->IsA<UEdGraphNode>()) |
| 322 | + else |
326 | 323 | { |
327 | | - node = (UEdGraphNode *)py_obj->ue_object; |
328 | | - if (node->GetOuter() != graph) |
| 324 | + node = Cast<UEdGraphNode>(u_obj); |
| 325 | + if (node) |
329 | 326 | { |
330 | | - node->Rename(*node->GetName(), graph); |
| 327 | + if (node->GetOuter() != graph) |
| 328 | + |
| 329 | + node->Rename(*node->GetName(), graph); |
331 | 330 | } |
332 | 331 | } |
333 | 332 |
|
334 | 333 | if (!node) |
335 | | - { |
336 | 334 | return PyErr_Format(PyExc_Exception, "argument is not a supported type"); |
337 | | - } |
| 335 | + |
338 | 336 |
|
339 | 337 | node->CreateNewGuid(); |
340 | 338 | node->PostPlacedNewNode(); |
341 | 339 | node->SetFlags(RF_Transactional); |
342 | | - node->AllocateDefaultPins(); |
| 340 | + if (node->Pins.Num() == 0) |
| 341 | + { |
| 342 | + node->AllocateDefaultPins(); |
| 343 | + } |
343 | 344 | node->NodePosX = x; |
344 | 345 | node->NodePosY = y; |
345 | 346 |
|
@@ -380,6 +381,60 @@ PyObject *py_ue_graph_add_node(ue_PyUObject * self, PyObject * args) |
380 | 381 | Py_RETURN_UOBJECT(node); |
381 | 382 | } |
382 | 383 |
|
| 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 | + |
383 | 438 | PyObject *py_ue_node_pins(ue_PyUObject * self, PyObject * args) |
384 | 439 | { |
385 | 440 |
|
@@ -582,4 +637,57 @@ PyObject *py_ue_node_create_pin(ue_PyUObject * self, PyObject * args) |
582 | 637 | Py_INCREF(ret); |
583 | 638 | return ret; |
584 | 639 | } |
| 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 | + |
585 | 693 | #endif |
0 commit comments