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.
Vector2f move;
//! @brief input value to select
bool select = false;
//! @brief input value for bomb
//! @brief input value for secondary inputs.
bool secondary = false;
//! @brief input value for bomb and selection
bool bomb = false;
//! @brief input value for pause
bool pause = false;
@@ -22,9 +22,9 @@ namespace BBM
int _ID;
public:
//! @brief jump key
Button keyJump = GAMEPAD_BUTTON_RIGHT_FACE_DOWN;
Button keySecondary = GAMEPAD_BUTTON_RIGHT_FACE_RIGHT;
//! @brief bomb key
Button keyBomb = GAMEPAD_BUTTON_RIGHT_FACE_RIGHT;
Button keyBomb = GAMEPAD_BUTTON_RIGHT_FACE_DOWN;
//! @brief pause key
Button keyPause = GAMEPAD_BUTTON_MIDDLE;
//! @brief move right key
@@ -16,16 +16,16 @@ namespace BBM
this->keyDown = KEY_S;
this->keyLeft = KEY_A;
this->keyRight = KEY_D;
this->keyJump = KEY_SPACE;
this->keyBomb = KEY_E;
this->keyBomb = KEY_SPACE;
this->keySecondary = KEY_LEFT_CONTROL;
this->keyPause = KEY_ESCAPE;
} else {
this->keyUp = KEY_UP;
this->keyDown = KEY_DOWN;
this->keyLeft = KEY_LEFT;
this->keyRight = KEY_RIGHT;
this->keyJump = KEY_RIGHT_CONTROL;
this->keyBomb = KEY_ENTER;
this->keyBomb = KEY_RIGHT_CONTROL;
this->keySecondary = KEY_RIGHT_SHIFT;
this->keyPause = KEY_BACKSPACE;
}
}
@@ -18,7 +18,7 @@ namespace BBM
{
public:
//! @brief jump key
Key keyJump = KEY_SPACE;
Key keySecondary = KEY_SPACE;
//! @brief bomb key
Key keyBomb = KEY_E;
//! @brief pause key
+4 -3
View File
@@ -67,19 +67,20 @@ namespace BBM
auto &back = scene->addEntity("back to menu")
.addComponent<PositionComponent>(10, 1080 - 85, 0)
.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;
})
.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");
})
.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");
});
+3 -3
View File
@@ -24,9 +24,9 @@ namespace BBM
Gamepad gamepad(gamepadComponent.getID());
const std::map<Button, bool &> keyPressedMap = {
{gamepadComponent.keyJump, controllable.select},
{gamepadComponent.keyBomb, controllable.bomb},
{gamepadComponent.keyPause, controllable.pause}
{gamepadComponent.keySecondary, controllable.secondary},
{gamepadComponent.keyBomb, controllable.bomb},
{gamepadComponent.keyPause, controllable.pause}
};
for (auto key : keyPressedMap)
@@ -166,7 +166,7 @@ namespace BBM
pushInfo(ia._state, player, bombHolder);
ia._state.callFunction(1, 4);
controllable.bomb = ia._state.getReturnBool();
controllable.select = ia._state.getReturnBool();
controllable.secondary = ia._state.getReturnBool();
controllable.move.y = ia._state.getReturnNumber();
controllable.move.x = ia._state.getReturnNumber();
ia._state.popLast();
+3 -3
View File
@@ -22,9 +22,9 @@ namespace BBM
auto &controllable = entity.get<ControllableComponent>();
const std::map<KeyboardKey, bool &> keyPressedMap = {
{keyboard.keyJump, controllable.select},
{keyboard.keyBomb, controllable.bomb},
{keyboard.keyPause, controllable.pause}
{keyboard.keySecondary, controllable.secondary},
{keyboard.keyBomb, controllable.bomb},
{keyboard.keyPause, controllable.pause}
};
for (auto key : keyPressedMap)
+5 -5
View File
@@ -75,7 +75,7 @@ namespace BBM
if (lobby.layout == ControllableComponent::NONE) {
for (auto &[_, ctrl] : this->_wal.getScene()->view<ControllableComponent>()) {
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) {
return view.get<LobbyComponent>().layout == controller.layout;
}))
@@ -84,7 +84,7 @@ namespace BBM
lobby.color = -1;
this->_nextColor(entity);
lobby.layout = controller.layout;
controller.select = false;
controller.bomb = false;
return;
}
}
@@ -93,16 +93,16 @@ namespace BBM
for (auto &[_, controller] : this->_wal.getScene()->view<ControllableComponent>()) {
if (controller.layout != lobby.layout)
continue;
if (controller.select && !lobby.ready) {
if (controller.bomb && !lobby.ready) {
lobby.ready = true;
lobby.lastInput = lastTick;
controller.select = false;
controller.bomb = false;
this->_wal.getSystem<MenuControllableSystem>().now = lastTick;
auto *texture = dynamic_cast<RAY::Texture *>(lobby.readyButton.getComponent<Drawable2DComponent>().drawable.get());
if (texture)
texture->use("assets/player/icons/ready.png");
}
if (controller.bomb && !lobby.ready) {
if (controller.secondary && !lobby.ready) {
lobby.lastInput = lastTick;
this->_nextColor(entity);
}
@@ -95,8 +95,8 @@ namespace BBM
if (!this->_currentButton)
return;
for (auto &[_, controllable]: controllableView)
if (controllable.move.x || controllable.move.y || controllable.select) {
this->_updateCurrentButton(controllable.select, controllable.move);
if (controllable.move.x || controllable.move.y || controllable.bomb) {
this->_updateCurrentButton(controllable.bomb, controllable.move);
return;
}
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 = {
{controllable.move.x, SoundComponent::MOVE},
{controllable.move.y, SoundComponent::MOVE},
{controllable.select, SoundComponent::JUMP},
{controllable.bomb, SoundComponent::BOMB},
};
for (auto &a : soundIndex) {
if (a.first) {
@@ -21,7 +21,6 @@ namespace BBM {
std::map<bool, SoundComponent::SoundIndex> soundIndex = {
{health.getHealthPoint() <= 0, SoundComponent::DEATH},
{controllable.bomb, SoundComponent::BOMB},
{controllable.select, SoundComponent::JUMP},
{controllable.move.x != 0 || controllable.move.y != 0, SoundComponent::MOVE}
};
for (auto &a : soundIndex) {