Compare commits
No commits in common. "c975599251c5f810dd3eb7cce800fe37bf1473bf" and "232105a89335ee775b73ae076e761eeb7c6f70a4" have entirely different histories.
c975599251
...
232105a893
|
@ -13,11 +13,10 @@ UIDrawable* UICaption::click_at(sf::Vector2f point)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void UICaption::render(sf::Vector2f offset, sf::RenderTarget& target)
|
||||
void UICaption::render(sf::Vector2f offset)
|
||||
{
|
||||
text.move(offset);
|
||||
//Resources::game->getWindow().draw(text);
|
||||
target.draw(text);
|
||||
Resources::game->getWindow().draw(text);
|
||||
text.move(-offset);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ class UICaption: public UIDrawable
|
|||
{
|
||||
public:
|
||||
sf::Text text;
|
||||
void render(sf::Vector2f, sf::RenderTarget&) override final;
|
||||
void render(sf::Vector2f) override final;
|
||||
PyObjectsEnum derived_type() override final;
|
||||
virtual UIDrawable* click_at(sf::Vector2f point) override final;
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
#include "UICaption.h"
|
||||
#include "UISprite.h"
|
||||
#include "UIGrid.h"
|
||||
#include "GameEngine.h"
|
||||
|
||||
UIDrawable::UIDrawable() { click_callable = NULL; }
|
||||
|
||||
|
@ -14,7 +13,7 @@ void UIDrawable::click_unregister()
|
|||
|
||||
void UIDrawable::render()
|
||||
{
|
||||
render(sf::Vector2f(), Resources::game->getWindow());
|
||||
render(sf::Vector2f());
|
||||
}
|
||||
|
||||
PyObject* UIDrawable::get_click(PyObject* self, void* closure) {
|
||||
|
|
|
@ -28,8 +28,7 @@ class UIDrawable
|
|||
{
|
||||
public:
|
||||
void render();
|
||||
//virtual void render(sf::Vector2f) = 0;
|
||||
virtual void render(sf::Vector2f, sf::RenderTarget&) = 0;
|
||||
virtual void render(sf::Vector2f) = 0;
|
||||
virtual PyObjectsEnum derived_type() = 0;
|
||||
|
||||
// Mouse input handling - callable object, methods to find event's destination
|
||||
|
|
|
@ -95,10 +95,6 @@ PyObject* sfVector2f_to_PyObject(sf::Vector2f vector) {
|
|||
return Py_BuildValue("(ff)", vector.x, vector.y);
|
||||
}
|
||||
|
||||
PyObject* sfVector2i_to_PyObject(sf::Vector2i vector) {
|
||||
return Py_BuildValue("(ii)", vector.x, vector.y);
|
||||
}
|
||||
|
||||
sf::Vector2f PyObject_to_sfVector2f(PyObject* obj) {
|
||||
float x, y;
|
||||
if (!PyArg_ParseTuple(obj, "ff", &x, &y)) {
|
||||
|
@ -107,14 +103,6 @@ sf::Vector2f PyObject_to_sfVector2f(PyObject* obj) {
|
|||
return sf::Vector2f(x, y);
|
||||
}
|
||||
|
||||
sf::Vector2i PyObject_to_sfVector2i(PyObject* obj) {
|
||||
int x, y;
|
||||
if (!PyArg_ParseTuple(obj, "ii", &x, &y)) {
|
||||
return sf::Vector2i(); // TODO / reconsider this default: Return default vector on parse error
|
||||
}
|
||||
return sf::Vector2i(x, y);
|
||||
}
|
||||
|
||||
// TODO - deprecate / remove this helper
|
||||
PyObject* UIGridPointState_to_PyObject(const UIGridPointState& state) {
|
||||
return PyObject_New(PyObject, (PyTypeObject*)PyObject_GetAttrString(McRFPy_API::mcrf_module, "GridPointState"));
|
||||
|
@ -137,19 +125,11 @@ PyObject* UIGridPointStateVector_to_PyList(const std::vector<UIGridPointState>&
|
|||
}
|
||||
|
||||
PyObject* UIEntity::get_position(PyUIEntityObject* self, void* closure) {
|
||||
if (reinterpret_cast<long>(closure) == 0) {
|
||||
return sfVector2f_to_PyObject(self->data->position);
|
||||
} else {
|
||||
return sfVector2i_to_PyObject(self->data->collision_pos);
|
||||
}
|
||||
return sfVector2f_to_PyObject(self->data->position);
|
||||
}
|
||||
|
||||
int UIEntity::set_position(PyUIEntityObject* self, PyObject* value, void* closure) {
|
||||
if (reinterpret_cast<long>(closure) == 0) {
|
||||
self->data->position = PyObject_to_sfVector2f(value);
|
||||
} else {
|
||||
self->data->collision_pos = PyObject_to_sfVector2i(value);
|
||||
}
|
||||
self->data->position = PyObject_to_sfVector2f(value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -178,8 +158,7 @@ PyMethodDef UIEntity::methods[] = {
|
|||
};
|
||||
|
||||
PyGetSetDef UIEntity::getsetters[] = {
|
||||
{"draw_pos", (getter)UIEntity::get_position, (setter)UIEntity::set_position, "Entity position (graphically)", (void*)0},
|
||||
{"pos", (getter)UIEntity::get_position, (setter)UIEntity::set_position, "Entity position (integer grid coordinates)", (void*)1},
|
||||
{"position", (getter)UIEntity::get_position, (setter)UIEntity::set_position, "Entity position", NULL},
|
||||
{"gridstate", (getter)UIEntity::get_gridstate, NULL, "Grid point states for the entity", NULL},
|
||||
{"sprite_number", (getter)UIEntity::get_spritenumber, (setter)UIEntity::set_spritenumber, "Sprite number (index) on the texture on the display", NULL},
|
||||
{NULL} /* Sentinel */
|
||||
|
|
|
@ -40,8 +40,7 @@ public:
|
|||
std::vector<UIGridPointState> gridstate;
|
||||
UISprite sprite;
|
||||
sf::Vector2f position; //(x,y) in grid coordinates; float for animation
|
||||
sf::Vector2i collision_pos; //(x, y) in grid coordinates: int for collision
|
||||
//void render(sf::Vector2f); //override final;
|
||||
void render(sf::Vector2f); //override final;
|
||||
|
||||
UIEntity();
|
||||
UIEntity(UIGrid&);
|
||||
|
|
|
@ -44,15 +44,14 @@ PyObjectsEnum UIFrame::derived_type()
|
|||
return PyObjectsEnum::UIFRAME;
|
||||
}
|
||||
|
||||
void UIFrame::render(sf::Vector2f offset, sf::RenderTarget& target)
|
||||
void UIFrame::render(sf::Vector2f offset)
|
||||
{
|
||||
box.move(offset);
|
||||
//Resources::game->getWindow().draw(box);
|
||||
target.draw(box);
|
||||
Resources::game->getWindow().draw(box);
|
||||
box.move(-offset);
|
||||
|
||||
for (auto drawable : *children) {
|
||||
drawable->render(offset + box.getPosition(), target);
|
||||
drawable->render(offset + box.getPosition());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ public:
|
|||
sf::RectangleShape box;
|
||||
float outline;
|
||||
std::shared_ptr<std::vector<std::shared_ptr<UIDrawable>>> children;
|
||||
void render(sf::Vector2f, sf::RenderTarget&) override final;
|
||||
void render(sf::Vector2f) override final;
|
||||
void move(sf::Vector2f);
|
||||
PyObjectsEnum derived_type() override final;
|
||||
virtual UIDrawable* click_at(sf::Vector2f point) override final;
|
||||
|
|
|
@ -32,9 +32,9 @@ UIGrid::UIGrid(int gx, int gy, std::shared_ptr<PyTexture> _ptex, sf::Vector2f _x
|
|||
void UIGrid::update() {}
|
||||
|
||||
|
||||
void UIGrid::render(sf::Vector2f offset, sf::RenderTarget& target)
|
||||
void UIGrid::render(sf::Vector2f)
|
||||
{
|
||||
output.setPosition(box.getPosition() + offset); // output sprite can move; update position when drawing
|
||||
output.setPosition(box.getPosition()); // output sprite can move; update position when drawing
|
||||
// output size can change; update size when drawing
|
||||
output.setTextureRect(
|
||||
sf::IntRect(0, 0,
|
||||
|
@ -172,8 +172,7 @@ void UIGrid::render(sf::Vector2f offset, sf::RenderTarget& target)
|
|||
|
||||
// render to window
|
||||
renderTexture.display();
|
||||
//Resources::game->getWindow().draw(output);
|
||||
target.draw(output);
|
||||
Resources::game->getWindow().draw(output);
|
||||
|
||||
}
|
||||
|
||||
|
@ -424,6 +423,22 @@ PyObject* UIGrid::get_children(PyUIGridObject* self, void* closure)
|
|||
|
||||
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 {
|
||||
|
|
|
@ -26,7 +26,7 @@ public:
|
|||
//UIGrid(int, int, IndexTexture*, float, float, float, float);
|
||||
UIGrid(int, int, std::shared_ptr<PyTexture>, sf::Vector2f, sf::Vector2f);
|
||||
void update();
|
||||
void render(sf::Vector2f, sf::RenderTarget&) override final;
|
||||
void render(sf::Vector2f) override final;
|
||||
UIGridPoint& at(int, int);
|
||||
PyObjectsEnum derived_type() override final;
|
||||
//void setSprite(int);
|
||||
|
|
|
@ -18,16 +18,14 @@ UISprite::UISprite(std::shared_ptr<PyTexture> _ptex, int _sprite_index, sf::Vect
|
|||
sprite = ptex->sprite(sprite_index, _pos, sf::Vector2f(_scale, _scale));
|
||||
}
|
||||
|
||||
/*
|
||||
void UISprite::render(sf::Vector2f offset)
|
||||
{
|
||||
sprite.move(offset);
|
||||
Resources::game->getWindow().draw(sprite);
|
||||
sprite.move(-offset);
|
||||
}
|
||||
*/
|
||||
|
||||
void UISprite::render(sf::Vector2f offset, sf::RenderTarget& target)
|
||||
void UISprite::render(sf::Vector2f offset, sf::RenderTexture& target)
|
||||
{
|
||||
sprite.move(offset);
|
||||
target.draw(sprite);
|
||||
|
|
|
@ -25,10 +25,10 @@ public:
|
|||
UISprite();
|
||||
UISprite(std::shared_ptr<PyTexture>, int, sf::Vector2f, float);
|
||||
void update();
|
||||
void render(sf::Vector2f, sf::RenderTarget&) override final;
|
||||
void render(sf::Vector2f) override final;
|
||||
virtual UIDrawable* click_at(sf::Vector2f point) override final;
|
||||
|
||||
//void render(sf::Vector2f, sf::RenderTexture&);
|
||||
void render(sf::Vector2f, sf::RenderTexture&);
|
||||
|
||||
void setPosition(sf::Vector2f);
|
||||
sf::Vector2f getPosition();
|
||||
|
|
|
@ -40,7 +40,6 @@ print("Lol, did it segfault?")
|
|||
s = mcrfpy.Sprite(25, 384+19, texture, 86, 9.0)
|
||||
# pos (LinkedVector / Vector): s.pos
|
||||
# texture (Texture): s.texture
|
||||
s.click = lambda *args, **kwargs: print("clicky", args, kwargs)
|
||||
|
||||
# Grid
|
||||
g = mcrfpy.Grid(10, 10, texture, 512+25, 384+19, 462, 346)
|
||||
|
@ -55,43 +54,6 @@ g.zoom = 2.0
|
|||
|
||||
[ui.append(d) for d in (f, c, s, g)]
|
||||
|
||||
# Entity
|
||||
e = mcrfpy.Entity(5, 5, mcrfpy.default_texture, 86)
|
||||
e.pos = e.draw_pos # TODO - sync draw/collision positions on init
|
||||
g.entities.append(e)
|
||||
import random
|
||||
def wander(*args, **kwargs):
|
||||
p = e.pos
|
||||
new_p = (p[0] + random.randint(-1, 1), p[1] + random.randint(-1, 1))
|
||||
if g.grid_size[0] >= new_p[0] >= 0 and g.grid_size[1] >= new_p[1] >= 0:
|
||||
e.pos = new_p
|
||||
#print(e.pos)
|
||||
|
||||
mcrfpy.setTimer("wander", wander, 400)
|
||||
|
||||
last_anim = None
|
||||
def anim(t, *args, **kwargs):
|
||||
global last_anim
|
||||
if last_anim is None:
|
||||
last_anim = t
|
||||
return
|
||||
duration = t - last_anim
|
||||
|
||||
entity_speed = 1 / 250 # 250 milliseconds to move one square
|
||||
if e.pos == e.draw_pos:
|
||||
return
|
||||
tx, ty = e.pos #"target" position - entity is already occupying that spot, animate them moving there.
|
||||
dx, dy = e.draw_pos #"draw" position
|
||||
newx = tx if (abs(dx - tx) < entity_speed * duration) else entity_speed * duration
|
||||
if tx < dx: newx *= -1
|
||||
newy = ty if (abs(dy - ty) < entity_speed * duration) else entity_speed * duration
|
||||
if ty < dy: newx *= -1
|
||||
|
||||
print(f"({dx}, {dy}) -> ({tx}, {ty}) = ({newx}, {newy}) ; @{entity_speed} * {duration} = {entity_speed * duration}")
|
||||
e.draw_pos = (newx, newy)
|
||||
|
||||
mcrfpy.setTimer("anim", anim, 67)
|
||||
|
||||
print("built!")
|
||||
|
||||
# tests
|
||||
|
|
Loading…
Reference in New Issue