Compare commits
3 Commits
3b07b2e130
...
0fc83cf9c1
| Author | SHA1 | Date | |
|---|---|---|---|
| 0fc83cf9c1 | |||
| 98f34c0a09 | |||
| 6f120dd4d2 |
@@ -105,7 +105,7 @@
|
||||
"[SERVICE_MENU] CONTROLLER2": "Mando 2",
|
||||
"[SERVICE_MENU] CONFIGURE1": "Configurar Mando 1",
|
||||
"[SERVICE_MENU] CONFIGURE2": "Configurar Mando 2",
|
||||
"[SERVICE_MENU] NO_CONTROLLER": "Cap",
|
||||
"[SERVICE_MENU] NO_CONTROLLER": "[ Desconectat ]",
|
||||
"[SERVICE_MENU] SWAP_CONTROLLERS": "Intercanvia mandos",
|
||||
|
||||
"[SCOREBOARD] 1": "Jugador 1",
|
||||
|
||||
@@ -104,7 +104,7 @@
|
||||
"[SERVICE_MENU] CONTROLLER2": "Controller 2",
|
||||
"[SERVICE_MENU] CONFIGURE1": "Configure Controller 1",
|
||||
"[SERVICE_MENU] CONFIGURE2": "Configure Controller 2",
|
||||
"[SERVICE_MENU] NO_CONTROLLER": "None",
|
||||
"[SERVICE_MENU] NO_CONTROLLER": "[No controller]",
|
||||
"[SERVICE_MENU] SWAP_CONTROLLERS": "Swap Controllers",
|
||||
|
||||
"[SCOREBOARD] 1" : "Player 1",
|
||||
|
||||
@@ -104,7 +104,7 @@
|
||||
"[SERVICE_MENU] CONTROLLER2": "Mando 2",
|
||||
"[SERVICE_MENU] CONFIGURE1": "Configurar Mando 1",
|
||||
"[SERVICE_MENU] CONFIGURE2": "Configurar Mando 2",
|
||||
"[SERVICE_MENU] NO_CONTROLLER": "Ninguno",
|
||||
"[SERVICE_MENU] NO_CONTROLLER": "[Desconectat]",
|
||||
"[SERVICE_MENU] SWAP_CONTROLLERS": "Intercambia mandos",
|
||||
|
||||
"[SCOREBOARD] 1": "Jugador 1",
|
||||
|
||||
@@ -35,14 +35,13 @@ DefineButtons::DefineButtons()
|
||||
config.text_safety_margin = 15.0F;
|
||||
config.min_width = 100;
|
||||
config.min_height = 32;
|
||||
config.animation_duration = 0.5F;
|
||||
config.animation_duration = 0.3F;
|
||||
|
||||
auto text_renderer = Resource::get()->getText("04b_25_flat");
|
||||
window_message_ = std::make_unique<WindowMessage>(
|
||||
text_renderer,
|
||||
Lang::getText("[DEFINE_BUTTONS] TITLE"),
|
||||
config
|
||||
);
|
||||
config);
|
||||
window_message_->setPosition(param.game.game_area.center_x, param.game.game_area.center_y, WindowMessage::PositionMode::CENTERED);
|
||||
}
|
||||
|
||||
@@ -56,27 +55,27 @@ void DefineButtons::update() {
|
||||
if (!enabled_) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Actualizar la ventana siempre
|
||||
if (window_message_) {
|
||||
window_message_->update();
|
||||
}
|
||||
|
||||
|
||||
// Manejar la secuencia de cierre si ya terminamos
|
||||
if (finished_ && message_shown_) {
|
||||
message_timer_++;
|
||||
|
||||
|
||||
// Después del delay, iniciar animación de cierre (solo una vez)
|
||||
if (message_timer_ > MESSAGE_DISPLAY_FRAMES && !closing_) {
|
||||
if (window_message_) {
|
||||
window_message_->hide(); // Iniciar animación de cierre
|
||||
window_message_->hide(); // Iniciar animación de cierre
|
||||
}
|
||||
closing_ = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DefineButtons::checkEvents(const SDL_Event &event) {
|
||||
void DefineButtons::handleEvents(const SDL_Event &event) {
|
||||
if (enabled_) {
|
||||
switch (event.type) {
|
||||
case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
|
||||
@@ -97,6 +96,8 @@ auto DefineButtons::enable(Options::Gamepad *options_gamepad) -> bool {
|
||||
enabled_ = true;
|
||||
finished_ = false;
|
||||
index_button_ = 0;
|
||||
message_shown_ = false;
|
||||
closing_ = false;
|
||||
clearButtons();
|
||||
updateWindowMessage();
|
||||
|
||||
@@ -113,6 +114,8 @@ auto DefineButtons::enable(Options::Gamepad *options_gamepad) -> bool {
|
||||
void DefineButtons::disable() {
|
||||
enabled_ = false;
|
||||
finished_ = false;
|
||||
message_shown_ = false;
|
||||
closing_ = false;
|
||||
|
||||
if (window_message_) {
|
||||
window_message_->hide();
|
||||
@@ -187,11 +190,11 @@ void DefineButtons::checkEnd() {
|
||||
bool DefineButtons::isReadyToClose() const {
|
||||
// Solo está listo para cerrar si:
|
||||
// 1. Terminó
|
||||
// 2. Ya mostró el mensaje
|
||||
// 2. Ya mostró el mensaje
|
||||
// 3. Está cerrando
|
||||
// 4. La ventana ya no está visible (animación terminada)
|
||||
return finished_ && message_shown_ && closing_ &&
|
||||
(!window_message_ || !window_message_->isVisible());
|
||||
return finished_ && message_shown_ && closing_ &&
|
||||
(!window_message_ || !window_message_->isVisible());
|
||||
}
|
||||
|
||||
void DefineButtons::updateWindowMessage() {
|
||||
|
||||
@@ -31,7 +31,7 @@ class DefineButtons {
|
||||
|
||||
void render();
|
||||
void update();
|
||||
void checkEvents(const SDL_Event &event);
|
||||
void handleEvents(const SDL_Event &event);
|
||||
auto enable(Options::Gamepad *options_gamepad) -> bool;
|
||||
void disable();
|
||||
bool isReadyToClose() const;
|
||||
@@ -40,7 +40,7 @@ class DefineButtons {
|
||||
|
||||
private:
|
||||
// Constante para cuánto tiempo mostrar el mensaje (en frames)
|
||||
static constexpr size_t MESSAGE_DISPLAY_FRAMES = 180; // ~3 segundos a 60fps
|
||||
static constexpr size_t MESSAGE_DISPLAY_FRAMES = 120; // ~2 segundos a 60fps
|
||||
|
||||
// Punteros
|
||||
Input *input_ = nullptr; // Entrada del usuario
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
|
||||
#include <SDL3/SDL.h> // Para SDL_LogInfo, SDL_LogCategory
|
||||
|
||||
#include "input.h"
|
||||
#include "mouse.h" // Para handleEvent
|
||||
#include "screen.h"
|
||||
#include "input.h" // Para Input
|
||||
#include "mouse.h" // Para handleEvent
|
||||
#include "options.h" // Para Options
|
||||
#include "screen.h" // Para Screen
|
||||
#include "section.hpp" // Para Name, Options, name, options
|
||||
#include "ui/service_menu.h" // Para ServiceMenu
|
||||
|
||||
@@ -34,6 +35,8 @@ void check(const SDL_Event &event) {
|
||||
Mouse::handleEvent(event);
|
||||
|
||||
static auto *input_ = Input::get();
|
||||
input_->handleEvent(event);
|
||||
if (input_->handleEvent(event)) {
|
||||
Options::gamepad_manager.assignAndLinkGamepads();
|
||||
}
|
||||
}
|
||||
} // namespace GlobalEvents
|
||||
@@ -66,48 +66,21 @@ void toggleShaders() {
|
||||
Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 13") + " " + boolToOnOff(Options::video.shaders)});
|
||||
}
|
||||
|
||||
// Obtiene una fichero a partir de un lang::Code
|
||||
auto getLangFile(Lang::Code code) -> std::string {
|
||||
switch (code) {
|
||||
case Lang::Code::VALENCIAN:
|
||||
return Asset::get()->get("ba_BA.json");
|
||||
break;
|
||||
case Lang::Code::SPANISH:
|
||||
return Asset::get()->get("es_ES.json");
|
||||
break;
|
||||
default:
|
||||
return Asset::get()->get("en_UK.json");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Obtiene una cadena a partir de un lang::Code
|
||||
auto getLangName(Lang::Code code) -> std::string {
|
||||
switch (code) {
|
||||
case Lang::Code::VALENCIAN:
|
||||
return " \"ba_BA\"";
|
||||
break;
|
||||
case Lang::Code::SPANISH:
|
||||
return " \"es_ES\"";
|
||||
break;
|
||||
default:
|
||||
return " \"en_UK\"";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Cambia el idioma
|
||||
void changeLang() {
|
||||
// Cambia al siguiente idioma
|
||||
void setNextLang() {
|
||||
const std::string CODE = "LANG";
|
||||
const auto NEXT_LANG_CODE = Lang::getNextLangCode(Options::settings.language);
|
||||
const auto NEXT_LANG_NAME = Lang::getLangName(NEXT_LANG_CODE);
|
||||
if (Notifier::get()->checkCode(CODE)) {
|
||||
Options::settings.language = Lang::getNextLangCode(Options::settings.language);
|
||||
Lang::loadFromFile(getLangFile(Options::settings.language));
|
||||
// Si la notificación de cambiar idioma está activa, cambia de de idioma
|
||||
Options::settings.language = NEXT_LANG_CODE;
|
||||
Lang::loadFromFile(Lang::getLangFile(NEXT_LANG_CODE));
|
||||
Section::name = Section::Name::RESET;
|
||||
Section::options = Section::Options::RELOAD;
|
||||
Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 05") + getLangName(Options::settings.language)});
|
||||
Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 05") + NEXT_LANG_NAME});
|
||||
} else {
|
||||
const auto NEXT = Lang::getNextLangCode(Options::settings.language);
|
||||
Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 04") + getLangName(NEXT), std::string()}, -1, CODE);
|
||||
// Si la notificación de cambiar idioma no está activa, muestra la notificación
|
||||
Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 04") + NEXT_LANG_NAME, std::string()}, -1, CODE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,109 +144,60 @@ auto checkServiceButton() -> bool {
|
||||
}
|
||||
|
||||
// Mandos
|
||||
{
|
||||
auto gamepads = Input::get()->getGamepads();
|
||||
for (auto gamepad : gamepads) {
|
||||
if (Input::get()->checkAction(Input::Action::SERVICE, Input::DO_NOT_ALLOW_REPEAT, Input::DO_NOT_CHECK_KEYBOARD, gamepad)) {
|
||||
toggleServiceMenu();
|
||||
return true;
|
||||
}
|
||||
for (auto gamepad : Input::get()->getGamepads()) {
|
||||
if (Input::get()->checkAction(Input::Action::SERVICE, Input::DO_NOT_ALLOW_REPEAT, Input::DO_NOT_CHECK_KEYBOARD, gamepad)) {
|
||||
toggleServiceMenu();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Comprueba las entradas para elementos del sistema
|
||||
auto checkSystemInputs() -> bool {
|
||||
using Action = Input::Action;
|
||||
|
||||
static const std::vector<std::pair<Action, std::function<void()>>> actions = {
|
||||
{Action::WINDOW_FULLSCREEN, toggleFullscreen},
|
||||
{Action::WINDOW_DEC_SIZE, decWindowSize},
|
||||
{Action::WINDOW_INC_SIZE, incWindowSize},
|
||||
{Action::EXIT, quit},
|
||||
{Action::RESET, reset},
|
||||
{Action::TOGGLE_AUDIO, toggleAudio},
|
||||
{Action::TOGGLE_AUTO_FIRE, toggleFireMode},
|
||||
{Action::CHANGE_LANG, setNextLang},
|
||||
{Action::TOGGLE_VIDEO_SHADERS, toggleShaders},
|
||||
{Action::TOGGLE_VIDEO_INTEGER_SCALE, toggleIntegerScale},
|
||||
{Action::TOGGLE_VIDEO_VSYNC, toggleVSync},
|
||||
#ifdef _DEBUG
|
||||
{Action::SHOW_INFO, [] { Screen::get()->toggleDebugInfo(); }},
|
||||
#endif
|
||||
};
|
||||
|
||||
for (const auto& [action, func] : actions) {
|
||||
if (Input::get()->checkAction(action, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
func();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Comprueba el resto de entradas
|
||||
auto checkOtherInputs() -> bool {
|
||||
// Saltar sección
|
||||
if ((Input::get()->checkAnyButton()) && !ServiceMenu::get()->isEnabled()) {
|
||||
skipSection();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Comprueba las entradas fuera del menú de servicio
|
||||
auto checkInputs() -> bool {
|
||||
// Teclado
|
||||
{
|
||||
// Comprueba el teclado para cambiar entre pantalla completa y ventana
|
||||
if (Input::get()->checkAction(Input::Action::WINDOW_FULLSCREEN, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
Screen::get()->toggleFullscreen();
|
||||
const std::string MODE = Options::video.fullscreen ? Lang::getText("[NOTIFICATIONS] 11") : Lang::getText("[NOTIFICATIONS] 10");
|
||||
Notifier::get()->show({MODE});
|
||||
return true;
|
||||
}
|
||||
|
||||
// Comprueba el teclado para decrementar el tamaño de la ventana
|
||||
if (Input::get()->checkAction(Input::Action::WINDOW_DEC_SIZE, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
if (Screen::get()->decWindowSize()) {
|
||||
Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 09") + " x" + std::to_string(Options::window.zoom)});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Comprueba el teclado para incrementar el tamaño de la ventana
|
||||
if (Input::get()->checkAction(Input::Action::WINDOW_INC_SIZE, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
if (Screen::get()->incWindowSize()) {
|
||||
Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 09") + " x" + std::to_string(Options::window.zoom)});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Salir
|
||||
if (Input::get()->checkAction(Input::Action::EXIT, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
quit();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Saltar sección
|
||||
if ((Input::get()->checkAnyButton()) && !ServiceMenu::get()->isEnabled()) {
|
||||
skipSection();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Reset
|
||||
if (Input::get()->checkAction(Input::Action::RESET, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Audio
|
||||
if (Input::get()->checkAction(Input::Action::TOGGLE_AUDIO, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
toggleAudio();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Autofire
|
||||
if (Input::get()->checkAction(Input::Action::TOGGLE_AUTO_FIRE, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
toggleFireMode();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Idioma
|
||||
if (Input::get()->checkAction(Input::Action::CHANGE_LANG, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
changeLang();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Shaders
|
||||
if (Input::get()->checkAction(Input::Action::TOGGLE_VIDEO_SHADERS, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
toggleShaders();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Integer Scale
|
||||
if (Input::get()->checkAction(Input::Action::TOGGLE_VIDEO_INTEGER_SCALE, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
toggleIntegerScale();
|
||||
return true;
|
||||
}
|
||||
|
||||
// VSync
|
||||
if (Input::get()->checkAction(Input::Action::TOGGLE_VIDEO_VSYNC, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
toggleVSync();
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
// Debug info
|
||||
if (Input::get()->checkAction(Input::Action::SHOW_INFO, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
Screen::get()->toggleDebugInfo();
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return false;
|
||||
// Comprueba las entradas del Menu de Servicio
|
||||
inline auto checkServiceMenuInputs() -> bool {
|
||||
return ServiceMenu::get()->checkInput();
|
||||
}
|
||||
|
||||
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
||||
@@ -281,12 +205,15 @@ auto check() -> bool {
|
||||
if (checkServiceButton()) {
|
||||
return true;
|
||||
}
|
||||
if (ServiceMenu::get()->checkInput()) {
|
||||
if (checkServiceMenuInputs()) {
|
||||
return true;
|
||||
}
|
||||
if (checkInputs()) {
|
||||
if (checkSystemInputs()) {
|
||||
return true;
|
||||
}
|
||||
if (checkOtherInputs()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} // namespace GlobalInputs
|
||||
} // namespace GlobalInputs
|
||||
|
||||
@@ -308,15 +308,16 @@ void Input::update() {
|
||||
}
|
||||
}
|
||||
|
||||
void Input::handleEvent(const SDL_Event &event) {
|
||||
auto Input::handleEvent(const SDL_Event &event) -> bool {
|
||||
switch (event.type) {
|
||||
case SDL_EVENT_GAMEPAD_ADDED:
|
||||
addGamepad(event.gdevice.which);
|
||||
break;
|
||||
return true;
|
||||
case SDL_EVENT_GAMEPAD_REMOVED:
|
||||
removeGamepad(event.gdevice.which);
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Input::addGamepad(int device_index) {
|
||||
|
||||
@@ -168,7 +168,7 @@ class Input {
|
||||
void resetInputStates();
|
||||
|
||||
// --- Eventos ---
|
||||
void handleEvent(const SDL_Event &event);
|
||||
auto handleEvent(const SDL_Event &event) -> bool;
|
||||
|
||||
void printConnectedGamepads() const;
|
||||
|
||||
|
||||
@@ -154,10 +154,40 @@ auto getLanguageFileName(Lang::Code code) -> std::string {
|
||||
}
|
||||
|
||||
// Establece el idioma
|
||||
void setLanguage(Code lang) {
|
||||
Options::settings.language = lang;
|
||||
loadFromFile(Asset::get()->get(getLanguage(lang).file_name));
|
||||
void setLanguage(Code code) {
|
||||
Options::settings.language = code;
|
||||
loadFromFile(Asset::get()->get(getLanguage(code).file_name));
|
||||
updateLanguageNames();
|
||||
updateDifficultyNames();
|
||||
}
|
||||
|
||||
// Obtiene una fichero a partir de un Code
|
||||
auto getLangFile(Code code) -> std::string {
|
||||
switch (code) {
|
||||
case Code::VALENCIAN:
|
||||
return Asset::get()->get("ba_BA.json");
|
||||
break;
|
||||
case Code::SPANISH:
|
||||
return Asset::get()->get("es_ES.json");
|
||||
break;
|
||||
default:
|
||||
return Asset::get()->get("en_UK.json");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Obtiene una cadena a partir de un Code
|
||||
auto getLangName(Code code) -> std::string {
|
||||
switch (code) {
|
||||
case Code::VALENCIAN:
|
||||
return " \"ba_BA\"";
|
||||
break;
|
||||
case Code::SPANISH:
|
||||
return " \"es_ES\"";
|
||||
break;
|
||||
default:
|
||||
return " \"en_UK\"";
|
||||
break;
|
||||
}
|
||||
}
|
||||
} // namespace Lang
|
||||
|
||||
@@ -11,7 +11,7 @@ enum class Code : int {
|
||||
ENGLISH = 2
|
||||
};
|
||||
|
||||
// Estructura que representa un idioma
|
||||
// --- Estructura que representa un idioma ---
|
||||
struct Language {
|
||||
Code code; // Código que identifica al idioma
|
||||
std::string name; // Nombre que identifica el idioma
|
||||
@@ -21,30 +21,16 @@ struct Language {
|
||||
: code(c), name(std::move(n)), file_name(std::move(fn)) {}
|
||||
};
|
||||
|
||||
// Carga los textos desde el fichero JSON especificado
|
||||
auto loadFromFile(const std::string &file_path) -> bool;
|
||||
|
||||
// Obtiene el texto por clave
|
||||
auto getText(const std::string &key) -> std::string;
|
||||
|
||||
// Obtiene el código del siguiente idioma (circular)
|
||||
auto getNextLangCode(Code current_lang) -> Code;
|
||||
|
||||
// Obtiene el idioma correspondiente al código proporcionado
|
||||
auto getLanguage(Code code) -> Language;
|
||||
|
||||
// Devuelve el código de un idioma a partir de un nombre
|
||||
auto getCodeFromName(const std::string &name) -> Code;
|
||||
|
||||
// Devuelve el nombre de un idioma a partir de un código
|
||||
auto getNameFromCode(Code code) -> std::string;
|
||||
|
||||
// Actualiza los nombres de los idiomas
|
||||
void updateLanguageNames();
|
||||
|
||||
// Obtiene el nombre del fichero de textos asociado a un código de idioma
|
||||
auto getLanguageFileName(Code code) -> std::string;
|
||||
|
||||
// Establece el idioma actual
|
||||
void setLanguage(Code lang);
|
||||
} // namespace Lang
|
||||
// --- Métodos ---
|
||||
auto loadFromFile(const std::string &file_path) -> bool; // Carga los textos desde el fichero JSON especificado
|
||||
auto getText(const std::string &key) -> std::string; // Obtiene el texto por clave
|
||||
auto getNextLangCode(Code current_lang) -> Code; // Obtiene el código del siguiente idioma (circular)
|
||||
auto getLanguage(Code code) -> Language; // Obtiene el idioma correspondiente al código proporcionado
|
||||
auto getCodeFromName(const std::string &name) -> Code; // Devuelve el código de un idioma a partir de un nombre
|
||||
auto getNameFromCode(Code code) -> std::string; // Devuelve el nombre de un idioma a partir de un código
|
||||
void updateLanguageNames(); // Actualiza los nombres de los idiomas
|
||||
auto getLanguageFileName(Code code) -> std::string; // Obtiene el nombre del fichero de textos asociado a un código de idioma
|
||||
void setLanguage(Code code); // Establece el idioma actual
|
||||
auto getLangFile(Code code) -> std::string; // Obtiene una fichero a partir de un Code
|
||||
auto getLangName(Code code) -> std::string; // Obtiene una cadena a partir de un Code
|
||||
} // namespace Lang
|
||||
@@ -386,7 +386,7 @@ void GamepadManager::clearUnassignedGamepadSlots() {
|
||||
if (gamepad_config.instance == nullptr) {
|
||||
// Limpiamos sus datos de configuración para no mostrar información
|
||||
// de un mando que ya no está conectado.
|
||||
gamepad_config.name = "";
|
||||
gamepad_config.name = Lang::getText("[SERVICE_MENU] NO_CONTROLLER");
|
||||
gamepad_config.path = "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <memory> // Para shared_ptr, swap
|
||||
#include <stdexcept> // Para out_of_range, invalid_argument
|
||||
#include <string> // Para char_traits, string, allocator, operator==, swap, operator<<, basic_string, stoi
|
||||
#include <string_view> // Para string_view
|
||||
#include <vector> // Para vector
|
||||
|
||||
#include "difficulty.h" // Para Code
|
||||
@@ -216,6 +217,7 @@ class GamepadManager {
|
||||
[[nodiscard]] static auto size() -> size_t { return MAX_PLAYERS; }
|
||||
|
||||
private:
|
||||
static constexpr std::string_view UNASSIGNED_TEXT = "---";
|
||||
static constexpr size_t MAX_PLAYERS = 2;
|
||||
std::array<Gamepad, MAX_PLAYERS> gamepads_;
|
||||
|
||||
|
||||
@@ -40,12 +40,14 @@ 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
|
||||
return; // No se puede mostrar u ocultar el menu de servicio si se estan definiendo los botones
|
||||
}
|
||||
|
||||
playBackSound();
|
||||
enabled_ = !enabled_;
|
||||
if (!enabled_) {
|
||||
if (enabled_) {
|
||||
Options::gamepad_manager.assignAndLinkGamepads();
|
||||
} else {
|
||||
reset();
|
||||
}
|
||||
}
|
||||
@@ -546,8 +548,8 @@ 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
|
||||
define_buttons_->handleEvents(event);
|
||||
// return; // No procesar otros eventos mientras DefineButtons está activo
|
||||
}
|
||||
}
|
||||
|
||||
@@ -557,85 +559,39 @@ bool ServiceMenu::checkInput() {
|
||||
}
|
||||
|
||||
if (define_buttons_ && define_buttons_->isEnabled()) {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
using Action = Input::Action;
|
||||
|
||||
// Derecha
|
||||
if (input->checkAction(Input::Action::RIGHT, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
adjustOption(true);
|
||||
return true;
|
||||
}
|
||||
const std::vector<std::pair<Action, std::function<void()>>> actions = {
|
||||
{Action::UP, [this]() { setSelectorUp(); }},
|
||||
{Action::DOWN, [this]() { setSelectorDown(); }},
|
||||
{Action::RIGHT, [this]() { adjustOption(true); }},
|
||||
{Action::LEFT, [this]() { adjustOption(false); }},
|
||||
{Action::SM_SELECT, [this]() { selectOption(); }},
|
||||
{Action::SM_BACK, [this]() { moveBack(); }},
|
||||
};
|
||||
|
||||
// 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();
|
||||
// Teclado
|
||||
for (const auto &[action, func] : actions) {
|
||||
if (input->checkAction(action, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
|
||||
func();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Mandos
|
||||
for (auto gamepad : input->getGamepads()) {
|
||||
for (const auto &[action, func] : actions) {
|
||||
if (input->checkAction(action, Input::DO_NOT_ALLOW_REPEAT, Input::DO_NOT_CHECK_KEYBOARD, gamepad)) {
|
||||
func();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user