Modify UI objects by calling mcrfpy.modMenu(m)

This commit is contained in:
John McCardle 2023-03-02 20:41:43 -05:00
parent de753713d5
commit f89896176c
2 changed files with 32 additions and 0 deletions

View File

@ -17,6 +17,9 @@ static PyMethodDef mcrfpyMethods[] = {
{"listMenus", McRFPy_API::_listMenus, METH_VARARGS, {"listMenus", McRFPy_API::_listMenus, METH_VARARGS,
"return a list of existing menus"}, "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, {"createCaption", McRFPy_API::_createCaption, METH_VARARGS,
"Create a new text caption (menu_str, text_str, fontsize, r, g, b)"}, "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; 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) { PyObject* McRFPy_API::_createCaption(PyObject* self, PyObject* args) {
const char* menukey_cstr, *text_cstr; const char* menukey_cstr, *text_cstr;
int fontsize, cr, cg, cb; int fontsize, cr, cg, cb;

View File

@ -48,6 +48,8 @@ public:
// Jank Python Method Exposures // Jank Python Method Exposures
static PyObject* _createMenu(PyObject*, PyObject*); // creates a new menu object in McRFPy_API::menus static PyObject* _createMenu(PyObject*, PyObject*); // creates a new menu object in McRFPy_API::menus
static PyObject* _listMenus(PyObject*, PyObject*); static PyObject* _listMenus(PyObject*, PyObject*);
static PyObject* _modMenu(PyObject*, PyObject*);
static PyObject* _createCaption(PyObject*, PyObject*); // calls menu.add_caption static PyObject* _createCaption(PyObject*, PyObject*); // calls menu.add_caption
static PyObject* _createButton(PyObject*, PyObject*); static PyObject* _createButton(PyObject*, PyObject*);
static PyObject* _createTexture(PyObject*, PyObject*); static PyObject* _createTexture(PyObject*, PyObject*);