Ya se puede modificar el JailerID desde la pantalla de titulo, aunque hay que pulirlo un poco
This commit is contained in:
@@ -31,21 +31,13 @@ EnterID::EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t
|
||||
SDL_SetTextureBlendMode(textTexture, SDL_BLENDMODE_BLEND);
|
||||
|
||||
// Inicializa variables
|
||||
oldJailerID = options->online.jailerID;
|
||||
loopRunning = true;
|
||||
counter = 0;
|
||||
ticks = 0;
|
||||
ticksSpeed = 15;
|
||||
pos = 0;
|
||||
name[pos] = 0;
|
||||
maxLenght = 15;
|
||||
|
||||
if (options->online.enabled && options->online.jailerID == "")
|
||||
{
|
||||
this->section->name = SECTION_PROG_ENTER_ID;
|
||||
}
|
||||
else
|
||||
{
|
||||
endSection();
|
||||
}
|
||||
jailerIDPos = 0;
|
||||
initName();
|
||||
|
||||
// Escribe el texto en la textura
|
||||
fillTexture();
|
||||
@@ -62,10 +54,7 @@ EnterID::~EnterID()
|
||||
// Bucle para el logo del juego
|
||||
void EnterID::run()
|
||||
{
|
||||
// Detiene la música
|
||||
JA_StopMusic();
|
||||
|
||||
while (section->name == SECTION_PROG_ENTER_ID)
|
||||
while (loopRunning)
|
||||
{
|
||||
update();
|
||||
checkEvents();
|
||||
@@ -83,6 +72,7 @@ void EnterID::checkEvents()
|
||||
if (eventHandler->type == SDL_QUIT)
|
||||
{
|
||||
section->name = SECTION_PROG_QUIT;
|
||||
loopRunning = false;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -100,6 +90,13 @@ void EnterID::checkEvents()
|
||||
// Comprueba las teclas que se han pulsado
|
||||
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)
|
||||
{ // Si pulsa una letra
|
||||
if (pos < maxLenght)
|
||||
@@ -138,6 +135,7 @@ void EnterID::checkEvents()
|
||||
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_ESCAPE)
|
||||
{
|
||||
section->name = SECTION_PROG_QUIT;
|
||||
loopRunning = false;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -188,6 +186,9 @@ void EnterID::update()
|
||||
|
||||
// Actualiza el cursor
|
||||
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
|
||||
screen->start();
|
||||
|
||||
// Limpia la pantalla
|
||||
screen->clean();
|
||||
|
||||
// Dibuja la textura con el texto en pantalla
|
||||
SDL_RenderCopy(renderer, textTexture, nullptr, nullptr);
|
||||
|
||||
// Escribe el jailerID
|
||||
const std::string jailerID = (std::string)name + cursor;
|
||||
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
|
||||
screen->blit();
|
||||
@@ -267,32 +265,28 @@ void EnterID::fillTexture()
|
||||
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
|
||||
void EnterID::initOnline()
|
||||
{
|
||||
// Si ya ha iniciado la sesión y no ha cambiado el jailerID, que no continue
|
||||
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 == "")
|
||||
{ // Jailer ID no definido
|
||||
|
||||
options->online.enabled = false;
|
||||
options->online.sessionEnabled = false;
|
||||
}
|
||||
else
|
||||
{ // Jailer ID iniciado
|
||||
|
||||
options->online.enabled = options->online.sessionEnabled = true;
|
||||
// Establece el servidor y el puerto
|
||||
jscore::init(options->online.server, options->online.port);
|
||||
|
||||
#ifdef DEBUG
|
||||
const std::string caption = "IS LOGGED IN (DEBUG)";
|
||||
#else
|
||||
@@ -309,7 +303,42 @@ void EnterID::initOnline()
|
||||
// Termina la sección
|
||||
void EnterID::endSection()
|
||||
{
|
||||
loopRunning = false;
|
||||
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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user