merdes varies

This commit is contained in:
2025-08-08 21:06:28 +02:00
parent 98f34c0a09
commit 0fc83cf9c1
11 changed files with 34 additions and 26 deletions

View File

@@ -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",

View File

@@ -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",

View File

@@ -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",

View File

@@ -75,7 +75,7 @@ void DefineButtons::update() {
}
}
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:

View File

@@ -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;

View File

@@ -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

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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 = "";
}
}

View File

@@ -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_;

View File

@@ -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
}
}
@@ -565,16 +567,16 @@ bool ServiceMenu::checkInput() {
using Action = Input::Action;
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(); } },
{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(); }},
};
// Teclado
for (const auto& [action, func] : actions) {
for (const auto &[action, func] : actions) {
if (input->checkAction(action, Input::DO_NOT_ALLOW_REPEAT, Input::CHECK_KEYBOARD)) {
func();
return true;
@@ -583,7 +585,7 @@ bool ServiceMenu::checkInput() {
// Mandos
for (auto gamepad : input->getGamepads()) {
for (const auto& [action, func] : actions) {
for (const auto &[action, func] : actions) {
if (input->checkAction(action, Input::DO_NOT_ALLOW_REPEAT, Input::DO_NOT_CHECK_KEYBOARD, gamepad)) {
func();
return true;