forked from jaildesigner-jailgames/jaildoctors_dilemma
Guardado de las opciones de las notificaciones
This commit is contained in:
@@ -4,11 +4,12 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Notify::Notify(SDL_Renderer *renderer, std::string bitmapFile, std::string textFile, std::string soundFile)
|
Notify::Notify(SDL_Renderer *renderer, std::string bitmapFile, std::string textFile, std::string soundFile, options_t *options)
|
||||||
{
|
{
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
this->renderer = renderer;
|
this->renderer = renderer;
|
||||||
bgColor = {64, 64, 64};
|
this->options = options;
|
||||||
|
bgColor = options->notifications.color;
|
||||||
waitTime = 300;
|
waitTime = 300;
|
||||||
|
|
||||||
// Crea objetos
|
// Crea objetos
|
||||||
@@ -54,7 +55,14 @@ void Notify::update()
|
|||||||
const float step = ((float)notifications.at(i).counter / notifications.at(i).travelDist);
|
const float step = ((float)notifications.at(i).counter / notifications.at(i).travelDist);
|
||||||
const int alpha = 255 * step;
|
const int alpha = 255 * step;
|
||||||
|
|
||||||
|
if (options->notifications.posV == pos_top)
|
||||||
|
{
|
||||||
notifications.at(i).rect.y++;
|
notifications.at(i).rect.y++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
notifications.at(i).rect.y--;
|
||||||
|
}
|
||||||
notifications.at(i).texture->setAlpha(alpha);
|
notifications.at(i).texture->setAlpha(alpha);
|
||||||
|
|
||||||
if (notifications.at(i).rect.y == notifications.at(i).y)
|
if (notifications.at(i).rect.y == notifications.at(i).y)
|
||||||
@@ -79,7 +87,14 @@ void Notify::update()
|
|||||||
const float step = (notifications.at(i).counter / (float)notifications.at(i).travelDist);
|
const float step = (notifications.at(i).counter / (float)notifications.at(i).travelDist);
|
||||||
const int alpha = 255 * (1 - step);
|
const int alpha = 255 * (1 - step);
|
||||||
|
|
||||||
|
if (options->notifications.posV == pos_top)
|
||||||
|
{
|
||||||
notifications.at(i).rect.y--;
|
notifications.at(i).rect.y--;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
notifications.at(i).rect.y++;
|
||||||
|
}
|
||||||
notifications.at(i).texture->setAlpha(alpha);
|
notifications.at(i).texture->setAlpha(alpha);
|
||||||
|
|
||||||
if (notifications.at(i).rect.y == notifications.at(i).y - notifications.at(i).travelDist)
|
if (notifications.at(i).rect.y == notifications.at(i).y - notifications.at(i).travelDist)
|
||||||
@@ -111,24 +126,67 @@ void Notify::clearFinishedNotifications()
|
|||||||
// Muestra una notificación de texto por pantalla;
|
// Muestra una notificación de texto por pantalla;
|
||||||
void Notify::showText(std::string text)
|
void Notify::showText(std::string text)
|
||||||
{
|
{
|
||||||
// Crea constantes
|
// Inicializa variables
|
||||||
const int width = this->text->lenght(text) + (this->text->getCharacterSize() * 2);
|
const int width = this->text->lenght(text) + (this->text->getCharacterSize() * 2);
|
||||||
const int height = this->text->getCharacterSize() * 2;
|
const int height = this->text->getCharacterSize() * 2;
|
||||||
const int despH = this->text->getCharacterSize() / 2;
|
const int padding = (this->text->getCharacterSize() / 2);
|
||||||
const int despV = despH;
|
|
||||||
const int travelDist = height + despV;
|
// Posición horizontal
|
||||||
const int offset = (int)notifications.size() > 0 ? notifications.back().y + travelDist : despV;
|
int despH = 0;
|
||||||
|
if (options->notifications.posH == pos_left)
|
||||||
|
{
|
||||||
|
despH = padding;
|
||||||
|
}
|
||||||
|
else if (options->notifications.posH == pos_middle)
|
||||||
|
{
|
||||||
|
despH = ((options->screen.windowWidth * options->windowSize) / 2 - (width / 2));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
despH = (options->screen.windowWidth * options->windowSize) - width - padding;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Posición vertical
|
||||||
|
int despV = 0;
|
||||||
|
if (options->notifications.posV == pos_top)
|
||||||
|
{
|
||||||
|
despV = padding;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
despV = (options->screen.windowHeight * options->windowSize) - height - padding;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int travelDist = height + padding;
|
||||||
|
|
||||||
|
// Offset
|
||||||
|
int offset = 0;
|
||||||
|
if (options->notifications.posV == pos_top)
|
||||||
|
{
|
||||||
|
offset = (int)notifications.size() > 0 ? notifications.back().y + travelDist : despV;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
offset = (int)notifications.size() > 0 ? notifications.back().y - travelDist : despV;
|
||||||
|
}
|
||||||
|
|
||||||
// Crea la notificacion
|
// Crea la notificacion
|
||||||
notification_t n;
|
notification_t n;
|
||||||
|
|
||||||
// inicializa variables
|
// Inicializa variables
|
||||||
n.y = offset;
|
n.y = offset;
|
||||||
n.travelDist = travelDist;
|
n.travelDist = travelDist;
|
||||||
n.counter = 0;
|
n.counter = 0;
|
||||||
n.state = ns_rising;
|
n.state = ns_rising;
|
||||||
n.text = text;
|
n.text = text;
|
||||||
|
if (options->notifications.posV == pos_top)
|
||||||
|
{
|
||||||
n.rect = {despH, offset - travelDist, width, height};
|
n.rect = {despH, offset - travelDist, width, height};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
n.rect = {despH, offset + travelDist, width, height};
|
||||||
|
}
|
||||||
|
|
||||||
// Crea la textura
|
// Crea la textura
|
||||||
n.texture = new Texture(renderer);
|
n.texture = new Texture(renderer);
|
||||||
@@ -137,7 +195,7 @@ void Notify::showText(std::string text)
|
|||||||
SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 255);
|
SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 255);
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
n.texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
n.texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
||||||
this->text->writeDX(TXT_CENTER | TXT_STROKE, width / 2, despV, text, 1, {255, 255, 255}, 1, {0, 0, 0});
|
this->text->writeDX(TXT_CENTER | TXT_STROKE, width / 2, padding, text, 1, {255, 255, 255}, 1, {0, 0, 0});
|
||||||
SDL_SetRenderTarget(renderer, nullptr);
|
SDL_SetRenderTarget(renderer, nullptr);
|
||||||
|
|
||||||
// Crea el sprite
|
// Crea el sprite
|
||||||
@@ -147,8 +205,11 @@ void Notify::showText(std::string text)
|
|||||||
notifications.push_back(n);
|
notifications.push_back(n);
|
||||||
|
|
||||||
// Reproduce el sonido de la notificación
|
// Reproduce el sonido de la notificación
|
||||||
|
if (options->notifications.sound)
|
||||||
|
{
|
||||||
JA_PlaySound(sound);
|
JA_PlaySound(sound);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Indica si hay notificaciones activas
|
// Indica si hay notificaciones activas
|
||||||
bool Notify::active()
|
bool Notify::active()
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ private:
|
|||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||||
Texture *texture; // Textura para la fuente de las notificaciones
|
Texture *texture; // Textura para la fuente de las notificaciones
|
||||||
Text *text; // Objeto para dibujar texto
|
Text *text; // Objeto para dibujar texto
|
||||||
|
options_t *options; // Variable con todas las opciones del programa
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
color_t bgColor; // Color de fondo de las notificaciones
|
color_t bgColor; // Color de fondo de las notificaciones
|
||||||
@@ -69,7 +70,7 @@ public:
|
|||||||
void update();
|
void update();
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Notify(SDL_Renderer *renderer, std::string bitmapFile, std::string textFile, std::string soundFile);
|
Notify(SDL_Renderer *renderer, std::string bitmapFile, std::string textFile, std::string soundFile, options_t *options);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Notify();
|
~Notify();
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options
|
|||||||
this->asset = asset;
|
this->asset = asset;
|
||||||
|
|
||||||
// Crea los objetos
|
// Crea los objetos
|
||||||
notify = new Notify(renderer, asset->get("smb2.png"), asset->get("smb2.txt"), asset->get("notify.wav"));
|
notify = new Notify(renderer, asset->get("smb2.png"), asset->get("smb2.txt"), asset->get("notify.wav"), options);
|
||||||
|
|
||||||
gameCanvasWidth = options->gameWidth;
|
gameCanvasWidth = options->gameWidth;
|
||||||
gameCanvasHeight = options->gameHeight;
|
gameCanvasHeight = options->gameHeight;
|
||||||
@@ -167,8 +167,10 @@ void Screen::setVideoMode(int videoMode)
|
|||||||
SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
|
SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el valor de la variable
|
// Actualiza las opciones
|
||||||
options->videoMode = videoMode;
|
options->videoMode = videoMode;
|
||||||
|
options->screen.windowWidth = windowWidth;
|
||||||
|
options->screen.windowHeight = windowHeight;
|
||||||
|
|
||||||
// Establece el tamaño de las notificaciones
|
// Establece el tamaño de las notificaciones
|
||||||
setNotificationSize();
|
setNotificationSize();
|
||||||
|
|||||||
@@ -54,6 +54,25 @@ enum palette_e
|
|||||||
p_zxarne
|
p_zxarne
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Posiciones de las notificaciones
|
||||||
|
enum not_pos_e
|
||||||
|
{
|
||||||
|
pos_top,
|
||||||
|
pos_bottom,
|
||||||
|
pos_left,
|
||||||
|
pos_middle,
|
||||||
|
pos_right
|
||||||
|
};
|
||||||
|
|
||||||
|
// Estructura para las opciones de las notificaciones
|
||||||
|
struct op_notification_t
|
||||||
|
{
|
||||||
|
not_pos_e posH; // Ubicación de las notificaciones en pantalla
|
||||||
|
not_pos_e posV; // Ubicación de las notificaciones en pantalla
|
||||||
|
bool sound; // Indica si las notificaciones suenan
|
||||||
|
color_t color; // Color de las notificaciones
|
||||||
|
};
|
||||||
|
|
||||||
// Estructura para saber la seccion y subseccion del programa
|
// Estructura para saber la seccion y subseccion del programa
|
||||||
struct section_t
|
struct section_t
|
||||||
{
|
{
|
||||||
@@ -89,6 +108,13 @@ struct op_stats_t
|
|||||||
std::string worstNightmare; // Habitación con más muertes acumuladas
|
std::string worstNightmare; // Habitación con más muertes acumuladas
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Estructura con opciones de la pantalla
|
||||||
|
struct op_screen_t
|
||||||
|
{
|
||||||
|
int windowWidth; // Ancho de la ventana
|
||||||
|
int windowHeight; // Alto de la ventana
|
||||||
|
};
|
||||||
|
|
||||||
// Estructura con todas las opciones de configuración del programa
|
// Estructura con todas las opciones de configuración del programa
|
||||||
struct options_t
|
struct options_t
|
||||||
{
|
{
|
||||||
@@ -108,6 +134,8 @@ struct options_t
|
|||||||
cheat_t cheat; // Contiene trucos y ventajas para el juego
|
cheat_t cheat; // Contiene trucos y ventajas para el juego
|
||||||
op_stats_t stats; // Datos con las estadisticas de juego
|
op_stats_t stats; // Datos con las estadisticas de juego
|
||||||
online_t online; // Datos del servicio online
|
online_t online; // Datos del servicio online
|
||||||
|
op_notification_t notifications; // Opciones relativas a las notificaciones;
|
||||||
|
op_screen_t screen; // Opciones relativas a la clase screen
|
||||||
};
|
};
|
||||||
|
|
||||||
// Calcula el cuadrado de la distancia entre dos puntos
|
// Calcula el cuadrado de la distancia entre dos puntos
|
||||||
|
|||||||
@@ -147,6 +147,12 @@ void Director::initOptions()
|
|||||||
options->online.gameID = "jaildoctors_dilemma";
|
options->online.gameID = "jaildoctors_dilemma";
|
||||||
#endif
|
#endif
|
||||||
options->online.jailerID = "";
|
options->online.jailerID = "";
|
||||||
|
|
||||||
|
// Opciones de las notificaciones
|
||||||
|
options->notifications.posV = pos_top;
|
||||||
|
options->notifications.posH = pos_left;
|
||||||
|
options->notifications.sound = true;
|
||||||
|
options->notifications.color = {64, 64, 64};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba los parametros del programa
|
// Comprueba los parametros del programa
|
||||||
@@ -346,6 +352,33 @@ bool Director::saveConfig()
|
|||||||
file << "port=" + std::to_string(options->online.port) + "\n";
|
file << "port=" + std::to_string(options->online.port) + "\n";
|
||||||
file << "jailerID=" + options->online.jailerID + "\n";
|
file << "jailerID=" + options->online.jailerID + "\n";
|
||||||
|
|
||||||
|
file << "\n## NOTIFICATION OPTIONS\n";
|
||||||
|
file << "## notifications.posV = pos_top | pos_bottom\n";
|
||||||
|
if (options->notifications.posV == pos_top)
|
||||||
|
{
|
||||||
|
file << "notifications.posV=pos_top\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
file << "notifications.posV=pos_bottom\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
file << "## notifications.posH = pos_left | pos_middle | pos_right\n";
|
||||||
|
if (options->notifications.posH == pos_left)
|
||||||
|
{
|
||||||
|
file << "notifications.posH=pos_left\n";
|
||||||
|
}
|
||||||
|
else if (options->notifications.posH == pos_middle)
|
||||||
|
{
|
||||||
|
file << "notifications.posH=pos_middle\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
file << "notifications.posH=pos_right\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
file << "notifications.sound=" + boolToString(options->notifications.sound) + "\n";
|
||||||
|
|
||||||
// Cierra el fichero
|
// Cierra el fichero
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
@@ -1081,6 +1114,39 @@ bool Director::setOptions(options_t *options, std::string var, std::string value
|
|||||||
options->online.jailerID = value;
|
options->online.jailerID = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (var == "notifications.posH")
|
||||||
|
{
|
||||||
|
if (value == "pos_left")
|
||||||
|
{
|
||||||
|
options->notifications.posH = pos_left;
|
||||||
|
}
|
||||||
|
else if (value == "pos_middle")
|
||||||
|
{
|
||||||
|
options->notifications.posH = pos_middle;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
options->notifications.posH = pos_right;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (var == "notifications.posV")
|
||||||
|
{
|
||||||
|
if (value == "pos_top")
|
||||||
|
{
|
||||||
|
options->notifications.posV = pos_top;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
options->notifications.posV = pos_bottom;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (var == "notifications.sound")
|
||||||
|
{
|
||||||
|
options->notifications.sound = stringToBool(value);
|
||||||
|
}
|
||||||
|
|
||||||
else if (var == "" || var.substr(0, 1) == "#")
|
else if (var == "" || var.substr(0, 1) == "#")
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user