music volume buttons

This commit is contained in:
arthur.jamet
2021-06-08 09:52:01 +02:00
parent f56a488a7e
commit c816db947e
3 changed files with 26 additions and 41 deletions

View File

@@ -51,8 +51,8 @@ namespace BBM
{
this->_up = up;
this->_down = down;
this->_right = right;
this->_left = left;
this->_right = right;
return *this;
}

View File

@@ -183,7 +183,16 @@ namespace BBM
auto scene = std::make_shared<WAL::Scene>();
WAL::Entity music(*scene, "music text");
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");
auto &music = scene->addEntity("music text");
music.addComponent<PositionComponent>(1920 / 2.5, 1080 - 540, 0)
.addComponent<Drawable2DComponent, RAY2D::Text>("Music Volume", 70, RAY::Vector2(), ORANGE)
.addComponent<OnClickComponent>()
@@ -196,7 +205,7 @@ namespace BBM
entity.getComponent<Drawable2DComponent>().drawable->setColor(ORANGE);
});
WAL::Entity musicUp(*scene, "music up button");
auto &musicUp = scene->addEntity("music up button");
musicUp.addComponent<PositionComponent>(1920 / 3, 1080 - 540, 0)
.addComponent<Drawable2DComponent, RAY::Texture>("assets/buttons/button_plus.png")
.addComponent<OnClickComponent>()
@@ -213,7 +222,7 @@ namespace BBM
texture->use("assets/buttons/button_plus_hovered.png");
});
WAL::Entity musicDown(*scene, "music down button");
auto &musicDown = scene->addEntity("music down button");
musicDown.addComponent<PositionComponent>(1920 / 1.5, 1080 - 540, 0)
.addComponent<Drawable2DComponent, RAY::Texture>("assets/buttons/button_minus.png")
.addComponent<OnClickComponent>()
@@ -230,7 +239,7 @@ namespace BBM
texture->use("assets/buttons/button_minus_hovered.png");
});
WAL::Entity sound(*scene, "sound text");
auto &sound = scene->addEntity("sound text");
sound.addComponent<PositionComponent>(1920 / 2.5, 1080 - 360, 0)
.addComponent<Drawable2DComponent, RAY2D::Text>("Sound Volume", 70, RAY::Vector2(), ORANGE)
.addComponent<OnClickComponent>()
@@ -243,7 +252,7 @@ namespace BBM
entity.getComponent<Drawable2DComponent>().drawable->setColor(ORANGE);
});
WAL::Entity debug(*scene, "debug text");
auto &debug = scene->addEntity("debug text");
debug.addComponent<PositionComponent>(1920 / 2.5, 1080 - 180, 0)
.addComponent<Drawable2DComponent, RAY2D::Text>("Debug Mode", 70, RAY::Vector2(), ORANGE)
.addComponent<OnClickComponent>()
@@ -260,8 +269,6 @@ namespace BBM
// sound logo
// plus button
// minus button
//mute music logo
//mute sound logo
//text for debug
// ticked box
// unticked box
@@ -272,27 +279,10 @@ namespace BBM
music.getComponent<OnClickComponent>().setButtonLinks(&debug, &sound, &musicUp, &musicDown);
musicUp.getComponent<OnClickComponent>().setButtonLinks(&debug, &sound, nullptr, &music);
musicDown.getComponent<OnClickComponent>().setButtonLinks(&debug, &sound, &music, nullptr);
musicDown.getComponent<OnClickComponent>().setButtonLinks(&debug, &sound, &music);
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;
}

View File

@@ -22,9 +22,9 @@ namespace BBM
this->currentButton = buttonComponent._up;
if (move.y < 0 && buttonComponent._down)
this->currentButton = buttonComponent._down;
if (move.x > 0 && buttonComponent._right)
if (move.x < 0 && buttonComponent._right)
this->currentButton = buttonComponent._right;
if (move.x < 0 && buttonComponent._left)
if (move.x > 0 && buttonComponent._left)
this->currentButton = buttonComponent._left;
}
@@ -32,31 +32,26 @@ namespace BBM
void MenuControllableSystem::onFixedUpdate(WAL::ViewEntity<ControllableComponent> &entity)
{
auto lastTick = std::chrono::steady_clock::now();
auto &controllable = entity.get<ControllableComponent>();
auto &buttons = _wal.scene->view<OnClickComponent>();
if (lastTick - this->_now < std::chrono::milliseconds(100))
return;
this->_now = lastTick;
auto &controllable = entity.get<ControllableComponent>();
move = controllable.move;
select = controllable.bomb;
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);
}
if (currentButton == nullptr && buttons.size())
currentButton = &(**buttons.begin());
this->updateCurrentButton();
for (auto &button : buttons) {
auto &buttonEntity = static_cast<WAL::Entity &>(button);
for (auto &[buttonEntity, clickComponent]: buttons) {
if (buttonEntity == *currentButton) {
buttonEntity.getComponent<OnHoverComponent>().onEvent(button);
buttonEntity.getComponent<OnHoverComponent>().onEvent(buttonEntity);
if (select)
button.get<OnClickComponent>().onEvent(button);
clickComponent.onEvent(buttonEntity);
continue;
}
buttonEntity.getComponent<OnIdleComponent>().onEvent(button);
buttonEntity.getComponent<OnIdleComponent>().onEvent(buttonEntity);
}
}