mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-05-31 17:33:20 +00:00
entity from wal now have a comparaison operator using uid
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 529 B |
Binary file not shown.
|
After Width: | Height: | Size: 860 B |
@@ -76,4 +76,9 @@ namespace WAL
|
||||
{
|
||||
this->_scene._componentRemoved(*this, type);
|
||||
}
|
||||
|
||||
bool Entity::operator==(const Entity &other) const
|
||||
{
|
||||
return other.getUid() == this->_uid;
|
||||
}
|
||||
} // namespace WAL
|
||||
@@ -165,5 +165,8 @@ namespace WAL
|
||||
~Entity() = default;
|
||||
//! @brief An entity is not assignable
|
||||
Entity &operator=(const Entity &) = delete;
|
||||
|
||||
//! @return true if the two entities hold the same uid
|
||||
bool operator==(const Entity &) const;
|
||||
};
|
||||
} // namespace WAL
|
||||
@@ -182,15 +182,6 @@ namespace BBM
|
||||
{
|
||||
auto scene = std::make_shared<WAL::Scene>();
|
||||
|
||||
scene->addEntity("Control entity")
|
||||
.addComponent<ControllableComponent>()
|
||||
.addComponent<KeyboardComponent>();
|
||||
scene->addEntity("background")
|
||||
.addComponent<PositionComponent>()
|
||||
.addComponent<Drawable2DComponent, RAY::Texture>("assets/plain_menu_background.png");
|
||||
scene->addEntity("logo")
|
||||
.addComponent<PositionComponent>(1920 / 3, 180, 0)
|
||||
.addComponent<Drawable2DComponent, RAY::Texture>("assets/logo_small.png");
|
||||
|
||||
WAL::Entity music(*scene, "music text");
|
||||
music.addComponent<PositionComponent>(1920 / 2.5, 1080 - 540, 0)
|
||||
@@ -205,6 +196,40 @@ namespace BBM
|
||||
entity.getComponent<Drawable2DComponent>().drawable->setColor(ORANGE);
|
||||
});
|
||||
|
||||
WAL::Entity musicUp(*scene, "music up button");
|
||||
musicUp.addComponent<PositionComponent>(1920 / 3, 1080 - 540, 0)
|
||||
.addComponent<Drawable2DComponent, RAY::Texture>("assets/buttons/button_plus.png")
|
||||
.addComponent<OnClickComponent>()
|
||||
.addComponent<OnIdleComponent>([](WAL::Entity &entity)
|
||||
{
|
||||
RAY::Texture *texture = dynamic_cast<RAY::Texture *>(entity.getComponent<Drawable2DComponent>().drawable.get());
|
||||
|
||||
texture->use("assets/buttons/button_plus.png");
|
||||
})
|
||||
.addComponent<OnHoverComponent>([](WAL::Entity &entity)
|
||||
{
|
||||
RAY::Texture *texture = dynamic_cast<RAY::Texture *>(entity.getComponent<Drawable2DComponent>().drawable.get());
|
||||
|
||||
texture->use("assets/buttons/button_plus_hovered.png");
|
||||
});
|
||||
|
||||
WAL::Entity musicDown(*scene, "music down button");
|
||||
musicDown.addComponent<PositionComponent>(1920 / 1.5, 1080 - 540, 0)
|
||||
.addComponent<Drawable2DComponent, RAY::Texture>("assets/buttons/button_minus.png")
|
||||
.addComponent<OnClickComponent>()
|
||||
.addComponent<OnIdleComponent>([](WAL::Entity &entity)
|
||||
{
|
||||
RAY::Texture *texture = dynamic_cast<RAY::Texture *>(entity.getComponent<Drawable2DComponent>().drawable.get());
|
||||
|
||||
texture->use("assets/buttons/button_minus.png");
|
||||
})
|
||||
.addComponent<OnHoverComponent>([](WAL::Entity &entity)
|
||||
{
|
||||
RAY::Texture *texture = dynamic_cast<RAY::Texture *>(entity.getComponent<Drawable2DComponent>().drawable.get());
|
||||
|
||||
texture->use("assets/buttons/button_minus_hovered.png");
|
||||
});
|
||||
|
||||
WAL::Entity sound(*scene, "sound text");
|
||||
sound.addComponent<PositionComponent>(1920 / 2.5, 1080 - 360, 0)
|
||||
.addComponent<Drawable2DComponent, RAY2D::Text>("Sound Volume", 70, RAY::Vector2(), ORANGE)
|
||||
@@ -244,9 +269,30 @@ namespace BBM
|
||||
// back button asset
|
||||
//music
|
||||
//sound
|
||||
|
||||
music.getComponent<OnClickComponent>().setButtonLinks(&debug, &sound, &musicUp, &musicDown);
|
||||
musicUp.getComponent<OnClickComponent>().setButtonLinks(&debug, &sound, nullptr, &music);
|
||||
musicDown.getComponent<OnClickComponent>().setButtonLinks(&debug, &sound, &music, nullptr);
|
||||
debug.getComponent<OnClickComponent>().setButtonLinks(&sound, &music);
|
||||
sound.getComponent<OnClickComponent>().setButtonLinks(&music, &debug);
|
||||
std::cout << music.getName() << std::endl;
|
||||
std::cout << music.getUid() << std::endl;
|
||||
printf("%p\n", &music);
|
||||
|
||||
scene->getEntities().push_back(music);
|
||||
scene->getEntities().push_back(musicUp);
|
||||
scene->getEntities().push_back(musicDown);
|
||||
scene->getEntities().push_back(sound);
|
||||
scene->getEntities().push_back(debug);
|
||||
scene->addEntity("Control entity")
|
||||
.addComponent<ControllableComponent>()
|
||||
.addComponent<KeyboardComponent>();
|
||||
scene->addEntity("background")
|
||||
.addComponent<PositionComponent>()
|
||||
.addComponent<Drawable2DComponent, RAY::Texture>("assets/plain_menu_background.png");
|
||||
scene->addEntity("logo")
|
||||
.addComponent<PositionComponent>(1920 / 3, 180, 0)
|
||||
.addComponent<Drawable2DComponent, RAY::Texture>("assets/logo_small.png");
|
||||
return scene;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,17 +12,20 @@
|
||||
namespace BBM
|
||||
{
|
||||
MenuControllableSystem::MenuControllableSystem(WAL::Wal &wal)
|
||||
: System(wal), wal(wal)
|
||||
: System(wal), wal(wal), currentButton()
|
||||
{}
|
||||
|
||||
void MenuControllableSystem::updateButtonIndex(int length)
|
||||
void MenuControllableSystem::updateCurrentButton()
|
||||
{
|
||||
_buttonIndex -= (move.y > 0);
|
||||
_buttonIndex += (move.y < 0);
|
||||
if (_buttonIndex < 0)
|
||||
_buttonIndex = length - 1;
|
||||
if (_buttonIndex == length)
|
||||
_buttonIndex = 0;
|
||||
auto buttonComponent = this->currentButton->getComponent<OnClickComponent>();
|
||||
if (move.y > 0 && buttonComponent._up)
|
||||
this->currentButton = buttonComponent._up;
|
||||
if (move.y < 0 && buttonComponent._down)
|
||||
this->currentButton = buttonComponent._down;
|
||||
if (move.x > 0 && buttonComponent._right)
|
||||
this->currentButton = buttonComponent._right;
|
||||
if (move.x < 0 && buttonComponent._left)
|
||||
this->currentButton = buttonComponent._left;
|
||||
|
||||
}
|
||||
|
||||
@@ -37,19 +40,17 @@ namespace BBM
|
||||
|
||||
move = controllable.move;
|
||||
select = controllable.bomb;
|
||||
auto &buttons = wal.scene->view<OnClickComponent>();
|
||||
ssize_t index = 0;
|
||||
//std::sort(buttons.begin(), buttons.end(),
|
||||
//[](WAL::Entity &first, WAL::Entity &second) {
|
||||
// auto &posA = first.getComponent<PositionComponent>();
|
||||
// auto &posB = second.getComponent<PositionComponent>();
|
||||
//
|
||||
// return (posA.position.y < posB.position.y);
|
||||
//});
|
||||
updateButtonIndex(buttons.size());
|
||||
auto &buttons = _wal.scene->view<OnClickComponent>();
|
||||
if (currentButton == nullptr && buttons.size()) {
|
||||
currentButton = &static_cast<WAL::Entity &>(buttons.front());
|
||||
std::cout << currentButton->getName() << std::endl;
|
||||
std::cout << currentButton->getUid() << std::endl;
|
||||
printf("%p\n", currentButton);
|
||||
}
|
||||
this->updateCurrentButton();
|
||||
for (auto &button : buttons) {
|
||||
auto &buttonEntity = static_cast<WAL::Entity &>(button);
|
||||
if (index++ == _buttonIndex) {
|
||||
if (buttonEntity == *currentButton) {
|
||||
buttonEntity.getComponent<OnHoverComponent>().onEvent(button);
|
||||
if (select)
|
||||
button.get<OnClickComponent>().onEvent(button);
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace BBM
|
||||
WAL::Wal &wal;
|
||||
|
||||
//! @brief index of the current button selected
|
||||
int _buttonIndex = 0;
|
||||
WAL::Entity *currentButton;
|
||||
|
||||
//! @brief move vector
|
||||
Vector2f move;
|
||||
@@ -29,9 +29,8 @@ namespace BBM
|
||||
//! @brief Cancel action
|
||||
bool cancel = false;
|
||||
|
||||
//! @brief update button index
|
||||
//! @param length length of the button set
|
||||
void updateButtonIndex(int length);
|
||||
//! @brief update current button reference
|
||||
void updateCurrentButton();
|
||||
|
||||
//! @brief time (in mili second) since last check
|
||||
std::chrono::time_point<std::chrono::steady_clock> _now;
|
||||
|
||||
Reference in New Issue
Block a user