Canviades certes opcions a parametres i afegides noves opcions

This commit is contained in:
2024-10-11 09:03:57 +02:00
parent 117b80bdfc
commit e1fa1d2102
8 changed files with 113 additions and 115 deletions

View File

@@ -41,4 +41,12 @@ balloon_2.grav 0.10f
balloon_3.vel 4.70f balloon_3.vel 4.70f
balloon_3.grav 0.10f balloon_3.grav 0.10f
balloon_4.vel 5.45f balloon_4.vel 5.45f
balloon_4.grav 0.10f balloon_4.grav 0.10f
## NOTIFICATION
notification.pos_v TOP
notification.pos_h LEFT
notification.sound false
notification.color.r 48
notification.color.g 48
notification.color.b 48

View File

@@ -1,11 +1,11 @@
## GAME ## GAME
game.item_size 20 game.item_size 20
game.width 320 game.width 320
game.height 256 game.height 256
game.play_area.rect.x 0 game.play_area.rect.x 0
game.play_area.rect.y 0 game.play_area.rect.y 0
game.play_area.rect.w 320 game.play_area.rect.w 320
game.play_area.rect.h 216 game.play_area.rect.h 216
## FADE ## FADE
fade.num_squares_width 160 fade.num_squares_width 160
@@ -41,4 +41,12 @@ balloon_2.grav 0.10f
balloon_3.vel 4.70f balloon_3.vel 4.70f
balloon_3.grav 0.10f balloon_3.grav 0.10f
balloon_4.vel 5.45f balloon_4.vel 5.45f
balloon_4.grav 0.10f balloon_4.grav 0.10f
## NOTIFICATION
notification.pos_v TOP
notification.pos_h LEFT
notification.sound false
notification.color.r 48
notification.color.g 48
notification.color.b 48

View File

@@ -243,7 +243,7 @@ void Director::initJailAudio()
bool Director::initSDL() bool Director::initSDL()
{ {
// Indicador de éxito // Indicador de éxito
bool success = true; auto success = true;
// Inicializa SDL // Inicializa SDL
if (SDL_Init(SDL_INIT_EVERYTHING) < 0) if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
@@ -291,7 +291,7 @@ bool Director::initSDL()
#endif // NO_SHADERS #endif // NO_SHADERS
// Crea la ventana // Crea la ventana
window = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, param.game.width * options.video.window.size, param.game.height * options.video.window.size, SDL_WINDOW_HIDDEN); window = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, param.game.width * options.video.window.size, param.game.height * options.video.window.size, SDL_WINDOW_HIDDEN);
if (window == nullptr) if (!window)
{ {
#ifdef VERBOSE #ifdef VERBOSE
std::cout << "Window could not be created!\nSDL Error: " << SDL_GetError() << std::endl; std::cout << "Window could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
@@ -312,7 +312,7 @@ bool Director::initSDL()
#endif #endif
renderer = SDL_CreateRenderer(window, -1, flags); renderer = SDL_CreateRenderer(window, -1, flags);
if (renderer == nullptr) if (!renderer)
{ {
#ifdef VERBOSE #ifdef VERBOSE
std::cout << "Renderer could not be created!\nSDL Error: " << SDL_GetError() << std::endl; std::cout << "Renderer could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
@@ -326,7 +326,7 @@ bool Director::initSDL()
// Establece el tamaño del buffer de renderizado // Establece el tamaño del buffer de renderizado
SDL_RenderSetLogicalSize(renderer, param.game.width, param.game.height); SDL_RenderSetLogicalSize(renderer, param.game.width, param.game.height);
SDL_RenderSetIntegerScale(renderer, SDL_TRUE); SDL_RenderSetIntegerScale(renderer, static_cast<SDL_bool>(options.video.integer_scale));
// Establece el modo de mezcla // Establece el modo de mezcla
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND); SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
@@ -520,7 +520,7 @@ void Director::createSystemFolder(std::string folder)
#elif __linux__ #elif __linux__
struct passwd *pw = getpwuid(getuid()); struct passwd *pw = getpwuid(getuid());
const char *homedir = pw->pw_dir; const char *homedir = pw->pw_dir;
systemFolder = std::string(homedir) + "/." + folder; systemFolder = std::string(homedir) + "/.config/" + folder;
#endif #endif
struct stat st = {0}; struct stat st = {0};

View File

@@ -14,7 +14,7 @@ Notify::Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapF
: renderer(renderer) : renderer(renderer)
{ {
// Inicializa variables // Inicializa variables
bgColor = options.notification.color; bgColor = param.notification.color;
waitTime = 150; waitTime = 150;
stack = false; stack = false;
hasIcons = iconFile == "" ? false : true; hasIcons = iconFile == "" ? false : true;
@@ -65,7 +65,7 @@ void Notify::update()
// Hace sonar la notificación en el primer frame // Hace sonar la notificación en el primer frame
if (notifications[i].counter == 1) if (notifications[i].counter == 1)
{ {
if (options.notification.sound) if (param.notification.sound)
{ {
if (notifications[i].status == NotificationStatus::RISING) if (notifications[i].status == NotificationStatus::RISING)
{ // Reproduce el sonido de la notificación { // Reproduce el sonido de la notificación
@@ -80,7 +80,7 @@ void Notify::update()
const float step = ((float)notifications[i].counter / notifications[i].travelDist); const float step = ((float)notifications[i].counter / notifications[i].travelDist);
const int alpha = 255 * step; const int alpha = 255 * step;
if (options.notification.pos_v == NotifyPosition::TOP) if (param.notification.pos_v == NotifyPosition::TOP)
{ {
notifications[i].rect.y++; notifications[i].rect.y++;
} }
@@ -112,7 +112,7 @@ void Notify::update()
const float step = (notifications[i].counter / (float)notifications[i].travelDist); const float step = (notifications[i].counter / (float)notifications[i].travelDist);
const int alpha = 255 * (1 - step); const int alpha = 255 * (1 - step);
if (options.notification.pos_v == NotifyPosition::TOP) if (param.notification.pos_v == NotifyPosition::TOP)
{ {
notifications[i].rect.y--; notifications[i].rect.y--;
} }
@@ -182,11 +182,11 @@ void Notify::showText(std::string text1, std::string text2, int icon)
// Posición horizontal // Posición horizontal
auto despH = 0; auto despH = 0;
if (options.notification.pos_h == NotifyPosition::LEFT) if (param.notification.pos_h == NotifyPosition::LEFT)
{ {
despH = paddingOut; despH = paddingOut;
} }
else if (options.notification.pos_h == NotifyPosition::MIDDLE) else if (param.notification.pos_h == NotifyPosition::MIDDLE)
{ {
despH = ((param.game.width / 2) - (width / 2)); despH = ((param.game.width / 2) - (width / 2));
} }
@@ -196,12 +196,12 @@ void Notify::showText(std::string text1, std::string text2, int icon)
} }
// Posición vertical // Posición vertical
const int despV = (options.notification.pos_v == NotifyPosition::TOP) ? paddingOut : (param.game.height - height - paddingOut); const int despV = (param.notification.pos_v == NotifyPosition::TOP) ? paddingOut : (param.game.height - height - paddingOut);
// Offset // Offset
const auto travelDist = height + paddingOut; const auto travelDist = height + paddingOut;
auto offset = 0; auto offset = 0;
if (options.notification.pos_v == NotifyPosition::TOP) if (param.notification.pos_v == NotifyPosition::TOP)
{ {
offset = (int)notifications.size() > 0 ? notifications.back().y + travelDist : despV; offset = (int)notifications.size() > 0 ? notifications.back().y + travelDist : despV;
} }
@@ -221,7 +221,7 @@ void Notify::showText(std::string text1, std::string text2, int icon)
n.text1 = text1; n.text1 = text1;
n.text2 = text2; n.text2 = text2;
n.shape = shape; n.shape = shape;
auto yPos = offset + (options.notification.pos_v == NotifyPosition::TOP ? -travelDist : travelDist); auto yPos = offset + (param.notification.pos_v == NotifyPosition::TOP ? -travelDist : travelDist);
n.rect = {despH, yPos, width, height}; n.rect = {despH, yPos, width, height};
// Crea la textura // Crea la textura

View File

@@ -28,14 +28,9 @@ void initOptions()
#endif #endif
options.video.filter = ScreenFilter::NEAREST; options.video.filter = ScreenFilter::NEAREST;
options.video.v_sync = true; options.video.v_sync = true;
options.video.integer_scale = true;
options.video.shaders = true; options.video.shaders = true;
// Opciones de las notificaciones
options.notification.pos_v = NotifyPosition::TOP;
options.notification.pos_h = NotifyPosition::LEFT;
options.notification.sound = false;
options.notification.color = (Color){48, 48, 48};
// Opciones de audio // Opciones de audio
options.audio.music.enabled = true; options.audio.music.enabled = true;
options.audio.music.volume = 128; options.audio.music.volume = 128;
@@ -51,8 +46,8 @@ void initOptions()
options.controller.clear(); options.controller.clear();
OptionsController c; OptionsController c;
constexpr int numPlayers = 2; constexpr int num_players = 2;
for (int index = 0; index < numPlayers; ++index) for (int index = 0; index < num_players; ++index)
{ {
c.index = index; c.index = index;
c.player_id = index + 1; c.player_id = index + 1;
@@ -91,7 +86,7 @@ bool loadOptionsFile(std::string file_path)
bool success = true; bool success = true;
// Variables para manejar el fichero // Variables para manejar el fichero
const std::string fileName = file_path.substr(file_path.find_last_of("\\/") + 1); const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
std::ifstream file(file_path); std::ifstream file(file_path);
// Si el fichero se puede abrir // Si el fichero se puede abrir
@@ -99,7 +94,7 @@ bool loadOptionsFile(std::string file_path)
{ {
// Procesa el fichero linea a linea // Procesa el fichero linea a linea
#ifdef VERBOSE #ifdef VERBOSE
std::cout << "Reading file: " << fileName << std::endl; std::cout << "Reading file: " << file_name << std::endl;
#endif #endif
std::string line; std::string line;
while (std::getline(file, line)) while (std::getline(file, line))
@@ -113,7 +108,7 @@ bool loadOptionsFile(std::string file_path)
if (!setOptions(line.substr(0, pos), line.substr(pos + 1, line.length()))) if (!setOptions(line.substr(0, pos), line.substr(pos + 1, line.length())))
{ {
#ifdef VERBOSE #ifdef VERBOSE
std::cout << "Warning: file " << fileName << std::endl; std::cout << "Warning: file " << file_name << std::endl;
std::cout << "Unknown parameter " << line.substr(0, pos).c_str() << std::endl; std::cout << "Unknown parameter " << line.substr(0, pos).c_str() << std::endl;
#endif #endif
success = false; success = false;
@@ -155,19 +150,19 @@ bool loadOptionsFile(std::string file_path)
// Guarda el fichero de configuración // Guarda el fichero de configuración
bool saveOptionsFile(std::string file_path) bool saveOptionsFile(std::string file_path)
{ {
const std::string fileName = file_path.substr(file_path.find_last_of("\\/") + 1); const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1);
std::ofstream file(file_path); std::ofstream file(file_path);
if (!file.good()) if (!file.good())
{ {
#ifdef VERBOSE #ifdef VERBOSE
std::cout << fileName << " can't be opened" << std::endl; std::cout << file_name << " can't be opened" << std::endl;
#endif #endif
return false; return false;
} }
#ifdef VERBOSE #ifdef VERBOSE
std::cout << "Writing file: " << fileName << std::endl; std::cout << "Writing file: " << file_name << std::endl;
#endif #endif
// Opciones de video // Opciones de video
@@ -189,41 +184,9 @@ bool saveOptionsFile(std::string file_path)
const auto valueFilter = std::to_string(static_cast<int>(options.video.filter)); const auto valueFilter = std::to_string(static_cast<int>(options.video.filter));
file << "video.filter=" << valueFilter << "\n"; file << "video.filter=" << valueFilter << "\n";
file << "video.shaders=" + boolToString(options.video.shaders) + "\n";
file << "video.v_sync=" + boolToString(options.video.v_sync) + "\n"; file << "video.v_sync=" + boolToString(options.video.v_sync) + "\n";
file << "video.integer_scale=" + boolToString(options.video.integer_scale) + "\n";
// Opciones de notificaciones file << "video.shaders=" + boolToString(options.video.shaders) + "\n";
file << "\n\n## NOTIFICATION\n";
file << "## notification.pos_v [TOP | BOTTOM]\n";
file << "## notification.pos_h [LEFT | MIDDLE | RIGHT]\n";
file << "\n";
if (options.notification.pos_v == NotifyPosition::TOP)
{
file << "notification.pos_v=TOP\n";
}
else
{
file << "notification.pos_v=BOTTOM\n";
}
if (options.notification.pos_h == NotifyPosition::LEFT)
{
file << "notification.pos_h=LEFT\n";
}
else if (options.notification.pos_h == NotifyPosition::MIDDLE)
{
file << "notification.posH=MIDDLE\n";
}
else
{
file << "notification.pos_h=RIGHT\n";
}
file << "notification.sound=" + boolToString(options.notification.sound) + "\n";
// Opciones de audio // Opciones de audio
file << "\n\n## AUDIO\n"; file << "\n\n## AUDIO\n";
@@ -252,8 +215,8 @@ bool saveOptionsFile(std::string file_path)
file << "\n\n## CONTROLLERS\n"; file << "\n\n## CONTROLLERS\n";
file << "\n"; file << "\n";
const int numPlayers = 2; const int num_players = 2;
for (int index = 0; index < numPlayers; ++index) for (int index = 0; index < num_players; ++index)
{ {
const std::string joyIndex = std::to_string(index + 1); const std::string joyIndex = std::to_string(index + 1);
file << "controller" + joyIndex + ".name=" + options.controller[index].name + "\n"; file << "controller" + joyIndex + ".name=" + options.controller[index].name + "\n";
@@ -264,7 +227,7 @@ bool saveOptionsFile(std::string file_path)
file << "controller" + joyIndex + ".button.start=" + std::to_string((int)options.controller[index].buttons[3]) + "\n"; file << "controller" + joyIndex + ".button.start=" + std::to_string((int)options.controller[index].buttons[3]) + "\n";
file << "controller" + joyIndex + ".button.service=" + std::to_string((int)options.controller[index].buttons[4]) + "\n"; file << "controller" + joyIndex + ".button.service=" + std::to_string((int)options.controller[index].buttons[4]) + "\n";
if (index < numPlayers - 1) if (index < num_players - 1)
{ {
file << "\n"; file << "\n";
} }
@@ -285,7 +248,6 @@ bool setOptions(std::string var, std::string value)
// Opciones de video // Opciones de video
if (var == "video.mode") if (var == "video.mode")
{ {
// options.video.mode = value == std::to_string(static_cast<int>(ScreenVideoMode::WINDOW)) ? ScreenVideoMode::WINDOW : ScreenVideoMode::FULLSCREEN;
options.video.mode = static_cast<ScreenVideoMode>(std::stoi(value)); options.video.mode = static_cast<ScreenVideoMode>(std::stoi(value));
} }
@@ -300,7 +262,6 @@ bool setOptions(std::string var, std::string value)
else if (var == "video.filter") else if (var == "video.filter")
{ {
// options.video.filter = value == std::to_string(static_cast<int>(ScreenFilter::NEAREST)) ? ScreenFilter::NEAREST : ScreenFilter::LINEAL;
options.video.filter = static_cast<ScreenFilter>(std::stoi(value)); options.video.filter = static_cast<ScreenFilter>(std::stoi(value));
} }
@@ -309,38 +270,16 @@ bool setOptions(std::string var, std::string value)
options.video.shaders = stringToBool(value); options.video.shaders = stringToBool(value);
} }
else if (var == "video.integer_scale")
{
options.video.integer_scale = stringToBool(value);
}
else if (var == "video.v_sync") else if (var == "video.v_sync")
{ {
options.video.v_sync = stringToBool(value); options.video.v_sync = stringToBool(value);
} }
// Opciones de notificaciones
else if (var == "notification.pos_h")
{
if (value == "LEFT")
{
options.notification.pos_h = NotifyPosition::LEFT;
}
else if (value == "MIDDLE")
{
options.notification.pos_h = NotifyPosition::MIDDLE;
}
else
{
options.notification.pos_h = NotifyPosition::RIGHT;
}
}
else if (var == "notification.pos_v")
{
options.notification.pos_v = value == "TOP" ? NotifyPosition::TOP : NotifyPosition::BOTTOM;
}
else if (var == "notification.sound")
{
options.notification.sound = stringToBool(value);
}
// Opciones de audio // Opciones de audio
else if (var == "audio.music.enabled") else if (var == "audio.music.enabled")
{ {

View File

@@ -7,7 +7,7 @@ struct Options;
extern Options options; extern Options options;
// Carga el fichero de configuración // Carga el fichero de configuración
bool loadOptionsFile(std::string filePath); bool loadOptionsFile(std::string file_path);
// Guarda el fichero de configuración // Guarda el fichero de configuración
bool saveOptionsFile(std::string filePath); bool saveOptionsFile(std::string file_path);

View File

@@ -328,6 +328,48 @@ bool setParams(std::string var, std::string value)
param.balloon_4.grav = std::stof(value); param.balloon_4.grav = std::stof(value);
} }
// NOTIFICACIONES
else if (var == "notification.pos_h")
{
if (value == "LEFT")
{
param.notification.pos_h = NotifyPosition::LEFT;
}
else if (value == "MIDDLE")
{
param.notification.pos_h = NotifyPosition::MIDDLE;
}
else
{
param.notification.pos_h = NotifyPosition::RIGHT;
}
}
else if (var == "notification.pos_v")
{
param.notification.pos_v = value == "TOP" ? NotifyPosition::TOP : NotifyPosition::BOTTOM;
}
else if (var == "notification.sound")
{
param.notification.sound = stringToBool(value);
}
else if (var == "notification.color.r")
{
param.notification.color.r = std::stoi(value);
}
else if (var == "notification.color.g")
{
param.notification.color.g = std::stoi(value);
}
else if (var == "notification.color.b")
{
param.notification.color.b = std::stoi(value);
}
// RESTO // RESTO
else else
{ {

View File

@@ -84,6 +84,7 @@ struct OptionsVideo
ScreenVideoMode mode; // Contiene el valor del modo de pantalla completa ScreenVideoMode mode; // Contiene el valor del modo de pantalla completa
ScreenFilter filter; // Filtro usado para el escalado de la imagen ScreenFilter filter; // Filtro usado para el escalado de la imagen
bool v_sync; // Indica si se quiere usar vsync o no bool v_sync; // Indica si se quiere usar vsync o no
bool integer_scale; // Indica si se va a usar el escalado entero
bool shaders; // Indica si se van a usar shaders para los filtros de video bool shaders; // Indica si se van a usar shaders para los filtros de video
}; };
@@ -129,22 +130,12 @@ struct OptionsController
std::vector<SDL_GameControllerButton> buttons; // Listado de botones asignados a cada input std::vector<SDL_GameControllerButton> buttons; // Listado de botones asignados a cada input
}; };
// Estructura para las opciones de las notificaciones
struct OptionsNotification
{
NotifyPosition pos_h; // Ubicación de las notificaciones en pantalla
NotifyPosition pos_v; // Ubicación de las notificaciones en pantalla
bool sound; // Indica si las notificaciones suenan
Color color; // Color de las notificaciones
};
// Estructura con todas las opciones de configuración del programa // Estructura con todas las opciones de configuración del programa
struct Options struct Options
{ {
OptionsGame game; // Opciones para el propio juego OptionsGame game; // Opciones para el propio juego
OptionsVideo video; // Opciones relativas a la clase screen OptionsVideo video; // Opciones relativas a la clase screen
OptionsAudio audio; // Opciones para el audio OptionsAudio audio; // Opciones para el audio
OptionsNotification notification; // Opciones para las notificaciones
std::vector<OptionsController> controller; // Opciones con las asignaciones del mando para cada jugador std::vector<OptionsController> controller; // Opciones con las asignaciones del mando para cada jugador
}; };
@@ -204,6 +195,15 @@ struct ParamBalloon
float vel; // Velocidad inicial que tienen al rebotar contra el suelo float vel; // Velocidad inicial que tienen al rebotar contra el suelo
}; };
// Estructura para las opciones de las notificaciones
struct ParamNotification
{
NotifyPosition pos_h; // Ubicación de las notificaciones en pantalla
NotifyPosition pos_v; // Ubicación de las notificaciones en pantalla
bool sound; // Indica si las notificaciones suenan
Color color; // Color de las notificaciones
};
// Estructura para almacenar todos los parámetros del juego // Estructura para almacenar todos los parámetros del juego
struct Param struct Param
{ {
@@ -213,6 +213,7 @@ struct Param
ParamTitle title; // Parametros con ajustes para la sección Title ParamTitle title; // Parametros con ajustes para la sección Title
ParamBackground background; // Parametros que afectan a la clase Background ParamBackground background; // Parametros que afectan a la clase Background
ParamBalloon balloon_1, balloon_2, balloon_3, balloon_4; // Parametros de velocidad y gravedad de cada tipo de globo ParamBalloon balloon_1, balloon_2, balloon_3, balloon_4; // Parametros de velocidad y gravedad de cada tipo de globo
ParamNotification notification; // Opciones para las notificaciones
}; };
// Estructura para almacenar ficheros de sonido y su nombre // Estructura para almacenar ficheros de sonido y su nombre