Compare commits
4 Commits
break_up_u
...
master
Author | SHA1 | Date |
---|---|---|
John McCardle | 232105a893 | |
John McCardle | c2de9b08d6 | |
John McCardle | a465a9861d | |
John McCardle | ac7f7052cd |
|
@ -59,7 +59,7 @@ void GameEngine::run()
|
||||||
if (!paused)
|
if (!paused)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
currentScene()->sRender();
|
currentScene()->render();
|
||||||
currentFrame++;
|
currentFrame++;
|
||||||
frameTime = clock.restart().asSeconds();
|
frameTime = clock.restart().asSeconds();
|
||||||
fps = 1 / frameTime;
|
fps = 1 / frameTime;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "PyColor.h"
|
#include "PyColor.h"
|
||||||
|
#include "McRFPy_API.h"
|
||||||
|
|
||||||
PyGetSetDef PyColor::getsetters[] = {
|
PyGetSetDef PyColor::getsetters[] = {
|
||||||
{"r", (getter)PyColor::get_member, (setter)PyColor::set_member, "Red component", (void*)0},
|
{"r", (getter)PyColor::get_member, (setter)PyColor::set_member, "Red component", (void*)0},
|
||||||
|
@ -134,3 +135,16 @@ int PyColor::set_member(PyObject* obj, PyObject* value, void* closure)
|
||||||
// TODO
|
// TODO
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PyColorObject* PyColor::from_arg(PyObject* args)
|
||||||
|
{
|
||||||
|
auto type = (PyTypeObject*)PyObject_GetAttrString(McRFPy_API::mcrf_module, "Color");
|
||||||
|
if (PyObject_IsInstance(args, (PyObject*)type)) return (PyColorObject*)args;
|
||||||
|
auto obj = (PyColorObject*)type->tp_alloc(type, 0);
|
||||||
|
int err = init(obj, args, NULL);
|
||||||
|
if (err) {
|
||||||
|
Py_DECREF(obj);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ public:
|
||||||
static int set_member(PyObject*, PyObject*, void*);
|
static int set_member(PyObject*, PyObject*, void*);
|
||||||
|
|
||||||
static PyGetSetDef getsetters[];
|
static PyGetSetDef getsetters[];
|
||||||
|
static PyColorObject* from_arg(PyObject*);
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace mcrfpydef {
|
namespace mcrfpydef {
|
||||||
|
|
|
@ -59,7 +59,7 @@ void PyScene::doAction(std::string name, std::string type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PyScene::sRender()
|
void PyScene::render()
|
||||||
{
|
{
|
||||||
game->getWindow().clear();
|
game->getWindow().clear();
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ public:
|
||||||
PyScene(GameEngine*);
|
PyScene(GameEngine*);
|
||||||
void update() override final;
|
void update() override final;
|
||||||
void doAction(std::string, std::string) override final;
|
void doAction(std::string, std::string) override final;
|
||||||
void sRender() override final;
|
void render() override final;
|
||||||
|
|
||||||
void do_mouse_input(std::string, std::string);
|
void do_mouse_input(std::string, std::string);
|
||||||
};
|
};
|
||||||
|
|
|
@ -31,7 +31,7 @@ public:
|
||||||
//Scene();
|
//Scene();
|
||||||
Scene(GameEngine*);
|
Scene(GameEngine*);
|
||||||
virtual void update() = 0;
|
virtual void update() = 0;
|
||||||
virtual void sRender() = 0;
|
virtual void render() = 0;
|
||||||
virtual void doAction(std::string, std::string) = 0;
|
virtual void doAction(std::string, std::string) = 0;
|
||||||
bool hasAction(std::string);
|
bool hasAction(std::string);
|
||||||
bool hasAction(int);
|
bool hasAction(int);
|
||||||
|
|
|
@ -212,7 +212,7 @@ PyObject* UICaption::repr(PyUICaptionObject* self)
|
||||||
"text='" << (std::string)text.getString() << "', " <<
|
"text='" << (std::string)text.getString() << "', " <<
|
||||||
"outline=" << text.getOutlineThickness() << ", " <<
|
"outline=" << text.getOutlineThickness() << ", " <<
|
||||||
"fill_color=(" << (int)fc.r << ", " << (int)fc.g << ", " << (int)fc.b << ", " << (int)fc.a <<"), " <<
|
"fill_color=(" << (int)fc.r << ", " << (int)fc.g << ", " << (int)fc.b << ", " << (int)fc.a <<"), " <<
|
||||||
"outlinecolor=(" << (int)oc.r << ", " << (int)oc.g << ", " << (int)oc.b << ", " << (int)oc.a <<"), " <<
|
"outline_color=(" << (int)oc.r << ", " << (int)oc.g << ", " << (int)oc.b << ", " << (int)oc.a <<"), " <<
|
||||||
")>";
|
")>";
|
||||||
}
|
}
|
||||||
std::string repr_str = ss.str();
|
std::string repr_str = ss.str();
|
||||||
|
@ -222,13 +222,13 @@ PyObject* UICaption::repr(PyUICaptionObject* self)
|
||||||
int UICaption::init(PyUICaptionObject* self, PyObject* args, PyObject* kwds)
|
int UICaption::init(PyUICaptionObject* self, PyObject* args, PyObject* kwds)
|
||||||
{
|
{
|
||||||
using namespace mcrfpydef;
|
using namespace mcrfpydef;
|
||||||
static const char* keywords[] = { "x", "y", "text", "font", "fill_color", "outline_color", nullptr };
|
static const char* keywords[] = { "x", "y", "text", "font", "fill_color", "outline_color", "outline", nullptr };
|
||||||
float x = 0.0f, y = 0.0f;
|
float x = 0.0f, y = 0.0f, outline = 0.0f;
|
||||||
char* text;
|
char* text;
|
||||||
PyObject* font, fill_color, outline_color;
|
PyObject* font=NULL, *fill_color=NULL, *outline_color=NULL;
|
||||||
|
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|ffzOOO",
|
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|ffzOOOf",
|
||||||
const_cast<char**>(keywords), &x, &y, &text, &font, &fill_color, &outline_color))
|
const_cast<char**>(keywords), &x, &y, &text, &font, &fill_color, &outline_color, &outline))
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -253,8 +253,30 @@ int UICaption::init(PyUICaptionObject* self, PyObject* args, PyObject* kwds)
|
||||||
|
|
||||||
self->data->text.setPosition(sf::Vector2f(x, y));
|
self->data->text.setPosition(sf::Vector2f(x, y));
|
||||||
self->data->text.setString((std::string)text);
|
self->data->text.setString((std::string)text);
|
||||||
self->data->text.setFillColor(sf::Color(0,0,0,255));
|
self->data->text.setOutlineThickness(outline);
|
||||||
self->data->text.setOutlineColor(sf::Color(128,128,128,255));
|
if (fill_color) {
|
||||||
|
auto fc = PyColor::from_arg(fill_color);
|
||||||
|
if (!fc) {
|
||||||
|
PyErr_SetString(PyExc_TypeError, "fill_color must be mcrfpy.Color or arguments to mcrfpy.Color.__init__");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
self->data->text.setFillColor(PyColor::fromPy(fc));
|
||||||
|
//Py_DECREF(fc);
|
||||||
|
} else {
|
||||||
|
self->data->text.setFillColor(sf::Color(0,0,0,255));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (outline_color) {
|
||||||
|
auto oc = PyColor::from_arg(outline_color);
|
||||||
|
if (!oc) {
|
||||||
|
PyErr_SetString(PyExc_TypeError, "outline_color must be mcrfpy.Color or arguments to mcrfpy.Color.__init__");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
self->data->text.setOutlineColor(PyColor::fromPy(oc));
|
||||||
|
//Py_DECREF(oc);
|
||||||
|
} else {
|
||||||
|
self->data->text.setOutlineColor(sf::Color(128,128,128,255));
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,3 +163,15 @@ PyGetSetDef UIEntity::getsetters[] = {
|
||||||
{"sprite_number", (getter)UIEntity::get_spritenumber, (setter)UIEntity::set_spritenumber, "Sprite number (index) on the texture on the display", NULL},
|
{"sprite_number", (getter)UIEntity::get_spritenumber, (setter)UIEntity::set_spritenumber, "Sprite number (index) on the texture on the display", NULL},
|
||||||
{NULL} /* Sentinel */
|
{NULL} /* Sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PyObject* UIEntity::repr(PyUIEntityObject* self) {
|
||||||
|
std::ostringstream ss;
|
||||||
|
if (!self->data) ss << "<Entity (invalid internal object)>";
|
||||||
|
else {
|
||||||
|
auto ent = self->data;
|
||||||
|
ss << "<Entity (x=" << self->data->position.x << ", y=" << self->data->position.y << ", sprite_number=" << self->data->sprite.getSpriteIndex() <<
|
||||||
|
")>";
|
||||||
|
}
|
||||||
|
std::string repr_str = ss.str();
|
||||||
|
return PyUnicode_DecodeUTF8(repr_str.c_str(), repr_str.size(), "replace");
|
||||||
|
}
|
||||||
|
|
155
src/UIEntity.h
155
src/UIEntity.h
|
@ -55,148 +55,21 @@ public:
|
||||||
static int set_spritenumber(PyUIEntityObject* self, PyObject* value, void* closure);
|
static int set_spritenumber(PyUIEntityObject* self, PyObject* value, void* closure);
|
||||||
static PyMethodDef methods[];
|
static PyMethodDef methods[];
|
||||||
static PyGetSetDef getsetters[];
|
static PyGetSetDef getsetters[];
|
||||||
|
static PyObject* repr(PyUIEntityObject* self);
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace mcrfpydef {
|
namespace mcrfpydef {
|
||||||
/*
|
static PyTypeObject PyUIEntityType = {
|
||||||
//TODO: add this method to class scope; move implementation to .cpp file; reconsider for moving to "UIBase.h/.cpp"
|
//PyVarObject_HEAD_INIT(NULL, 0)
|
||||||
// TODO: sf::Vector2f convenience functions here might benefit from a PyVectorObject much like PyColorObject
|
.tp_name = "mcrfpy.Entity",
|
||||||
// Utility function to convert sf::Vector2f to PyObject*
|
.tp_basicsize = sizeof(PyUIEntityObject),
|
||||||
static PyObject* sfVector2f_to_PyObject(sf::Vector2f vector) {
|
.tp_itemsize = 0,
|
||||||
return Py_BuildValue("(ff)", vector.x, vector.y);
|
.tp_repr = (reprfunc)UIEntity::repr,
|
||||||
}
|
.tp_flags = Py_TPFLAGS_DEFAULT,
|
||||||
|
.tp_doc = "UIEntity objects",
|
||||||
//TODO: add this method to class scope; move implementation to .cpp file; reconsider for moving to "UIBase.h/.cpp"
|
.tp_methods = UIEntity::methods,
|
||||||
// Utility function to convert PyObject* to sf::Vector2f
|
.tp_getset = UIEntity::getsetters,
|
||||||
static sf::Vector2f PyObject_to_sfVector2f(PyObject* obj) {
|
.tp_init = (initproc)UIEntity::init,
|
||||||
float x, y;
|
.tp_new = PyType_GenericNew,
|
||||||
if (!PyArg_ParseTuple(obj, "ff", &x, &y)) {
|
};
|
||||||
return sf::Vector2f(); // TODO / reconsider this default: Return default vector on parse error
|
|
||||||
}
|
|
||||||
return sf::Vector2f(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: add this method to class scope; move implementation to .cpp file
|
|
||||||
// Utility function to convert UIGridPointState to PyObject*
|
|
||||||
static PyObject* UIGridPointState_to_PyObject(const UIGridPointState& state) {
|
|
||||||
PyObject* obj = PyObject_New(PyObject, &PyUIGridPointStateType);
|
|
||||||
if (!obj) return PyErr_NoMemory();
|
|
||||||
|
|
||||||
// Assuming PyUIGridPointStateObject structure has a UIGridPointState* member called 'data'
|
|
||||||
//((PyUIGridPointStateObject*)obj)->data = new UIGridPointState(state); // Copy constructor // wontimplement / feat - don't use new, get shared_ptr working
|
|
||||||
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
//TODO: add this method to class scope; move implementation to .cpp file
|
|
||||||
// Function to convert std::vector<UIGridPointState> to a Python list TODO need a PyUICollection style iterable
|
|
||||||
static PyObject* UIGridPointStateVector_to_PyList(const std::vector<UIGridPointState>& vec) {
|
|
||||||
PyObject* list = PyList_New(vec.size());
|
|
||||||
if (!list) return PyErr_NoMemory();
|
|
||||||
|
|
||||||
for (size_t i = 0; i < vec.size(); ++i) {
|
|
||||||
PyObject* obj = UIGridPointState_to_PyObject(vec[i]);
|
|
||||||
if (!obj) { // Cleanup on failure
|
|
||||||
Py_DECREF(list);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
PyList_SET_ITEM(list, i, obj); // This steals a reference to obj
|
|
||||||
}
|
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: add this method to class scope; move implementation to .cpp file
|
|
||||||
static PyObject* PyUIEntity_get_position(PyUIEntityObject* self, void* closure) {
|
|
||||||
return sfVector2f_to_PyObject(self->data->position);
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: add this method to class scope; move implementation to .cpp file
|
|
||||||
static int PyUIEntity_set_position(PyUIEntityObject* self, PyObject* value, void* closure) {
|
|
||||||
self->data->position = PyObject_to_sfVector2f(value);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: add this method to class scope; move implementation to .cpp file
|
|
||||||
static PyObject* PyUIEntity_get_gridstate(PyUIEntityObject* self, void* closure) {
|
|
||||||
// Assuming a function to convert std::vector<UIGridPointState> to PyObject* list
|
|
||||||
return UIGridPointStateVector_to_PyList(self->data->gridstate);
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: add this method to class scope; move implementation to .cpp file
|
|
||||||
static PyObject* PyUIEntity_get_spritenumber(PyUIEntityObject* self, void* closure) {
|
|
||||||
return PyLong_FromDouble(self->data->sprite.getSpriteIndex());
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: add this method to class scope; move implementation to .cpp file
|
|
||||||
static int PyUIEntity_set_spritenumber(PyUIEntityObject* self, PyObject* value, void* closure) {
|
|
||||||
int val;
|
|
||||||
if (PyLong_Check(value))
|
|
||||||
val = PyLong_AsLong(value);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
PyErr_SetString(PyExc_TypeError, "Value must be an integer.");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
//self->data->sprite.sprite_index = val;
|
|
||||||
self->data->sprite.setSpriteIndex(val); // todone - I don't like ".sprite.sprite" in this stack of UIEntity.UISprite.sf::Sprite
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: add this method to class scope; move implementation to .cpp file
|
|
||||||
|
|
||||||
static PyObject* PyUIEntity_at(PyUIEntityObject* self, PyObject* o)
|
|
||||||
{
|
|
||||||
int x, y;
|
|
||||||
if (!PyArg_ParseTuple(o, "ii", &x, &y)) {
|
|
||||||
PyErr_SetString(PyExc_TypeError, "UIEntity.at requires two integer arguments: (x, y)");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (self->data->grid == NULL) {
|
|
||||||
PyErr_SetString(PyExc_ValueError, "Entity cannot access surroundings because it is not associated with a grid");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
PyUIGridPointStateObject* obj = (PyUIGridPointStateObject*)((&PyUIGridPointStateType)->tp_alloc(&PyUIGridPointStateType, 0));
|
|
||||||
//auto target = std::static_pointer_cast<UIEntity>(target);
|
|
||||||
obj->data = &(self->data->gridstate[y + self->data->grid->grid_x * x]);
|
|
||||||
obj->grid = self->data->grid;
|
|
||||||
obj->entity = self->data;
|
|
||||||
return (PyObject*)obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//TODO: add this static array to class scope; move implementation to .cpp file
|
|
||||||
static PyMethodDef PyUIEntity_methods[] = {
|
|
||||||
{"at", (PyCFunction)UIEntity::at, METH_O},
|
|
||||||
{NULL, NULL, 0, NULL}
|
|
||||||
};
|
|
||||||
|
|
||||||
//TODO: add this static array to class scope; move implementation to .cpp file
|
|
||||||
// Define getters and setters
|
|
||||||
static PyGetSetDef PyUIEntity_getsetters[] = {
|
|
||||||
{"position", (getter)PyUIEntity_get_position, (setter)PyUIEntity_set_position, "Entity position", NULL},
|
|
||||||
{"gridstate", (getter)PyUIEntity_get_gridstate, NULL, "Grid point states for the entity", NULL},
|
|
||||||
{"sprite_number", (getter)PyUIEntity_get_spritenumber, (setter)PyUIEntity_set_spritenumber, "Sprite number (index) on the texture on the display", NULL},
|
|
||||||
{NULL} // Sentinel
|
|
||||||
};
|
|
||||||
|
|
||||||
//TODO: add this method to class scope; forward declaration not required after .h/.cpp split
|
|
||||||
//static int PyUIEntity_init(PyUIEntityObject*, PyObject*, PyObject*); // forward declare
|
|
||||||
|
|
||||||
*/
|
|
||||||
// Define the PyTypeObject for UIEntity
|
|
||||||
static PyTypeObject PyUIEntityType = {
|
|
||||||
//PyVarObject_HEAD_INIT(NULL, 0)
|
|
||||||
.tp_name = "mcrfpy.Entity",
|
|
||||||
.tp_basicsize = sizeof(PyUIEntityObject),
|
|
||||||
.tp_itemsize = 0,
|
|
||||||
// Methods omitted for brevity
|
|
||||||
.tp_flags = Py_TPFLAGS_DEFAULT,
|
|
||||||
.tp_doc = "UIEntity objects",
|
|
||||||
.tp_methods = UIEntity::methods,
|
|
||||||
.tp_getset = UIEntity::getsetters,
|
|
||||||
.tp_init = (initproc)UIEntity::init,
|
|
||||||
.tp_new = PyType_GenericNew,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -225,7 +225,7 @@ PyObject* UIFrame::repr(PyUIFrameObject* self)
|
||||||
auto box = self->data->box;
|
auto box = self->data->box;
|
||||||
auto fc = box.getFillColor();
|
auto fc = box.getFillColor();
|
||||||
auto oc = box.getOutlineColor();
|
auto oc = box.getOutlineColor();
|
||||||
ss << "<Frame (x=" << box.getPosition().x << ", y=" << box.getPosition().y << ", x=" <<
|
ss << "<Frame (x=" << box.getPosition().x << ", y=" << box.getPosition().y << ", w=" <<
|
||||||
box.getSize().x << ", w=" << box.getSize().y << ", " <<
|
box.getSize().x << ", w=" << box.getSize().y << ", " <<
|
||||||
"outline=" << box.getOutlineThickness() << ", " <<
|
"outline=" << box.getOutlineThickness() << ", " <<
|
||||||
"fill_color=(" << (int)fc.r << ", " << (int)fc.g << ", " << (int)fc.b << ", " << (int)fc.a <<"), " <<
|
"fill_color=(" << (int)fc.r << ", " << (int)fc.g << ", " << (int)fc.b << ", " << (int)fc.a <<"), " <<
|
||||||
|
|
|
@ -45,9 +45,6 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace mcrfpydef {
|
namespace mcrfpydef {
|
||||||
//TODO: add this method to class scope; move implementation to .cpp file
|
|
||||||
|
|
||||||
|
|
||||||
static PyTypeObject PyUIFrameType = {
|
static PyTypeObject PyUIFrameType = {
|
||||||
//PyVarObject_HEAD_INIT(NULL, 0)
|
//PyVarObject_HEAD_INIT(NULL, 0)
|
||||||
.tp_name = "mcrfpy.Frame",
|
.tp_name = "mcrfpy.Frame",
|
||||||
|
|
|
@ -421,6 +421,37 @@ PyObject* UIGrid::get_children(PyUIGridObject* self, void* closure)
|
||||||
return (PyObject*)o;
|
return (PyObject*)o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PyObject* UIGrid::repr(PyUIGridObject* self)
|
||||||
|
{
|
||||||
|
|
||||||
|
// if (member_ptr == 0) // x
|
||||||
|
// self->data->box.setPosition(val, self->data->box.getPosition().y);
|
||||||
|
// else if (member_ptr == 1) // y
|
||||||
|
// self->data->box.setPosition(self->data->box.getPosition().x, val);
|
||||||
|
// else if (member_ptr == 2) // w
|
||||||
|
// self->data->box.setSize(sf::Vector2f(val, self->data->box.getSize().y));
|
||||||
|
// else if (member_ptr == 3) // h
|
||||||
|
// self->data->box.setSize(sf::Vector2f(self->data->box.getSize().x, val));
|
||||||
|
// else if (member_ptr == 4) // center_x
|
||||||
|
// self->data->center_x = val;
|
||||||
|
// else if (member_ptr == 5) // center_y
|
||||||
|
// self->data->center_y = val;
|
||||||
|
// else if (member_ptr == 6) // zoom
|
||||||
|
// self->data->zoom = val;
|
||||||
|
|
||||||
|
std::ostringstream ss;
|
||||||
|
if (!self->data) ss << "<Grid (invalid internal object)>";
|
||||||
|
else {
|
||||||
|
auto grid = self->data;
|
||||||
|
auto box = grid->box;
|
||||||
|
ss << "<Grid (x=" << box.getPosition().x << ", y=" << box.getPosition().y << ", w=" << box.getSize().x << ", h=" << box.getSize().y << ", " <<
|
||||||
|
"center=(" << grid->center_x << ", " << grid->center_y << "), zoom=" << grid->zoom <<
|
||||||
|
")>";
|
||||||
|
}
|
||||||
|
std::string repr_str = ss.str();
|
||||||
|
return PyUnicode_DecodeUTF8(repr_str.c_str(), repr_str.size(), "replace");
|
||||||
|
}
|
||||||
|
|
||||||
/* // TODO standard pointer would need deleted, but I opted for a shared pointer. tp_dealloc currently not even defined in the PyTypeObject
|
/* // TODO standard pointer would need deleted, but I opted for a shared pointer. tp_dealloc currently not even defined in the PyTypeObject
|
||||||
void PyUIGrid_dealloc(PyUIGridObject* self) {
|
void PyUIGrid_dealloc(PyUIGridObject* self) {
|
||||||
delete self->data; // Clean up the allocated UIGrid object
|
delete self->data; // Clean up the allocated UIGrid object
|
||||||
|
|
|
@ -58,6 +58,7 @@ public:
|
||||||
static PyMethodDef methods[];
|
static PyMethodDef methods[];
|
||||||
static PyGetSetDef getsetters[];
|
static PyGetSetDef getsetters[];
|
||||||
static PyObject* get_children(PyUIGridObject* self, void* closure);
|
static PyObject* get_children(PyUIGridObject* self, void* closure);
|
||||||
|
static PyObject* repr(PyUIGridObject* self);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -97,7 +98,6 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace mcrfpydef {
|
namespace mcrfpydef {
|
||||||
|
|
||||||
static PyTypeObject PyUIGridType = {
|
static PyTypeObject PyUIGridType = {
|
||||||
//PyVarObject_HEAD_INIT(NULL, 0)
|
//PyVarObject_HEAD_INIT(NULL, 0)
|
||||||
.tp_name = "mcrfpy.Grid",
|
.tp_name = "mcrfpy.Grid",
|
||||||
|
@ -110,7 +110,7 @@ namespace mcrfpydef {
|
||||||
// Py_TYPE(self)->tp_free(self);
|
// Py_TYPE(self)->tp_free(self);
|
||||||
//},
|
//},
|
||||||
//TODO - PyUIGrid REPR def:
|
//TODO - PyUIGrid REPR def:
|
||||||
// .tp_repr = (reprfunc)UIGrid::repr,
|
.tp_repr = (reprfunc)UIGrid::repr,
|
||||||
//.tp_hash = NULL,
|
//.tp_hash = NULL,
|
||||||
//.tp_iter
|
//.tp_iter
|
||||||
//.tp_iternext
|
//.tp_iternext
|
||||||
|
|
|
@ -98,6 +98,19 @@ PyGetSetDef UIGridPoint::getsetters[] = {
|
||||||
{NULL} /* Sentinel */
|
{NULL} /* Sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PyObject* UIGridPoint::repr(PyUIGridPointObject* self) {
|
||||||
|
std::ostringstream ss;
|
||||||
|
if (!self->data) ss << "<GridPoint (invalid internal object)>";
|
||||||
|
else {
|
||||||
|
auto gp = self->data;
|
||||||
|
ss << "<GridPoint (walkable=" << (gp->walkable ? "True" : "False") << ", transparent=" << (gp->transparent ? "True" : "False") <<
|
||||||
|
", tilesprite=" << gp->tilesprite << ", tile_overlay=" << gp->tile_overlay << ", uisprite=" << gp->uisprite <<
|
||||||
|
")>";
|
||||||
|
}
|
||||||
|
std::string repr_str = ss.str();
|
||||||
|
return PyUnicode_DecodeUTF8(repr_str.c_str(), repr_str.size(), "replace");
|
||||||
|
}
|
||||||
|
|
||||||
PyObject* UIGridPointState::get_bool_member(PyUIGridPointStateObject* self, void* closure) {
|
PyObject* UIGridPointState::get_bool_member(PyUIGridPointStateObject* self, void* closure) {
|
||||||
if (reinterpret_cast<long>(closure) == 0) { // visible
|
if (reinterpret_cast<long>(closure) == 0) { // visible
|
||||||
return PyBool_FromLong(self->data->visible);
|
return PyBool_FromLong(self->data->visible);
|
||||||
|
@ -132,3 +145,14 @@ PyGetSetDef UIGridPointState::getsetters[] = {
|
||||||
{NULL} /* Sentinel */
|
{NULL} /* Sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PyObject* UIGridPointState::repr(PyUIGridPointStateObject* self) {
|
||||||
|
std::ostringstream ss;
|
||||||
|
if (!self->data) ss << "<GridPointState (invalid internal object)>";
|
||||||
|
else {
|
||||||
|
auto gps = self->data;
|
||||||
|
ss << "<GridPointState (visible=" << (gps->visible ? "True" : "False") << ", discovered=" << (gps->discovered ? "True" : "False") <<
|
||||||
|
")>";
|
||||||
|
}
|
||||||
|
std::string repr_str = ss.str();
|
||||||
|
return PyUnicode_DecodeUTF8(repr_str.c_str(), repr_str.size(), "replace");
|
||||||
|
}
|
||||||
|
|
|
@ -49,6 +49,7 @@ public:
|
||||||
static int set_bool_member(PyUIGridPointObject* self, PyObject* value, void* closure);
|
static int set_bool_member(PyUIGridPointObject* self, PyObject* value, void* closure);
|
||||||
static PyObject* get_bool_member(PyUIGridPointObject* self, void* closure);
|
static PyObject* get_bool_member(PyUIGridPointObject* self, void* closure);
|
||||||
static int set_color(PyUIGridPointObject* self, PyObject* value, void* closure);
|
static int set_color(PyUIGridPointObject* self, PyObject* value, void* closure);
|
||||||
|
static PyObject* repr(PyUIGridPointObject* self);
|
||||||
};
|
};
|
||||||
|
|
||||||
// UIGridPointState - entity-specific info for each cell
|
// UIGridPointState - entity-specific info for each cell
|
||||||
|
@ -60,33 +61,32 @@ public:
|
||||||
static PyObject* get_bool_member(PyUIGridPointStateObject* self, void* closure);
|
static PyObject* get_bool_member(PyUIGridPointStateObject* self, void* closure);
|
||||||
static int set_bool_member(PyUIGridPointStateObject* self, PyObject* value, void* closure);
|
static int set_bool_member(PyUIGridPointStateObject* self, PyObject* value, void* closure);
|
||||||
static PyGetSetDef getsetters[];
|
static PyGetSetDef getsetters[];
|
||||||
|
static PyObject* repr(PyUIGridPointStateObject* self);
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace mcrfpydef {
|
namespace mcrfpydef {
|
||||||
|
static PyTypeObject PyUIGridPointType = {
|
||||||
|
//PyVarObject_HEAD_INIT(NULL, 0)
|
||||||
|
.tp_name = "mcrfpy.GridPoint",
|
||||||
|
.tp_basicsize = sizeof(PyUIGridPointObject),
|
||||||
|
.tp_itemsize = 0,
|
||||||
|
.tp_repr = (reprfunc)UIGridPoint::repr,
|
||||||
|
.tp_flags = Py_TPFLAGS_DEFAULT,
|
||||||
|
.tp_doc = "UIGridPoint object",
|
||||||
|
.tp_getset = UIGridPoint::getsetters,
|
||||||
|
//.tp_init = (initproc)PyUIGridPoint_init, // TODO Define the init function
|
||||||
|
.tp_new = PyType_GenericNew,
|
||||||
|
};
|
||||||
|
|
||||||
static PyTypeObject PyUIGridPointType = {
|
static PyTypeObject PyUIGridPointStateType = {
|
||||||
//PyVarObject_HEAD_INIT(NULL, 0)
|
//PyVarObject_HEAD_INIT(NULL, 0)
|
||||||
.tp_name = "mcrfpy.GridPoint",
|
.tp_name = "mcrfpy.GridPointState",
|
||||||
.tp_basicsize = sizeof(PyUIGridPointObject),
|
.tp_basicsize = sizeof(PyUIGridPointStateObject),
|
||||||
.tp_itemsize = 0,
|
.tp_itemsize = 0,
|
||||||
// Methods omitted for brevity
|
.tp_repr = (reprfunc)UIGridPointState::repr,
|
||||||
.tp_flags = Py_TPFLAGS_DEFAULT,
|
.tp_flags = Py_TPFLAGS_DEFAULT,
|
||||||
.tp_doc = "UIGridPoint object",
|
.tp_doc = "UIGridPointState object", // TODO: Add PyUIGridPointState tp_init
|
||||||
.tp_getset = UIGridPoint::getsetters,
|
.tp_getset = UIGridPointState::getsetters,
|
||||||
//.tp_init = (initproc)PyUIGridPoint_init, // TODO Define the init function
|
.tp_new = PyType_GenericNew,
|
||||||
.tp_new = PyType_GenericNew,
|
};
|
||||||
};
|
|
||||||
|
|
||||||
static PyTypeObject PyUIGridPointStateType = {
|
|
||||||
//PyVarObject_HEAD_INIT(NULL, 0)
|
|
||||||
.tp_name = "mcrfpy.GridPointState",
|
|
||||||
.tp_basicsize = sizeof(PyUIGridPointStateObject),
|
|
||||||
.tp_itemsize = 0,
|
|
||||||
// Methods omitted for brevity
|
|
||||||
.tp_flags = Py_TPFLAGS_DEFAULT,
|
|
||||||
.tp_doc = "UIGridPointState object", // TODO: Add PyUIGridPointState tp_init
|
|
||||||
.tp_getset = UIGridPointState::getsetters,
|
|
||||||
.tp_new = PyType_GenericNew,
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,14 +55,7 @@ public:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//typedef struct {
|
|
||||||
// PyObject_HEAD
|
|
||||||
// std::shared_ptr<UISprite> data;
|
|
||||||
//} PyUISpriteObject;
|
|
||||||
|
|
||||||
namespace mcrfpydef {
|
namespace mcrfpydef {
|
||||||
|
|
||||||
|
|
||||||
static PyTypeObject PyUISpriteType = {
|
static PyTypeObject PyUISpriteType = {
|
||||||
//PyVarObject_HEAD_INIT(NULL, 0)
|
//PyVarObject_HEAD_INIT(NULL, 0)
|
||||||
.tp_name = "mcrfpy.Sprite",
|
.tp_name = "mcrfpy.Sprite",
|
||||||
|
|
|
@ -154,7 +154,7 @@ void UITestScene::doAction(std::string name, std::string type)
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void UITestScene::sRender()
|
void UITestScene::render()
|
||||||
{
|
{
|
||||||
game->getWindow().clear();
|
game->getWindow().clear();
|
||||||
game->getWindow().draw(text);
|
game->getWindow().draw(text);
|
||||||
|
|
|
@ -18,5 +18,5 @@ public:
|
||||||
UITestScene(GameEngine*);
|
UITestScene(GameEngine*);
|
||||||
void update() override final;
|
void update() override final;
|
||||||
void doAction(std::string, std::string) override final;
|
void doAction(std::string, std::string) override final;
|
||||||
void sRender() override final;
|
void render() override final;
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,18 +14,23 @@ ui = mcrfpy.sceneUI("pytest")
|
||||||
|
|
||||||
# Frame
|
# Frame
|
||||||
f = mcrfpy.Frame(25, 19, 462, 346, fill_color=(255, 92, 92))
|
f = mcrfpy.Frame(25, 19, 462, 346, fill_color=(255, 92, 92))
|
||||||
|
print("Frame alive")
|
||||||
# fill (LinkedColor / Color): f.fill_color
|
# fill (LinkedColor / Color): f.fill_color
|
||||||
# outline (LinkedColor / Color): f.outline_color
|
# outline (LinkedColor / Color): f.outline_color
|
||||||
# pos (LinkedVector / Vector): f.pos
|
# pos (LinkedVector / Vector): f.pos
|
||||||
# size (LinkedVector / Vector): f.size
|
# size (LinkedVector / Vector): f.size
|
||||||
|
|
||||||
# Caption
|
# Caption
|
||||||
c = mcrfpy.Caption(512+25, 19, "Hi.", font)
|
print("Caption attempt w/ fill_color:")
|
||||||
|
#c = mcrfpy.Caption(512+25, 19, "Hi.", font)
|
||||||
|
#c = mcrfpy.Caption(512+25, 19, "Hi.", font, fill_color=(255, 128, 128))
|
||||||
|
c = mcrfpy.Caption(512+25, 19, "Hi.", font, fill_color=mcrfpy.Color(255, 128, 128), outline_color=(128, 255, 128))
|
||||||
|
print("Caption alive")
|
||||||
# fill (LinkedColor / Color): c.fill_color
|
# fill (LinkedColor / Color): c.fill_color
|
||||||
#color_val = c.fill_color
|
#color_val = c.fill_color
|
||||||
print(c.fill_color)
|
print(c.fill_color)
|
||||||
print("Set a fill color")
|
#print("Set a fill color")
|
||||||
c.fill_color = (255, 255, 255)
|
#c.fill_color = (255, 255, 255)
|
||||||
print("Lol, did it segfault?")
|
print("Lol, did it segfault?")
|
||||||
# outline (LinkedColor / Color): c.outline_color
|
# outline (LinkedColor / Color): c.outline_color
|
||||||
# font (Font): c.font
|
# font (Font): c.font
|
||||||
|
|
Loading…
Reference in New Issue