|
| 1 | +#include "UnrealEnginePythonPrivatePCH.h" |
| 2 | + |
| 3 | + |
| 4 | +PyObject *py_ue_is_input_key_down(ue_PyUObject *self, PyObject * args) { |
| 5 | + |
| 6 | + ue_py_check(self); |
| 7 | + |
| 8 | + char *key; |
| 9 | + if (!PyArg_ParseTuple(args, "s:is_input_key_down", &key)) { |
| 10 | + return NULL; |
| 11 | + } |
| 12 | + |
| 13 | + UWorld *world = ue_get_uworld(self); |
| 14 | + if (!world) |
| 15 | + return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject"); |
| 16 | + |
| 17 | + APlayerController *controller = world->GetFirstPlayerController(); |
| 18 | + |
| 19 | + if (controller->IsInputKeyDown(key)) { |
| 20 | + Py_INCREF(Py_True); |
| 21 | + return Py_True; |
| 22 | + } |
| 23 | + |
| 24 | + Py_INCREF(Py_False); |
| 25 | + return Py_False; |
| 26 | +} |
| 27 | + |
| 28 | +PyObject *py_ue_enable_input(ue_PyUObject *self, PyObject * args) { |
| 29 | + |
| 30 | + ue_py_check(self); |
| 31 | + |
| 32 | + /* |
| 33 | + TODO manage controller index |
| 34 | + }*/ |
| 35 | + |
| 36 | + UWorld *world = ue_get_uworld(self); |
| 37 | + if (!world) |
| 38 | + return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject"); |
| 39 | + |
| 40 | + APlayerController *controller = world->GetFirstPlayerController(); |
| 41 | + if (!controller) |
| 42 | + return PyErr_Format(PyExc_Exception, "no player controller available"); |
| 43 | + |
| 44 | + if (self->ue_object->IsA<AActor>()) { |
| 45 | + ((AActor *)self->ue_object)->EnableInput(controller); |
| 46 | + } |
| 47 | + else if (self->ue_object->IsA<UActorComponent>()) { |
| 48 | + ((UActorComponent *)self->ue_object)->GetOwner()->EnableInput(controller); |
| 49 | + } |
| 50 | + else { |
| 51 | + return PyErr_Format(PyExc_Exception, "uobject is not an actor or a component"); |
| 52 | + } |
| 53 | + |
| 54 | + Py_INCREF(Py_None); |
| 55 | + return Py_None; |
| 56 | + |
| 57 | +} |
| 58 | + |
| 59 | +PyObject *py_ue_get_input_axis(ue_PyUObject *self, PyObject * args) { |
| 60 | + |
| 61 | + ue_py_check(self); |
| 62 | + |
| 63 | + char *axis_name; |
| 64 | + if (!PyArg_ParseTuple(args, "s:get_input_axis", &axis_name)) { |
| 65 | + return NULL; |
| 66 | + } |
| 67 | + |
| 68 | + UInputComponent *input = nullptr; |
| 69 | + |
| 70 | + if (self->ue_object->IsA<AActor>()) { |
| 71 | + input = ((AActor *)self->ue_object)->InputComponent; |
| 72 | + } |
| 73 | + else if (self->ue_object->IsA<UActorComponent>()) { |
| 74 | + input = ((UActorComponent *)self->ue_object)->GetOwner()->InputComponent; |
| 75 | + } |
| 76 | + else { |
| 77 | + return PyErr_Format(PyExc_Exception, "uobject is not an actor or a component"); |
| 78 | + } |
| 79 | + |
| 80 | + if (!input) { |
| 81 | + return PyErr_Format(PyExc_Exception, "no input manager for this uobject"); |
| 82 | + } |
| 83 | + |
| 84 | + return Py_BuildValue("f", input->GetAxisValue(FName(UTF8_TO_TCHAR(axis_name)))); |
| 85 | + |
| 86 | +} |
| 87 | + |
| 88 | +PyObject *py_ue_bind_input_axis(ue_PyUObject *self, PyObject * args) { |
| 89 | + |
| 90 | + ue_py_check(self); |
| 91 | + |
| 92 | + char *axis_name; |
| 93 | + if (!PyArg_ParseTuple(args, "s:bind_input_axis", &axis_name)) { |
| 94 | + return NULL; |
| 95 | + } |
| 96 | + |
| 97 | + UInputComponent *input = nullptr; |
| 98 | + |
| 99 | + if (self->ue_object->IsA<AActor>()) { |
| 100 | + input = ((AActor *)self->ue_object)->InputComponent; |
| 101 | + } |
| 102 | + else if (self->ue_object->IsA<UActorComponent>()) { |
| 103 | + input = ((UActorComponent *)self->ue_object)->GetOwner()->InputComponent; |
| 104 | + } |
| 105 | + else { |
| 106 | + return PyErr_Format(PyExc_Exception, "uobject is not an actor or a component"); |
| 107 | + } |
| 108 | + |
| 109 | + if (!input) { |
| 110 | + return PyErr_Format(PyExc_Exception, "no input manager for this uobject"); |
| 111 | + } |
| 112 | + |
| 113 | + input->BindAxis(FName(UTF8_TO_TCHAR(axis_name))); |
| 114 | + |
| 115 | + Py_INCREF(Py_None); |
| 116 | + return Py_None; |
| 117 | + |
| 118 | +} |
| 119 | + |
| 120 | +PyObject *py_ue_show_mouse_cursor(ue_PyUObject * self, PyObject * args) { |
| 121 | + |
| 122 | + ue_py_check(self); |
| 123 | + |
| 124 | + bool enabled = true; |
| 125 | + |
| 126 | + PyObject *is_true = NULL; |
| 127 | + if (!PyArg_ParseTuple(args, "|O:show_mouse_cursor", &is_true)) { |
| 128 | + return NULL; |
| 129 | + } |
| 130 | + |
| 131 | + if (is_true && !PyObject_IsTrue(is_true)) |
| 132 | + enabled = false; |
| 133 | + |
| 134 | + UWorld *world = ue_get_uworld(self); |
| 135 | + if (!world) |
| 136 | + return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject"); |
| 137 | + |
| 138 | + APlayerController *controller = world->GetFirstPlayerController(); |
| 139 | + if (controller) |
| 140 | + controller->bShowMouseCursor = enabled; |
| 141 | + |
| 142 | + Py_INCREF(Py_None); |
| 143 | + return Py_None; |
| 144 | +} |
| 145 | + |
| 146 | +PyObject *py_ue_enable_click_events(ue_PyUObject * self, PyObject * args) { |
| 147 | + |
| 148 | + ue_py_check(self); |
| 149 | + |
| 150 | + bool enabled = true; |
| 151 | + |
| 152 | + PyObject *is_true = NULL; |
| 153 | + if (!PyArg_ParseTuple(args, "|O:enable_click_events", &is_true)) { |
| 154 | + return NULL; |
| 155 | + } |
| 156 | + |
| 157 | + if (is_true && !PyObject_IsTrue(is_true)) |
| 158 | + enabled = false; |
| 159 | + |
| 160 | + UWorld *world = ue_get_uworld(self); |
| 161 | + if (!world) |
| 162 | + return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject"); |
| 163 | + |
| 164 | + APlayerController *controller = world->GetFirstPlayerController(); |
| 165 | + if (controller) |
| 166 | + controller->bEnableClickEvents = enabled; |
| 167 | + |
| 168 | + Py_INCREF(Py_None); |
| 169 | + return Py_None; |
| 170 | +} |
| 171 | + |
| 172 | +PyObject *py_ue_enable_mouse_over_events(ue_PyUObject * self, PyObject * args) { |
| 173 | + |
| 174 | + ue_py_check(self); |
| 175 | + |
| 176 | + bool enabled = true; |
| 177 | + |
| 178 | + PyObject *is_true = NULL; |
| 179 | + if (!PyArg_ParseTuple(args, "|O:enable_mouse_over_events", &is_true)) { |
| 180 | + return NULL; |
| 181 | + } |
| 182 | + |
| 183 | + if (is_true && !PyObject_IsTrue(is_true)) |
| 184 | + enabled = false; |
| 185 | + |
| 186 | + UWorld *world = ue_get_uworld(self); |
| 187 | + if (!world) |
| 188 | + return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject"); |
| 189 | + |
| 190 | + |
| 191 | + APlayerController *controller = world->GetFirstPlayerController(); |
| 192 | + if (controller) |
| 193 | + controller->bEnableMouseOverEvents = enabled; |
| 194 | + |
| 195 | + Py_INCREF(Py_None); |
| 196 | + return Py_None; |
| 197 | +} |
| 198 | + |
| 199 | + |
| 200 | + |
| 201 | + |
| 202 | + |
0 commit comments