Test animation now moves the entire UIMenu object (and children)
This commit is contained in:
parent
c551c721ce
commit
fedfcd46a3
|
@ -108,12 +108,12 @@ bool Animation::isDone() {
|
||||||
|
|
||||||
namespace animation_template_implementations {
|
namespace animation_template_implementations {
|
||||||
// instantiate to compile concrete templates
|
// instantiate to compile concrete templates
|
||||||
LerpAnimation<sf::Vector2f> implement_vector2f;
|
//LerpAnimation<sf::Vector2f> implement_vector2f;
|
||||||
|
|
||||||
auto implement_v2f_const = LerpAnimation<sf::Vector2<float>>(4.0, sf::Vector2<float>(), sf::Vector2f(1,1), [](){}, [](sf::Vector2f v){}, false);
|
auto implement_v2f_const = LerpAnimation<sf::Vector2<float>>(4.0, sf::Vector2<float>(), sf::Vector2f(1,1), [](){}, [](sf::Vector2f v){}, false);
|
||||||
LerpAnimation<sf::Vector2i> implement_vector2i;
|
//LerpAnimation<sf::Vector2i> implement_vector2i;
|
||||||
LerpAnimation<int> implment_int;
|
//LerpAnimation<int> implment_int;
|
||||||
LerpAnimation<std::string> implment_string;
|
//LerpAnimation<std::string> implment_string;
|
||||||
LerpAnimation<float> implement_float;
|
//LerpAnimation<float> implement_float;
|
||||||
DiscreteAnimation<int> implement_int_discrete;
|
//DiscreteAnimation<int> implement_int_discrete;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ public:
|
||||||
//Animation(float, T, T*, std::function<void()>, bool); // lerp
|
//Animation(float, T, T*, std::function<void()>, bool); // lerp
|
||||||
//Animation(float, std::vector<T>, T*, std::function<void()>, bool); // discrete
|
//Animation(float, std::vector<T>, T*, std::function<void()>, bool); // discrete
|
||||||
Animation(float, std::function<void()>, bool);
|
Animation(float, std::function<void()>, bool);
|
||||||
Animation() {};
|
//Animation() {};
|
||||||
virtual void step(float) = 0;
|
virtual void step(float) = 0;
|
||||||
virtual void cancel() = 0;
|
virtual void cancel() = 0;
|
||||||
bool isDone();
|
bool isDone();
|
||||||
|
@ -27,7 +27,7 @@ class LerpAnimation: public Animation
|
||||||
public:
|
public:
|
||||||
~LerpAnimation() { cancel(); }
|
~LerpAnimation() { cancel(); }
|
||||||
LerpAnimation(float, T, T, std::function<void()>, std::function<void(T)>, bool);
|
LerpAnimation(float, T, T, std::function<void()>, std::function<void(T)>, bool);
|
||||||
LerpAnimation() {};
|
//LerpAnimation() {};
|
||||||
void step(float) override final;
|
void step(float) override final;
|
||||||
void cancel() override final;
|
void cancel() override final;
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,6 +26,9 @@ public:
|
||||||
void setTextColor(sf::Color c) { caption.setFillColor(c); }
|
void setTextColor(sf::Color c) { caption.setFillColor(c); }
|
||||||
void render(sf::RenderWindow & window);
|
void render(sf::RenderWindow & window);
|
||||||
auto contains(sf::Vector2i p) { return rect.getGlobalBounds().contains(p.x, p.y); }
|
auto contains(sf::Vector2i p) { return rect.getGlobalBounds().contains(p.x, p.y); }
|
||||||
|
auto contains(sf::Vector2f rel, sf::Vector2i p) {
|
||||||
|
return rect.getGlobalBounds().contains(p.x - rel.x, p.y - rel.y);
|
||||||
|
}
|
||||||
auto getAction() { return action; }
|
auto getAction() { return action; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -639,7 +639,12 @@ PyObject* McRFPy_API::_createAnimation(PyObject *self, PyObject *args) {
|
||||||
sf::Vector2f(100, 100),
|
sf::Vector2f(100, 100),
|
||||||
McRFPy_API::menus[menu_key]->box.getPosition(),
|
McRFPy_API::menus[menu_key]->box.getPosition(),
|
||||||
[](){McRFPy_API::executePyString("print('animation callback')");},
|
[](){McRFPy_API::executePyString("print('animation callback')");},
|
||||||
[=](sf::Vector2f v) {std::cout << "write lambda!" << std::endl; McRFPy_API::menus[menu_key]->box.setPosition(v); std::cout << "Position set to" << McRFPy_API::menus[menu_key]->box.getPosition().x << ", " << McRFPy_API::menus[menu_key]->box.getPosition().y << std::endl;},
|
[=](sf::Vector2f v) {
|
||||||
|
std::cout << "write lambda!" << std::endl;
|
||||||
|
McRFPy_API::menus[menu_key]->box.setPosition(v);
|
||||||
|
std::cout << "Position set to" << McRFPy_API::menus[menu_key]->box.getPosition().x
|
||||||
|
<< ", " << McRFPy_API::menus[menu_key]->box.getPosition().y << std::endl;
|
||||||
|
},
|
||||||
false)
|
false)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ PythonScene::PythonScene(GameEngine* g, std::string pymodule)
|
||||||
}
|
}
|
||||||
|
|
||||||
void PythonScene::animate() {
|
void PythonScene::animate() {
|
||||||
std::cout << "Number of animations: " << McRFPy_API::animations.size() << std::endl;
|
//std::cout << "Number of animations: " << McRFPy_API::animations.size() << std::endl;
|
||||||
auto frametime = game->getFrameTime();
|
auto frametime = game->getFrameTime();
|
||||||
auto it = McRFPy_API::animations.begin();
|
auto it = McRFPy_API::animations.begin();
|
||||||
while (it != McRFPy_API::animations.end()) {
|
while (it != McRFPy_API::animations.end()) {
|
||||||
|
@ -122,7 +122,13 @@ void PythonScene::doLClick(sf::Vector2i mousepos) {
|
||||||
for (auto pair : McRFPy_API::menus) {
|
for (auto pair : McRFPy_API::menus) {
|
||||||
if (!pair.second->visible) continue;
|
if (!pair.second->visible) continue;
|
||||||
for (auto b : pair.second->buttons) {
|
for (auto b : pair.second->buttons) {
|
||||||
if (b.contains(mousepos)) {
|
//std::cout << "Box: " << pair.second->box.getPosition().x << ", "
|
||||||
|
//<< pair.second->box.getPosition().y << "; Button:" << b.rect.getPosition().x <<
|
||||||
|
//", " << b.rect.getPosition().y << "; Mouse: " << mousepos.x << ", " <<
|
||||||
|
//mousepos.y << std::endl;
|
||||||
|
|
||||||
|
// JANK: provide the button a relative coordinate.
|
||||||
|
if (b.contains(pair.second->box.getPosition(), mousepos)) {
|
||||||
McRFPy_API::doAction(b.getAction());
|
McRFPy_API::doAction(b.getAction());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,9 +21,18 @@ void UIMenu::render(sf::RenderWindow & window)
|
||||||
for (auto& c : captions) {
|
for (auto& c : captions) {
|
||||||
//auto s = std::string(c.getString());
|
//auto s = std::string(c.getString());
|
||||||
//std::cout << s << std::flush << std::endl;
|
//std::cout << s << std::flush << std::endl;
|
||||||
|
c.move(box.getPosition());
|
||||||
window.draw(c);
|
window.draw(c);
|
||||||
|
c.move(-box.getPosition());
|
||||||
|
}
|
||||||
|
for (auto& b : buttons) {
|
||||||
|
//b.render(window);
|
||||||
|
b.setPosition(box.getPosition() + b.rect.getPosition());
|
||||||
|
//b.caption.setPosition(box.getPosition() + b.caption.getPosition());
|
||||||
|
b.render(window);
|
||||||
|
b.setPosition(b.rect.getPosition() - box.getPosition());
|
||||||
|
//b.caption.setPosition(b.caption.getPosition() - box.getPosition());
|
||||||
}
|
}
|
||||||
for (auto& b : buttons) { b.render(window); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIMenu::refresh()
|
void UIMenu::refresh()
|
||||||
|
@ -34,10 +43,10 @@ void UIMenu::refresh()
|
||||||
void UIMenu::add_caption(const char* text, int tsize, sf::Color color)
|
void UIMenu::add_caption(const char* text, int tsize, sf::Color color)
|
||||||
{
|
{
|
||||||
auto c = sf::Text();
|
auto c = sf::Text();
|
||||||
auto bpos = box.getPosition();
|
//auto bpos = box.getPosition();
|
||||||
|
|
||||||
c.setFillColor(color);
|
c.setFillColor(color);
|
||||||
c.setPosition(bpos.x + 10, bpos.y + next_text);
|
c.setPosition(10, next_text);
|
||||||
next_text += 50;
|
next_text += 50;
|
||||||
c.setCharacterSize(tsize);
|
c.setCharacterSize(tsize);
|
||||||
c.setString(text);
|
c.setString(text);
|
||||||
|
@ -48,7 +57,7 @@ void UIMenu::add_caption(const char* text, int tsize, sf::Color color)
|
||||||
|
|
||||||
void UIMenu::add_button(Button b)
|
void UIMenu::add_button(Button b)
|
||||||
{
|
{
|
||||||
b.setPosition(box.getPosition() + sf::Vector2f(box.getSize().x / 2.0f, next_button));
|
b.setPosition(sf::Vector2f(box.getSize().x / 2.0f, next_button));
|
||||||
next_button += 50;
|
next_button += 50;
|
||||||
buttons.push_back(b);
|
buttons.push_back(b);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue