Un altre punteret a pendre per cul: options
This commit is contained in:
@@ -6,7 +6,11 @@ Asset::Asset(std::string executablePath)
|
||||
{
|
||||
this->executablePath = executablePath.substr(0, executablePath.find_last_of("\\/"));
|
||||
longestName = 0;
|
||||
#ifdef VERBOSE
|
||||
verbose = true;
|
||||
#else
|
||||
verbose = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Añade un elemento a la lista
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#include "define_buttons.h"
|
||||
#include "param.h"
|
||||
#include "options.h"
|
||||
|
||||
// Constructor
|
||||
DefineButtons::DefineButtons(Input *input, Text *text, options_t *options, section_t *section)
|
||||
DefineButtons::DefineButtons(Input *input, Text *text, section_t *section)
|
||||
{
|
||||
// Copia punteros a los objetos
|
||||
this->input = input;
|
||||
this->text = text;
|
||||
this->options = options;
|
||||
this->section = section;
|
||||
|
||||
// Inicializa variables
|
||||
@@ -69,7 +69,7 @@ void DefineButtons::render()
|
||||
{
|
||||
if (enabled)
|
||||
{
|
||||
text->writeCentered(x, y - 10, lang::getText(100) + std::to_string(options->controller[indexController].playerId));
|
||||
text->writeCentered(x, y - 10, lang::getText(100) + std::to_string(options.controller[indexController].playerId));
|
||||
text->writeCentered(x, y, controllerNames[indexController]);
|
||||
text->writeCentered(x, y + 10, buttons[indexButton].label);
|
||||
}
|
||||
@@ -171,17 +171,17 @@ void DefineButtons::incIndexButton()
|
||||
void DefineButtons::saveBindingsToOptions()
|
||||
{
|
||||
// Modifica las opciones para colocar los valores asignados
|
||||
options->controller[indexController].name = input->getControllerName(indexController);
|
||||
for (int j = 0; j < (int)options->controller[indexController].inputs.size(); ++j)
|
||||
options.controller[indexController].name = input->getControllerName(indexController);
|
||||
for (int j = 0; j < (int)options.controller[indexController].inputs.size(); ++j)
|
||||
{
|
||||
options->controller[indexController].buttons[j] = input->getControllerBinding(indexController, options->controller[indexController].inputs[j]);
|
||||
options.controller[indexController].buttons[j] = input->getControllerBinding(indexController, options.controller[indexController].inputs[j]);
|
||||
}
|
||||
}
|
||||
|
||||
// Intercambia los jugadores asignados a los dos primeros mandos
|
||||
void DefineButtons::swapControllers()
|
||||
{
|
||||
const int temp = options->controller[0].playerId;
|
||||
options->controller[0].playerId = options->controller[1].playerId;
|
||||
options->controller[1].playerId = temp;
|
||||
const int temp = options.controller[0].playerId;
|
||||
options.controller[0].playerId = options.controller[1].playerId;
|
||||
options.controller[1].playerId = temp;
|
||||
}
|
||||
@@ -22,7 +22,6 @@ private:
|
||||
Text *text; // Objeto para escribir texto
|
||||
|
||||
// Variables
|
||||
options_t *options; // Opciones del programa
|
||||
section_t *section; // Indicador para el bucle del titulo
|
||||
bool enabled; // Indica si el objeto está habilitado
|
||||
int x; // Posición donde dibujar el texto
|
||||
@@ -46,7 +45,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
DefineButtons(Input *input, Text *text, options_t *options, section_t *section);
|
||||
DefineButtons(Input *input, Text *text, section_t *section);
|
||||
|
||||
// Destructor
|
||||
~DefineButtons();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "director.h"
|
||||
#include "utils.h"
|
||||
#include "const.h"
|
||||
#include "director.h"
|
||||
#include "options.h"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
@@ -33,12 +34,8 @@ Director::Director(int argc, char *argv[])
|
||||
createSystemFolder("jailgames");
|
||||
createSystemFolder("jailgames/coffee_crisis_arcade_edition");
|
||||
|
||||
// Inicializa las opciones del programa
|
||||
initOptions();
|
||||
|
||||
// Crea el objeto que controla los ficheros de recursos
|
||||
asset = new Asset(executablePath);
|
||||
asset->setVerbose(options->console);
|
||||
|
||||
// Si falta algún fichero no inicia el programa
|
||||
if (!setFileList())
|
||||
@@ -46,8 +43,10 @@ Director::Director(int argc, char *argv[])
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Carga los parametros para configurar el juego
|
||||
// Carga el fichero de configuración
|
||||
loadOptionsFile(asset->get("config.txt"));
|
||||
|
||||
// Carga los parametros para configurar el juego
|
||||
#ifdef ANBERNIC
|
||||
const std::string paramFilePath = asset->get("param_320x240.txt");
|
||||
#else
|
||||
@@ -55,11 +54,8 @@ Director::Director(int argc, char *argv[])
|
||||
#endif
|
||||
loadParams(paramFilePath);
|
||||
|
||||
// Carga el fichero de configuración
|
||||
loadConfigFile();
|
||||
|
||||
// Carga el fichero de puntuaciones
|
||||
ManageHiScoreTable *manager = new ManageHiScoreTable(&options->game.hiScoreTable);
|
||||
ManageHiScoreTable *manager = new ManageHiScoreTable(&options.game.hiScoreTable);
|
||||
manager->loadFromFile(asset->get("score.bin"));
|
||||
delete manager;
|
||||
|
||||
@@ -73,12 +69,12 @@ Director::Director(int argc, char *argv[])
|
||||
dbg_init(renderer);
|
||||
|
||||
// Crea los objetos
|
||||
lang::loadFromFile(getLangFile((lang::lang_e)options->game.language));
|
||||
lang::loadFromFile(getLangFile((lang::lang_e)options.game.language));
|
||||
|
||||
input = new Input(asset->get("gamecontrollerdb.txt"));
|
||||
initInput();
|
||||
|
||||
screen = new Screen(window, renderer, asset, input, options);
|
||||
screen = new Screen(window, renderer, asset, input);
|
||||
|
||||
// Carga los sonidos del juego
|
||||
loadSounds();
|
||||
@@ -89,12 +85,11 @@ Director::Director(int argc, char *argv[])
|
||||
|
||||
Director::~Director()
|
||||
{
|
||||
saveConfigFile();
|
||||
saveOptionsFile(asset->get("config.txt"));
|
||||
|
||||
delete asset;
|
||||
delete input;
|
||||
delete screen;
|
||||
delete options;
|
||||
delete section;
|
||||
|
||||
deleteSounds();
|
||||
@@ -113,7 +108,7 @@ void Director::initInput()
|
||||
#ifdef VERBOSE
|
||||
input->setVerbose(true);
|
||||
#else
|
||||
input->setVerbose(options->console);
|
||||
input->setVerbose(options.console);
|
||||
#endif
|
||||
// Busca si hay mandos conectados
|
||||
input->discoverGameControllers();
|
||||
@@ -171,11 +166,11 @@ void Director::initInput()
|
||||
|
||||
// Mapea las asignaciones a los botones desde el archivo de configuración, si se da el caso
|
||||
for (int i = 0; i < numGamePads; ++i)
|
||||
for (int index = 0; index < (int)options->controller.size(); ++index)
|
||||
if (input->getControllerName(i) == options->controller[index].name)
|
||||
for (int j = 0; j < (int)options->controller[index].inputs.size(); ++j)
|
||||
for (int index = 0; index < (int)options.controller.size(); ++index)
|
||||
if (input->getControllerName(i) == options.controller[index].name)
|
||||
for (int j = 0; j < (int)options.controller[index].inputs.size(); ++j)
|
||||
{
|
||||
input->bindGameControllerButton(i, options->controller[index].inputs[j], options->controller[index].buttons[j]);
|
||||
input->bindGameControllerButton(i, options.controller[index].inputs[j], options.controller[index].buttons[j]);
|
||||
}
|
||||
|
||||
// Asigna botones a inputs desde otros inputs
|
||||
@@ -194,10 +189,10 @@ void Director::initInput()
|
||||
// Guarda las asignaciones de botones en las opciones
|
||||
for (int i = 0; i < numGamePads; ++i)
|
||||
{
|
||||
options->controller[i].name = input->getControllerName(i);
|
||||
for (int j = 0; j < (int)options->controller[i].inputs.size(); ++j)
|
||||
options.controller[i].name = input->getControllerName(i);
|
||||
for (int j = 0; j < (int)options.controller[i].inputs.size(); ++j)
|
||||
{
|
||||
options->controller[i].buttons[j] = input->getControllerBinding(i, options->controller[i].inputs[j]);
|
||||
options.controller[i].buttons[j] = input->getControllerBinding(i, options.controller[i].inputs[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -206,10 +201,10 @@ void Director::initInput()
|
||||
void Director::initJailAudio()
|
||||
{
|
||||
JA_Init(48000, AUDIO_S16, 2);
|
||||
JA_EnableMusic(options->audio.music.enabled);
|
||||
JA_EnableSound(options->audio.sound.enabled);
|
||||
JA_SetMusicVolume(options->audio.music.volume);
|
||||
JA_SetSoundVolume(options->audio.sound.volume);
|
||||
JA_EnableMusic(options.audio.music.enabled);
|
||||
JA_EnableSound(options.audio.sound.enabled);
|
||||
JA_SetMusicVolume(options.audio.music.volume);
|
||||
JA_SetSoundVolume(options.audio.sound.volume);
|
||||
}
|
||||
|
||||
// Arranca SDL y crea la ventana
|
||||
@@ -221,7 +216,7 @@ bool Director::initSDL()
|
||||
// Inicializa SDL
|
||||
if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
|
||||
{
|
||||
if (options->console)
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "SDL could not initialize!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
}
|
||||
@@ -233,7 +228,7 @@ bool Director::initSDL()
|
||||
std::srand(static_cast<unsigned int>(SDL_GetTicks()));
|
||||
|
||||
// Muestra información de la pantalla
|
||||
if (options->console)
|
||||
if (options.console)
|
||||
{
|
||||
/*std::cout << "\nDisplay modes list:" << std::endl;
|
||||
for (int i = 0; i < SDL_GetNumDisplayModes(0); ++i)
|
||||
@@ -246,13 +241,13 @@ bool Director::initSDL()
|
||||
SDL_DisplayMode DM;
|
||||
SDL_GetCurrentDisplayMode(0, &DM);
|
||||
std::cout << "\nCurrent display mode: " + std::to_string(DM.w) + "x" + std::to_string(DM.h) + " @ " + std::to_string(DM.refresh_rate) + "Hz" << std::endl;
|
||||
std::cout << "Window resolution : " + std::to_string(param.game.width) + "x" + std::to_string(param.game.height) + " x" + std::to_string(options->video.window.size) << std::endl;
|
||||
std::cout << "Window resolution : " + std::to_string(param.game.width) + "x" + std::to_string(param.game.height) + " x" + std::to_string(options.video.window.size) << std::endl;
|
||||
}
|
||||
|
||||
// Establece el filtro de la textura
|
||||
if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, std::to_string(options->video.filter).c_str()))
|
||||
if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, std::to_string(options.video.filter).c_str()))
|
||||
{
|
||||
if (options->console)
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "Warning: texture filtering not enabled!\n";
|
||||
}
|
||||
@@ -260,17 +255,17 @@ bool Director::initSDL()
|
||||
#ifndef NO_SHADERS
|
||||
if (!SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl"))
|
||||
{
|
||||
if (options->console)
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "Warning: opengl not enabled!\n";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
// 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 (options->console)
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "Window could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
}
|
||||
@@ -280,7 +275,7 @@ bool Director::initSDL()
|
||||
{
|
||||
// Crea un renderizador para la ventana. El vsync se activa en funcion de las opciones
|
||||
Uint32 flags = 0;
|
||||
if (options->video.vSync)
|
||||
if (options.video.vSync)
|
||||
{
|
||||
flags = flags | SDL_RENDERER_PRESENTVSYNC;
|
||||
}
|
||||
@@ -292,7 +287,7 @@ bool Director::initSDL()
|
||||
|
||||
if (renderer == nullptr)
|
||||
{
|
||||
if (options->console)
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "Renderer could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
}
|
||||
@@ -312,7 +307,7 @@ bool Director::initSDL()
|
||||
}
|
||||
}
|
||||
|
||||
if (options->console)
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << std::endl;
|
||||
}
|
||||
@@ -469,89 +464,10 @@ void Director::loadParams(std::string filepath)
|
||||
loadParamsFromFile(filepath);
|
||||
|
||||
// Modifica las opciones desde el fichero de parametros
|
||||
options->video.window.width = options->video.window.size * param.game.width;
|
||||
options->video.window.height = options->video.window.size * param.game.height;
|
||||
options->video.gameWidth = param.game.width;
|
||||
options->video.gameHeight = param.game.height;
|
||||
}
|
||||
|
||||
// Inicializa las opciones del programa
|
||||
void Director::initOptions()
|
||||
{
|
||||
// Crea el puntero a la estructura de opciones
|
||||
options = new options_t;
|
||||
|
||||
// Pone unos valores por defecto para las opciones
|
||||
|
||||
// Opciones varias
|
||||
#ifdef VERBOSE
|
||||
options->console = true;
|
||||
#else
|
||||
options->console = false;
|
||||
#endif
|
||||
|
||||
// Opciones de video
|
||||
#ifdef ANBERNIC
|
||||
options->video.mode = 0;
|
||||
options->video.window.size = 3;
|
||||
#else
|
||||
options->video.mode = 0;
|
||||
options->video.window.size = 2;
|
||||
#endif
|
||||
options->video.filter = SCREEN_FILTER_NEAREST;
|
||||
options->video.vSync = true;
|
||||
options->video.integerScale = true;
|
||||
options->video.keepAspect = true;
|
||||
options->video.shaders = true;
|
||||
|
||||
// Opciones de las notificaciones
|
||||
options->notification.posV = pos_top;
|
||||
options->notification.posH = pos_left;
|
||||
options->notification.sound = false;
|
||||
options->notification.color = {48, 48, 48};
|
||||
|
||||
// Opciones de audio
|
||||
options->audio.music.enabled = true;
|
||||
options->audio.music.volume = 128;
|
||||
options->audio.sound.enabled = true;
|
||||
options->audio.sound.volume = 64;
|
||||
|
||||
// Opciones de juego
|
||||
options->game.difficulty = DIFFICULTY_NORMAL;
|
||||
options->game.language = lang::ba_BA;
|
||||
options->game.autofire = true;
|
||||
|
||||
// Opciones de control
|
||||
options->controller.clear();
|
||||
op_controller_t c;
|
||||
|
||||
const int numPlayers = 2;
|
||||
for (int index = 0; index < numPlayers; ++index)
|
||||
{
|
||||
c.index = index;
|
||||
c.playerId = index + 1;
|
||||
c.deviceType = INPUT_USE_GAMECONTROLLER;
|
||||
c.name = "NO NAME";
|
||||
|
||||
// Inputs que se guardan en las opciones y, por tanto, a disco
|
||||
c.inputs.clear();
|
||||
c.inputs.push_back(input_fire_left);
|
||||
c.inputs.push_back(input_fire_center);
|
||||
c.inputs.push_back(input_fire_right);
|
||||
c.inputs.push_back(input_start);
|
||||
c.inputs.push_back(input_service);
|
||||
|
||||
// Botones asociados a los inputs anteriores
|
||||
c.buttons.clear();
|
||||
c.buttons.push_back(SDL_CONTROLLER_BUTTON_X);
|
||||
c.buttons.push_back(SDL_CONTROLLER_BUTTON_Y);
|
||||
c.buttons.push_back(SDL_CONTROLLER_BUTTON_B);
|
||||
c.buttons.push_back(SDL_CONTROLLER_BUTTON_START);
|
||||
c.buttons.push_back(SDL_CONTROLLER_BUTTON_BACK);
|
||||
|
||||
options->controller.push_back(c);
|
||||
}
|
||||
options->controller[0].deviceType = INPUT_USE_ANY; // El primer jugador puede usar tanto el teclado como el primer mando
|
||||
options.video.window.width = options.video.window.size * param.game.width;
|
||||
options.video.window.height = options.video.window.size * param.game.height;
|
||||
options.video.gameWidth = param.game.width;
|
||||
options.video.gameHeight = param.game.height;
|
||||
}
|
||||
|
||||
// Comprueba los parametros del programa
|
||||
@@ -568,7 +484,7 @@ void Director::checkProgramArguments(int argc, char *argv[])
|
||||
{
|
||||
if (strcmp(argv[i], "--console") == 0)
|
||||
{
|
||||
options->console = true;
|
||||
options.console = true;
|
||||
}
|
||||
|
||||
if (strcmp(argv[i], "--320x240") == 0)
|
||||
@@ -627,203 +543,6 @@ void Director::createSystemFolder(std::string folder)
|
||||
}
|
||||
}
|
||||
|
||||
// Carga el fichero de configuración
|
||||
bool Director::loadConfigFile()
|
||||
{
|
||||
// Indicador de éxito en la carga
|
||||
bool success = true;
|
||||
|
||||
// Variables para manejar el fichero
|
||||
const std::string filePath = "config.txt";
|
||||
std::string line;
|
||||
std::ifstream file(asset->get(filePath));
|
||||
|
||||
// Si el fichero se puede abrir
|
||||
if (file.good())
|
||||
{
|
||||
// Procesa el fichero linea a linea
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "Reading file: " << filePath << std::endl;
|
||||
}
|
||||
while (std::getline(file, line))
|
||||
{
|
||||
// Comprueba que la linea no sea un comentario
|
||||
if (line.substr(0, 1) != "#")
|
||||
{
|
||||
// Encuentra la posición del caracter '='
|
||||
int pos = line.find("=");
|
||||
// Procesa las dos subcadenas
|
||||
if (!setOptions(options, line.substr(0, pos), line.substr(pos + 1, line.length())))
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "Warning: file " << filePath << std::endl;
|
||||
std::cout << "Unknown parameter " << line.substr(0, pos).c_str() << std::endl;
|
||||
}
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cierra el fichero
|
||||
file.close();
|
||||
}
|
||||
|
||||
// El fichero no existe
|
||||
else
|
||||
{ // Crea el fichero con los valores por defecto
|
||||
saveConfigFile();
|
||||
}
|
||||
|
||||
// Normaliza los valores
|
||||
const bool a = options->video.mode == 0;
|
||||
const bool b = options->video.mode == SDL_WINDOW_FULLSCREEN;
|
||||
const bool c = options->video.mode == SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||
if (!(a || b || c))
|
||||
{
|
||||
options->video.mode = SCREEN_VIDEO_MODE_WINDOW;
|
||||
}
|
||||
|
||||
if (options->video.window.size < 1 || options->video.window.size > 4)
|
||||
{
|
||||
options->video.window.size = 3;
|
||||
}
|
||||
|
||||
if (options->game.language < 0 || options->game.language > 2)
|
||||
{
|
||||
options->game.language = lang::en_UK;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
// Guarda el fichero de configuración
|
||||
bool Director::saveConfigFile()
|
||||
{
|
||||
const std::string filename = "config.txt";
|
||||
std::ofstream file(asset->get(filename));
|
||||
|
||||
if (!file.good())
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << filename << " can't be opened" << std::endl;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "Writing file: " << filename << std::endl;
|
||||
}
|
||||
|
||||
// Opciones de video
|
||||
file << "## VIDEO\n";
|
||||
file << "## video.mode [0: window, 1: full screen]\n";
|
||||
file << "## video.filter [0: nearest, 1: lineal]\n";
|
||||
file << "\n";
|
||||
|
||||
if (options->video.mode == SCREEN_VIDEO_MODE_WINDOW)
|
||||
{
|
||||
file << "video.mode=0\n";
|
||||
}
|
||||
|
||||
else if (options->video.mode == SCREEN_VIDEO_MODE_FULLSCREEN)
|
||||
{
|
||||
file << "video.mode=1\n";
|
||||
}
|
||||
|
||||
file << "video.window.size=" + std::to_string(options->video.window.size) + "\n";
|
||||
|
||||
options->video.filter == SCREEN_FILTER_NEAREST ? file << "video.filter=0\n" : file << "video.filter=1\n";
|
||||
|
||||
file << "video.shaders=" + boolToString(options->video.shaders) + "\n";
|
||||
file << "video.vSync=" + boolToString(options->video.vSync) + "\n";
|
||||
file << "video.integerScale=" + boolToString(options->video.integerScale) + "\n";
|
||||
file << "video.keepAspect=" + boolToString(options->video.keepAspect) + "\n";
|
||||
|
||||
// Opciones de notificaciones
|
||||
file << "\n\n## NOTIFICATION\n";
|
||||
file << "## notification.posV [pos_top | pos_bottom]\n";
|
||||
file << "## notification.posH [pos_left | pos_middle | pos_right]\n";
|
||||
file << "\n";
|
||||
|
||||
if (options->notification.posV == pos_top)
|
||||
{
|
||||
file << "notification.posV=pos_top\n";
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
file << "notification.posV=pos_bottom\n";
|
||||
}
|
||||
|
||||
if (options->notification.posH == pos_left)
|
||||
{
|
||||
file << "notification.posH=pos_left\n";
|
||||
}
|
||||
|
||||
else if (options->notification.posH == pos_middle)
|
||||
{
|
||||
file << "notification.posH=pos_middle\n";
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
file << "notification.posH=pos_right\n";
|
||||
}
|
||||
|
||||
file << "notification.sound=" + boolToString(options->notification.sound) + "\n";
|
||||
|
||||
// Opciones de audio
|
||||
file << "\n\n## AUDIO\n";
|
||||
file << "## volume [0 .. 128]\n";
|
||||
file << "\n";
|
||||
|
||||
file << "audio.music.enabled=" + boolToString(options->audio.music.enabled) + "\n";
|
||||
file << "audio.music.volume=" + std::to_string(options->audio.music.volume) + "\n";
|
||||
file << "audio.sound.enabled=" + boolToString(options->audio.sound.enabled) + "\n";
|
||||
file << "audio.sound.volume=" + std::to_string(options->audio.sound.volume) + "\n";
|
||||
|
||||
// Opciones del juego
|
||||
file << "\n\n## GAME\n";
|
||||
file << "## game.language [0: spanish, 1: valencian, 2: english]\n";
|
||||
file << "## game.difficulty [0: easy, 1: normal, 2: hard]\n";
|
||||
file << "\n";
|
||||
|
||||
file << "game.language=" + std::to_string(options->game.language) + "\n";
|
||||
file << "game.difficulty=" + std::to_string(options->game.difficulty) + "\n";
|
||||
file << "game.autofire=" + boolToString(options->game.autofire) + "\n";
|
||||
|
||||
// Opciones de mandos
|
||||
file << "\n\n## CONTROLLERS\n";
|
||||
file << "\n";
|
||||
|
||||
const int numPlayers = 2;
|
||||
for (int index = 0; index < numPlayers; ++index)
|
||||
{
|
||||
const std::string joyIndex = std::to_string(index + 1);
|
||||
file << "controller" + joyIndex + ".name=" + options->controller[index].name + "\n";
|
||||
file << "controller" + joyIndex + ".player=" + std::to_string(options->controller[index].playerId) + "\n";
|
||||
file << "controller" + joyIndex + ".button.fire_left=" + std::to_string((int)options->controller[index].buttons[0]) + "\n";
|
||||
file << "controller" + joyIndex + ".button.fire_center=" + std::to_string((int)options->controller[index].buttons[1]) + "\n";
|
||||
file << "controller" + joyIndex + ".button.fire_right=" + std::to_string((int)options->controller[index].buttons[2]) + "\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";
|
||||
|
||||
if (index < numPlayers - 1)
|
||||
{
|
||||
file << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Cierra el fichero
|
||||
file.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Carga los sonidos del juego
|
||||
void Director::loadSounds()
|
||||
{
|
||||
@@ -883,7 +602,7 @@ void Director::deleteMusics()
|
||||
// Ejecuta la sección con el logo
|
||||
void Director::runLogo()
|
||||
{
|
||||
logo = new Logo(screen, asset, input, options, section);
|
||||
logo = new Logo(screen, asset, input, section);
|
||||
logo->run();
|
||||
delete logo;
|
||||
}
|
||||
@@ -891,7 +610,7 @@ void Director::runLogo()
|
||||
// Ejecuta la sección con la secuencia de introducción
|
||||
void Director::runIntro()
|
||||
{
|
||||
intro = new Intro(screen, asset, input, options, section, getMusic(musics, "intro.ogg"));
|
||||
intro = new Intro(screen, asset, input, section, getMusic(musics, "intro.ogg"));
|
||||
intro->run();
|
||||
delete intro;
|
||||
}
|
||||
@@ -899,7 +618,7 @@ void Director::runIntro()
|
||||
// Ejecuta la sección con el titulo del juego
|
||||
void Director::runTitle()
|
||||
{
|
||||
title = new Title(screen, asset, input, options, section, getMusic(musics, "title.ogg"));
|
||||
title = new Title(screen, asset, input, section, getMusic(musics, "title.ogg"));
|
||||
title->run();
|
||||
delete title;
|
||||
}
|
||||
@@ -909,7 +628,7 @@ void Director::runGame()
|
||||
{
|
||||
const int playerID = section->options;
|
||||
const int currentStage = 0;
|
||||
game = new Game(playerID, currentStage, GAME_MODE_DEMO_OFF, screen, asset, input, options, section, getMusic(musics, "playing.ogg"));
|
||||
game = new Game(playerID, currentStage, GAME_MODE_DEMO_OFF, screen, asset, input, section, getMusic(musics, "playing.ogg"));
|
||||
game->run();
|
||||
delete game;
|
||||
}
|
||||
@@ -917,7 +636,7 @@ void Director::runGame()
|
||||
// Ejecuta la sección donde se muestran las instrucciones
|
||||
void Director::runInstructions()
|
||||
{
|
||||
instructions = new Instructions(screen, asset, input, options, section, getMusic(musics, "title.ogg"));
|
||||
instructions = new Instructions(screen, asset, input, section, getMusic(musics, "title.ogg"));
|
||||
instructions->run();
|
||||
delete instructions;
|
||||
}
|
||||
@@ -925,7 +644,7 @@ void Director::runInstructions()
|
||||
// Ejecuta la sección donde se muestra la tabla de puntuaciones
|
||||
void Director::runHiScoreTable()
|
||||
{
|
||||
hiScoreTable = new HiScoreTable(screen, asset, input, options, section, getMusic(musics, "title.ogg"));
|
||||
hiScoreTable = new HiScoreTable(screen, asset, input, section, getMusic(musics, "title.ogg"));
|
||||
hiScoreTable->run();
|
||||
delete hiScoreTable;
|
||||
}
|
||||
@@ -935,7 +654,7 @@ void Director::runDemoGame()
|
||||
{
|
||||
const int playerID = (rand() % 2) + 1;
|
||||
const int currentStage = 0;
|
||||
demoGame = new Game(playerID, currentStage, GAME_MODE_DEMO_ON, screen, asset, input, options, section, nullptr);
|
||||
demoGame = new Game(playerID, currentStage, GAME_MODE_DEMO_ON, screen, asset, input, section, nullptr);
|
||||
demoGame->run();
|
||||
delete demoGame;
|
||||
}
|
||||
@@ -985,200 +704,6 @@ int Director::run()
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
// Asigna variables a partir de dos cadenas
|
||||
bool Director::setOptions(options_t *options, std::string var, std::string value)
|
||||
{
|
||||
// Indicador de éxito en la asignación
|
||||
bool success = true;
|
||||
|
||||
// Opciones de video
|
||||
if (var == "video.mode")
|
||||
{
|
||||
options->video.mode = value == std::to_string(SCREEN_VIDEO_MODE_WINDOW) ? SCREEN_VIDEO_MODE_WINDOW : SCREEN_VIDEO_MODE_FULLSCREEN;
|
||||
}
|
||||
|
||||
else if (var == "video.window.size")
|
||||
{
|
||||
options->video.window.size = std::stoi(value);
|
||||
if ((options->video.window.size < 1) || (options->video.window.size > 4))
|
||||
{
|
||||
options->video.window.size = 3;
|
||||
}
|
||||
}
|
||||
|
||||
else if (var == "video.filter")
|
||||
{
|
||||
options->video.filter = value == std::to_string(SCREEN_FILTER_NEAREST) ? SCREEN_FILTER_NEAREST : SCREEN_FILTER_LINEAL;
|
||||
}
|
||||
|
||||
else if (var == "video.shaders")
|
||||
{
|
||||
options->video.shaders = stringToBool(value);
|
||||
}
|
||||
|
||||
else if (var == "video.vSync")
|
||||
{
|
||||
options->video.vSync = stringToBool(value);
|
||||
}
|
||||
|
||||
else if (var == "video.integerScale")
|
||||
{
|
||||
options->video.integerScale = stringToBool(value);
|
||||
}
|
||||
|
||||
else if (var == "video.keepAspect")
|
||||
{
|
||||
options->video.keepAspect = stringToBool(value);
|
||||
}
|
||||
|
||||
// Opciones de notificaciones
|
||||
else if (var == "notification.posH")
|
||||
{
|
||||
if (value == "pos_left")
|
||||
{
|
||||
options->notification.posH = pos_left;
|
||||
}
|
||||
else if (value == "pos_middle")
|
||||
{
|
||||
options->notification.posH = pos_middle;
|
||||
}
|
||||
else
|
||||
{
|
||||
options->notification.posH = pos_right;
|
||||
}
|
||||
}
|
||||
|
||||
else if (var == "notification.posV")
|
||||
{
|
||||
options->notification.posV = value == "pos_top" ? pos_top : pos_bottom;
|
||||
}
|
||||
|
||||
else if (var == "notification.sound")
|
||||
{
|
||||
options->notification.sound = stringToBool(value);
|
||||
}
|
||||
|
||||
// Opciones de audio
|
||||
else if (var == "audio.music.enabled")
|
||||
{
|
||||
options->audio.music.enabled = stringToBool(value);
|
||||
}
|
||||
|
||||
else if (var == "audio.music.volume")
|
||||
{
|
||||
options->audio.music.volume = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "audio.sound.enabled")
|
||||
{
|
||||
options->audio.sound.enabled = stringToBool(value);
|
||||
}
|
||||
|
||||
else if (var == "audio.sound.volume")
|
||||
{
|
||||
options->audio.sound.volume = std::stoi(value);
|
||||
}
|
||||
|
||||
// Opciones de juego
|
||||
else if (var == "game.language")
|
||||
{
|
||||
options->game.language = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "game.difficulty")
|
||||
{
|
||||
options->game.difficulty = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "game.autofire")
|
||||
{
|
||||
options->game.autofire = stringToBool(value);
|
||||
}
|
||||
|
||||
// Opciones de mandos
|
||||
else if (var == "controller1.name")
|
||||
{
|
||||
options->controller[0].name = value;
|
||||
}
|
||||
|
||||
else if (var == "controller1.player")
|
||||
{
|
||||
options->controller[0].playerId = std::max(1, std::min(2, std::stoi(value)));
|
||||
}
|
||||
|
||||
else if (var == "controller1.button.fire_left")
|
||||
{
|
||||
options->controller[0].buttons[0] = (SDL_GameControllerButton)std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "controller1.button.fire_center")
|
||||
{
|
||||
options->controller[0].buttons[1] = (SDL_GameControllerButton)std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "controller1.button.fire_right")
|
||||
{
|
||||
options->controller[0].buttons[2] = (SDL_GameControllerButton)std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "controller1.button.start")
|
||||
{
|
||||
options->controller[0].buttons[3] = (SDL_GameControllerButton)std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "controller1.button.service")
|
||||
{
|
||||
options->controller[0].buttons[4] = (SDL_GameControllerButton)std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "controller2.name")
|
||||
{
|
||||
options->controller[1].name = value;
|
||||
}
|
||||
|
||||
else if (var == "controller2.player")
|
||||
{
|
||||
options->controller[1].playerId = std::max(1, std::min(2, std::stoi(value)));
|
||||
}
|
||||
|
||||
else if (var == "controller2.button.fire_left")
|
||||
{
|
||||
options->controller[1].buttons[0] = (SDL_GameControllerButton)std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "controller2.button.fire_center")
|
||||
{
|
||||
options->controller[1].buttons[1] = (SDL_GameControllerButton)std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "controller2.button.fire_right")
|
||||
{
|
||||
options->controller[1].buttons[2] = (SDL_GameControllerButton)std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "controller2.button.start")
|
||||
{
|
||||
options->controller[1].buttons[3] = (SDL_GameControllerButton)std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "controller2.button.service")
|
||||
{
|
||||
options->controller[1].buttons[4] = (SDL_GameControllerButton)std::stoi(value);
|
||||
}
|
||||
|
||||
// Lineas vacias o que empiezan por comentario
|
||||
else if (var == "" || var.substr(0, 1) == "#")
|
||||
{
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
success = false;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
// Obtiene una fichero a partir de un lang_e
|
||||
std::string Director::getLangFile(lang::lang_e lang)
|
||||
{
|
||||
|
||||
@@ -41,7 +41,6 @@ private:
|
||||
section_t *section; // Sección y subsección actual del programa;
|
||||
|
||||
// Variables
|
||||
options_t *options; // Opciones del programa
|
||||
std::string executablePath; // Path del ejecutable
|
||||
std::string systemFolder; // Carpeta del sistema donde guardar datos
|
||||
std::string paramFileArgument; // Argumento para gestionar el fichero con los parametros del programa
|
||||
@@ -60,21 +59,9 @@ private:
|
||||
// Carga los parametros para configurar el juego
|
||||
void loadParams(std::string filepath);
|
||||
|
||||
// Inicializa las opciones del programa
|
||||
void initOptions();
|
||||
|
||||
// Asigna variables a partir de dos cadenas
|
||||
bool setOptions(options_t *options, std::string var, std::string value);
|
||||
|
||||
// Crea el indice de ficheros
|
||||
bool setFileList();
|
||||
|
||||
// Carga el fichero de configuración
|
||||
bool loadConfigFile();
|
||||
|
||||
// Guarda el fichero de configuración
|
||||
bool saveConfigFile();
|
||||
|
||||
// Carga los sonidos del juego
|
||||
void loadSounds();
|
||||
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
#include "game.h"
|
||||
#include "param.h"
|
||||
#include "options.h"
|
||||
|
||||
#define GAME_OVER_COUNTER 350
|
||||
|
||||
// Constructor
|
||||
Game::Game(int playerID, int currentStage, bool demo, Screen *screen, Asset *asset, Input *input, options_t *options, section_t *section, JA_Music_t *music)
|
||||
Game::Game(int playerID, int currentStage, bool demo, Screen *screen, Asset *asset, Input *input, section_t *section, JA_Music_t *music)
|
||||
{
|
||||
// Copia los punteros
|
||||
this->screen = screen;
|
||||
this->asset = asset;
|
||||
this->input = input;
|
||||
this->options = options;
|
||||
this->section = section;
|
||||
this->music = music;
|
||||
renderer = screen->getRenderer();
|
||||
@@ -19,12 +19,12 @@ Game::Game(int playerID, int currentStage, bool demo, Screen *screen, Asset *ass
|
||||
this->demo.enabled = demo;
|
||||
this->currentStage = currentStage;
|
||||
lastStageReached = currentStage;
|
||||
difficulty = options->game.difficulty;
|
||||
difficulty = options.game.difficulty;
|
||||
|
||||
// Crea los objetos
|
||||
fade = new Fade(renderer);
|
||||
eventHandler = new SDL_Event();
|
||||
scoreboard = new Scoreboard(renderer, asset, options);
|
||||
scoreboard = new Scoreboard(renderer, asset);
|
||||
background = new Background(renderer, asset);
|
||||
explosions = new Explosions();
|
||||
enemyFormations = new EnemyFormations();
|
||||
@@ -62,7 +62,7 @@ Game::Game(int playerID, int currentStage, bool demo, Screen *screen, Asset *ass
|
||||
Game::~Game()
|
||||
{
|
||||
// Guarda las puntuaciones en un fichero
|
||||
ManageHiScoreTable *manager = new ManageHiScoreTable(&options->game.hiScoreTable);
|
||||
ManageHiScoreTable *manager = new ManageHiScoreTable(&options.game.hiScoreTable);
|
||||
manager->saveToFile(asset->get("score.bin"));
|
||||
delete manager;
|
||||
#ifdef RECORDING
|
||||
@@ -171,8 +171,8 @@ void Game::init(int playerID)
|
||||
scoreboard->setMode(SCOREBOARD_CENTER_PANEL, SCOREBOARD_MODE_STAGE_INFO);
|
||||
|
||||
// Resto de variables
|
||||
hiScore.score = options->game.hiScoreTable[0].score;
|
||||
hiScore.name = options->game.hiScoreTable[0].name;
|
||||
hiScore.score = options.game.hiScoreTable[0].score;
|
||||
hiScore.name = options.game.hiScoreTable[0].name;
|
||||
paused = false;
|
||||
gameCompleted = false;
|
||||
gameCompletedCounter = 0;
|
||||
@@ -328,7 +328,7 @@ void Game::init(int playerID)
|
||||
// Carga los recursos necesarios para la sección 'Game'
|
||||
void Game::loadMedia()
|
||||
{
|
||||
if (options->console)
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << std::endl
|
||||
<< "** LOADING RESOURCES FOR GAME SECTION" << std::endl;
|
||||
@@ -521,7 +521,7 @@ void Game::loadMedia()
|
||||
stageChangeSound = JA_LoadSound(asset->get("stage_change.wav").c_str());
|
||||
coffeeMachineSound = JA_LoadSound(asset->get("title.wav").c_str());
|
||||
|
||||
if (options->console)
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "** RESOURCES FOR GAME SECTION LOADED" << std::endl
|
||||
<< std::endl;
|
||||
@@ -652,7 +652,7 @@ bool Game::loadDemoFile(std::string f, demoKeys_t (*dataFile)[TOTAL_DEMO_DATA])
|
||||
// El fichero no existe
|
||||
if (file == nullptr)
|
||||
{
|
||||
if (options->console)
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "Warning: Unable to open " << filename.c_str() << " file" << std::endl;
|
||||
}
|
||||
@@ -663,7 +663,7 @@ bool Game::loadDemoFile(std::string f, demoKeys_t (*dataFile)[TOTAL_DEMO_DATA])
|
||||
// Si no existe el fichero
|
||||
if (file != nullptr)
|
||||
{
|
||||
if (options->console)
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "New file (" << filename.c_str() << ") created!" << std::endl;
|
||||
}
|
||||
@@ -687,7 +687,7 @@ bool Game::loadDemoFile(std::string f, demoKeys_t (*dataFile)[TOTAL_DEMO_DATA])
|
||||
}
|
||||
else
|
||||
{ // Si no puede crear el fichero
|
||||
if (options->console)
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "Error: Unable to create file " << filename.c_str() << std::endl;
|
||||
}
|
||||
@@ -698,7 +698,7 @@ bool Game::loadDemoFile(std::string f, demoKeys_t (*dataFile)[TOTAL_DEMO_DATA])
|
||||
else
|
||||
{
|
||||
// Mensaje de proceder a la carga de los datos
|
||||
if (options->console)
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "Reading file: " << filename.c_str() << std::endl;
|
||||
}
|
||||
@@ -735,7 +735,7 @@ bool Game::saveDemoFile()
|
||||
SDL_RWwrite(file, &demo.dataFile[0][i], sizeof(demoKeys_t), 1);
|
||||
}
|
||||
|
||||
if (options->console)
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "Writing file " << filename.c_str() << std::endl;
|
||||
}
|
||||
@@ -745,7 +745,7 @@ bool Game::saveDemoFile()
|
||||
}
|
||||
else
|
||||
{
|
||||
if (options->console)
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "Error: Unable to save " << filename.c_str() << " file! " << SDL_GetError() << std::endl;
|
||||
}
|
||||
@@ -2063,10 +2063,10 @@ void Game::checkInput()
|
||||
// Comprueba si se va a activar o desactivar el audio
|
||||
if (input->checkModInput(input_service, input_mute, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
{
|
||||
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));
|
||||
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));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2159,11 +2159,11 @@ void Game::checkInput()
|
||||
for (auto player : players)
|
||||
{
|
||||
const int controllerIndex = player->getController();
|
||||
const bool autofire = player->isPowerUp() || options->game.autofire;
|
||||
const bool autofire = player->isPowerUp() || options.game.autofire;
|
||||
if (player->isPlaying())
|
||||
{
|
||||
// Input a la izquierda
|
||||
if (input->checkInput(input_left, INPUT_ALLOW_REPEAT, options->controller[controllerIndex].deviceType, options->controller[controllerIndex].index))
|
||||
if (input->checkInput(input_left, INPUT_ALLOW_REPEAT, options.controller[controllerIndex].deviceType, options.controller[controllerIndex].index))
|
||||
{
|
||||
player->setInput(input_left);
|
||||
#ifdef RECORDING
|
||||
@@ -2173,7 +2173,7 @@ void Game::checkInput()
|
||||
else
|
||||
{
|
||||
// Input a la derecha
|
||||
if (input->checkInput(input_right, INPUT_ALLOW_REPEAT, options->controller[controllerIndex].deviceType, options->controller[controllerIndex].index))
|
||||
if (input->checkInput(input_right, INPUT_ALLOW_REPEAT, options.controller[controllerIndex].deviceType, options.controller[controllerIndex].index))
|
||||
{
|
||||
player->setInput(input_right);
|
||||
#ifdef RECORDING
|
||||
@@ -2190,7 +2190,7 @@ void Game::checkInput()
|
||||
}
|
||||
}
|
||||
// Comprueba el input de disparar al centro
|
||||
if (input->checkInput(input_fire_center, autofire, options->controller[controllerIndex].deviceType, options->controller[controllerIndex].index))
|
||||
if (input->checkInput(input_fire_center, autofire, options.controller[controllerIndex].deviceType, options.controller[controllerIndex].index))
|
||||
{
|
||||
if (player->canFire())
|
||||
{
|
||||
@@ -2207,7 +2207,7 @@ void Game::checkInput()
|
||||
}
|
||||
|
||||
// Comprueba el input de disparar a la izquierda
|
||||
else if (input->checkInput(input_fire_left, autofire, options->controller[controllerIndex].deviceType, options->controller[controllerIndex].index))
|
||||
else if (input->checkInput(input_fire_left, autofire, options.controller[controllerIndex].deviceType, options.controller[controllerIndex].index))
|
||||
{
|
||||
if (player->canFire())
|
||||
{
|
||||
@@ -2224,7 +2224,7 @@ void Game::checkInput()
|
||||
}
|
||||
|
||||
// Comprueba el input de disparar a la derecha
|
||||
else if (input->checkInput(input_fire_right, autofire, options->controller[controllerIndex].deviceType, options->controller[controllerIndex].index))
|
||||
else if (input->checkInput(input_fire_right, autofire, options.controller[controllerIndex].deviceType, options.controller[controllerIndex].index))
|
||||
{
|
||||
if (player->canFire())
|
||||
{
|
||||
@@ -2252,7 +2252,7 @@ void Game::checkInput()
|
||||
else
|
||||
{
|
||||
// Si no está jugando, el botón de start le permite continuar jugando
|
||||
if (input->checkInput(input_start, INPUT_ALLOW_REPEAT, options->controller[controllerIndex].deviceType, options->controller[controllerIndex].index))
|
||||
if (input->checkInput(input_start, INPUT_ALLOW_REPEAT, options.controller[controllerIndex].deviceType, options.controller[controllerIndex].index))
|
||||
{
|
||||
// Si no ha entrado ya en el estado de game over, entonces se puede continuar
|
||||
if (gameOverCounter == GAME_OVER_COUNTER)
|
||||
@@ -2262,9 +2262,9 @@ void Game::checkInput()
|
||||
}
|
||||
|
||||
// Si está continuando, los botones de fuego hacen decrementar el contador
|
||||
const bool fire1 = input->checkInput(input_fire_left, false, options->controller[controllerIndex].deviceType, options->controller[controllerIndex].index);
|
||||
const bool fire2 = input->checkInput(input_fire_center, false, options->controller[controllerIndex].deviceType, options->controller[controllerIndex].index);
|
||||
const bool fire3 = input->checkInput(input_fire_right, false, options->controller[controllerIndex].deviceType, options->controller[controllerIndex].index);
|
||||
const bool fire1 = input->checkInput(input_fire_left, false, options.controller[controllerIndex].deviceType, options.controller[controllerIndex].index);
|
||||
const bool fire2 = input->checkInput(input_fire_center, false, options.controller[controllerIndex].deviceType, options.controller[controllerIndex].index);
|
||||
const bool fire3 = input->checkInput(input_fire_right, false, options.controller[controllerIndex].deviceType, options.controller[controllerIndex].index);
|
||||
if (fire1 || fire2 || fire3)
|
||||
{
|
||||
player->decContinueCounter();
|
||||
@@ -2391,7 +2391,7 @@ void Game::run()
|
||||
// Vuelve a dejar el sonido como estaba
|
||||
if (demo.enabled)
|
||||
{
|
||||
JA_EnableSound(options->audio.sound.enabled);
|
||||
JA_EnableSound(options.audio.sound.enabled);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2648,7 +2648,7 @@ void Game::loadAnimations(std::string filePath, std::vector<std::string> *buffer
|
||||
|
||||
if (file)
|
||||
{
|
||||
if (options->console)
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "Animation loaded: " << filePath.substr(filePath.find_last_of("\\/") + 1).c_str() << std::endl;
|
||||
}
|
||||
@@ -2752,7 +2752,7 @@ void Game::pause(bool value)
|
||||
void Game::addScoreToScoreBoard(std::string name, int score)
|
||||
{
|
||||
const hiScoreEntry_t entry = {name, score};
|
||||
ManageHiScoreTable *manager = new ManageHiScoreTable(&options->game.hiScoreTable);
|
||||
ManageHiScoreTable *manager = new ManageHiScoreTable(&options.game.hiScoreTable);
|
||||
manager->add(entry);
|
||||
delete manager;
|
||||
}
|
||||
@@ -2805,9 +2805,9 @@ Player *Game::getPlayer(int id)
|
||||
// Obtiene un controlador a partir del "id" del jugador
|
||||
int Game::getController(int playerId)
|
||||
{
|
||||
for (int i = 0; i < (int)options->controller.size(); ++i)
|
||||
for (int i = 0; i < (int)options.controller.size(); ++i)
|
||||
{
|
||||
if (options->controller[i].playerId == playerId)
|
||||
if (options.controller[i].playerId == playerId)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
|
||||
@@ -194,7 +194,6 @@ private:
|
||||
int difficulty; // Dificultad del juego
|
||||
float difficultyScoreMultiplier; // Multiplicador de puntos en función de la dificultad
|
||||
color_t difficultyColor; // Color asociado a la dificultad
|
||||
options_t *options; // Opciones del programa
|
||||
int lastStageReached; // Contiene el número de la última pantalla que se ha alcanzado
|
||||
demo_t demo; // Variable con todas las variables relacionadas con el modo demo
|
||||
int totalPowerToCompleteGame; // La suma del poder necesario para completar todas las fases
|
||||
@@ -449,7 +448,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Game(int playerID, int currentStage, bool demo, Screen *screen, Asset *asset, Input *input, options_t *options, section_t *section, JA_Music_t *music);
|
||||
Game(int playerID, int currentStage, bool demo, Screen *screen, Asset *asset, Input *input, section_t *section, JA_Music_t *music);
|
||||
|
||||
// Destructor
|
||||
~Game();
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
#include "hiscore_table.h"
|
||||
#include "param.h"
|
||||
#include "options.h"
|
||||
#include <iostream>
|
||||
|
||||
// Constructor
|
||||
HiScoreTable::HiScoreTable(Screen *screen, Asset *asset, Input *input, options_t *options, section_t *section, JA_Music_t *music)
|
||||
HiScoreTable::HiScoreTable(Screen *screen, Asset *asset, Input *input, section_t *section, JA_Music_t *music)
|
||||
{
|
||||
// Copia punteros
|
||||
this->screen = screen;
|
||||
this->asset = asset;
|
||||
this->input = input;
|
||||
this->section = section;
|
||||
this->options = options;
|
||||
this->music = music;
|
||||
renderer = screen->getRenderer();
|
||||
|
||||
@@ -118,8 +118,8 @@ void HiScoreTable::fillTexture()
|
||||
// Escribe los nombres de la tabla de puntuaciones
|
||||
for (int i = 0; i < maxNames; ++i)
|
||||
{
|
||||
const int nameLenght = options->game.hiScoreTable[i].name.length();
|
||||
const std::string score = format(options->game.hiScoreTable[i].score);
|
||||
const int nameLenght = options.game.hiScoreTable[i].name.length();
|
||||
const std::string score = format(options.game.hiScoreTable[i].score);
|
||||
const int scoreLenght = score.size();
|
||||
const int numDots = 25 - nameLenght - scoreLenght;
|
||||
std::string dots = "";
|
||||
@@ -127,7 +127,7 @@ void HiScoreTable::fillTexture()
|
||||
{
|
||||
dots = dots + ".";
|
||||
}
|
||||
const std::string line = options->game.hiScoreTable[i].name + dots + score;
|
||||
const std::string line = options.game.hiScoreTable[i].name + dots + score;
|
||||
text->writeDX(TXT_CENTER | TXT_SHADOW, param.game.gameArea.centerX, (i * spaceBetweenLines) + firstLine + spaceBetweenHeader, line, 1, orangeColor, 1, shdwTxtColor);
|
||||
}
|
||||
|
||||
@@ -229,10 +229,10 @@ void HiScoreTable::checkInput()
|
||||
// Comprueba si se va a activar o desactivar el audio
|
||||
if (input->checkModInput(input_service, input_mute, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
{
|
||||
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));
|
||||
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));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,6 @@ private:
|
||||
Fade *fade; // Objeto para renderizar fades
|
||||
Text *text; // Objeto para escribir texto
|
||||
JA_Music_t *music; // Musica de fondo
|
||||
options_t *options; // Opciones del programa
|
||||
section_t *section; // Estado del bucle principal para saber si continua o se sale
|
||||
|
||||
// Variables
|
||||
@@ -81,7 +80,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
HiScoreTable(Screen *screen, Asset *asset, Input *input, options_t *options, section_t *section, JA_Music_t *music);
|
||||
HiScoreTable(Screen *screen, Asset *asset, Input *input, section_t *section, JA_Music_t *music);
|
||||
|
||||
// Destructor
|
||||
~HiScoreTable();
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
#include "instructions.h"
|
||||
#include "param.h"
|
||||
#include "options.h"
|
||||
#include <iostream>
|
||||
|
||||
// Constructor
|
||||
Instructions::Instructions(Screen *screen, Asset *asset, Input *input, options_t *options, section_t *section, JA_Music_t *music)
|
||||
Instructions::Instructions(Screen *screen, Asset *asset, Input *input, section_t *section, JA_Music_t *music)
|
||||
{
|
||||
// Copia los punteros
|
||||
this->screen = screen;
|
||||
@@ -11,7 +12,6 @@ Instructions::Instructions(Screen *screen, Asset *asset, Input *input, options_t
|
||||
this->input = input;
|
||||
this->section = section;
|
||||
this->music = music;
|
||||
this->options = options;
|
||||
renderer = screen->getRenderer();
|
||||
|
||||
// Crea objetos
|
||||
@@ -359,10 +359,10 @@ void Instructions::checkInput()
|
||||
// Comprueba si se va a activar o desactivar el audio
|
||||
if (input->checkModInput(input_service, input_mute, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
{
|
||||
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));
|
||||
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));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,6 @@ private:
|
||||
Fade *fade; // Objeto para renderizar fades
|
||||
JA_Music_t *music; // Musica de fondo
|
||||
section_t *section; // Estado del bucle principal para saber si continua o se sale
|
||||
options_t *options; // Opciones del programa
|
||||
|
||||
// Variables
|
||||
int counter; // Contador
|
||||
@@ -88,7 +87,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Instructions(Screen *screen, Asset *asset, Input *input, options_t *options, section_t *section, JA_Music_t *music);
|
||||
Instructions(Screen *screen, Asset *asset, Input *input, section_t *section, JA_Music_t *music);
|
||||
|
||||
// Destructor
|
||||
~Instructions();
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#include "intro.h"
|
||||
#include "param.h"
|
||||
#include "options.h"
|
||||
|
||||
// Constructor
|
||||
Intro::Intro(Screen *screen, Asset *asset, Input *input, options_t *options, section_t *section, JA_Music_t *music)
|
||||
Intro::Intro(Screen *screen, Asset *asset, Input *input, section_t *section, JA_Music_t *music)
|
||||
{
|
||||
// Copia los punteros
|
||||
this->screen = screen;
|
||||
@@ -228,10 +229,10 @@ void Intro::checkInput()
|
||||
// Comprueba si se va a activar o desactivar el audio
|
||||
if (input->checkModInput(input_service, input_mute, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
{
|
||||
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));
|
||||
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));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ private:
|
||||
std::vector<Writer *> texts; // Textos de la intro
|
||||
Text *text; // Textos de la intro
|
||||
section_t *section; // Estado del bucle principal para saber si continua o se sale
|
||||
options_t *options; // Opciones del programa
|
||||
|
||||
// Variables
|
||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||
@@ -62,7 +61,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Intro(Screen *screen, Asset *asset, Input *input, options_t *options, section_t *section, JA_Music_t *music);
|
||||
Intro(Screen *screen, Asset *asset, Input *input, section_t *section, JA_Music_t *music);
|
||||
|
||||
// Destructor
|
||||
~Intro();
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
#include "logo.h"
|
||||
#include "param.h"
|
||||
#include "options.h"
|
||||
#include <iostream>
|
||||
|
||||
// Constructor
|
||||
Logo::Logo(Screen *screen, Asset *asset, Input *input, options_t *options, section_t *section)
|
||||
Logo::Logo(Screen *screen, Asset *asset, Input *input, section_t *section)
|
||||
{
|
||||
// Copia la dirección de los objetos
|
||||
this->screen = screen;
|
||||
this->asset = asset;
|
||||
this->input = input;
|
||||
this->options = options;
|
||||
this->section = section;
|
||||
SDL_Renderer *renderer = screen->getRenderer();
|
||||
|
||||
@@ -148,10 +148,10 @@ void Logo::checkInput()
|
||||
// Comprueba si se va a activar o desactivar el audio
|
||||
if (input->checkModInput(input_service, input_mute, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
{
|
||||
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));
|
||||
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));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ private:
|
||||
std::vector<Sprite *> jailSprite; // Vector con los sprites de cada linea que forman el bitmap JAILGAMES
|
||||
Sprite *sinceSprite; // Sprite para manejar la sinceTexture
|
||||
section_t *section; // Estado del bucle principal para saber si continua o se sale
|
||||
options_t *options; // Opciones del programa
|
||||
|
||||
// Variables
|
||||
std::vector<color_t> color; // Vector con los colores para el fade
|
||||
@@ -73,7 +72,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Logo(Screen *screen, Asset *asset, Input *input, options_t *options, section_t *section);
|
||||
Logo(Screen *screen, Asset *asset, Input *input, section_t *section);
|
||||
|
||||
// Destructor
|
||||
~Logo();
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
#include "notify.h"
|
||||
#include "options.h"
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
|
||||
// Constructor
|
||||
Notify::Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapFile, std::string textFile, std::string soundFile, options_t *options)
|
||||
Notify::Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapFile, std::string textFile, std::string soundFile)
|
||||
{
|
||||
// Inicializa variables
|
||||
this->renderer = renderer;
|
||||
this->options = options;
|
||||
bgColor = options->notification.color;
|
||||
bgColor = options.notification.color;
|
||||
waitTime = 150;
|
||||
stack = false;
|
||||
|
||||
@@ -64,7 +64,7 @@ void Notify::update()
|
||||
// Hace sonar la notificación en el primer frame
|
||||
if (notifications[i].counter == 1)
|
||||
{
|
||||
if (options->notification.sound)
|
||||
if (options.notification.sound)
|
||||
{
|
||||
if (notifications[i].state == ns_rising)
|
||||
{ // Reproduce el sonido de la notificación
|
||||
@@ -79,7 +79,7 @@ void Notify::update()
|
||||
const float step = ((float)notifications[i].counter / notifications[i].travelDist);
|
||||
const int alpha = 255 * step;
|
||||
|
||||
if (options->notification.posV == pos_top)
|
||||
if (options.notification.posV == pos_top)
|
||||
{
|
||||
notifications[i].rect.y++;
|
||||
}
|
||||
@@ -111,7 +111,7 @@ void Notify::update()
|
||||
const float step = (notifications[i].counter / (float)notifications[i].travelDist);
|
||||
const int alpha = 255 * (1 - step);
|
||||
|
||||
if (options->notification.posV == pos_top)
|
||||
if (options.notification.posV == pos_top)
|
||||
{
|
||||
notifications[i].rect.y--;
|
||||
}
|
||||
@@ -187,35 +187,35 @@ void Notify::showText(std::string text1, std::string text2, int icon)
|
||||
|
||||
// Posición horizontal
|
||||
int despH = 0;
|
||||
if (options->notification.posH == pos_left)
|
||||
if (options.notification.posH == pos_left)
|
||||
{
|
||||
despH = paddingOut;
|
||||
}
|
||||
else if (options->notification.posH == pos_middle)
|
||||
else if (options.notification.posH == pos_middle)
|
||||
{
|
||||
despH = ((options->video.gameWidth / 2) - (width / 2));
|
||||
despH = ((options.video.gameWidth / 2) - (width / 2));
|
||||
}
|
||||
else
|
||||
{
|
||||
despH = options->video.gameWidth - width - paddingOut;
|
||||
despH = options.video.gameWidth - width - paddingOut;
|
||||
}
|
||||
|
||||
// Posición vertical
|
||||
int despV = 0;
|
||||
if (options->notification.posV == pos_top)
|
||||
if (options.notification.posV == pos_top)
|
||||
{
|
||||
despV = paddingOut;
|
||||
}
|
||||
else
|
||||
{
|
||||
despV = options->video.gameHeight - height - paddingOut;
|
||||
despV = options.video.gameHeight - height - paddingOut;
|
||||
}
|
||||
|
||||
const int travelDist = height + paddingOut;
|
||||
|
||||
// Offset
|
||||
int offset = 0;
|
||||
if (options->notification.posV == pos_top)
|
||||
if (options.notification.posV == pos_top)
|
||||
{
|
||||
offset = (int)notifications.size() > 0 ? notifications.back().y + travelDist : despV;
|
||||
}
|
||||
@@ -235,7 +235,7 @@ void Notify::showText(std::string text1, std::string text2, int icon)
|
||||
n.text1 = text1;
|
||||
n.text2 = text2;
|
||||
n.shape = shape;
|
||||
if (options->notification.posV == pos_top)
|
||||
if (options.notification.posV == pos_top)
|
||||
{
|
||||
n.rect = {despH, offset - travelDist, width, height};
|
||||
}
|
||||
|
||||
@@ -60,7 +60,6 @@ private:
|
||||
Texture *textTexture; // Textura para la fuente de las notificaciones
|
||||
Texture *iconTexture; // Textura para los iconos de las notificaciones
|
||||
Text *text; // Objeto para dibujar texto
|
||||
options_t *options; // Opciones del programa
|
||||
|
||||
// Variables
|
||||
color_t bgColor; // Color de fondo de las notificaciones
|
||||
@@ -77,7 +76,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapFile, std::string textFile, std::string soundFile, options_t *options);
|
||||
Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapFile, std::string textFile, std::string soundFile);
|
||||
|
||||
// Destructor
|
||||
~Notify();
|
||||
|
||||
478
source/options.cpp
Normal file
478
source/options.cpp
Normal file
@@ -0,0 +1,478 @@
|
||||
#include "options.h"
|
||||
#include "screen.h"
|
||||
#include "lang.h"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
// Variables
|
||||
options_t options;
|
||||
|
||||
// Declaraciones
|
||||
bool setOptions(std::string var, std::string value);
|
||||
|
||||
// Inicializa las opciones del programa
|
||||
void initOptions()
|
||||
{
|
||||
// Opciones varias
|
||||
#ifdef VERBOSE
|
||||
options.console = true;
|
||||
#else
|
||||
options.console = false;
|
||||
#endif
|
||||
|
||||
// Opciones de video
|
||||
#ifdef ANBERNIC
|
||||
options.video.mode = 0;
|
||||
options.video.window.size = 3;
|
||||
#else
|
||||
options.video.mode = 0;
|
||||
options.video.window.size = 2;
|
||||
#endif
|
||||
options.video.filter = SCREEN_FILTER_NEAREST;
|
||||
options.video.vSync = true;
|
||||
options.video.integerScale = true;
|
||||
options.video.keepAspect = true;
|
||||
options.video.shaders = true;
|
||||
|
||||
// Opciones de las notificaciones
|
||||
options.notification.posV = pos_top;
|
||||
options.notification.posH = pos_left;
|
||||
options.notification.sound = false;
|
||||
options.notification.color = {48, 48, 48};
|
||||
|
||||
// Opciones de audio
|
||||
options.audio.music.enabled = true;
|
||||
options.audio.music.volume = 128;
|
||||
options.audio.sound.enabled = true;
|
||||
options.audio.sound.volume = 64;
|
||||
|
||||
// Opciones de juego
|
||||
options.game.difficulty = DIFFICULTY_NORMAL;
|
||||
options.game.language = lang::ba_BA;
|
||||
options.game.autofire = true;
|
||||
|
||||
// Opciones de control
|
||||
options.controller.clear();
|
||||
op_controller_t c;
|
||||
|
||||
const int numPlayers = 2;
|
||||
for (int index = 0; index < numPlayers; ++index)
|
||||
{
|
||||
c.index = index;
|
||||
c.playerId = index + 1;
|
||||
c.deviceType = INPUT_USE_GAMECONTROLLER;
|
||||
c.name = "NO NAME";
|
||||
|
||||
// Inputs que se guardan en las opciones y, por tanto, a disco
|
||||
c.inputs.clear();
|
||||
c.inputs.push_back(input_fire_left);
|
||||
c.inputs.push_back(input_fire_center);
|
||||
c.inputs.push_back(input_fire_right);
|
||||
c.inputs.push_back(input_start);
|
||||
c.inputs.push_back(input_service);
|
||||
|
||||
// Botones asociados a los inputs anteriores
|
||||
c.buttons.clear();
|
||||
c.buttons.push_back(SDL_CONTROLLER_BUTTON_X);
|
||||
c.buttons.push_back(SDL_CONTROLLER_BUTTON_Y);
|
||||
c.buttons.push_back(SDL_CONTROLLER_BUTTON_B);
|
||||
c.buttons.push_back(SDL_CONTROLLER_BUTTON_START);
|
||||
c.buttons.push_back(SDL_CONTROLLER_BUTTON_BACK);
|
||||
|
||||
options.controller.push_back(c);
|
||||
}
|
||||
options.controller[0].deviceType = INPUT_USE_ANY; // El primer jugador puede usar tanto el teclado como el primer mando
|
||||
}
|
||||
|
||||
// Carga el fichero de configuración
|
||||
bool loadOptionsFile(std::string filePath)
|
||||
{
|
||||
// Inicializa las opciones del programa
|
||||
initOptions();
|
||||
|
||||
// Indicador de éxito en la carga
|
||||
bool success = true;
|
||||
|
||||
// Variables para manejar el fichero
|
||||
std::string line;
|
||||
std::ifstream file(filePath);
|
||||
|
||||
// Si el fichero se puede abrir
|
||||
if (file.good())
|
||||
{
|
||||
// Procesa el fichero linea a linea
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "Reading file: " << filePath << std::endl;
|
||||
}
|
||||
while (std::getline(file, line))
|
||||
{
|
||||
// Comprueba que la linea no sea un comentario
|
||||
if (line.substr(0, 1) != "#")
|
||||
{
|
||||
// Encuentra la posición del caracter '='
|
||||
int pos = line.find("=");
|
||||
// Procesa las dos subcadenas
|
||||
if (!setOptions(line.substr(0, pos), line.substr(pos + 1, line.length())))
|
||||
{
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "Warning: file " << filePath << std::endl;
|
||||
std::cout << "Unknown parameter " << line.substr(0, pos).c_str() << std::endl;
|
||||
}
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cierra el fichero
|
||||
file.close();
|
||||
}
|
||||
|
||||
// El fichero no existe
|
||||
else
|
||||
{ // Crea el fichero con los valores por defecto
|
||||
saveOptionsFile(filePath);
|
||||
}
|
||||
|
||||
// Normaliza los valores
|
||||
const bool a = options.video.mode == 0;
|
||||
const bool b = options.video.mode == SDL_WINDOW_FULLSCREEN;
|
||||
const bool c = options.video.mode == SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||
if (!(a || b || c))
|
||||
{
|
||||
options.video.mode = SCREEN_VIDEO_MODE_WINDOW;
|
||||
}
|
||||
|
||||
if (options.video.window.size < 1 || options.video.window.size > 4)
|
||||
{
|
||||
options.video.window.size = 3;
|
||||
}
|
||||
|
||||
if (options.game.language < 0 || options.game.language > 2)
|
||||
{
|
||||
options.game.language = lang::en_UK;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
// Guarda el fichero de configuración
|
||||
bool saveOptionsFile(std::string filePath)
|
||||
{
|
||||
const std::string filename = filePath;
|
||||
std::ofstream file(filePath);
|
||||
|
||||
if (!file.good())
|
||||
{
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << filename << " can't be opened" << std::endl;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "Writing file: " << filename << std::endl;
|
||||
}
|
||||
|
||||
// Opciones de video
|
||||
file << "## VIDEO\n";
|
||||
file << "## video.mode [0: window, 1: full screen]\n";
|
||||
file << "## video.filter [0: nearest, 1: lineal]\n";
|
||||
file << "\n";
|
||||
|
||||
if (options.video.mode == SCREEN_VIDEO_MODE_WINDOW)
|
||||
{
|
||||
file << "video.mode=0\n";
|
||||
}
|
||||
|
||||
else if (options.video.mode == SCREEN_VIDEO_MODE_FULLSCREEN)
|
||||
{
|
||||
file << "video.mode=1\n";
|
||||
}
|
||||
|
||||
file << "video.window.size=" + std::to_string(options.video.window.size) + "\n";
|
||||
|
||||
options.video.filter == SCREEN_FILTER_NEAREST ? file << "video.filter=0\n" : file << "video.filter=1\n";
|
||||
|
||||
file << "video.shaders=" + boolToString(options.video.shaders) + "\n";
|
||||
file << "video.vSync=" + boolToString(options.video.vSync) + "\n";
|
||||
file << "video.integerScale=" + boolToString(options.video.integerScale) + "\n";
|
||||
file << "video.keepAspect=" + boolToString(options.video.keepAspect) + "\n";
|
||||
|
||||
// Opciones de notificaciones
|
||||
file << "\n\n## NOTIFICATION\n";
|
||||
file << "## notification.posV [pos_top | pos_bottom]\n";
|
||||
file << "## notification.posH [pos_left | pos_middle | pos_right]\n";
|
||||
file << "\n";
|
||||
|
||||
if (options.notification.posV == pos_top)
|
||||
{
|
||||
file << "notification.posV=pos_top\n";
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
file << "notification.posV=pos_bottom\n";
|
||||
}
|
||||
|
||||
if (options.notification.posH == pos_left)
|
||||
{
|
||||
file << "notification.posH=pos_left\n";
|
||||
}
|
||||
|
||||
else if (options.notification.posH == pos_middle)
|
||||
{
|
||||
file << "notification.posH=pos_middle\n";
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
file << "notification.posH=pos_right\n";
|
||||
}
|
||||
|
||||
file << "notification.sound=" + boolToString(options.notification.sound) + "\n";
|
||||
|
||||
// Opciones de audio
|
||||
file << "\n\n## AUDIO\n";
|
||||
file << "## volume [0 .. 128]\n";
|
||||
file << "\n";
|
||||
|
||||
file << "audio.music.enabled=" + boolToString(options.audio.music.enabled) + "\n";
|
||||
file << "audio.music.volume=" + std::to_string(options.audio.music.volume) + "\n";
|
||||
file << "audio.sound.enabled=" + boolToString(options.audio.sound.enabled) + "\n";
|
||||
file << "audio.sound.volume=" + std::to_string(options.audio.sound.volume) + "\n";
|
||||
|
||||
// Opciones del juego
|
||||
file << "\n\n## GAME\n";
|
||||
file << "## game.language [0: spanish, 1: valencian, 2: english]\n";
|
||||
file << "## game.difficulty [0: easy, 1: normal, 2: hard]\n";
|
||||
file << "\n";
|
||||
|
||||
file << "game.language=" + std::to_string(options.game.language) + "\n";
|
||||
file << "game.difficulty=" + std::to_string(options.game.difficulty) + "\n";
|
||||
file << "game.autofire=" + boolToString(options.game.autofire) + "\n";
|
||||
|
||||
// Opciones de mandos
|
||||
file << "\n\n## CONTROLLERS\n";
|
||||
file << "\n";
|
||||
|
||||
const int numPlayers = 2;
|
||||
for (int index = 0; index < numPlayers; ++index)
|
||||
{
|
||||
const std::string joyIndex = std::to_string(index + 1);
|
||||
file << "controller" + joyIndex + ".name=" + options.controller[index].name + "\n";
|
||||
file << "controller" + joyIndex + ".player=" + std::to_string(options.controller[index].playerId) + "\n";
|
||||
file << "controller" + joyIndex + ".button.fire_left=" + std::to_string((int)options.controller[index].buttons[0]) + "\n";
|
||||
file << "controller" + joyIndex + ".button.fire_center=" + std::to_string((int)options.controller[index].buttons[1]) + "\n";
|
||||
file << "controller" + joyIndex + ".button.fire_right=" + std::to_string((int)options.controller[index].buttons[2]) + "\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";
|
||||
|
||||
if (index < numPlayers - 1)
|
||||
{
|
||||
file << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Cierra el fichero
|
||||
file.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Asigna variables a partir de dos cadenas
|
||||
bool setOptions(std::string var, std::string value)
|
||||
{
|
||||
// Indicador de éxito en la asignación
|
||||
bool success = true;
|
||||
|
||||
// Opciones de video
|
||||
if (var == "video.mode")
|
||||
{
|
||||
options.video.mode = value == std::to_string(SCREEN_VIDEO_MODE_WINDOW) ? SCREEN_VIDEO_MODE_WINDOW : SCREEN_VIDEO_MODE_FULLSCREEN;
|
||||
}
|
||||
|
||||
else if (var == "video.window.size")
|
||||
{
|
||||
options.video.window.size = std::stoi(value);
|
||||
if ((options.video.window.size < 1) || (options.video.window.size > 4))
|
||||
{
|
||||
options.video.window.size = 3;
|
||||
}
|
||||
}
|
||||
|
||||
else if (var == "video.filter")
|
||||
{
|
||||
options.video.filter = value == std::to_string(SCREEN_FILTER_NEAREST) ? SCREEN_FILTER_NEAREST : SCREEN_FILTER_LINEAL;
|
||||
}
|
||||
|
||||
else if (var == "video.shaders")
|
||||
{
|
||||
options.video.shaders = stringToBool(value);
|
||||
}
|
||||
|
||||
else if (var == "video.vSync")
|
||||
{
|
||||
options.video.vSync = stringToBool(value);
|
||||
}
|
||||
|
||||
else if (var == "video.integerScale")
|
||||
{
|
||||
options.video.integerScale = stringToBool(value);
|
||||
}
|
||||
|
||||
else if (var == "video.keepAspect")
|
||||
{
|
||||
options.video.keepAspect = stringToBool(value);
|
||||
}
|
||||
|
||||
// Opciones de notificaciones
|
||||
else if (var == "notification.posH")
|
||||
{
|
||||
if (value == "pos_left")
|
||||
{
|
||||
options.notification.posH = pos_left;
|
||||
}
|
||||
else if (value == "pos_middle")
|
||||
{
|
||||
options.notification.posH = pos_middle;
|
||||
}
|
||||
else
|
||||
{
|
||||
options.notification.posH = pos_right;
|
||||
}
|
||||
}
|
||||
|
||||
else if (var == "notification.posV")
|
||||
{
|
||||
options.notification.posV = value == "pos_top" ? pos_top : pos_bottom;
|
||||
}
|
||||
|
||||
else if (var == "notification.sound")
|
||||
{
|
||||
options.notification.sound = stringToBool(value);
|
||||
}
|
||||
|
||||
// Opciones de audio
|
||||
else if (var == "audio.music.enabled")
|
||||
{
|
||||
options.audio.music.enabled = stringToBool(value);
|
||||
}
|
||||
|
||||
else if (var == "audio.music.volume")
|
||||
{
|
||||
options.audio.music.volume = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "audio.sound.enabled")
|
||||
{
|
||||
options.audio.sound.enabled = stringToBool(value);
|
||||
}
|
||||
|
||||
else if (var == "audio.sound.volume")
|
||||
{
|
||||
options.audio.sound.volume = std::stoi(value);
|
||||
}
|
||||
|
||||
// Opciones de juego
|
||||
else if (var == "game.language")
|
||||
{
|
||||
options.game.language = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "game.difficulty")
|
||||
{
|
||||
options.game.difficulty = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "game.autofire")
|
||||
{
|
||||
options.game.autofire = stringToBool(value);
|
||||
}
|
||||
|
||||
// Opciones de mandos
|
||||
else if (var == "controller1.name")
|
||||
{
|
||||
options.controller[0].name = value;
|
||||
}
|
||||
|
||||
else if (var == "controller1.player")
|
||||
{
|
||||
options.controller[0].playerId = std::max(1, std::min(2, std::stoi(value)));
|
||||
}
|
||||
|
||||
else if (var == "controller1.button.fire_left")
|
||||
{
|
||||
options.controller[0].buttons[0] = (SDL_GameControllerButton)std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "controller1.button.fire_center")
|
||||
{
|
||||
options.controller[0].buttons[1] = (SDL_GameControllerButton)std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "controller1.button.fire_right")
|
||||
{
|
||||
options.controller[0].buttons[2] = (SDL_GameControllerButton)std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "controller1.button.start")
|
||||
{
|
||||
options.controller[0].buttons[3] = (SDL_GameControllerButton)std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "controller1.button.service")
|
||||
{
|
||||
options.controller[0].buttons[4] = (SDL_GameControllerButton)std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "controller2.name")
|
||||
{
|
||||
options.controller[1].name = value;
|
||||
}
|
||||
|
||||
else if (var == "controller2.player")
|
||||
{
|
||||
options.controller[1].playerId = std::max(1, std::min(2, std::stoi(value)));
|
||||
}
|
||||
|
||||
else if (var == "controller2.button.fire_left")
|
||||
{
|
||||
options.controller[1].buttons[0] = (SDL_GameControllerButton)std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "controller2.button.fire_center")
|
||||
{
|
||||
options.controller[1].buttons[1] = (SDL_GameControllerButton)std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "controller2.button.fire_right")
|
||||
{
|
||||
options.controller[1].buttons[2] = (SDL_GameControllerButton)std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "controller2.button.start")
|
||||
{
|
||||
options.controller[1].buttons[3] = (SDL_GameControllerButton)std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "controller2.button.service")
|
||||
{
|
||||
options.controller[1].buttons[4] = (SDL_GameControllerButton)std::stoi(value);
|
||||
}
|
||||
|
||||
// Lineas vacias o que empiezan por comentario
|
||||
else if (var == "" || var.substr(0, 1) == "#")
|
||||
{
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
success = false;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
14
source/options.h
Normal file
14
source/options.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "utils.h"
|
||||
#include "const.h"
|
||||
|
||||
// Variables
|
||||
extern options_t options;
|
||||
|
||||
// Carga el fichero de configuración
|
||||
bool loadOptionsFile(std::string filePath);
|
||||
|
||||
// Guarda el fichero de configuración
|
||||
bool saveOptionsFile(std::string filePath);
|
||||
@@ -5,7 +5,7 @@
|
||||
param_t param;
|
||||
|
||||
// Asigna variables a partir de dos cadenas
|
||||
bool setOptions(std::string var, std::string value);
|
||||
bool setParams(std::string var, std::string value);
|
||||
|
||||
// Calcula variables a partir de otras variables
|
||||
void precalculateZones();
|
||||
@@ -136,7 +136,7 @@ void loadParamsFromFile(std::string filePath)
|
||||
}
|
||||
}
|
||||
|
||||
setOptions(param1, param2);
|
||||
setParams(param1, param2);
|
||||
}
|
||||
|
||||
// Cierra el fichero
|
||||
@@ -151,7 +151,7 @@ void loadParamsFromFile(std::string filePath)
|
||||
}
|
||||
|
||||
// Asigna variables a partir de dos cadenas
|
||||
bool setOptions(std::string var, std::string value)
|
||||
bool setParams(std::string var, std::string value)
|
||||
{
|
||||
// Indicador de éxito en la asignación
|
||||
bool success = true;
|
||||
|
||||
@@ -2,12 +2,11 @@
|
||||
#include <math.h>
|
||||
|
||||
// Constructor
|
||||
Scoreboard::Scoreboard(SDL_Renderer *renderer, Asset *asset, options_t *options)
|
||||
Scoreboard::Scoreboard(SDL_Renderer *renderer, Asset *asset)
|
||||
{
|
||||
// Copia los punteros
|
||||
this->renderer = renderer;
|
||||
this->asset = asset;
|
||||
this->options = options;
|
||||
|
||||
// Inicializa punteros
|
||||
gamePowerMeterTexture = nullptr;
|
||||
|
||||
@@ -49,7 +49,6 @@ private:
|
||||
std::vector<SDL_Texture *> panelTexture; // Texturas para dibujar cada panel;
|
||||
|
||||
// Variables
|
||||
options_t *options; // Opciones del programa
|
||||
int stage; // Número de fase actual
|
||||
std::string name[SCOREBOARD_MAX_PANELS]; // Nom de cada jugador
|
||||
int score[SCOREBOARD_MAX_PANELS]; // Puntuación de los jugadores
|
||||
@@ -93,7 +92,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Scoreboard(SDL_Renderer *renderer, Asset *asset, options_t *options);
|
||||
Scoreboard(SDL_Renderer *renderer, Asset *asset);
|
||||
|
||||
// Destructor
|
||||
~Scoreboard();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "screen.h"
|
||||
#include "options.h"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
@@ -9,19 +10,18 @@
|
||||
#include "dbgtxt.h"
|
||||
|
||||
// Constructor
|
||||
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, Input *input, options_t *options)
|
||||
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, Input *input)
|
||||
{
|
||||
// Copia punteros
|
||||
this->window = window;
|
||||
this->renderer = renderer;
|
||||
this->asset = asset;
|
||||
this->input = input;
|
||||
this->options = options;
|
||||
|
||||
// Inicializa variables
|
||||
SDL_GetRendererOutputSize(renderer, &windowWidth, &windowHeight);
|
||||
gameCanvasWidth = options->video.gameWidth;
|
||||
gameCanvasHeight = options->video.gameHeight;
|
||||
gameCanvasWidth = options.video.gameWidth;
|
||||
gameCanvasHeight = options.video.gameHeight;
|
||||
dest = {0, 0, 0, 0};
|
||||
borderColor = {0, 0, 0};
|
||||
flashEffect.enabled = false;
|
||||
@@ -48,7 +48,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, Input *
|
||||
infoResolution = std::to_string(DM.w) + " X " + std::to_string(DM.h) + " AT " + std::to_string(DM.refresh_rate) + " HZ";
|
||||
|
||||
// Crea los objetos
|
||||
notify = new Notify(renderer, asset->get("notify.png"), asset->get("8bithud.png"), asset->get("8bithud.txt"), asset->get("notify.wav"), options);
|
||||
notify = new Notify(renderer, asset->get("notify.png"), asset->get("8bithud.png"), asset->get("8bithud.txt"), asset->get("notify.wav"));
|
||||
|
||||
// Define el color del borde para el modo de pantalla completa
|
||||
borderColor = {0x00, 0x00, 0x00};
|
||||
@@ -57,7 +57,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, Input *
|
||||
gameCanvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, gameCanvasWidth, gameCanvasHeight);
|
||||
|
||||
// Establece el modo de video
|
||||
setVideoMode(options->video.mode);
|
||||
setVideoMode(options.video.mode);
|
||||
|
||||
// Muestra la ventana
|
||||
SDL_ShowWindow(window);
|
||||
@@ -115,7 +115,7 @@ void Screen::blit()
|
||||
// Muestra por pantalla el renderizador
|
||||
SDL_RenderPresent(renderer);
|
||||
#else
|
||||
if (options->video.shaders)
|
||||
if (options.video.shaders)
|
||||
{
|
||||
shader::render();
|
||||
}
|
||||
@@ -164,7 +164,7 @@ void Screen::setVideoMode(int videoMode)
|
||||
dest = {0, 0, windowWidth, windowHeight};
|
||||
|
||||
// Modifica el tamaño de la ventana
|
||||
SDL_SetWindowSize(window, windowWidth * options->video.window.size, windowHeight * options->video.window.size);
|
||||
SDL_SetWindowSize(window, windowWidth * options.video.window.size, windowHeight * options.video.window.size);
|
||||
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ void Screen::setVideoMode(int videoMode)
|
||||
// SDL_GetWindowSize(window, &windowWidth, &windowHeight);
|
||||
|
||||
// Aplica el escalado al rectangulo donde se pinta la textura del juego
|
||||
if (options->video.integerScale)
|
||||
if (options.video.integerScale)
|
||||
{
|
||||
// Calcula el tamaño de la escala máxima
|
||||
int scale = 0;
|
||||
@@ -209,7 +209,7 @@ void Screen::setVideoMode(int videoMode)
|
||||
dest.x = (windowWidth - dest.w) / 2;
|
||||
dest.y = (windowHeight - dest.h) / 2;
|
||||
}
|
||||
else if (options->video.keepAspect)
|
||||
else if (options.video.keepAspect)
|
||||
{
|
||||
float ratio = (float)gameCanvasWidth / (float)gameCanvasHeight;
|
||||
if ((windowWidth - gameCanvasWidth) >= (windowHeight - gameCanvasHeight))
|
||||
@@ -239,7 +239,7 @@ void Screen::setVideoMode(int videoMode)
|
||||
SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
|
||||
#else
|
||||
// Reinicia los shaders
|
||||
if (options->video.shaders)
|
||||
if (options.video.shaders)
|
||||
{
|
||||
std::ifstream f(asset->get("crtpi.glsl").c_str());
|
||||
std::string source((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
|
||||
@@ -257,9 +257,9 @@ void Screen::setVideoMode(int videoMode)
|
||||
#endif
|
||||
|
||||
// Actualiza las opciones
|
||||
options->video.mode = videoMode;
|
||||
options->video.window.width = windowWidth;
|
||||
options->video.window.height = windowHeight;
|
||||
options.video.mode = videoMode;
|
||||
options.video.window.width = windowWidth;
|
||||
options.video.window.height = windowHeight;
|
||||
|
||||
// Actualiza variables
|
||||
shakeEffect.origin = dest.x;
|
||||
@@ -268,30 +268,30 @@ void Screen::setVideoMode(int videoMode)
|
||||
// Camibia entre pantalla completa y ventana
|
||||
void Screen::switchVideoMode()
|
||||
{
|
||||
options->video.mode = options->video.mode == SCREEN_VIDEO_MODE_WINDOW ? SCREEN_VIDEO_MODE_FULLSCREEN : SCREEN_VIDEO_MODE_WINDOW;
|
||||
setVideoMode(options->video.mode);
|
||||
options.video.mode = options.video.mode == SCREEN_VIDEO_MODE_WINDOW ? SCREEN_VIDEO_MODE_FULLSCREEN : SCREEN_VIDEO_MODE_WINDOW;
|
||||
setVideoMode(options.video.mode);
|
||||
}
|
||||
|
||||
// Cambia el tamaño de la ventana
|
||||
void Screen::setWindowSize(int size)
|
||||
{
|
||||
options->video.window.size = size;
|
||||
options.video.window.size = size;
|
||||
setVideoMode(SCREEN_VIDEO_MODE_WINDOW);
|
||||
}
|
||||
|
||||
// Reduce el tamaño de la ventana
|
||||
void Screen::decWindowSize()
|
||||
{
|
||||
--options->video.window.size;
|
||||
options->video.window.size = std::max(options->video.window.size, 1);
|
||||
--options.video.window.size;
|
||||
options.video.window.size = std::max(options.video.window.size, 1);
|
||||
setVideoMode(SCREEN_VIDEO_MODE_WINDOW);
|
||||
}
|
||||
|
||||
// Aumenta el tamaño de la ventana
|
||||
void Screen::incWindowSize()
|
||||
{
|
||||
++options->video.window.size;
|
||||
options->video.window.size = std::min(options->video.window.size, 4);
|
||||
++options.video.window.size;
|
||||
options.video.window.size = std::min(options.video.window.size, 4);
|
||||
setVideoMode(SCREEN_VIDEO_MODE_WINDOW);
|
||||
}
|
||||
|
||||
@@ -323,7 +323,7 @@ void Screen::checkInput()
|
||||
if (input->checkInput(input_window_fullscreen, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
{
|
||||
switchVideoMode();
|
||||
const std::string mode = options->video.mode == SCREEN_VIDEO_MODE_WINDOW ? "Window" : "Fullscreen";
|
||||
const std::string mode = options.video.mode == SCREEN_VIDEO_MODE_WINDOW ? "Window" : "Fullscreen";
|
||||
showNotification(mode + " mode");
|
||||
return;
|
||||
}
|
||||
@@ -332,7 +332,7 @@ void Screen::checkInput()
|
||||
if (input->checkInput(input_window_dec_size, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
{
|
||||
decWindowSize();
|
||||
const std::string size = std::to_string(options->video.window.size);
|
||||
const std::string size = std::to_string(options.video.window.size);
|
||||
showNotification("Window size x" + size);
|
||||
return;
|
||||
}
|
||||
@@ -341,7 +341,7 @@ void Screen::checkInput()
|
||||
if (input->checkInput(input_window_inc_size, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
|
||||
{
|
||||
incWindowSize();
|
||||
const std::string size = std::to_string(options->video.window.size);
|
||||
const std::string size = std::to_string(options.video.window.size);
|
||||
showNotification("Window size x" + size);
|
||||
return;
|
||||
}
|
||||
@@ -459,9 +459,9 @@ void Screen::doAttenuate()
|
||||
// Activa/desactiva los shaders
|
||||
void Screen::switchShaders()
|
||||
{
|
||||
options->video.shaders = !options->video.shaders;
|
||||
setVideoMode(options->video.mode);
|
||||
const std::string value = options->video.shaders ? "on" : "off";
|
||||
options.video.shaders = !options.video.shaders;
|
||||
setVideoMode(options.video.mode);
|
||||
const std::string value = options.video.shaders ? "on" : "off";
|
||||
showNotification("Shaders " + value);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ private:
|
||||
Input *input; // Objeto para leer las entradas de teclado o mando
|
||||
Notify *notify; // Pinta notificaciones en pantalla
|
||||
SDL_Texture *gameCanvas; // Textura para completar la ventana de juego hasta la pantalla completa
|
||||
options_t *options; // Opciones del programa
|
||||
|
||||
// Variables
|
||||
int windowWidth; // Ancho de la pantalla o ventana
|
||||
@@ -78,7 +77,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, Input *input, options_t *options);
|
||||
Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, Input *input);
|
||||
|
||||
// Destructor
|
||||
~Screen();
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
#include "title.h"
|
||||
#include "param.h"
|
||||
#include "options.h"
|
||||
|
||||
// Constructor
|
||||
Title::Title(Screen *screen, Asset *asset, Input *input, options_t *options, section_t *section, JA_Music_t *music)
|
||||
Title::Title(Screen *screen, Asset *asset, Input *input, section_t *section, JA_Music_t *music)
|
||||
{
|
||||
// Copia las direcciones de los punteros y objetos
|
||||
this->screen = screen;
|
||||
this->input = input;
|
||||
this->asset = asset;
|
||||
this->options = options;
|
||||
this->section = section;
|
||||
this->music = music;
|
||||
SDL_Renderer *renderer = screen->getRenderer();
|
||||
@@ -30,7 +30,7 @@ Title::Title(Screen *screen, Asset *asset, Input *input, options_t *options, sec
|
||||
gameLogo = new GameLogo(renderer, screen, asset, param.game.gameArea.centerX, param.title.titleCCPosition);
|
||||
gameLogo->enable();
|
||||
|
||||
defineButtons = new DefineButtons(input, text2, options, section);
|
||||
defineButtons = new DefineButtons(input, text2, section);
|
||||
|
||||
// Inicializa los valores
|
||||
init();
|
||||
@@ -261,7 +261,7 @@ void Title::checkInput()
|
||||
if (section->options == SECTION_OPTIONS_TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP)
|
||||
{
|
||||
fade->activate();
|
||||
postFade = options->controller[0].playerId;
|
||||
postFade = options.controller[0].playerId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,10 +290,10 @@ void Title::checkInput()
|
||||
// Comprueba si se va a activar o desactivar el audio
|
||||
if (input->checkModInput(input_service, input_mute, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
|
||||
{
|
||||
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));
|
||||
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));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -317,7 +317,7 @@ void Title::checkInput()
|
||||
if (section->options == SECTION_OPTIONS_TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP)
|
||||
{
|
||||
fade->activate();
|
||||
postFade = options->controller[i].playerId;
|
||||
postFade = options.controller[i].playerId;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -379,16 +379,16 @@ void Title::swapControllers()
|
||||
// Obtiene para cada jugador el índice del mando correspondiente
|
||||
for (int i = 0; i < MAX_CONTROLLERS; ++i)
|
||||
{
|
||||
playerControllerIndex[options->controller[i].playerId - 1] = i;
|
||||
playerControllerIndex[options.controller[i].playerId - 1] = i;
|
||||
}
|
||||
|
||||
// Genera el texto correspondiente
|
||||
for (int i = 0; i < MAX_CONTROLLERS; ++i)
|
||||
{
|
||||
const int index = playerControllerIndex[i];
|
||||
if (options->controller[index].name != "NO NAME")
|
||||
if (options.controller[index].name != "NO NAME")
|
||||
{
|
||||
text[i] = "Jugador " + std::to_string(i + 1) + ": " + options->controller[index].name;
|
||||
text[i] = "Jugador " + std::to_string(i + 1) + ": " + options.controller[index].name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,6 @@ private:
|
||||
section_t nextSection; // Indica cual es la siguiente sección a cargar cuando termine el contador del titulo
|
||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||
int postFade; // Opción a realizar cuando termina el fundido
|
||||
options_t *options; // Opciones del programa
|
||||
int numControllers; // Número de mandos conectados
|
||||
|
||||
// Inicializa los valores de las variables
|
||||
@@ -103,7 +102,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Title(Screen *screen, Asset *asset, Input *input, options_t *options, section_t *section, JA_Music_t *music);
|
||||
Title(Screen *screen, Asset *asset, Input *input, section_t *section, JA_Music_t *music);
|
||||
|
||||
// Destructor
|
||||
~Title();
|
||||
|
||||
Reference in New Issue
Block a user