2023-02-25 04:46:34 +00:00
|
|
|
#include "UIMenu.h"
|
2023-03-01 04:19:43 +00:00
|
|
|
#include "Common.h"
|
2023-02-25 04:46:34 +00:00
|
|
|
|
|
|
|
UIMenu::UIMenu(sf::Font & _font)
|
|
|
|
: font(_font)
|
|
|
|
{
|
|
|
|
//font = _font;
|
|
|
|
box.setSize(sf::Vector2f(300, 400));
|
|
|
|
box.setPosition(sf::Vector2f(300, 250));
|
|
|
|
box.setFillColor(sf::Color(0,0,255));
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIMenu::render(sf::RenderWindow & window)
|
|
|
|
{
|
|
|
|
window.draw(box);
|
2023-03-04 03:16:47 +00:00
|
|
|
for (auto& s: sprites) {
|
|
|
|
auto _s = s.drawable();
|
2023-03-11 22:15:06 +00:00
|
|
|
//std::cout << "Sprite has values " << s.x << ", " << s.y << std::endl;
|
|
|
|
//std::cout << "Drawable generated @ " << _s.getPosition().x << ", " << _s.getPosition().y << std::endl;
|
2023-03-04 03:16:47 +00:00
|
|
|
_s.move(box.getPosition());
|
2023-03-11 22:15:06 +00:00
|
|
|
//std::cout << "Moved by " << box.getPosition().x << ", " << box.getPosition().y << std::endl;
|
|
|
|
//std::cout << "Render UIMenu Sprite @ " << _s.getPosition().x << ", " << _s.getPosition().y << std::endl;
|
2023-03-04 03:16:47 +00:00
|
|
|
window.draw(_s);
|
|
|
|
}
|
2023-02-25 04:46:34 +00:00
|
|
|
for (auto& c : captions) {
|
|
|
|
//auto s = std::string(c.getString());
|
|
|
|
//std::cout << s << std::flush << std::endl;
|
2023-03-08 01:03:09 +00:00
|
|
|
c.move(box.getPosition());
|
2023-02-25 04:46:34 +00:00
|
|
|
window.draw(c);
|
2023-03-08 01:03:09 +00:00
|
|
|
c.move(-box.getPosition());
|
2023-02-25 04:46:34 +00:00
|
|
|
}
|
2023-03-08 01:03:09 +00:00
|
|
|
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());
|
|
|
|
}
|
2023-02-25 04:46:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void UIMenu::refresh()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIMenu::add_caption(const char* text, int tsize, sf::Color color)
|
|
|
|
{
|
|
|
|
auto c = sf::Text();
|
2023-03-08 01:03:09 +00:00
|
|
|
//auto bpos = box.getPosition();
|
2023-02-25 04:46:34 +00:00
|
|
|
|
|
|
|
c.setFillColor(color);
|
2023-03-08 01:03:09 +00:00
|
|
|
c.setPosition(10, next_text);
|
2023-02-25 04:46:34 +00:00
|
|
|
next_text += 50;
|
|
|
|
c.setCharacterSize(tsize);
|
|
|
|
c.setString(text);
|
|
|
|
c.setFont(font);
|
|
|
|
captions.push_back(c);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIMenu::add_button(Button b)
|
|
|
|
{
|
2023-03-08 01:03:09 +00:00
|
|
|
b.setPosition(sf::Vector2f(box.getSize().x / 2.0f, next_button));
|
2023-02-25 04:46:34 +00:00
|
|
|
next_button += 50;
|
|
|
|
buttons.push_back(b);
|
|
|
|
}
|
2023-03-01 04:19:43 +00:00
|
|
|
|
2023-03-02 02:37:42 +00:00
|
|
|
void UIMenu::add_sprite(IndexSprite s)
|
2023-03-01 04:19:43 +00:00
|
|
|
{
|
2023-03-11 22:15:06 +00:00
|
|
|
//std::cout << "Adding sprite to UIMenu x,y " << s.x << ", " << s.y << std::endl;
|
2023-03-01 04:19:43 +00:00
|
|
|
sprites.push_back(s);
|
|
|
|
}
|
|
|
|
|