Compare commits

...

5 Commits

11 changed files with 114 additions and 150 deletions

View File

@@ -150,6 +150,26 @@ void Notify::clearFinishedNotifications()
// Muestra una notificación de texto por pantalla;
void Notify::showText(std::string text1, std::string text2, int icon)
{
// Cuenta el número de textos a mostrar
int numTexts = 0;
if (text1 != "")
numTexts++;
if (text2 != "")
numTexts++;
// Si no hay texto, acaba
if (numTexts == 0)
{
return;
}
// Si solo hay un texto, lo coloca en la primera variable
else if (numTexts == 1)
{
text1 = text1 + text2;
text2 = "";
}
// Si las notificaciones no se apilan, elimina las anteriores
if (!stack)
{
clearNotifications();
@@ -162,7 +182,6 @@ void Notify::showText(std::string text1, std::string text2, int icon)
const int iconSpace = icon >= 0 ? iconSize + paddingIn : 0;
const std::string txt = text1.length() > text2.length() ? text1 : text2;
const int width = text->lenght(txt) + (paddingIn * 2) + iconSpace;
const int numTexts = text2 == "" ? 1 : 2;
const int height = (text->getCharacterSize() * numTexts) + (paddingIn * 2);
const notification_shape_t shape = notification_shape_squared;

View File

@@ -353,9 +353,14 @@ void Screen::checkInput()
}
// Comprueba el botón de SERVICE
if (checkServiceButton(input) == SERVICE_SHADERS)
switch (checkServiceButton(input))
{
case SERVICE_SHADERS:
switchShaders();
break;
default:
break;
}
}

View File

@@ -146,27 +146,19 @@ bool checkCollision(SDL_Point &p, SDL_Rect &r)
// Convierte una cadena en un valor booleano
bool stringToBool(std::string str)
{
if (str == "true")
{
return true;
}
else
{
return false;
}
return str == "true" ? true : false;
}
// Convierte un valor booleano en una cadena
std::string boolToString(bool value)
{
if (value)
{
return "true";
}
else
{
return "false";
}
return value == true ? "true" : "false";
}
// Convierte un valor booleano en una cadena "on" o "off"
std::string boolToOnOff(bool value)
{
return value == true ? "on" : "off";
}
// Convierte una cadena a minusculas
@@ -225,40 +217,40 @@ hiScoreEntry_t sortHiScoreTable(hiScoreEntry_t entry1, hiScoreEntry_t entry2)
}
// Dibuja un circulo
void DrawCircle(SDL_Renderer * renderer, int32_t centerX, int32_t centerY, int32_t radius)
void DrawCircle(SDL_Renderer *renderer, int32_t centerX, int32_t centerY, int32_t radius)
{
const int32_t diameter = (radius * 2);
const int32_t diameter = (radius * 2);
int32_t x = (radius - 1);
int32_t y = 0;
int32_t tx = 1;
int32_t ty = 1;
int32_t error = (tx - diameter);
int32_t x = (radius - 1);
int32_t y = 0;
int32_t tx = 1;
int32_t ty = 1;
int32_t error = (tx - diameter);
while (x >= y)
{
// Each of the following renders an octant of the circle
SDL_RenderDrawPoint(renderer, centerX + x, centerY - y);
SDL_RenderDrawPoint(renderer, centerX + x, centerY + y);
SDL_RenderDrawPoint(renderer, centerX - x, centerY - y);
SDL_RenderDrawPoint(renderer, centerX - x, centerY + y);
SDL_RenderDrawPoint(renderer, centerX + y, centerY - x);
SDL_RenderDrawPoint(renderer, centerX + y, centerY + x);
SDL_RenderDrawPoint(renderer, centerX - y, centerY - x);
SDL_RenderDrawPoint(renderer, centerX - y, centerY + x);
while (x >= y)
{
// Each of the following renders an octant of the circle
SDL_RenderDrawPoint(renderer, centerX + x, centerY - y);
SDL_RenderDrawPoint(renderer, centerX + x, centerY + y);
SDL_RenderDrawPoint(renderer, centerX - x, centerY - y);
SDL_RenderDrawPoint(renderer, centerX - x, centerY + y);
SDL_RenderDrawPoint(renderer, centerX + y, centerY - x);
SDL_RenderDrawPoint(renderer, centerX + y, centerY + x);
SDL_RenderDrawPoint(renderer, centerX - y, centerY - x);
SDL_RenderDrawPoint(renderer, centerX - y, centerY + x);
if (error <= 0)
{
++y;
error += ty;
ty += 2;
}
if (error <= 0)
{
++y;
error += ty;
ty += 2;
}
if (error > 0)
{
--x;
tx += 2;
error += (tx - diameter);
}
}
if (error > 0)
{
--x;
tx += 2;
error += (tx - diameter);
}
}
}

View File

@@ -272,6 +272,9 @@ bool stringToBool(std::string str);
// Convierte un valor booleano en una cadena
std::string boolToString(bool value);
// Convierte un valor booleano en una cadena "on" o "off"
std::string boolToOnOff(bool value);
// Convierte una cadena a minusculas
std::string toLower(std::string str);

View File

@@ -2050,35 +2050,24 @@ void Game::checkInput()
switch (checkServiceButton(input))
{
case SERVICE_RESET:
{
section->name = SECTION_PROG_LOGO;
screen->showNotification("Reset");
break;
}
case SERVICE_MUTE:
{
const bool value = !options->audio.music.enabled;
options->audio.music.enabled = value;
options->audio.sound.enabled = value;
JA_EnableMusic(value);
JA_EnableSound(value);
const std::string text = value ? "on" : "off";
screen->showNotification("Audio " + text);
options->audio.sound.enabled = options->audio.music.enabled = !options->audio.music.enabled;
JA_EnableMusic(options->audio.music.enabled);
JA_EnableSound(options->audio.sound.enabled);
screen->showNotification("Audio " + boolToOnOff(options->audio.music.enabled));
break;
}
case SERVICE_PAUSE:
{
pause(!paused);
break;
}
default:
{
break;
}
}
// Modo Demo activo
if (demo.enabled)

View File

@@ -212,29 +212,20 @@ void HiScoreTable::checkInput()
switch (checkServiceButton(input))
{
case SERVICE_RESET:
{
section->name = SECTION_PROG_LOGO;
screen->showNotification("Reset");
break;
}
case SERVICE_MUTE:
{
const bool value = !options->audio.music.enabled;
options->audio.music.enabled = value;
options->audio.sound.enabled = value;
JA_EnableMusic(value);
JA_EnableSound(value);
const std::string text = value ? "on" : "off";
screen->showNotification("Audio " + text);
options->audio.sound.enabled = options->audio.music.enabled = !options->audio.music.enabled;
JA_EnableMusic(options->audio.music.enabled);
JA_EnableSound(options->audio.sound.enabled);
screen->showNotification("Audio " + boolToOnOff(options->audio.music.enabled));
break;
}
default:
{
break;
}
}
// Comprueba el input para el resto de objetos
screen->checkInput();

View File

@@ -342,29 +342,20 @@ void Instructions::checkInput()
switch (checkServiceButton(input))
{
case SERVICE_RESET:
{
section->name = SECTION_PROG_LOGO;
screen->showNotification("Reset");
break;
}
case SERVICE_MUTE:
{
const bool value = !options->audio.music.enabled;
options->audio.music.enabled = value;
options->audio.sound.enabled = value;
JA_EnableMusic(value);
JA_EnableSound(value);
const std::string text = value ? "on" : "off";
screen->showNotification("Audio " + text);
options->audio.sound.enabled = options->audio.music.enabled = !options->audio.music.enabled;
JA_EnableMusic(options->audio.music.enabled);
JA_EnableSound(options->audio.sound.enabled);
screen->showNotification("Audio " + boolToOnOff(options->audio.music.enabled));
break;
}
default:
{
break;
}
}
// Comprueba el input para el resto de objetos
screen->checkInput();

View File

@@ -211,29 +211,20 @@ void Intro::checkInput()
switch (checkServiceButton(input))
{
case SERVICE_RESET:
{
section->name = SECTION_PROG_LOGO;
screen->showNotification("Reset");
break;
}
case SERVICE_MUTE:
{
const bool value = !options->audio.music.enabled;
options->audio.music.enabled = value;
options->audio.sound.enabled = value;
JA_EnableMusic(value);
JA_EnableSound(value);
const std::string text = value ? "on" : "off";
screen->showNotification("Audio " + text);
options->audio.sound.enabled = options->audio.music.enabled = !options->audio.music.enabled;
JA_EnableMusic(options->audio.music.enabled);
JA_EnableSound(options->audio.sound.enabled);
screen->showNotification("Audio " + boolToOnOff(options->audio.music.enabled));
break;
}
default:
{
break;
}
}
// Comprueba el input para el resto de objetos
screen->checkInput();

View File

@@ -122,37 +122,21 @@ void Logo::checkInput()
switch (checkServiceButton(input))
{
case SERVICE_EXIT:
{
section->name = SECTION_PROG_QUIT;
section->options = SECTION_OPTIONS_QUIT_SHUTDOWN;
return;
break;
}
case SERVICE_RESET:
{
section->name = SECTION_PROG_LOGO;
screen->showNotification("Reset");
break;
}
case SERVICE_MUTE:
{
const bool value = !options->audio.music.enabled;
options->audio.music.enabled = value;
options->audio.sound.enabled = value;
JA_EnableMusic(value);
JA_EnableSound(value);
const std::string text = value ? "on" : "off";
screen->showNotification("Audio " + text);
options->audio.sound.enabled = options->audio.music.enabled = !options->audio.music.enabled;
JA_EnableMusic(options->audio.music.enabled);
JA_EnableSound(options->audio.sound.enabled);
screen->showNotification("Audio " + boolToOnOff(options->audio.music.enabled));
break;
}
default:
{
break;
}
}
// Comprueba el input para el resto de objetos
screen->checkInput();

View File

@@ -16,12 +16,12 @@ int checkServiceButton(Input *input, int index)
else if (input->checkInput(input_fire_left, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
{
return SERVICE_CONFIG;
return SERVICE_SHADERS;
}
else if (input->checkInput(input_fire_center, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
{
return SERVICE_SHADERS;
return SERVICE_RESET;
}
else if (input->checkInput(input_fire_right, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
@@ -36,7 +36,7 @@ int checkServiceButton(Input *input, int index)
else if (input->checkInput(input_down, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
{
return SERVICE_RESET;
return SERVICE_CONFIG;
}
else if (input->checkInput(input_left, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
@@ -57,12 +57,12 @@ int checkServiceButton(Input *input, int index)
else if (input->checkInput(input_fire_left, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, index))
{
return SERVICE_CONFIG;
return SERVICE_SHADERS;
}
else if (input->checkInput(input_fire_center, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, index))
{
return SERVICE_SHADERS;
return SERVICE_RESET;
}
else if (input->checkInput(input_fire_right, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, index))
@@ -77,7 +77,7 @@ int checkServiceButton(Input *input, int index)
else if (input->checkInput(input_down, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, index))
{
return SERVICE_RESET;
return SERVICE_CONFIG;
}
else if (input->checkInput(input_left, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, index))

View File

@@ -271,35 +271,24 @@ void Title::checkInput()
switch (checkServiceButton(input))
{
case SERVICE_RESET:
{
section->name = SECTION_PROG_LOGO;
screen->showNotification("Reset");
break;
}
case SERVICE_MUTE:
{
const bool value = !options->audio.music.enabled;
options->audio.music.enabled = value;
options->audio.sound.enabled = value;
JA_EnableMusic(value);
JA_EnableSound(value);
const std::string text = value ? "on" : "off";
screen->showNotification("Audio " + text);
options->audio.sound.enabled = options->audio.music.enabled = !options->audio.music.enabled;
JA_EnableMusic(options->audio.music.enabled);
JA_EnableSound(options->audio.sound.enabled);
screen->showNotification("Audio " + boolToOnOff(options->audio.music.enabled));
break;
}
case SERVICE_SWAP_CONTROLLERS:
{
swapControllers();
break;
}
default:
{
break;
}
}
// Comprueba si algun mando quiere ser configurado
for (int i = 0; i < input->getNumControllers(); ++i)
@@ -365,17 +354,27 @@ void Title::swapControllers()
}
defineButtons->swapControllers();
const std::string text0 = "Jugador " + std::to_string(options->controller[0].playerId) + " -> " + options->controller[0].name;
const std::string text1 = "Jugador " + std::to_string(options->controller[1].playerId) + " -> " + options->controller[1].name;
if (numControllers == 1)
// Crea cadenas de texto vacias para un numero máximo de mandos
const int MAX_CONTROLLERS = 2;
std::string text[MAX_CONTROLLERS];
for (int i = 0; i < MAX_CONTROLLERS; ++i)
text[i] = "";
// Obtiene para cada jugador el índice del mando correspondiente
int playerControllerIndex[numControllers];
for (int i = 0; i < numControllers; ++i)
{
screen->showNotification(text0);
playerControllerIndex[options->controller[i].playerId - 1] = i;
}
else
// Genera el texto correspondiente
for (int i = 0; i < numControllers; ++i)
{
screen->showNotification(text0, text1);
text[i] = "Jugador " + std::to_string(i + 1) + ": " + options->controller[playerControllerIndex[i]].name;
}
screen->showNotification(text[0], text[1]);
resetCounter();
}