From c07fd620370f18605b03b07632889248c87781b1 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Thu, 3 Oct 2024 19:26:32 +0200 Subject: [PATCH] =?UTF-8?q?Corregit=20bug=20en=20el=20text=20a=20l'hora=20?= =?UTF-8?q?d'intercanviar=20els=20mandos.=20Apareixia=20el=20nom=20del=20m?= =?UTF-8?q?ando=20que=20te=20guardat=20a=20la=20configuraci=C3=B3=20pero?= =?UTF-8?q?=20no=20estava=20connectat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/director.cpp | 3 +++ source/input.cpp | 20 +++++++++----------- source/input.h | 18 +++++++++--------- source/options.cpp | 1 + source/title.cpp | 3 ++- source/utils.h | 17 +++++++++-------- 6 files changed, 33 insertions(+), 29 deletions(-) diff --git a/source/director.cpp b/source/director.cpp index 204a230..7ca3727 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -197,10 +197,13 @@ void Director::initInput() for (int i = 0; i < numGamePads; ++i) for (int index = 0; index < (int)options.controller.size(); ++index) if (Input::get()->getControllerName(i) == options.controller[index].name) + { + options.controller[index].plugged = true; for (int j = 0; j < (int)options.controller[index].inputs.size(); ++j) { Input::get()->bindGameControllerButton(i, options.controller[index].inputs[j], options.controller[index].buttons[j]); } + } // Asigna botones a inputs desde otros inputs for (int i = 0; i < numGamePads; ++i) diff --git a/source/input.cpp b/source/input.cpp index de0d5cf..e723da9 100644 --- a/source/input.cpp +++ b/source/input.cpp @@ -454,8 +454,6 @@ bool Input::discoverGameControllers() connectedControllers.push_back(pad); const std::string separator(" #"); std::string name = SDL_GameControllerNameForIndex(i); - // name.resize(25); - // name = name + separator + std::to_string(i); if (verbose) { std::cout << name << std::endl; @@ -484,13 +482,13 @@ bool Input::gameControllerFound() } // Obten el nombre de un mando de juego -std::string Input::getControllerName(int index) +std::string Input::getControllerName(int index) const { return numGamepads > 0 ? controllerNames[index] : ""; } // Obten el número de mandos conectados -int Input::getNumControllers() +int Input::getNumControllers() const { return numGamepads; } @@ -516,7 +514,7 @@ void Input::enable() } // Obtiene el indice del controlador a partir de un event.id -int Input::getJoyIndex(int id) +int Input::getJoyIndex(int id) const { for (int i = 0; i < numJoysticks; ++i) { @@ -529,7 +527,7 @@ int Input::getJoyIndex(int id) } // Muestra por consola los controles asignados -void Input::printBindings(int device, int index) +void Input::printBindings(int device, int index) const { if (device == INPUT_USE_ANY || device == INPUT_USE_KEYBOARD) { @@ -556,13 +554,13 @@ void Input::printBindings(int device, int index) } // Obtiene el SDL_GameControllerButton asignado a un input -SDL_GameControllerButton Input::getControllerBinding(int index, inputs_e input) +SDL_GameControllerButton Input::getControllerBinding(int index, inputs_e input) const { return gameControllerBindings[index][input].button; } // Obtiene el indice a partir del nombre del mando -int Input::getIndexByName(std::string name) +int Input::getIndexByName(std::string name) const { for (int i = 0; i < numGamepads; ++i) { @@ -575,7 +573,7 @@ int Input::getIndexByName(std::string name) } // Convierte un inputs_e a std::string -std::string Input::to_string(inputs_e input) +std::string Input::to_string(inputs_e input) const { if (input == input_fire_left) { @@ -606,7 +604,7 @@ std::string Input::to_string(inputs_e input) } // Convierte un std::string a inputs_e -inputs_e Input::to_inputs_e(std::string name) +inputs_e Input::to_inputs_e(std::string name) const { if (name == "input_fire_left") { @@ -646,7 +644,7 @@ void Input::allActive(int index) } // Comprueba el eje del mando -bool Input::checkAxisInput(inputs_e input, int index) +bool Input::checkAxisInput(inputs_e input, int index) const { bool success = false; diff --git a/source/input.h b/source/input.h index 03c8466..d2d64bf 100644 --- a/source/input.h +++ b/source/input.h @@ -97,7 +97,7 @@ private: bool enabled; // Indica si está habilitado // Comprueba el eje del mando - bool checkAxisInput(inputs_e input, int index = 0); + bool checkAxisInput(inputs_e input, int index = 0) const; // Constructor Input(std::string file); @@ -144,10 +144,10 @@ public: bool gameControllerFound(); // Obten el número de mandos conectados - int getNumControllers(); + int getNumControllers() const; // Obten el nombre de un mando de juego - std::string getControllerName(int index); + std::string getControllerName(int index) const; // Establece si ha de mostrar mensajes void setVerbose(bool value); @@ -159,22 +159,22 @@ public: void enable(); // Obtiene el indice del controlador a partir de un event.id - int getJoyIndex(int id); + int getJoyIndex(int id) const; // Muestra por consola los controles asignados - void printBindings(int device = INPUT_USE_KEYBOARD, int index = 0); + void printBindings(int device = INPUT_USE_KEYBOARD, int index = 0) const; // Obtiene el SDL_GameControllerButton asignado a un input - SDL_GameControllerButton getControllerBinding(int index, inputs_e input); + SDL_GameControllerButton getControllerBinding(int index, inputs_e input) const; // Convierte un inputs_e a std::string - std::string to_string(inputs_e input); + std::string to_string(inputs_e input) const; // Convierte un std::string a inputs_e - inputs_e to_inputs_e(std::string name); + inputs_e to_inputs_e(std::string name) const; // Obtiene el indice a partir del nombre del mando - int getIndexByName(std::string name); + int getIndexByName(std::string name) const; // Activa todos los inputs. Sirve para evitar inputs sin repeticiones pero que ya vienen pulsados cuando checkInput no estaba monitorizando void allActive(int index); diff --git a/source/options.cpp b/source/options.cpp index 950c692..09496c1 100644 --- a/source/options.cpp +++ b/source/options.cpp @@ -61,6 +61,7 @@ void initOptions() c.playerId = index + 1; c.deviceType = INPUT_USE_GAMECONTROLLER; c.name = "NO NAME"; + c.plugged = false; // Inputs que se guardan en las opciones y, por tanto, a disco c.inputs.clear(); diff --git a/source/title.cpp b/source/title.cpp index 9594168..5e4b03e 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -378,7 +378,8 @@ void Title::swapControllers() for (int i = 0; i < MAX_CONTROLLERS; ++i) { const int index = playerControllerIndex[i]; - if (options.controller[index].name != "NO NAME") + //if (options.controller[index].name != "NO NAME") + if (options.controller[index].plugged) { text[i] = "Jugador " + std::to_string(i + 1) + ": " + options.controller[index].name; } diff --git a/source/utils.h b/source/utils.h index 54ea480..36909b3 100644 --- a/source/utils.h +++ b/source/utils.h @@ -1,13 +1,13 @@ #pragma once -#include // for SDL_GameControllerButton -#include // for SDL_Rect, SDL_Point -#include // for SDL_Renderer -#include // for Uint8, Uint32 -#include // for int32_t -#include // for string, basic_string -#include // for vector -#include "input.h" // for inputs_e +#include // for SDL_GameControllerButton +#include // for SDL_Rect, SDL_Point +#include // for SDL_Renderer +#include // for Uint8, Uint32 +#include // for int32_t +#include // for string, basic_string +#include // for vector +#include "input.h" // for inputs_e struct JA_Music_t; struct JA_Sound_t; @@ -153,6 +153,7 @@ struct op_controller_t int playerId; // Jugador asociado al mando Uint8 deviceType; // Indica si se utilizará teclado o mando o ambos std::string name; // Nombre del dispositivo + bool plugged; // Indica si el mando se encuentra conectado std::vector inputs; // Listado de inputs std::vector buttons; // Listado de botones asignados a cada input };