fix DefineButtons i Title: ja no fa coses rares al definir la ultima tecla
This commit is contained in:
@@ -63,9 +63,19 @@ void DefineButtons::bindButtons()
|
||||
// Comprueba los eventos
|
||||
void DefineButtons::checkEvents(const SDL_Event &event)
|
||||
{
|
||||
if (enabled_ && event.type == SDL_EVENT_GAMEPAD_BUTTON_DOWN)
|
||||
if (enabled_)
|
||||
{
|
||||
doControllerButtonDown(event.gbutton);
|
||||
switch (event.type)
|
||||
{
|
||||
case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
|
||||
doControllerButtonDown(event.gbutton);
|
||||
break;
|
||||
case SDL_EVENT_GAMEPAD_BUTTON_UP:
|
||||
checkEnd();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,6 +85,7 @@ bool DefineButtons::enable(int index)
|
||||
if (index < input_->getNumControllers())
|
||||
{
|
||||
enabled_ = true;
|
||||
finished_ = false;
|
||||
index_controller_ = index;
|
||||
index_button_ = 0;
|
||||
clearButtons();
|
||||
@@ -90,19 +101,13 @@ bool DefineButtons::isEnabled() const { return enabled_; }
|
||||
// Incrementa el indice de los botones
|
||||
void DefineButtons::incIndexButton()
|
||||
{
|
||||
++index_button_;
|
||||
|
||||
// Comprueba si ha finalizado
|
||||
if (index_button_ == buttons_.size())
|
||||
if (index_button_ < buttons_.size() - 1)
|
||||
{
|
||||
// Asigna los botones definidos al input_
|
||||
bindButtons();
|
||||
|
||||
// Guarda los cambios en las opciones
|
||||
saveBindingsToOptions();
|
||||
|
||||
// Deshabilita
|
||||
enabled_ = false;
|
||||
++index_button_;
|
||||
}
|
||||
else
|
||||
{
|
||||
finished_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,4 +145,24 @@ void DefineButtons::clearButtons()
|
||||
buttons_.emplace_back(Lang::getText("[DEFINE_BUTTONS] FIRE_RIGHT"), InputAction::FIRE_RIGHT, SDL_GAMEPAD_BUTTON_INVALID);
|
||||
buttons_.emplace_back(Lang::getText("[DEFINE_BUTTONS] START"), InputAction::START, SDL_GAMEPAD_BUTTON_INVALID);
|
||||
buttons_.emplace_back(Lang::getText("[DEFINE_BUTTONS] SERVICE_MENU"), InputAction::SERVICE, SDL_GAMEPAD_BUTTON_INVALID);
|
||||
}
|
||||
|
||||
// Comprueba si ha finalizado
|
||||
void DefineButtons::checkEnd()
|
||||
{
|
||||
// Comprueba si ha finalizado
|
||||
if (finished_)
|
||||
{
|
||||
// Asigna los botones definidos al input_
|
||||
bindButtons();
|
||||
|
||||
// Guarda los cambios en las opciones
|
||||
saveBindingsToOptions();
|
||||
|
||||
// Reinicia los estados de las pulsaciones de los botones
|
||||
input_->resetInputStates();
|
||||
|
||||
// Deshabilita
|
||||
enabled_ = false;
|
||||
}
|
||||
}
|
||||
@@ -47,6 +47,7 @@ private:
|
||||
size_t index_controller_ = 0; // Índice del controlador asignado
|
||||
size_t index_button_ = 0; // Índice del botón en proceso
|
||||
std::vector<std::string> controller_names_; // Nombres de los mandos
|
||||
bool finished_ = false;
|
||||
|
||||
// Métodos internos
|
||||
void incIndexButton(); // Incrementa el índice de botones
|
||||
@@ -55,4 +56,5 @@ private:
|
||||
void saveBindingsToOptions(); // Guarda configuraciones
|
||||
bool checkButtonNotInUse(SDL_GamepadButton button); // Verifica uso de botones
|
||||
void clearButtons(); // Limpia asignaciones actuales
|
||||
void checkEnd(); // Comprueba si ha finalizado
|
||||
};
|
||||
|
||||
@@ -451,4 +451,17 @@ void Input::initSDL()
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_TEST, "** SDL_GAMEPAD: INITIALIZATION COMPLETE\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Input::resetInputStates() {
|
||||
// Resetear todos los KeyBindings.active a false
|
||||
for (auto &key : key_bindings_) {
|
||||
key.active = false;
|
||||
}
|
||||
// Resetear todos los ControllerBindings.active a false
|
||||
for (auto &controller_vec : controller_bindings_) {
|
||||
for (auto &binding : controller_vec) {
|
||||
binding.active = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -103,6 +103,9 @@ public:
|
||||
InputAction to_inputs_e(const std::string &name) const; // Convierte un std::string a InputAction
|
||||
int getIndexByName(const std::string &name) const; // Obtiene el índice a partir del nombre del mando
|
||||
|
||||
// --- Métodos de reseteo de estado de entrada ---
|
||||
void resetInputStates(); // Pone todos los KeyBindings.active y ControllerBindings.active a false
|
||||
|
||||
private:
|
||||
// --- Singleton ---
|
||||
static Input *instance_;
|
||||
|
||||
@@ -143,42 +143,33 @@ void Title::checkEvents()
|
||||
{
|
||||
if (event.type == SDL_EVENT_KEY_DOWN && event.key.repeat == 0)
|
||||
{
|
||||
bool should_reset = false;
|
||||
|
||||
switch (event.key.key)
|
||||
{
|
||||
case SDLK_1: // Redefine los botones del mando #0
|
||||
should_reset = define_buttons_->enable(0);
|
||||
define_buttons_->enable(0);
|
||||
break;
|
||||
|
||||
case SDLK_2: // Redefine los botones del mando #1
|
||||
should_reset = define_buttons_->enable(1);
|
||||
define_buttons_->enable(1);
|
||||
break;
|
||||
|
||||
case SDLK_3: // Intercambia los mandos entre los dos jugadores
|
||||
swapControllers();
|
||||
should_reset = true;
|
||||
break;
|
||||
|
||||
case SDLK_4: // Intercambia la asignación del teclado
|
||||
swapKeyboard();
|
||||
should_reset = true;
|
||||
break;
|
||||
|
||||
case SDLK_5: // Muestra la asignación de mandos y teclado
|
||||
showControllers();
|
||||
should_reset = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Resetear el contador si es necesario
|
||||
if (should_reset)
|
||||
{
|
||||
resetCounter();
|
||||
}
|
||||
resetCounter();
|
||||
}
|
||||
|
||||
GlobalEvents::check(event);
|
||||
@@ -198,8 +189,7 @@ void Title::checkInput()
|
||||
for (const auto &CONTROLLER : Options::controllers)
|
||||
{
|
||||
// START
|
||||
if (Input::get()->checkInput(InputAction::START, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index) &&
|
||||
!Input::get()->checkInput(InputAction::SERVICE, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index))
|
||||
if (Input::get()->checkInput(InputAction::START, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index))
|
||||
{
|
||||
if ((state_ == TitleState::LOGO_FINISHED || ALLOW_TITLE_ANIMATION_SKIP) && !fade_->isEnabled())
|
||||
{
|
||||
@@ -222,28 +212,15 @@ void Title::checkInput()
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// SWAP_CONTROLLERS
|
||||
if (Input::get()->checkInput(InputAction::SERVICE, INPUT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index) &&
|
||||
Input::get()->checkInput(InputAction::SWAP_CONTROLLERS, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index))
|
||||
{
|
||||
swapControllers();
|
||||
return;
|
||||
}
|
||||
|
||||
// CONFIG
|
||||
if (Input::get()->checkInput(InputAction::SERVICE, INPUT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index) &&
|
||||
Input::get()->checkInput(InputAction::CONFIG, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index))
|
||||
{
|
||||
define_buttons_->enable(CONTROLLER.index);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
||||
GlobalInputs::check();
|
||||
if (!define_buttons_->isEnabled())
|
||||
{
|
||||
GlobalInputs::check();
|
||||
}
|
||||
}
|
||||
|
||||
// Bucle para el titulo del juego
|
||||
|
||||
Reference in New Issue
Block a user