Abans de clavar-li ma a Input
This commit is contained in:
@@ -110,30 +110,18 @@ Director::Director(int argc, const char *argv[])
|
||||
manager->loadFromFile(Asset::get()->get("score.bin"));
|
||||
}
|
||||
|
||||
// Inicializa SDL
|
||||
// Inicializa todo
|
||||
initSDL();
|
||||
|
||||
// Inicializa JailAudio
|
||||
initJailAudio();
|
||||
|
||||
// Inicializa el texto de debug
|
||||
dbg_init(renderer_);
|
||||
|
||||
// Crea los objetos
|
||||
lang::loadFromFile(getLangFile((lang::Code)options.game.language));
|
||||
|
||||
lang::loadFromFile(getLangFile(static_cast<lang::Code>(options.game.language)));
|
||||
Screen::init(window_, renderer_);
|
||||
|
||||
Resource::init();
|
||||
|
||||
Input::init(Asset::get()->get("gamecontrollerdb.txt"));
|
||||
bindInputs();
|
||||
|
||||
auto notifier_text = std::make_shared<Text>(Resource::get()->getTexture("8bithud.png"), Resource::get()->getTextFile("8bithud.txt"));
|
||||
Notifier::init(std::string(), notifier_text, Asset::get()->get("notify.wav"));
|
||||
|
||||
OnScreenHelp::init();
|
||||
|
||||
globalInputs::init();
|
||||
}
|
||||
|
||||
@@ -204,16 +192,20 @@ void Director::bindInputs()
|
||||
}
|
||||
|
||||
// Mapea las asignaciones a los botones desde el archivo de configuración, si se da el caso
|
||||
for (int i = 0; i < num_gamepads; ++i)
|
||||
for (int index = 0; index < (int)options.controller.size(); ++index)
|
||||
if (Input::get()->getControllerName(i) == options.controller[index].name)
|
||||
for (size_t i = 0; i < num_gamepads; ++i)
|
||||
{
|
||||
for (size_t index = 0; index < options.controller.size(); ++index)
|
||||
{
|
||||
if (Input::get()->getControllerName(i) == options.controller.at(index).name)
|
||||
{
|
||||
options.controller[index].plugged = true;
|
||||
for (int j = 0; j < (int)options.controller[index].inputs.size(); ++j)
|
||||
options.controller.at(index).plugged = true;
|
||||
for (size_t j = 0; j < options.controller.at(index).inputs.size(); ++j)
|
||||
{
|
||||
Input::get()->bindGameControllerButton(i, options.controller[index].inputs[j], options.controller[index].buttons[j]);
|
||||
Input::get()->bindGameControllerButton(i, options.controller.at(index).inputs.at(j), options.controller.at(index).buttons.at(j));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Asigna botones a inputs desde otros inputs
|
||||
for (int i = 0; i < num_gamepads; ++i)
|
||||
|
||||
@@ -75,7 +75,7 @@ void initOptions()
|
||||
|
||||
options.controller.push_back(c);
|
||||
}
|
||||
options.controller[0].device_type = INPUT_USE_ANY; // El primer jugador puede usar tanto el teclado como el primer mando
|
||||
options.controller.at(0).device_type = INPUT_USE_ANY; // El primer jugador puede usar tanto el teclado como el primer mando
|
||||
}
|
||||
|
||||
// Carga el fichero de configuración
|
||||
|
||||
@@ -323,32 +323,28 @@ void Title::swapControllers()
|
||||
// Muestra información sobre los controles y los jugadores
|
||||
void Title::showControllers()
|
||||
{
|
||||
// Crea cadenas de texto vacias para un numero máximo de mandos
|
||||
constexpr int MAX_CONTROLLERS = 2;
|
||||
std::string text[MAX_CONTROLLERS];
|
||||
int playerControllerIndex[MAX_CONTROLLERS];
|
||||
for (int i = 0; i < MAX_CONTROLLERS; ++i)
|
||||
{
|
||||
text[i].clear();
|
||||
playerControllerIndex[i] = -1;
|
||||
}
|
||||
// Crea vectores de texto vacíos para un número máximo de mandos
|
||||
constexpr size_t NUM_CONTROLLERS = 2;
|
||||
std::vector<std::string> text(NUM_CONTROLLERS);
|
||||
std::vector<int> playerControllerIndex(NUM_CONTROLLERS, -1);
|
||||
|
||||
// Obtiene para cada jugador el índice del mando correspondiente
|
||||
for (int i = 0; i < MAX_CONTROLLERS; ++i)
|
||||
// Obtiene de cada jugador el índice del mando que tiene asignado
|
||||
for (size_t i = 0; i < NUM_CONTROLLERS; ++i)
|
||||
{
|
||||
playerControllerIndex[options.controller[i].player_id - 1] = i;
|
||||
// Ejemplo: el jugador 1 tiene el mando 2
|
||||
playerControllerIndex.at(options.controller.at(i).player_id - 1) = i;
|
||||
}
|
||||
|
||||
// Genera el texto correspondiente
|
||||
for (int i = 0; i < MAX_CONTROLLERS; ++i)
|
||||
for (size_t i = 0; i < NUM_CONTROLLERS; ++i)
|
||||
{
|
||||
const int index = playerControllerIndex[i];
|
||||
if (options.controller[index].plugged)
|
||||
const size_t index = playerControllerIndex.at(i);
|
||||
if (options.controller.at(index).plugged)
|
||||
{
|
||||
text[i] = lang::getText(100) + std::to_string(i + 1) + ": " + options.controller[index].name;
|
||||
text.at(i) = lang::getText(100) + std::to_string(i + 1) + ": " + options.controller.at(index).name;
|
||||
}
|
||||
}
|
||||
|
||||
Notifier::get()->showText(text[0], text[1]);
|
||||
Notifier::get()->showText(text.at(0), text.at(1));
|
||||
resetCounter();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user