From f89896176c3bff4075210684db98579d7c9faefb Mon Sep 17 00:00:00 2001 From: John McCardle Date: Thu, 2 Mar 2023 20:41:43 -0500 Subject: [PATCH] Modify UI objects by calling mcrfpy.modMenu(m) --- src/McRFPy_API.cpp | 30 ++++++++++++++++++++++++++++++ src/McRFPy_API.h | 2 ++ 2 files changed, 32 insertions(+) diff --git a/src/McRFPy_API.cpp b/src/McRFPy_API.cpp index 4b80664..c96216c 100644 --- a/src/McRFPy_API.cpp +++ b/src/McRFPy_API.cpp @@ -17,6 +17,9 @@ static PyMethodDef mcrfpyMethods[] = { {"listMenus", McRFPy_API::_listMenus, METH_VARARGS, "return a list of existing menus"}, + {"modMenu", McRFPy_API::_modMenu, METH_VARARGS, + "call with a UIMenu object to update all fields"}, + {"createCaption", McRFPy_API::_createCaption, METH_VARARGS, "Create a new text caption (menu_str, text_str, fontsize, r, g, b)"}, @@ -275,6 +278,33 @@ PyObject* McRFPy_API::_listMenus(PyObject*, PyObject*) { return menulist; } +PyObject* McRFPy_API::_modMenu(PyObject* self, PyObject* args) { + PyObject* o; + if (!PyArg_ParseTuple(args, "O", &o)) return NULL; + std::string title = PyUnicode_AsUTF8(PyObject_GetAttrString(o, "title")); + int x = PyLong_AsLong(PyObject_GetAttrString(o, "x")); + int y = PyLong_AsLong(PyObject_GetAttrString(o, "y")); + int w = PyLong_AsLong(PyObject_GetAttrString(o, "w")); + int h = PyLong_AsLong(PyObject_GetAttrString(o, "h")); + PyObject* bgtuple = PyObject_GetAttrString(o, "bgcolor"); + auto bgcolor = sf::Color( + PyLong_AsLong(PyTuple_GetItem(bgtuple, 0)), + PyLong_AsLong(PyTuple_GetItem(bgtuple, 1)), + PyLong_AsLong(PyTuple_GetItem(bgtuple, 2)) + ); + bool visible = PyObject_IsTrue(PyObject_GetAttrString(o, "visible")); + + auto menu = menus[title]; + if (menu == NULL) return NULL; + menu->box.setPosition(sf::Vector2f(x, y)); + menu->box.setSize(sf::Vector2f(w, h)); + menu->box.setFillColor(bgcolor); + menu->visible = visible; + + Py_INCREF(Py_None); + return Py_None; +} + PyObject* McRFPy_API::_createCaption(PyObject* self, PyObject* args) { const char* menukey_cstr, *text_cstr; int fontsize, cr, cg, cb; diff --git a/src/McRFPy_API.h b/src/McRFPy_API.h index ecff7b3..45c675f 100644 --- a/src/McRFPy_API.h +++ b/src/McRFPy_API.h @@ -48,6 +48,8 @@ public: // Jank Python Method Exposures static PyObject* _createMenu(PyObject*, PyObject*); // creates a new menu object in McRFPy_API::menus static PyObject* _listMenus(PyObject*, PyObject*); + static PyObject* _modMenu(PyObject*, PyObject*); + static PyObject* _createCaption(PyObject*, PyObject*); // calls menu.add_caption static PyObject* _createButton(PyObject*, PyObject*); static PyObject* _createTexture(PyObject*, PyObject*);