mirror of
https://github.com/zoriya/Bomberman.git
synced 2025-12-20 13:25:10 +00:00
menu controllable but still needs view
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include "Component/Button/ButtonComponent.hpp"
|
||||||
#include "Component/Position/PositionComponent.hpp"
|
#include "Component/Position/PositionComponent.hpp"
|
||||||
#include "System/MenuControllable/MenuControllableSystem.hpp"
|
#include "System/MenuControllable/MenuControllableSystem.hpp"
|
||||||
#include "Component/Controllable/ControllableComponent.hpp"
|
#include "Component/Controllable/ControllableComponent.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)
|
void MenuControllableSystem::onFixedUpdate(WAL::Entity &entity)
|
||||||
{
|
{
|
||||||
auto &controllable = entity.getComponent<ControllableComponent>();
|
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(),
|
std::sort(buttons.begin(), buttons.end(),
|
||||||
[](WAL::Entity &first, WAL::Entity &second) {
|
[](WAL::Entity &first, WAL::Entity &second) {
|
||||||
auto &posA = first.getComponent<PositionComponent>();
|
auto &posA = first.getComponent<PositionComponent>();
|
||||||
@@ -27,18 +47,15 @@ namespace BBM
|
|||||||
|
|
||||||
return (posA.position.y < posB.position.y);
|
return (posA.position.y < posB.position.y);
|
||||||
});
|
});
|
||||||
_buttonIndex -= (controllable.move.y > 0);
|
updateButtonIndex(buttons.length);
|
||||||
_buttonIndex += (controllable.move.y < 0);
|
auto currentButton = buttons[_buttonIndex].getComponent<ButtonComponent>();
|
||||||
if (_buttonIndex < 0)
|
|
||||||
_buttonIndex = buttons.length() - 1;
|
|
||||||
_buttonIndex %= buttons.length();
|
|
||||||
auto currentButton = buttons[_buttonIndex].getComponent<Button>();
|
|
||||||
currentButton.onSelected();
|
currentButton.onSelected();
|
||||||
if (controllable.bomb)
|
if (select)
|
||||||
currentButton.onClick();
|
currentButton.onClick();
|
||||||
std::for_each_n(buttons.begin(), _buttonIndex,
|
for (auto &button : buttons) {
|
||||||
[](WAL::Entity &curr) {
|
if (index++ == _buttonIndex)
|
||||||
curr.getComponent<Button>().onIdle();
|
continue;
|
||||||
});
|
button.onIdle();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,8 +12,24 @@ namespace BBM
|
|||||||
class MenuControllableSystem : public WAL::System
|
class MenuControllableSystem : public WAL::System
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
//! @brief index of the current button selected
|
||||||
unsigned _buttonIndex = 0;
|
unsigned _buttonIndex = 0;
|
||||||
|
|
||||||
|
//! @brief move vector
|
||||||
|
Vector2f move;
|
||||||
|
|
||||||
|
//! @brief Select action
|
||||||
|
bool select = false;
|
||||||
|
|
||||||
|
//! @brief Cancel action
|
||||||
|
bool cancel = false;
|
||||||
|
|
||||||
|
//! @brief update button index
|
||||||
|
//! @param length length of the button set
|
||||||
|
void updateButtonIndex(int length);
|
||||||
public:
|
public:
|
||||||
|
//! @inherit
|
||||||
|
void onSelfUpdate(void) override;
|
||||||
|
|
||||||
//! @inherit
|
//! @inherit
|
||||||
void onFixedUpdate(WAL::Entity &entity) override;
|
void onFixedUpdate(WAL::Entity &entity) override;
|
||||||
|
|||||||
Reference in New Issue
Block a user