Varios arreglos a tot lo de definir botons dins del service menu i lo de triar mando
This commit is contained in:
@@ -2,21 +2,21 @@
|
||||
|
||||
#include <algorithm> // Para max
|
||||
|
||||
#include "audio.h" // Para Audio
|
||||
#include "difficulty.h" // Para getCodeFromName, getNameFromCode
|
||||
#include "input.h" // Para Input
|
||||
#include "lang.h" // Para getText, getCodeFromName, getNameFromCode
|
||||
#include "menu_option.h" // Para MenuOption, ListOption, ActionOption, BoolOption, FolderOption, IntOption
|
||||
#include "menu_renderer.h" // Para MenuRenderer
|
||||
#include "options.h" // Para PendingChanges, pending_changes, checkPendingChanges, GamepadManager, Video, gamepad_manager, video, Audio, Settings, audio, settings, Gamepad, Window, window, Music, Sound
|
||||
#include "param.h" // Para Param, param, ParamGame, ParamServiceMenu
|
||||
#include "player.h" // Para Player
|
||||
#include "resource.h" // Para Resource
|
||||
#include "screen.h" // Para Screen
|
||||
#include "section.hpp" // Para Name, name, Options, options
|
||||
#include "ui/ui_message.h" // Para UIMessage
|
||||
#include "utils.h" // Para Zone
|
||||
#include "define_buttons.h" // Para DefineButtons
|
||||
#include "audio.h" // Para Audio
|
||||
#include "define_buttons.h" // Para DefineButtons
|
||||
#include "difficulty.h" // Para getCodeFromName, getNameFromCode
|
||||
#include "input.h" // Para Input
|
||||
#include "lang.h" // Para getText, getCodeFromName, getNameFromCode
|
||||
#include "menu_option.h" // Para MenuOption, ListOption, ActionOption, BoolOption, FolderOption, IntOption
|
||||
#include "menu_renderer.h" // Para MenuRenderer
|
||||
#include "options.h" // Para PendingChanges, pending_changes, checkPendingChanges, GamepadManager, Video, gamepad_manager, video, Audio, Settings, audio, settings, Gamepad, Window, window, Music, Sound
|
||||
#include "param.h" // Para Param, param, ParamGame, ParamServiceMenu
|
||||
#include "player.h" // Para Player
|
||||
#include "resource.h" // Para Resource
|
||||
#include "screen.h" // Para Screen
|
||||
#include "section.hpp" // Para Name, name, Options, options
|
||||
#include "ui/ui_message.h" // Para UIMessage
|
||||
#include "utils.h" // Para Zone
|
||||
|
||||
// Singleton
|
||||
ServiceMenu *ServiceMenu::instance = nullptr;
|
||||
@@ -39,6 +39,10 @@ ServiceMenu::ServiceMenu()
|
||||
}
|
||||
|
||||
void ServiceMenu::toggle() {
|
||||
if (define_buttons_ && define_buttons_->isEnabled()) {
|
||||
return; // No se puede mostrar u ocultar el menu de servicio si se estan definiendo los botones
|
||||
}
|
||||
|
||||
playBackSound();
|
||||
enabled_ = !enabled_;
|
||||
if (!enabled_) {
|
||||
@@ -81,13 +85,13 @@ void ServiceMenu::update() {
|
||||
// Actualizar DefineButtons
|
||||
if (define_buttons_) {
|
||||
define_buttons_->update();
|
||||
|
||||
|
||||
// Si DefineButtons ha terminado, deshabilitarlo
|
||||
if (define_buttons_->isEnabled() && define_buttons_->isFinished()) {
|
||||
// Pequeño delay antes de cerrar
|
||||
static int finish_delay = 0;
|
||||
static size_t finish_delay = 0;
|
||||
finish_delay++;
|
||||
if (finish_delay > 60) { // 1 segundo a 60 FPS
|
||||
if (finish_delay > DEFINE_BUTTONS_FINISH_DELAY_FRAMES) {
|
||||
define_buttons_->disable();
|
||||
finish_delay = 0;
|
||||
}
|
||||
@@ -283,7 +287,7 @@ void ServiceMenu::initializeOptions() {
|
||||
},
|
||||
[this]() {
|
||||
// Acción: configurar botones del mando del jugador 1
|
||||
auto* gamepad = &Options::gamepad_manager.getGamepad(Player::Id::PLAYER1);
|
||||
auto *gamepad = &Options::gamepad_manager.getGamepad(Player::Id::PLAYER1);
|
||||
if (gamepad && gamepad->instance) {
|
||||
define_buttons_->enable(gamepad);
|
||||
}
|
||||
@@ -301,7 +305,7 @@ void ServiceMenu::initializeOptions() {
|
||||
},
|
||||
[this]() {
|
||||
// Acción: configurar botones del mando del jugador 2
|
||||
auto* gamepad = &Options::gamepad_manager.getGamepad(Player::Id::PLAYER2);
|
||||
auto *gamepad = &Options::gamepad_manager.getGamepad(Player::Id::PLAYER2);
|
||||
if (gamepad && gamepad->instance) {
|
||||
define_buttons_->enable(gamepad);
|
||||
}
|
||||
@@ -550,66 +554,95 @@ void ServiceMenu::handleEvent(const SDL_Event &event) {
|
||||
// Si DefineButtons está activo, que maneje todos los eventos
|
||||
if (define_buttons_ && define_buttons_->isEnabled()) {
|
||||
define_buttons_->checkEvents(event);
|
||||
return; // No procesar otros eventos mientras DefineButtons está activo
|
||||
return; // No procesar otros eventos mientras DefineButtons está activo
|
||||
}
|
||||
}
|
||||
|
||||
bool ServiceMenu::checkInput() {
|
||||
if (!enabled_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Procesar eventos normales del ServiceMenu
|
||||
/*switch (event.type) {
|
||||
case SDL_EVENT_KEY_DOWN:
|
||||
switch (event.key.key) {
|
||||
case SDLK_ESCAPE:
|
||||
case SDLK_BACKSPACE:
|
||||
moveBack();
|
||||
break;
|
||||
case SDLK_RETURN:
|
||||
case SDLK_KP_ENTER:
|
||||
selectOption();
|
||||
break;
|
||||
case SDLK_UP:
|
||||
setSelectorUp();
|
||||
break;
|
||||
case SDLK_DOWN:
|
||||
setSelectorDown();
|
||||
break;
|
||||
case SDLK_LEFT:
|
||||
adjustOption(false);
|
||||
break;
|
||||
case SDLK_RIGHT:
|
||||
adjustOption(true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
|
||||
switch (event.gbutton.button) {
|
||||
case SDL_GAMEPAD_BUTTON_SOUTH:
|
||||
case SDL_GAMEPAD_BUTTON_BACK:
|
||||
moveBack();
|
||||
break;
|
||||
case SDL_GAMEPAD_BUTTON_EAST:
|
||||
case SDL_GAMEPAD_BUTTON_START:
|
||||
selectOption();
|
||||
break;
|
||||
case SDL_GAMEPAD_BUTTON_DPAD_UP:
|
||||
setSelectorUp();
|
||||
break;
|
||||
case SDL_GAMEPAD_BUTTON_DPAD_DOWN:
|
||||
setSelectorDown();
|
||||
break;
|
||||
case SDL_GAMEPAD_BUTTON_DPAD_LEFT:
|
||||
adjustOption(false);
|
||||
break;
|
||||
case SDL_GAMEPAD_BUTTON_DPAD_RIGHT:
|
||||
adjustOption(true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}*/
|
||||
if (define_buttons_ && define_buttons_->isEnabled()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static auto input = Input::get();
|
||||
// --- Teclado ---
|
||||
// Arriba
|
||||
if (input->checkAction(Input::Action::UP, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
setSelectorUp();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Abajo
|
||||
if (input->checkAction(Input::Action::DOWN, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
setSelectorDown();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Derecha
|
||||
if (input->checkAction(Input::Action::RIGHT, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
adjustOption(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Izquierda
|
||||
if (input->checkAction(Input::Action::LEFT, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
adjustOption(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Aceptar
|
||||
if (input->checkAction(Input::Action::SM_SELECT, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
selectOption();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Atras
|
||||
if (input->checkAction(Input::Action::SM_BACK, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
moveBack();
|
||||
return true;
|
||||
}
|
||||
|
||||
// --- Mandos ---
|
||||
auto gamepads = input->getGamepads();
|
||||
for (auto gamepad : gamepads) {
|
||||
// Arriba
|
||||
if (input->checkAction(Input::Action::UP, Input::DO_NOT_ALLOW_REPEAT, Input::DO_NOT_CHECK_KEYBOARD, gamepad)) {
|
||||
setSelectorUp();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Abajo
|
||||
if (input->checkAction(Input::Action::DOWN, Input::DO_NOT_ALLOW_REPEAT, Input::DO_NOT_CHECK_KEYBOARD, gamepad)) {
|
||||
setSelectorDown();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Derecha
|
||||
if (input->checkAction(Input::Action::RIGHT, Input::DO_NOT_ALLOW_REPEAT, Input::DO_NOT_CHECK_KEYBOARD, gamepad)) {
|
||||
adjustOption(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Izquierda
|
||||
if (input->checkAction(Input::Action::LEFT, Input::DO_NOT_ALLOW_REPEAT, Input::DO_NOT_CHECK_KEYBOARD, gamepad)) {
|
||||
adjustOption(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Aceptar
|
||||
if (input->checkAction(Input::Action::SM_SELECT, Input::DO_NOT_ALLOW_REPEAT, Input::DO_NOT_CHECK_KEYBOARD, gamepad)) {
|
||||
selectOption();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Atras
|
||||
if (input->checkAction(Input::Action::SM_BACK, Input::DO_NOT_ALLOW_REPEAT, Input::DO_NOT_CHECK_KEYBOARD, gamepad)) {
|
||||
moveBack();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user