tidy-fix automàtic (sense naming)
This commit is contained in:
@@ -52,8 +52,8 @@ namespace Gamepad {
|
||||
// Recorta el nom visible del mando: trim des del primer '(' o '['
|
||||
// (per a evitar coses com "Retroid Controller (vendor: 1001) ..."),
|
||||
// elimina espais finals i talla a 25 caràcters.
|
||||
static std::string prettyName(const char* raw) {
|
||||
std::string name = (raw && *raw) ? raw : "Gamepad";
|
||||
static auto prettyName(const char* raw) -> std::string {
|
||||
std::string name = ((raw != nullptr) && (*raw != 0)) ? raw : "Gamepad";
|
||||
const auto pos = name.find_first_of("([");
|
||||
if (pos != std::string::npos) {
|
||||
name.erase(pos);
|
||||
@@ -64,7 +64,9 @@ namespace Gamepad {
|
||||
if (name.size() > 25) {
|
||||
name.resize(25);
|
||||
}
|
||||
if (name.empty()) name = "Gamepad";
|
||||
if (name.empty()) {
|
||||
name = "Gamepad";
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -98,12 +100,14 @@ namespace Gamepad {
|
||||
static void openFirstGamepad() {
|
||||
int count = 0;
|
||||
SDL_JoystickID* ids = SDL_GetJoysticks(&count);
|
||||
if (ids) {
|
||||
if (ids != nullptr) {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
installWebStandardMapping(ids[i]);
|
||||
if (!SDL_IsGamepad(ids[i])) continue;
|
||||
if (!SDL_IsGamepad(ids[i])) {
|
||||
continue;
|
||||
}
|
||||
pad_ = SDL_OpenGamepad(ids[i]);
|
||||
if (pad_) {
|
||||
if (pad_ != nullptr) {
|
||||
pad_id_ = ids[i];
|
||||
SDL_Log("Gamepad connectat: %s", SDL_GetGamepadName(pad_));
|
||||
break;
|
||||
@@ -128,7 +132,7 @@ namespace Gamepad {
|
||||
}
|
||||
|
||||
void destroy() {
|
||||
if (pad_) {
|
||||
if (pad_ != nullptr) {
|
||||
SDL_CloseGamepad(pad_);
|
||||
pad_ = nullptr;
|
||||
pad_id_ = 0;
|
||||
@@ -145,12 +149,14 @@ namespace Gamepad {
|
||||
// GAMEPAD_ADDED) perquè SDL no reconeix el GUID. Escoltem els dos i
|
||||
// injectem el mapping estàndard abans d'obrir el mando.
|
||||
if (event.type == SDL_EVENT_GAMEPAD_ADDED || event.type == SDL_EVENT_JOYSTICK_ADDED) {
|
||||
if (!pad_) {
|
||||
if (pad_ == nullptr) {
|
||||
SDL_JoystickID jid = event.jdevice.which;
|
||||
installWebStandardMapping(jid);
|
||||
if (!SDL_IsGamepad(jid)) return;
|
||||
if (!SDL_IsGamepad(jid)) {
|
||||
return;
|
||||
}
|
||||
pad_ = SDL_OpenGamepad(jid);
|
||||
if (pad_) {
|
||||
if (pad_ != nullptr) {
|
||||
pad_id_ = jid;
|
||||
std::string name = prettyName(SDL_GetGamepadName(pad_));
|
||||
SDL_Log("Gamepad connectat: %s", name.c_str());
|
||||
@@ -158,7 +164,7 @@ namespace Gamepad {
|
||||
}
|
||||
}
|
||||
} else if (event.type == SDL_EVENT_GAMEPAD_REMOVED || event.type == SDL_EVENT_JOYSTICK_REMOVED) {
|
||||
if (pad_ && event.jdevice.which == pad_id_) {
|
||||
if ((pad_ != nullptr) && event.jdevice.which == pad_id_) {
|
||||
std::string saved_name = prettyName(SDL_GetGamepadName(pad_));
|
||||
SDL_Log("Gamepad desconnectat: %s", saved_name.c_str());
|
||||
SDL_CloseGamepad(pad_);
|
||||
@@ -190,7 +196,9 @@ namespace Gamepad {
|
||||
}
|
||||
|
||||
void update() {
|
||||
if (!pad_) return;
|
||||
if (pad_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
// D-pad
|
||||
bool dup = SDL_GetGamepadButton(pad_, SDL_GAMEPAD_BUTTON_DPAD_UP);
|
||||
@@ -220,19 +228,35 @@ namespace Gamepad {
|
||||
bool back = SDL_GetGamepadButton(pad_, SDL_GAMEPAD_BUTTON_BACK);
|
||||
|
||||
// Select (Back) → obre/tanca menú de servei (flanc)
|
||||
if (back && !prev_back_) pushKey(KeyConfig::scancode("menu_toggle"));
|
||||
if (back && !prev_back_) {
|
||||
pushKey(KeyConfig::scancode("menu_toggle"));
|
||||
}
|
||||
// Start → pausa (flanc)
|
||||
if (start && !prev_start_) pushKey(KeyConfig::scancode("pause_toggle"));
|
||||
if (start && !prev_start_) {
|
||||
pushKey(KeyConfig::scancode("pause_toggle"));
|
||||
}
|
||||
|
||||
if (Menu::isOpen()) {
|
||||
// Navegació del menú per flanc
|
||||
if (up && !prev_up_) pushKey(SDL_SCANCODE_UP);
|
||||
if (dn && !prev_down_) pushKey(SDL_SCANCODE_DOWN);
|
||||
if (lt && !prev_left_) pushKey(SDL_SCANCODE_LEFT);
|
||||
if (rt && !prev_right_) pushKey(SDL_SCANCODE_RIGHT);
|
||||
if (up && !prev_up_) {
|
||||
pushKey(SDL_SCANCODE_UP);
|
||||
}
|
||||
if (dn && !prev_down_) {
|
||||
pushKey(SDL_SCANCODE_DOWN);
|
||||
}
|
||||
if (lt && !prev_left_) {
|
||||
pushKey(SDL_SCANCODE_LEFT);
|
||||
}
|
||||
if (rt && !prev_right_) {
|
||||
pushKey(SDL_SCANCODE_RIGHT);
|
||||
}
|
||||
// EAST accepta, SOUTH cancela / endarrere
|
||||
if (east && !prev_east_) pushKey(SDL_SCANCODE_RETURN);
|
||||
if (south && !prev_south_) pushKey(SDL_SCANCODE_BACKSPACE);
|
||||
if (east && !prev_east_) {
|
||||
pushKey(SDL_SCANCODE_RETURN);
|
||||
}
|
||||
if (south && !prev_south_) {
|
||||
pushKey(SDL_SCANCODE_BACKSPACE);
|
||||
}
|
||||
|
||||
// Assegura que el joc no rep tecles de moviment mentre el menú està obert
|
||||
JI_SetVirtualKey(SDL_SCANCODE_UP, JI_VSRC_GAMEPAD, false);
|
||||
|
||||
Reference in New Issue
Block a user