mirror of
https://github.com/zoriya/Bomberman.git
synced 2025-12-20 05:15:10 +00:00
menu controllable but still needs view
This commit is contained in:
@@ -3,8 +3,9 @@
|
||||
//
|
||||
|
||||
#include <algorithm>
|
||||
#include "Component/Button/ButtonComponent.hpp"
|
||||
#include "Component/Position/PositionComponent.hpp"
|
||||
#include "System/MenuControllable/MenuControllableSystem.hpp"
|
||||
#include "System/MenuControllable/MenuControllableSystem.hpp"
|
||||
#include "Component/Controllable/ControllableComponent.hpp"
|
||||
#include "Entity/Entity.hpp"
|
||||
|
||||
@@ -16,10 +17,29 @@ namespace BBM
|
||||
})
|
||||
{}
|
||||
|
||||
void MenuControllableSystem::updateButtonIndex(int length)
|
||||
{
|
||||
_buttonIndex -= (move.y > 0);
|
||||
_buttonIndex += (move.y < 0);
|
||||
if (_buttonIndex < 0)
|
||||
_buttonIndex = length - 1;
|
||||
if (_buttonIndex == length)
|
||||
_buttonIndex = 0;
|
||||
|
||||
}
|
||||
|
||||
void MenuControllableSystem::onFixedUpdate(WAL::Entity &entity)
|
||||
{
|
||||
auto &controllable = entity.getComponent<ControllableComponent>();
|
||||
auto buttons = ecs.view<<Button>(entities);
|
||||
|
||||
move = controllable.move;
|
||||
select = controllable.bomb;
|
||||
}
|
||||
|
||||
void MenuControllableSystem::onSelfUpdate(void)
|
||||
{
|
||||
auto buttons = ecs.view<<ButtonComponent>(entities);
|
||||
ssize_t index = 0;
|
||||
std::sort(buttons.begin(), buttons.end(),
|
||||
[](WAL::Entity &first, WAL::Entity &second) {
|
||||
auto &posA = first.getComponent<PositionComponent>();
|
||||
@@ -27,18 +47,15 @@ namespace BBM
|
||||
|
||||
return (posA.position.y < posB.position.y);
|
||||
});
|
||||
_buttonIndex -= (controllable.move.y > 0);
|
||||
_buttonIndex += (controllable.move.y < 0);
|
||||
if (_buttonIndex < 0)
|
||||
_buttonIndex = buttons.length() - 1;
|
||||
_buttonIndex %= buttons.length();
|
||||
auto currentButton = buttons[_buttonIndex].getComponent<Button>();
|
||||
updateButtonIndex(buttons.length);
|
||||
auto currentButton = buttons[_buttonIndex].getComponent<ButtonComponent>();
|
||||
currentButton.onSelected();
|
||||
if (controllable.bomb)
|
||||
if (select)
|
||||
currentButton.onClick();
|
||||
std::for_each_n(buttons.begin(), _buttonIndex,
|
||||
[](WAL::Entity &curr) {
|
||||
curr.getComponent<Button>().onIdle();
|
||||
});
|
||||
for (auto &button : buttons) {
|
||||
if (index++ == _buttonIndex)
|
||||
continue;
|
||||
button.onIdle();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user