Input: mogudes structs, enums i consts a la part publica

This commit is contained in:
2025-07-30 08:53:57 +02:00
parent 677feb3afe
commit 989f081a25
14 changed files with 302 additions and 275 deletions

View File

@@ -22,7 +22,7 @@
#include "global_events.h" // Para check
#include "global_inputs.h" // Para check
#include "hit.h" // Para Hit
#include "input.h" // Para InputAction, Input, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_ALLOW_REPEAT, InputDevice
#include "input.h" // Para InputAction, Input, Input::DO_NOT_ALLOW_REPEAT, Input::ALLOW_REPEAT, InputDevice
#include "item.h" // Para Item, ItemType
#include "lang.h" // Para getText
#include "manage_hiscore_table.h" // Para ManageHiScoreTable, HiScoreEntry
@@ -1244,14 +1244,14 @@ void Game::checkInput() {
void Game::checkPauseInput() {
// Comprueba los mandos
for (int i = 0; i < input_->getNumControllers(); ++i) {
if (input_->checkInput(InputAction::PAUSE, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::CONTROLLER, i)) {
if (input_->checkInput(Input::Action::PAUSE, Input::DO_NOT_ALLOW_REPEAT, Input::Device::CONTROLLER, i)) {
pause(!paused_);
return;
}
}
// Comprueba el teclado
if (input_->checkInput(InputAction::PAUSE, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) {
if (input_->checkInput(Input::Action::PAUSE, Input::DO_NOT_ALLOW_REPEAT, Input::Device::KEYBOARD)) {
pause(!paused_);
return;
}
@@ -1283,11 +1283,11 @@ void Game::demoHandlePlayerInput(const std::shared_ptr<Player> &player, int inde
const auto &demo_data = demo_.data[index][demo_.counter];
if (demo_data.left == 1) {
player->setInput(InputAction::LEFT);
player->setInput(Input::Action::LEFT);
} else if (demo_data.right == 1) {
player->setInput(InputAction::RIGHT);
player->setInput(Input::Action::RIGHT);
} else if (demo_data.no_input == 1) {
player->setInput(InputAction::NONE);
player->setInput(Input::Action::NONE);
}
if (demo_data.fire == 1) {
@@ -1305,17 +1305,17 @@ void Game::handleFireInput(const std::shared_ptr<Player> &player, BulletType bul
SDL_Point bullet = {0, 0};
switch (bullet_type) {
case BulletType::UP:
player->setInput(InputAction::FIRE_CENTER);
player->setInput(Input::Action::FIRE_CENTER);
bullet.x = 2 + player->getPosX() + (player->getWidth() - Bullet::WIDTH) / 2;
bullet.y = player->getPosY() - (Bullet::HEIGHT / 2);
break;
case BulletType::LEFT:
player->setInput(InputAction::FIRE_LEFT);
player->setInput(Input::Action::FIRE_LEFT);
bullet.x = player->getPosX() - (Bullet::WIDTH / 2);
bullet.y = player->getPosY();
break;
case BulletType::RIGHT:
player->setInput(InputAction::FIRE_RIGHT);
player->setInput(Input::Action::FIRE_RIGHT);
bullet.x = player->getPosX() + player->getWidth() - (Bullet::WIDTH / 2);
bullet.y = player->getPosY();
break;
@@ -1362,18 +1362,18 @@ void Game::handlePlayersInput() {
void Game::handleNormalPlayerInput(const std::shared_ptr<Player> &player) {
const auto &controller = Options::controllers.at(player->getController());
if (input_->checkInput(InputAction::LEFT, INPUT_ALLOW_REPEAT, controller.type, controller.index)) {
player->setInput(InputAction::LEFT);
if (input_->checkInput(Input::Action::LEFT, Input::ALLOW_REPEAT, controller.type, controller.index)) {
player->setInput(Input::Action::LEFT);
#ifdef RECORDING
demo_.keys.left = 1;
#endif
} else if (input_->checkInput(InputAction::RIGHT, INPUT_ALLOW_REPEAT, controller.type, controller.index)) {
player->setInput(InputAction::RIGHT);
} else if (input_->checkInput(Input::Action::RIGHT, Input::ALLOW_REPEAT, controller.type, controller.index)) {
player->setInput(Input::Action::RIGHT);
#ifdef RECORDING
demo_.keys.right = 1;
#endif
} else {
player->setInput(InputAction::NONE);
player->setInput(Input::Action::NONE);
#ifdef RECORDING
demo_.keys.no_input = 1;
#endif
@@ -1386,17 +1386,17 @@ void Game::handleNormalPlayerInput(const std::shared_ptr<Player> &player) {
// Procesa las entradas de disparo del jugador, permitiendo disparos automáticos si está habilitado.
void Game::handleFireInputs(const std::shared_ptr<Player> &player, bool autofire, int controller_index) {
const auto CONTROLLER = Options::controllers.at(player->getController());
if (input_->checkInput(InputAction::FIRE_CENTER, autofire, CONTROLLER.type, CONTROLLER.index)) {
if (input_->checkInput(Input::Action::FIRE_CENTER, autofire, CONTROLLER.type, CONTROLLER.index)) {
handleFireInput(player, BulletType::UP);
#ifdef RECORDING
demo_.keys.fire = 1;
#endif
} else if (input_->checkInput(InputAction::FIRE_LEFT, autofire, CONTROLLER.type, CONTROLLER.index)) {
} else if (input_->checkInput(Input::Action::FIRE_LEFT, autofire, CONTROLLER.type, CONTROLLER.index)) {
handleFireInput(player, BulletType::LEFT);
#ifdef RECORDING
demo_.keys.fire_left = 1;
#endif
} else if (input_->checkInput(InputAction::FIRE_RIGHT, autofire, CONTROLLER.type, CONTROLLER.index)) {
} else if (input_->checkInput(Input::Action::FIRE_RIGHT, autofire, CONTROLLER.type, CONTROLLER.index)) {
handleFireInput(player, BulletType::RIGHT);
#ifdef RECORDING
demo_.keys.fire_right = 1;
@@ -1407,16 +1407,16 @@ void Game::handleFireInputs(const std::shared_ptr<Player> &player, bool autofire
// Maneja la continuación del jugador cuando no está jugando, permitiendo que continúe si se pulsa el botón de inicio.
void Game::handlePlayerContinueInput(const std::shared_ptr<Player> &player) {
const auto CONTROLLER = Options::controllers.at(player->getController());
if (input_->checkInput(InputAction::START, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) {
if (input_->checkInput(Input::Action::START, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) {
player->setPlayingState(Player::State::RESPAWNING);
player->addCredit();
sendPlayerToTheFront(player);
}
// Disminuye el contador de continuación si se presiona cualquier botón de disparo.
if (input_->checkInput(InputAction::FIRE_LEFT, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index) ||
input_->checkInput(InputAction::FIRE_CENTER, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index) ||
input_->checkInput(InputAction::FIRE_RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) {
if (input_->checkInput(Input::Action::FIRE_LEFT, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index) ||
input_->checkInput(Input::Action::FIRE_CENTER, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index) ||
input_->checkInput(Input::Action::FIRE_RIGHT, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) {
if (player->getContinueCounter() < param.scoreboard.skip_countdown_value) {
player->decContinueCounter();
}
@@ -1426,7 +1426,7 @@ void Game::handlePlayerContinueInput(const std::shared_ptr<Player> &player) {
// Maneja la continuación del jugador cuando no está jugando, permitiendo que continúe si se pulsa el botón de inicio.
void Game::handlePlayerWaitingInput(const std::shared_ptr<Player> &player) {
const auto CONTROLLER = Options::controllers.at(player->getController());
if (input_->checkInput(InputAction::START, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) {
if (input_->checkInput(Input::Action::START, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) {
player->setPlayingState(Player::State::ENTERING_SCREEN);
player->addCredit();
sendPlayerToTheFront(player);
@@ -1436,32 +1436,32 @@ void Game::handlePlayerWaitingInput(const std::shared_ptr<Player> &player) {
// Procesa las entradas para la introducción del nombre del jugador.
void Game::handleNameInput(const std::shared_ptr<Player> &player) {
const auto CONTROLLER = Options::controllers.at(player->getController());
if (input_->checkInput(InputAction::FIRE_LEFT, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) {
if (input_->checkInput(Input::Action::FIRE_LEFT, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) {
if (player->isShowingName()) {
player->setPlayingState(Player::State::CONTINUE);
} else if (player->getEnterNamePositionOverflow()) {
player->setInput(InputAction::START);
player->setInput(Input::Action::START);
addScoreToScoreBoard(player);
player->setPlayingState(Player::State::SHOWING_NAME);
} else {
player->setInput(InputAction::RIGHT);
player->setInput(Input::Action::RIGHT);
}
} else if (input_->checkInput(InputAction::FIRE_CENTER, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index) ||
input_->checkInput(InputAction::FIRE_RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) {
} else if (input_->checkInput(Input::Action::FIRE_CENTER, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index) ||
input_->checkInput(Input::Action::FIRE_RIGHT, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) {
if (player->isShowingName()) {
player->setPlayingState(Player::State::CONTINUE);
} else {
player->setInput(InputAction::LEFT);
player->setInput(Input::Action::LEFT);
}
} else if (input_->checkInput(InputAction::UP, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) {
player->setInput(InputAction::UP);
} else if (input_->checkInput(InputAction::DOWN, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) {
player->setInput(InputAction::DOWN);
} else if (input_->checkInput(InputAction::START, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) {
} else if (input_->checkInput(Input::Action::UP, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) {
player->setInput(Input::Action::UP);
} else if (input_->checkInput(Input::Action::DOWN, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) {
player->setInput(Input::Action::DOWN);
} else if (input_->checkInput(Input::Action::START, Input::DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) {
if (player->isShowingName()) {
player->setPlayingState(Player::State::CONTINUE);
} else {
player->setInput(InputAction::START);
player->setInput(Input::Action::START);
addScoreToScoreBoard(player);
player->setPlayingState(Player::State::SHOWING_NAME);
}
@@ -1882,7 +1882,7 @@ void Game::checkDebugEvents(const SDL_Event &event) {
case SDLK_1: // Crea una powerball
{
// balloon_manager_->createPowerBall();
//throwCoffee(players_.at(0)->getPosX() + (players_.at(0)->getWidth() / 2), players_.at(0)->getPosY() + (players_.at(0)->getHeight() / 2));
// throwCoffee(players_.at(0)->getPosX() + (players_.at(0)->getWidth() / 2), players_.at(0)->getPosY() + (players_.at(0)->getHeight() / 2));
break;
}
case SDLK_2: // Activa o desactiva la aparición de globos