Switching keyboard layouts

This commit is contained in:
Zoe Roux
2021-06-18 13:43:28 +02:00
parent 8d9432c1f4
commit 63044f756a
12 changed files with 29 additions and 29 deletions
@@ -31,9 +31,9 @@ namespace BBM
//! @brief The X and Z abscis of the movement. //! @brief The X and Z abscis of the movement.
Vector2f move; Vector2f move;
//! @brief input value to select //! @brief input value for secondary inputs.
bool select = false; bool secondary = false;
//! @brief input value for bomb //! @brief input value for bomb and selection
bool bomb = false; bool bomb = false;
//! @brief input value for pause //! @brief input value for pause
bool pause = false; bool pause = false;
@@ -22,9 +22,9 @@ namespace BBM
int _ID; int _ID;
public: public:
//! @brief jump key //! @brief jump key
Button keyJump = GAMEPAD_BUTTON_RIGHT_FACE_DOWN; Button keySecondary = GAMEPAD_BUTTON_RIGHT_FACE_RIGHT;
//! @brief bomb key //! @brief bomb key
Button keyBomb = GAMEPAD_BUTTON_RIGHT_FACE_RIGHT; Button keyBomb = GAMEPAD_BUTTON_RIGHT_FACE_DOWN;
//! @brief pause key //! @brief pause key
Button keyPause = GAMEPAD_BUTTON_MIDDLE; Button keyPause = GAMEPAD_BUTTON_MIDDLE;
//! @brief move right key //! @brief move right key
@@ -16,16 +16,16 @@ namespace BBM
this->keyDown = KEY_S; this->keyDown = KEY_S;
this->keyLeft = KEY_A; this->keyLeft = KEY_A;
this->keyRight = KEY_D; this->keyRight = KEY_D;
this->keyJump = KEY_SPACE; this->keyBomb = KEY_SPACE;
this->keyBomb = KEY_E; this->keySecondary = KEY_LEFT_CONTROL;
this->keyPause = KEY_ESCAPE; this->keyPause = KEY_ESCAPE;
} else { } else {
this->keyUp = KEY_UP; this->keyUp = KEY_UP;
this->keyDown = KEY_DOWN; this->keyDown = KEY_DOWN;
this->keyLeft = KEY_LEFT; this->keyLeft = KEY_LEFT;
this->keyRight = KEY_RIGHT; this->keyRight = KEY_RIGHT;
this->keyJump = KEY_RIGHT_CONTROL; this->keyBomb = KEY_RIGHT_CONTROL;
this->keyBomb = KEY_ENTER; this->keySecondary = KEY_RIGHT_SHIFT;
this->keyPause = KEY_BACKSPACE; this->keyPause = KEY_BACKSPACE;
} }
} }
@@ -18,7 +18,7 @@ namespace BBM
{ {
public: public:
//! @brief jump key //! @brief jump key
Key keyJump = KEY_SPACE; Key keySecondary = KEY_SPACE;
//! @brief bomb key //! @brief bomb key
Key keyBomb = KEY_E; Key keyBomb = KEY_E;
//! @brief pause key //! @brief pause key
+4 -3
View File
@@ -67,19 +67,20 @@ namespace BBM
auto &back = scene->addEntity("back to menu") auto &back = scene->addEntity("back to menu")
.addComponent<PositionComponent>(10, 1080 - 85, 0) .addComponent<PositionComponent>(10, 1080 - 85, 0)
.addComponent<Drawable2DComponent, RAY::Texture>("assets/buttons/button_back.png") .addComponent<Drawable2DComponent, RAY::Texture>("assets/buttons/button_back.png")
.addComponent<OnClickComponent>([](WAL::Entity &entity, WAL::Wal &) .addComponent<OnClickComponent>([](WAL::Entity &, WAL::Wal &wal)
{ {
wal.getSystem<LobbySystem>().unloadLobby();
gameState.nextScene = BBM::GameState::SceneID::MainMenuScene; gameState.nextScene = BBM::GameState::SceneID::MainMenuScene;
}) })
.addComponent<OnIdleComponent>([](WAL::Entity &entity, WAL::Wal &) .addComponent<OnIdleComponent>([](WAL::Entity &entity, WAL::Wal &)
{ {
RAY::Texture *texture = dynamic_cast<RAY::Texture *>(entity.getComponent<Drawable2DComponent>().drawable.get()); auto *texture = dynamic_cast<RAY::Texture *>(entity.getComponent<Drawable2DComponent>().drawable.get());
texture->use("assets/buttons/button_back.png"); texture->use("assets/buttons/button_back.png");
}) })
.addComponent<OnHoverComponent>([](WAL::Entity &entity, WAL::Wal &) .addComponent<OnHoverComponent>([](WAL::Entity &entity, WAL::Wal &)
{ {
RAY::Texture *texture = dynamic_cast<RAY::Texture *>(entity.getComponent<Drawable2DComponent>().drawable.get()); auto *texture = dynamic_cast<RAY::Texture *>(entity.getComponent<Drawable2DComponent>().drawable.get());
texture->use("assets/buttons/button_back_hovered.png"); texture->use("assets/buttons/button_back_hovered.png");
}); });
+3 -3
View File
@@ -24,9 +24,9 @@ namespace BBM
Gamepad gamepad(gamepadComponent.getID()); Gamepad gamepad(gamepadComponent.getID());
const std::map<Button, bool &> keyPressedMap = { const std::map<Button, bool &> keyPressedMap = {
{gamepadComponent.keyJump, controllable.select}, {gamepadComponent.keySecondary, controllable.secondary},
{gamepadComponent.keyBomb, controllable.bomb}, {gamepadComponent.keyBomb, controllable.bomb},
{gamepadComponent.keyPause, controllable.pause} {gamepadComponent.keyPause, controllable.pause}
}; };
for (auto key : keyPressedMap) for (auto key : keyPressedMap)
@@ -166,7 +166,7 @@ namespace BBM
pushInfo(ia._state, player, bombHolder); pushInfo(ia._state, player, bombHolder);
ia._state.callFunction(1, 4); ia._state.callFunction(1, 4);
controllable.bomb = ia._state.getReturnBool(); controllable.bomb = ia._state.getReturnBool();
controllable.select = ia._state.getReturnBool(); controllable.secondary = ia._state.getReturnBool();
controllable.move.y = ia._state.getReturnNumber(); controllable.move.y = ia._state.getReturnNumber();
controllable.move.x = ia._state.getReturnNumber(); controllable.move.x = ia._state.getReturnNumber();
ia._state.popLast(); ia._state.popLast();
+3 -3
View File
@@ -22,9 +22,9 @@ namespace BBM
auto &controllable = entity.get<ControllableComponent>(); auto &controllable = entity.get<ControllableComponent>();
const std::map<KeyboardKey, bool &> keyPressedMap = { const std::map<KeyboardKey, bool &> keyPressedMap = {
{keyboard.keyJump, controllable.select}, {keyboard.keySecondary, controllable.secondary},
{keyboard.keyBomb, controllable.bomb}, {keyboard.keyBomb, controllable.bomb},
{keyboard.keyPause, controllable.pause} {keyboard.keyPause, controllable.pause}
}; };
for (auto key : keyPressedMap) for (auto key : keyPressedMap)
+5 -5
View File
@@ -75,7 +75,7 @@ namespace BBM
if (lobby.layout == ControllableComponent::NONE) { if (lobby.layout == ControllableComponent::NONE) {
for (auto &[_, ctrl] : this->_wal.getScene()->view<ControllableComponent>()) { for (auto &[_, ctrl] : this->_wal.getScene()->view<ControllableComponent>()) {
auto &controller = ctrl; auto &controller = ctrl;
if (controller.select) { if (controller.bomb) {
if (std::any_of(this->getView().begin(), this->getView().end(), [&controller](WAL::ViewEntity<LobbyComponent, Drawable2DComponent> &view) { if (std::any_of(this->getView().begin(), this->getView().end(), [&controller](WAL::ViewEntity<LobbyComponent, Drawable2DComponent> &view) {
return view.get<LobbyComponent>().layout == controller.layout; return view.get<LobbyComponent>().layout == controller.layout;
})) }))
@@ -84,7 +84,7 @@ namespace BBM
lobby.color = -1; lobby.color = -1;
this->_nextColor(entity); this->_nextColor(entity);
lobby.layout = controller.layout; lobby.layout = controller.layout;
controller.select = false; controller.bomb = false;
return; return;
} }
} }
@@ -93,16 +93,16 @@ namespace BBM
for (auto &[_, controller] : this->_wal.getScene()->view<ControllableComponent>()) { for (auto &[_, controller] : this->_wal.getScene()->view<ControllableComponent>()) {
if (controller.layout != lobby.layout) if (controller.layout != lobby.layout)
continue; continue;
if (controller.select && !lobby.ready) { if (controller.bomb && !lobby.ready) {
lobby.ready = true; lobby.ready = true;
lobby.lastInput = lastTick; lobby.lastInput = lastTick;
controller.select = false; controller.bomb = false;
this->_wal.getSystem<MenuControllableSystem>().now = lastTick; this->_wal.getSystem<MenuControllableSystem>().now = lastTick;
auto *texture = dynamic_cast<RAY::Texture *>(lobby.readyButton.getComponent<Drawable2DComponent>().drawable.get()); auto *texture = dynamic_cast<RAY::Texture *>(lobby.readyButton.getComponent<Drawable2DComponent>().drawable.get());
if (texture) if (texture)
texture->use("assets/player/icons/ready.png"); texture->use("assets/player/icons/ready.png");
} }
if (controller.bomb && !lobby.ready) { if (controller.secondary && !lobby.ready) {
lobby.lastInput = lastTick; lobby.lastInput = lastTick;
this->_nextColor(entity); this->_nextColor(entity);
} }
@@ -95,8 +95,8 @@ namespace BBM
if (!this->_currentButton) if (!this->_currentButton)
return; return;
for (auto &[_, controllable]: controllableView) for (auto &[_, controllable]: controllableView)
if (controllable.move.x || controllable.move.y || controllable.select) { if (controllable.move.x || controllable.move.y || controllable.bomb) {
this->_updateCurrentButton(controllable.select, controllable.move); this->_updateCurrentButton(controllable.bomb, controllable.move);
return; return;
} }
if (relativeMousePos == this->_oldMousePosition && !RAYControl::Mouse::isPressed(RAYControl::Mouse::Button::MOUSE_BUTTON_LEFT)) if (relativeMousePos == this->_oldMousePosition && !RAYControl::Mouse::isPressed(RAYControl::Mouse::Button::MOUSE_BUTTON_LEFT))
@@ -20,7 +20,7 @@ namespace BBM {
std::map<bool, SoundComponent::SoundIndex> soundIndex = { std::map<bool, SoundComponent::SoundIndex> soundIndex = {
{controllable.move.x, SoundComponent::MOVE}, {controllable.move.x, SoundComponent::MOVE},
{controllable.move.y, SoundComponent::MOVE}, {controllable.move.y, SoundComponent::MOVE},
{controllable.select, SoundComponent::JUMP}, {controllable.bomb, SoundComponent::BOMB},
}; };
for (auto &a : soundIndex) { for (auto &a : soundIndex) {
if (a.first) { if (a.first) {
@@ -21,7 +21,6 @@ namespace BBM {
std::map<bool, SoundComponent::SoundIndex> soundIndex = { std::map<bool, SoundComponent::SoundIndex> soundIndex = {
{health.getHealthPoint() <= 0, SoundComponent::DEATH}, {health.getHealthPoint() <= 0, SoundComponent::DEATH},
{controllable.bomb, SoundComponent::BOMB}, {controllable.bomb, SoundComponent::BOMB},
{controllable.select, SoundComponent::JUMP},
{controllable.move.x != 0 || controllable.move.y != 0, SoundComponent::MOVE} {controllable.move.x != 0 || controllable.move.y != 0, SoundComponent::MOVE}
}; };
for (auto &a : soundIndex) { for (auto &a : soundIndex) {