Retocados los nombres de las variables de la clase menu
This commit is contained in:
@@ -5,16 +5,16 @@
|
||||
Input::Input(std::string file)
|
||||
{
|
||||
// Fichero gamecontrollerdb.txt
|
||||
mDBpath = file;
|
||||
dbPath = file;
|
||||
|
||||
// Inicializa las variables
|
||||
for (int i = 0; i < 17; i++)
|
||||
{
|
||||
mKeyBindings[i].scancode = 0;
|
||||
mKeyBindings[i].active = false;
|
||||
keyBindings[i].scancode = 0;
|
||||
keyBindings[i].active = false;
|
||||
|
||||
mGameControllerBindings[i].button = SDL_CONTROLLER_BUTTON_INVALID;
|
||||
mGameControllerBindings[i].active = false;
|
||||
gameControllerBindings[i].button = SDL_CONTROLLER_BUTTON_INVALID;
|
||||
gameControllerBindings[i].active = false;
|
||||
}
|
||||
|
||||
discoverGameController();
|
||||
@@ -23,20 +23,20 @@ Input::Input(std::string file)
|
||||
// Destructor
|
||||
Input::~Input()
|
||||
{
|
||||
for (int i = 0; i < mNumGamepads; i++)
|
||||
mConnectedControllers[i] = nullptr;
|
||||
for (int i = 0; i < numGamepads; i++)
|
||||
connectedControllers[i] = nullptr;
|
||||
}
|
||||
|
||||
// Asigna uno de los posibles inputs a una tecla del teclado
|
||||
void Input::bindKey(Uint8 input, SDL_Scancode code)
|
||||
{
|
||||
mKeyBindings[input].scancode = code;
|
||||
keyBindings[input].scancode = code;
|
||||
}
|
||||
|
||||
// Asigna uno de los posibles inputs a un botón del mando
|
||||
void Input::bindGameControllerButton(Uint8 input, SDL_GameControllerButton button)
|
||||
{
|
||||
mGameControllerBindings[input].button = button;
|
||||
gameControllerBindings[input].button = button;
|
||||
}
|
||||
|
||||
// Comprueba si un input esta activo
|
||||
@@ -54,18 +54,18 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
|
||||
|
||||
if (repeat)
|
||||
{
|
||||
if (mKeystates[mKeyBindings[input].scancode] != 0)
|
||||
if (mKeystates[keyBindings[input].scancode] != 0)
|
||||
successKeyboard = true;
|
||||
else
|
||||
successKeyboard = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!mKeyBindings[input].active)
|
||||
if (!keyBindings[input].active)
|
||||
{
|
||||
if (mKeystates[mKeyBindings[input].scancode] != 0)
|
||||
if (mKeystates[keyBindings[input].scancode] != 0)
|
||||
{
|
||||
mKeyBindings[input].active = true;
|
||||
keyBindings[input].active = true;
|
||||
successKeyboard = true;
|
||||
}
|
||||
else
|
||||
@@ -75,9 +75,9 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mKeystates[mKeyBindings[input].scancode] == 0)
|
||||
if (mKeystates[keyBindings[input].scancode] == 0)
|
||||
{
|
||||
mKeyBindings[input].active = false;
|
||||
keyBindings[input].active = false;
|
||||
successKeyboard = false;
|
||||
}
|
||||
else
|
||||
@@ -93,18 +93,18 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
|
||||
{
|
||||
if (repeat)
|
||||
{
|
||||
if (SDL_GameControllerGetButton(mConnectedControllers[index], mGameControllerBindings[input].button) != 0)
|
||||
if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[input].button) != 0)
|
||||
successGameController = true;
|
||||
else
|
||||
successGameController = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!mGameControllerBindings[input].active)
|
||||
if (!gameControllerBindings[input].active)
|
||||
{
|
||||
if (SDL_GameControllerGetButton(mConnectedControllers[index], mGameControllerBindings[input].button) != 0)
|
||||
if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[input].button) != 0)
|
||||
{
|
||||
mGameControllerBindings[input].active = true;
|
||||
gameControllerBindings[input].active = true;
|
||||
successGameController = true;
|
||||
}
|
||||
else
|
||||
@@ -114,9 +114,9 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (SDL_GameControllerGetButton(mConnectedControllers[index], mGameControllerBindings[input].button) == 0)
|
||||
if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[input].button) == 0)
|
||||
{
|
||||
mGameControllerBindings[input].active = false;
|
||||
gameControllerBindings[input].active = false;
|
||||
successGameController = false;
|
||||
}
|
||||
else
|
||||
@@ -138,43 +138,43 @@ bool Input::discoverGameController()
|
||||
if (SDL_WasInit(SDL_INIT_GAMECONTROLLER) != 1)
|
||||
SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER);
|
||||
|
||||
if (SDL_GameControllerAddMappingsFromFile(mDBpath.c_str()) < 0)
|
||||
printf("Error, could not load %s file: %s\n", mDBpath.c_str(), SDL_GetError());
|
||||
if (SDL_GameControllerAddMappingsFromFile(dbPath.c_str()) < 0)
|
||||
printf("Error, could not load %s file: %s\n", dbPath.c_str(), SDL_GetError());
|
||||
|
||||
int nJoysticks = SDL_NumJoysticks();
|
||||
mNumGamepads = 0;
|
||||
numGamepads = 0;
|
||||
|
||||
// Cuenta el numero de mandos
|
||||
for (int i = 0; i < nJoysticks; i++)
|
||||
if (SDL_IsGameController(i))
|
||||
mNumGamepads++;
|
||||
numGamepads++;
|
||||
|
||||
printf("\nChecking for game controllers...\n");
|
||||
printf("%i joysticks found, %i are gamepads\n", nJoysticks, mNumGamepads);
|
||||
printf("%i joysticks found, %i are gamepads\n", nJoysticks, numGamepads);
|
||||
|
||||
if (mNumGamepads > 0)
|
||||
if (numGamepads > 0)
|
||||
{
|
||||
found = true;
|
||||
|
||||
for (int i = 0; i < mNumGamepads; i++)
|
||||
for (int i = 0; i < numGamepads; i++)
|
||||
{
|
||||
// Abre el mando y lo añade a la lista
|
||||
SDL_GameController *pad = SDL_GameControllerOpen(i);
|
||||
if (SDL_GameControllerGetAttached(pad) == 1)
|
||||
{
|
||||
mConnectedControllers.push_back(pad);
|
||||
connectedControllers.push_back(pad);
|
||||
std::string separator(" #");
|
||||
std::string name = SDL_GameControllerNameForIndex(i);
|
||||
name.resize(25);
|
||||
name = name + separator + std::to_string(i);
|
||||
std::cout << name << std::endl;
|
||||
mControllerNames.push_back(name);
|
||||
controllerNames.push_back(name);
|
||||
}
|
||||
else
|
||||
std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl;
|
||||
}
|
||||
|
||||
//mGameController = mConnectedControllers[0];
|
||||
//mGameController = connectedControllers[0];
|
||||
SDL_GameControllerEventState(SDL_ENABLE);
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ bool Input::discoverGameController()
|
||||
// Comprueba si hay algun mando conectado
|
||||
bool Input::gameControllerFound()
|
||||
{
|
||||
if (mNumGamepads > 0)
|
||||
if (numGamepads > 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
@@ -193,8 +193,8 @@ bool Input::gameControllerFound()
|
||||
// Obten el nombre de un mando de juego
|
||||
std::string Input::getControllerName(int index)
|
||||
{
|
||||
if (mNumGamepads > 0)
|
||||
return mControllerNames[index];
|
||||
if (numGamepads > 0)
|
||||
return controllerNames[index];
|
||||
else
|
||||
return "";
|
||||
}
|
||||
@@ -202,5 +202,5 @@ std::string Input::getControllerName(int index)
|
||||
// Obten el numero de mandos conectados
|
||||
int Input::getNumControllers()
|
||||
{
|
||||
return mNumGamepads;
|
||||
return numGamepads;
|
||||
}
|
||||
Reference in New Issue
Block a user