From c816db947e028258e78338a02301e2dfae53d5cc Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Tue, 8 Jun 2021 09:52:01 +0200 Subject: [PATCH] music volume buttons --- sources/Component/Button/ButtonComponent.hpp | 2 +- sources/Runner/Runner.cpp | 40 +++++++------------ .../MenuControllableSystem.cpp | 25 +++++------- 3 files changed, 26 insertions(+), 41 deletions(-) diff --git a/sources/Component/Button/ButtonComponent.hpp b/sources/Component/Button/ButtonComponent.hpp index 90329b89..869ad5a2 100644 --- a/sources/Component/Button/ButtonComponent.hpp +++ b/sources/Component/Button/ButtonComponent.hpp @@ -51,8 +51,8 @@ namespace BBM { this->_up = up; this->_down = down; - this->_right = right; this->_left = left; + this->_right = right; return *this; } diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index 43d0ca24..c2576333 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -183,7 +183,16 @@ namespace BBM auto scene = std::make_shared(); - WAL::Entity music(*scene, "music text"); + scene->addEntity("Control entity") + .addComponent() + .addComponent(); + scene->addEntity("background") + .addComponent() + .addComponent("assets/plain_menu_background.png"); + scene->addEntity("logo") + .addComponent(1920 / 3, 180, 0) + .addComponent("assets/logo_small.png"); + auto &music = scene->addEntity("music text"); music.addComponent(1920 / 2.5, 1080 - 540, 0) .addComponent("Music Volume", 70, RAY::Vector2(), ORANGE) .addComponent() @@ -196,7 +205,7 @@ namespace BBM entity.getComponent().drawable->setColor(ORANGE); }); - WAL::Entity musicUp(*scene, "music up button"); + auto &musicUp = scene->addEntity("music up button"); musicUp.addComponent(1920 / 3, 1080 - 540, 0) .addComponent("assets/buttons/button_plus.png") .addComponent() @@ -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(1920 / 1.5, 1080 - 540, 0) .addComponent("assets/buttons/button_minus.png") .addComponent() @@ -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(1920 / 2.5, 1080 - 360, 0) .addComponent("Sound Volume", 70, RAY::Vector2(), ORANGE) .addComponent() @@ -243,7 +252,7 @@ namespace BBM entity.getComponent().drawable->setColor(ORANGE); }); - WAL::Entity debug(*scene, "debug text"); + auto &debug = scene->addEntity("debug text"); debug.addComponent(1920 / 2.5, 1080 - 180, 0) .addComponent("Debug Mode", 70, RAY::Vector2(), ORANGE) .addComponent() @@ -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().setButtonLinks(&debug, &sound, &musicUp, &musicDown); musicUp.getComponent().setButtonLinks(&debug, &sound, nullptr, &music); - musicDown.getComponent().setButtonLinks(&debug, &sound, &music, nullptr); + musicDown.getComponent().setButtonLinks(&debug, &sound, &music); debug.getComponent().setButtonLinks(&sound, &music); sound.getComponent().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() - .addComponent(); - scene->addEntity("background") - .addComponent() - .addComponent("assets/plain_menu_background.png"); - scene->addEntity("logo") - .addComponent(1920 / 3, 180, 0) - .addComponent("assets/logo_small.png"); return scene; } diff --git a/sources/System/MenuControllable/MenuControllableSystem.cpp b/sources/System/MenuControllable/MenuControllableSystem.cpp index d1e5d548..e59b0d43 100644 --- a/sources/System/MenuControllable/MenuControllableSystem.cpp +++ b/sources/System/MenuControllable/MenuControllableSystem.cpp @@ -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 &entity) { auto lastTick = std::chrono::steady_clock::now(); + auto &controllable = entity.get(); + auto &buttons = _wal.scene->view(); if (lastTick - this->_now < std::chrono::milliseconds(100)) return; this->_now = lastTick; - auto &controllable = entity.get(); move = controllable.move; select = controllable.bomb; - auto &buttons = _wal.scene->view(); - if (currentButton == nullptr && buttons.size()) { - currentButton = &static_cast(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(button); + for (auto &[buttonEntity, clickComponent]: buttons) { if (buttonEntity == *currentButton) { - buttonEntity.getComponent().onEvent(button); + buttonEntity.getComponent().onEvent(buttonEntity); if (select) - button.get().onEvent(button); + clickComponent.onEvent(buttonEntity); continue; } - buttonEntity.getComponent().onEvent(button); + buttonEntity.getComponent().onEvent(buttonEntity); } }