Ya se puede modificar el JailerID desde la pantalla de titulo, aunque hay que pulirlo un poco
This commit is contained in:
@@ -1888,10 +1888,6 @@ void Director::run()
|
|||||||
runDemo();
|
runDemo();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SECTION_PROG_ENTER_ID:
|
|
||||||
runEnterID();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SECTION_PROG_GAME:
|
case SECTION_PROG_GAME:
|
||||||
runGame();
|
runGame();
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -31,21 +31,13 @@ EnterID::EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t
|
|||||||
SDL_SetTextureBlendMode(textTexture, SDL_BLENDMODE_BLEND);
|
SDL_SetTextureBlendMode(textTexture, SDL_BLENDMODE_BLEND);
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
|
oldJailerID = options->online.jailerID;
|
||||||
|
loopRunning = true;
|
||||||
counter = 0;
|
counter = 0;
|
||||||
ticks = 0;
|
ticks = 0;
|
||||||
ticksSpeed = 15;
|
ticksSpeed = 15;
|
||||||
pos = 0;
|
jailerIDPos = 0;
|
||||||
name[pos] = 0;
|
initName();
|
||||||
maxLenght = 15;
|
|
||||||
|
|
||||||
if (options->online.enabled && options->online.jailerID == "")
|
|
||||||
{
|
|
||||||
this->section->name = SECTION_PROG_ENTER_ID;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
endSection();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Escribe el texto en la textura
|
// Escribe el texto en la textura
|
||||||
fillTexture();
|
fillTexture();
|
||||||
@@ -62,10 +54,7 @@ EnterID::~EnterID()
|
|||||||
// Bucle para el logo del juego
|
// Bucle para el logo del juego
|
||||||
void EnterID::run()
|
void EnterID::run()
|
||||||
{
|
{
|
||||||
// Detiene la música
|
while (loopRunning)
|
||||||
JA_StopMusic();
|
|
||||||
|
|
||||||
while (section->name == SECTION_PROG_ENTER_ID)
|
|
||||||
{
|
{
|
||||||
update();
|
update();
|
||||||
checkEvents();
|
checkEvents();
|
||||||
@@ -83,6 +72,7 @@ void EnterID::checkEvents()
|
|||||||
if (eventHandler->type == SDL_QUIT)
|
if (eventHandler->type == SDL_QUIT)
|
||||||
{
|
{
|
||||||
section->name = SECTION_PROG_QUIT;
|
section->name = SECTION_PROG_QUIT;
|
||||||
|
loopRunning = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,6 +90,13 @@ void EnterID::checkEvents()
|
|||||||
// Comprueba las teclas que se han pulsado
|
// Comprueba las teclas que se han pulsado
|
||||||
if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN))
|
if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN))
|
||||||
{
|
{
|
||||||
|
if (eventHandler->key.keysym.scancode == SDL_SCANCODE_RETURN)
|
||||||
|
{
|
||||||
|
options->online.jailerID = toLower((std::string)name);
|
||||||
|
endSection();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (eventHandler->key.keysym.scancode >= SDL_SCANCODE_A && eventHandler->key.keysym.scancode <= SDL_SCANCODE_Z)
|
if (eventHandler->key.keysym.scancode >= SDL_SCANCODE_A && eventHandler->key.keysym.scancode <= SDL_SCANCODE_Z)
|
||||||
{ // Si pulsa una letra
|
{ // Si pulsa una letra
|
||||||
if (pos < maxLenght)
|
if (pos < maxLenght)
|
||||||
@@ -138,6 +135,7 @@ void EnterID::checkEvents()
|
|||||||
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_ESCAPE)
|
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_ESCAPE)
|
||||||
{
|
{
|
||||||
section->name = SECTION_PROG_QUIT;
|
section->name = SECTION_PROG_QUIT;
|
||||||
|
loopRunning = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,6 +186,9 @@ void EnterID::update()
|
|||||||
|
|
||||||
// Actualiza el cursor
|
// Actualiza el cursor
|
||||||
cursor = (counter % 20 >= 10) ? " " : "_";
|
cursor = (counter % 20 >= 10) ? " " : "_";
|
||||||
|
|
||||||
|
// Actualiza las notificaciones
|
||||||
|
screen->updateNotifier();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,16 +198,13 @@ void EnterID::render()
|
|||||||
// Prepara para empezar a dibujar en la textura de juego
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
screen->start();
|
screen->start();
|
||||||
|
|
||||||
// Limpia la pantalla
|
|
||||||
screen->clean();
|
|
||||||
|
|
||||||
// Dibuja la textura con el texto en pantalla
|
// Dibuja la textura con el texto en pantalla
|
||||||
SDL_RenderCopy(renderer, textTexture, nullptr, nullptr);
|
SDL_RenderCopy(renderer, textTexture, nullptr, nullptr);
|
||||||
|
|
||||||
// Escribe el jailerID
|
// Escribe el jailerID
|
||||||
const std::string jailerID = (std::string)name + cursor;
|
const std::string jailerID = (std::string)name + cursor;
|
||||||
const color_t color = stringToColor(options->palette, "white");
|
const color_t color = stringToColor(options->palette, "white");
|
||||||
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, (16 * 8 + 1), jailerID, 1, color);
|
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, jailerIDPos, jailerID, 1, color);
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
screen->blit();
|
screen->blit();
|
||||||
@@ -267,32 +265,28 @@ void EnterID::fillTexture()
|
|||||||
SDL_SetRenderTarget(renderer, nullptr);
|
SDL_SetRenderTarget(renderer, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cambia la paleta
|
|
||||||
void EnterID::switchPalette()
|
|
||||||
{
|
|
||||||
options->palette = options->palette == p_zxspectrum ? p_zxarne : p_zxspectrum;
|
|
||||||
fillTexture();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inicializa los servicios online
|
// Inicializa los servicios online
|
||||||
void EnterID::initOnline()
|
void EnterID::initOnline()
|
||||||
{
|
{
|
||||||
|
// Si ya ha iniciado la sesión y no ha cambiado el jailerID, que no continue
|
||||||
if (options->online.sessionEnabled)
|
if (options->online.sessionEnabled)
|
||||||
{ // Si ya ha iniciado la sesión, que no continue
|
{
|
||||||
return;
|
if (oldJailerID == options->online.jailerID)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options->online.jailerID == "")
|
if (options->online.jailerID == "")
|
||||||
{ // Jailer ID no definido
|
{ // Jailer ID no definido
|
||||||
|
|
||||||
options->online.enabled = false;
|
options->online.enabled = false;
|
||||||
|
options->online.sessionEnabled = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ // Jailer ID iniciado
|
{ // Jailer ID iniciado
|
||||||
|
|
||||||
options->online.enabled = options->online.sessionEnabled = true;
|
options->online.enabled = options->online.sessionEnabled = true;
|
||||||
|
// Establece el servidor y el puerto
|
||||||
jscore::init(options->online.server, options->online.port);
|
jscore::init(options->online.server, options->online.port);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
const std::string caption = "IS LOGGED IN (DEBUG)";
|
const std::string caption = "IS LOGGED IN (DEBUG)";
|
||||||
#else
|
#else
|
||||||
@@ -309,7 +303,42 @@ void EnterID::initOnline()
|
|||||||
// Termina la sección
|
// Termina la sección
|
||||||
void EnterID::endSection()
|
void EnterID::endSection()
|
||||||
{
|
{
|
||||||
|
loopRunning = false;
|
||||||
initOnline();
|
initOnline();
|
||||||
section->name = (section->subsection == SUBSECTION_LOGO_TO_INTRO) ? SECTION_PROG_INTRO : SECTION_PROG_TITLE;
|
}
|
||||||
section->subsection = 0;
|
|
||||||
}
|
// Inicializa el vector utilizado para almacenar el texto que se escribe en pantalla
|
||||||
|
void EnterID::initName()
|
||||||
|
{
|
||||||
|
// Calcula el tamaño del vector
|
||||||
|
name[0] = 0;
|
||||||
|
maxLenght = sizeof(name) / sizeof(name[pos]);
|
||||||
|
|
||||||
|
// Inicializa el vector con ceros
|
||||||
|
for (int i = 0; i < maxLenght; ++i)
|
||||||
|
{
|
||||||
|
name[i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Si no hay definido ningun JailerID, coloca el cursor en primera posición
|
||||||
|
if (options->online.jailerID == "")
|
||||||
|
{
|
||||||
|
pos = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ // En caso contrario, copia el texto al vector y coloca el cursor en posición
|
||||||
|
const int len = std::min((int)options->online.jailerID.size(), maxLenght);
|
||||||
|
for (int i = 0; i < len; ++i)
|
||||||
|
{
|
||||||
|
name[i] = (char)options->online.jailerID[i];
|
||||||
|
}
|
||||||
|
pos = len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cambia la paleta
|
||||||
|
void EnterID::switchPalette()
|
||||||
|
{
|
||||||
|
options->palette = options->palette == p_zxspectrum ? p_zxarne : p_zxspectrum;
|
||||||
|
fillTexture();
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#ifndef ENTER_ID_H
|
#ifndef ENTER_ID_H
|
||||||
#define ASK_ME_H
|
#define ENTER_ID_H
|
||||||
|
|
||||||
class EnterID
|
class EnterID
|
||||||
{
|
{
|
||||||
@@ -32,15 +32,18 @@ private:
|
|||||||
section_t *section; // Estado del bucle principal para saber si continua o se sale
|
section_t *section; // Estado del bucle principal para saber si continua o se sale
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
|
bool loopRunning; // Indica si ha de terminar el bucle principal
|
||||||
int counter; // Contador
|
int counter; // Contador
|
||||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||||
std::vector<captions_t> texts; // Vector con los textos
|
std::vector<captions_t> texts; // Vector con los textos
|
||||||
std::string cursor; // Contiene el caracter que se muestra como cursor
|
std::string cursor; // Contiene el caracter que se muestra como cursor
|
||||||
|
|
||||||
char name[15];
|
char name[15]; // Aqui se guardan los caracteres de las teclas que se van pulsando
|
||||||
int pos;
|
int pos; // Posición actual en el vector name
|
||||||
int maxLenght; // Tamaño máximo del jailerID
|
int maxLenght; // Tamaño máximo del jailerID
|
||||||
|
std::string oldJailerID; // Almacena el valor de jailerID al inicio para ver si se ha modificado
|
||||||
|
int jailerIDPos; // Posición en el eje Y donde ser va a escribir el texto
|
||||||
|
|
||||||
// Actualiza las variables
|
// Actualiza las variables
|
||||||
void update();
|
void update();
|
||||||
@@ -57,15 +60,18 @@ private:
|
|||||||
// Escribe el texto en la textura
|
// Escribe el texto en la textura
|
||||||
void fillTexture();
|
void fillTexture();
|
||||||
|
|
||||||
// Cambia la paleta
|
|
||||||
void switchPalette();
|
|
||||||
|
|
||||||
// Inicializa los servicios online
|
// Inicializa los servicios online
|
||||||
void initOnline();
|
void initOnline();
|
||||||
|
|
||||||
// Termina la sección
|
// Termina la sección
|
||||||
void endSection();
|
void endSection();
|
||||||
|
|
||||||
|
// Inicializa el vector utilizado para almacenar el texto que se escribe en pantalla
|
||||||
|
void initName();
|
||||||
|
|
||||||
|
// Cambia la paleta
|
||||||
|
void switchPalette();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t *options, section_t *section);
|
EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t *options, section_t *section);
|
||||||
@@ -77,4 +83,4 @@ public:
|
|||||||
void run();
|
void run();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -553,4 +553,20 @@ bool colorAreEqual(color_t color1, color_t color2)
|
|||||||
const bool b = color1.b == color2.b;
|
const bool b = color1.b == color2.b;
|
||||||
|
|
||||||
return (r && g && b);
|
return (r && g && b);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convierte una cadena a minusculas
|
||||||
|
std::string toLower(std::string str)
|
||||||
|
{
|
||||||
|
const char *original = str.c_str();
|
||||||
|
char *lower = (char *)malloc(str.size() + 1);
|
||||||
|
for (int i = 0; i < (int)str.size(); ++i)
|
||||||
|
{
|
||||||
|
char c = original[i];
|
||||||
|
lower[i] = (c >= 65 && c <= 90) ? c + 32 : c;
|
||||||
|
}
|
||||||
|
lower[str.size()] = 0;
|
||||||
|
std::string nova(lower);
|
||||||
|
free(lower);
|
||||||
|
return nova;
|
||||||
}
|
}
|
||||||
@@ -197,4 +197,7 @@ std::string boolToString(bool value);
|
|||||||
// Compara dos colores
|
// Compara dos colores
|
||||||
bool colorAreEqual(color_t color1, color_t color2);
|
bool colorAreEqual(color_t color1, color_t color2);
|
||||||
|
|
||||||
|
// Convierte una cadena a minusculas
|
||||||
|
std::string toLower(std::string str);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -153,6 +153,10 @@ void Title::checkEvents()
|
|||||||
showCheevos = !showCheevos;
|
showCheevos = !showCheevos;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SDL_SCANCODE_Z:
|
||||||
|
runEnterID();
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -389,4 +393,12 @@ void Title::moveCheevosList(int direction)
|
|||||||
cheevosTextureView.y = bottom;
|
cheevosTextureView.y = bottom;
|
||||||
|
|
||||||
cheevosSprite->setSpriteClip(cheevosTextureView);
|
cheevosSprite->setSpriteClip(cheevosTextureView);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ejecuta la seccion en la que se solicita al usuario su ID online
|
||||||
|
void Title::runEnterID()
|
||||||
|
{
|
||||||
|
enterID = new EnterID(renderer, screen, asset, options, section);
|
||||||
|
enterID->run();
|
||||||
|
delete enterID;
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include "cheevos.h"
|
#include "cheevos.h"
|
||||||
|
#include "enter_id.h"
|
||||||
#include "jail_engine/asset.h"
|
#include "jail_engine/asset.h"
|
||||||
#include "jail_engine/input.h"
|
#include "jail_engine/input.h"
|
||||||
#include "jail_engine/jail_audio.h"
|
#include "jail_engine/jail_audio.h"
|
||||||
@@ -43,6 +44,7 @@ private:
|
|||||||
Texture *cheevosTexture; // Textura con lo lista de logros
|
Texture *cheevosTexture; // Textura con lo lista de logros
|
||||||
Sprite *cheevosSprite; // Sprite para manejar la textura con la lista de logros
|
Sprite *cheevosSprite; // Sprite para manejar la textura con la lista de logros
|
||||||
Cheevos *cheevos; // Objeto encargado de gestionar los logros del juego
|
Cheevos *cheevos; // Objeto encargado de gestionar los logros del juego
|
||||||
|
EnterID *enterID; // Objeto para recoger el JailerID desde el teclado
|
||||||
section_t *section; // Estado del bucle principal para saber si continua o se sale
|
section_t *section; // Estado del bucle principal para saber si continua o se sale
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
@@ -88,6 +90,9 @@ private:
|
|||||||
// Desplaza la lista de logros
|
// Desplaza la lista de logros
|
||||||
void moveCheevosList(int direction);
|
void moveCheevosList(int direction);
|
||||||
|
|
||||||
|
// Ejecuta la seccion en la que se solicita al usuario su ID online
|
||||||
|
void runEnterID();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Title(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, Input *input, options_t *options, section_t *section);
|
Title(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, Input *input, options_t *options, section_t *section);
|
||||||
|
|||||||
Reference in New Issue
Block a user