|
6 | 6 | #include "Editor/BlueprintGraph/Classes/K2Node_CallFunction.h" |
7 | 7 | #include "Editor/BlueprintGraph/Classes/EdGraphSchema_K2.h" |
8 | 8 | #include "Editor/BlueprintGraph/Classes/K2Node_CustomEvent.h" |
| 9 | +#include "Editor/BlueprintGraph/Classes/K2Node_VariableGet.h" |
| 10 | +#include "Editor/BlueprintGraph/Classes/K2Node_VariableSet.h" |
| 11 | +#include "Editor/UnrealEd/Public/Kismet2/BlueprintEditorUtils.h" |
9 | 12 |
|
10 | 13 | PyObject *py_ue_graph_add_node_call_function(ue_PyUObject * self, PyObject * args) { |
11 | 14 |
|
@@ -98,5 +101,105 @@ PyObject *py_ue_graph_add_node_custom_event(ue_PyUObject * self, PyObject * args |
98 | 101 | Py_INCREF(ret); |
99 | 102 | return ret; |
100 | 103 |
|
| 104 | +} |
| 105 | + |
| 106 | +PyObject *py_ue_graph_add_node_variable_get(ue_PyUObject * self, PyObject * args) { |
| 107 | + |
| 108 | + ue_py_check(self); |
| 109 | + |
| 110 | + char *name = nullptr; |
| 111 | + PyObject *py_struct = nullptr; |
| 112 | + int x = 0; |
| 113 | + int y = 0; |
| 114 | + if (!PyArg_ParseTuple(args, "s|Oii:graph_add_node_variable_get", &name, &py_struct, &x, &y)) { |
| 115 | + return NULL; |
| 116 | + } |
| 117 | + |
| 118 | + if (!self->ue_object->IsA<UEdGraph>()) { |
| 119 | + return PyErr_Format(PyExc_Exception, "uobject is not a UEdGraph"); |
| 120 | + } |
| 121 | + |
| 122 | + UEdGraph *graph = (UEdGraph *)self->ue_object; |
| 123 | + UStruct *u_struct = nullptr; |
| 124 | + |
| 125 | + if (py_struct && py_struct != Py_None) { |
| 126 | + if (!ue_is_pyuobject(py_struct)) { |
| 127 | + return PyErr_Format(PyExc_Exception, "argument is not a UObject"); |
| 128 | + } |
| 129 | + ue_PyUObject *ue_py_struct = (ue_PyUObject *)py_struct; |
| 130 | + if (!ue_py_struct->ue_object->IsA<UStruct>()) { |
| 131 | + return PyErr_Format(PyExc_Exception, "argument is not a UStruct"); |
| 132 | + } |
| 133 | + u_struct = (UStruct *)ue_py_struct->ue_object; |
| 134 | + } |
| 135 | + |
| 136 | + UK2Node_VariableGet *node = NewObject<UK2Node_VariableGet>(graph); |
| 137 | + |
| 138 | + node->CreateNewGuid(); |
| 139 | + node->PostPlacedNewNode(); |
| 140 | + node->SetFlags(RF_Transactional); |
| 141 | + node->AllocateDefaultPins(); |
| 142 | + node->NodePosX = x; |
| 143 | + node->NodePosY = y; |
| 144 | + UEdGraphSchema_K2::ConfigureVarNode(node, FName(UTF8_TO_TCHAR(name)), u_struct, FBlueprintEditorUtils::FindBlueprintForGraph(graph)); |
| 145 | + UEdGraphSchema_K2::SetNodeMetaData(node, FNodeMetadata::DefaultGraphNode); |
| 146 | + graph->AddNode(node); |
| 147 | + |
| 148 | + PyObject *ret = (PyObject *)ue_get_python_wrapper(node); |
| 149 | + if (!ret) |
| 150 | + return PyErr_Format(PyExc_Exception, "uobject is in invalid state"); |
| 151 | + Py_INCREF(ret); |
| 152 | + return ret; |
| 153 | + |
| 154 | +} |
| 155 | + |
| 156 | +PyObject *py_ue_graph_add_node_variable_set(ue_PyUObject * self, PyObject * args) { |
| 157 | + |
| 158 | + ue_py_check(self); |
| 159 | + |
| 160 | + char *name = nullptr; |
| 161 | + PyObject *py_struct = nullptr; |
| 162 | + int x = 0; |
| 163 | + int y = 0; |
| 164 | + if (!PyArg_ParseTuple(args, "s|Oii:graph_add_node_variable_set", &name, &py_struct, &x, &y)) { |
| 165 | + return NULL; |
| 166 | + } |
| 167 | + |
| 168 | + if (!self->ue_object->IsA<UEdGraph>()) { |
| 169 | + return PyErr_Format(PyExc_Exception, "uobject is not a UEdGraph"); |
| 170 | + } |
| 171 | + |
| 172 | + UEdGraph *graph = (UEdGraph *)self->ue_object; |
| 173 | + UStruct *u_struct = nullptr; |
| 174 | + |
| 175 | + if (py_struct && py_struct != Py_None) { |
| 176 | + if (!ue_is_pyuobject(py_struct)) { |
| 177 | + return PyErr_Format(PyExc_Exception, "argument is not a UObject"); |
| 178 | + } |
| 179 | + ue_PyUObject *ue_py_struct = (ue_PyUObject *)py_struct; |
| 180 | + if (!ue_py_struct->ue_object->IsA<UStruct>()) { |
| 181 | + return PyErr_Format(PyExc_Exception, "argument is not a UStruct"); |
| 182 | + } |
| 183 | + u_struct = (UStruct *)ue_py_struct->ue_object; |
| 184 | + } |
| 185 | + |
| 186 | + UK2Node_VariableSet *node = NewObject<UK2Node_VariableSet>(graph); |
| 187 | + |
| 188 | + node->CreateNewGuid(); |
| 189 | + node->PostPlacedNewNode(); |
| 190 | + node->SetFlags(RF_Transactional); |
| 191 | + node->AllocateDefaultPins(); |
| 192 | + node->NodePosX = x; |
| 193 | + node->NodePosY = y; |
| 194 | + UEdGraphSchema_K2::ConfigureVarNode(node, FName(UTF8_TO_TCHAR(name)), u_struct, FBlueprintEditorUtils::FindBlueprintForGraph(graph)); |
| 195 | + UEdGraphSchema_K2::SetNodeMetaData(node, FNodeMetadata::DefaultGraphNode); |
| 196 | + graph->AddNode(node); |
| 197 | + |
| 198 | + PyObject *ret = (PyObject *)ue_get_python_wrapper(node); |
| 199 | + if (!ret) |
| 200 | + return PyErr_Format(PyExc_Exception, "uobject is in invalid state"); |
| 201 | + Py_INCREF(ret); |
| 202 | + return ret; |
| 203 | + |
101 | 204 | } |
102 | 205 | #endif |
0 commit comments