forked from jaildesigner-jailgames/jaildoctors_dilemma
Reestructurant la classe Options
This commit is contained in:
390
source/options.h
390
source/options.h
@@ -4,110 +4,366 @@
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint8, Uint32
|
||||
#include <string> // Para string, basic_string
|
||||
#include "utils.h"
|
||||
#include "screen.h"
|
||||
|
||||
constexpr int DEFAULT_WINDOW_WIDTH = 320; // Ancho de la ventana por defecto
|
||||
constexpr int DEFAULT_WINDOW_HEIGHT = 240; // Alto de la ventana por defecto
|
||||
constexpr int DEFAULT_WINDOW_ZOOM = 2; // Zoom de la ventana por defecto
|
||||
constexpr int DEFAULT_VIDEO_MODE = 0; // Modo de pantalla completa por defecto
|
||||
constexpr int DEFAULT_BORDER_WIDTH = 32; // Ancho del borde por defecto
|
||||
constexpr int DEFAULT_BORDER_HEIGHT = 24; // Alto del borde por defecto
|
||||
constexpr Palette DEFAULT_PALETTE = Palette::ZXSPECTRUM; // Paleta por defecto
|
||||
|
||||
// Secciones del programa
|
||||
constexpr int SECTION_LOGO = 0;
|
||||
constexpr int SECTION_LOADING_SCREEN = 1;
|
||||
constexpr int SECTION_TITLE = 2;
|
||||
constexpr int SECTION_CREDITS = 3;
|
||||
constexpr int SECTION_GAME = 4;
|
||||
constexpr int SECTION_DEMO = 5;
|
||||
constexpr int SECTION_GAME_OVER = 6;
|
||||
constexpr int SECTION_ENDING = 7;
|
||||
constexpr int SECTION_ENDING2 = 8;
|
||||
constexpr int SECTION_QUIT = 9;
|
||||
enum class Section
|
||||
{
|
||||
LOGO,
|
||||
LOADING_SCREEN,
|
||||
TITLE,
|
||||
CREDITS,
|
||||
GAME,
|
||||
DEMO,
|
||||
GAME_OVER,
|
||||
ENDING,
|
||||
ENDING2,
|
||||
QUIT
|
||||
};
|
||||
|
||||
// Subsecciones
|
||||
constexpr int SUBSECTION_LOGO_TO_INTRO = 0;
|
||||
constexpr int SUBSECTION_LOGO_TO_TITLE = 1;
|
||||
constexpr int SUBSECTION_TITLE_WITH_LOADING_SCREEN = 2;
|
||||
constexpr int SUBSECTION_TITLE_WITHOUT_LOADING_SCREEN = 3;
|
||||
enum class Subsection
|
||||
{
|
||||
NONE,
|
||||
LOGO_TO_INTRO,
|
||||
LOGO_TO_TITLE,
|
||||
TITLE_WITH_LOADING_SCREEN,
|
||||
TITLE_WITHOUT_LOADING_SCREEN
|
||||
};
|
||||
|
||||
// Posiciones de las notificaciones
|
||||
enum not_pos_e
|
||||
enum class NotificationPosition
|
||||
{
|
||||
pos_top,
|
||||
pos_bottom,
|
||||
pos_left,
|
||||
pos_middle,
|
||||
pos_right
|
||||
UPPER_LEFT,
|
||||
UPPER_CENTER,
|
||||
UPPER_RIGHT,
|
||||
MIDDLE_LEFT,
|
||||
MIDDLE_RIGHT,
|
||||
BOTTOM_LEFT,
|
||||
BOTTOM_CENTER,
|
||||
BOTTOM_RIGHT
|
||||
};
|
||||
|
||||
// Tipos de control de teclado
|
||||
enum ctrl_schem_e
|
||||
enum class ControlScheme
|
||||
{
|
||||
ctrl_cursor,
|
||||
ctrl_opqa,
|
||||
ctrl_wasd
|
||||
CURSOR,
|
||||
OPQA,
|
||||
WASD
|
||||
};
|
||||
|
||||
// Estructura para las opciones de las notificaciones
|
||||
struct op_notification_t
|
||||
struct OptionsNotification
|
||||
{
|
||||
not_pos_e posH; // Ubicación de las notificaciones en pantalla
|
||||
not_pos_e posV; // Ubicación de las notificaciones en pantalla
|
||||
bool sound; // Indica si las notificaciones suenan
|
||||
color_t color; // Color de las notificaciones
|
||||
NotificationPosition pos; // Ubicación de las notificaciones en pantalla
|
||||
bool sound; // Indica si las notificaciones suenan
|
||||
Color color; // Color de las notificaciones
|
||||
|
||||
// Constructor por defecto
|
||||
OptionsNotification()
|
||||
{
|
||||
pos = NotificationPosition::UPPER_LEFT;
|
||||
sound = true;
|
||||
color = {48, 48, 48};
|
||||
}
|
||||
|
||||
// Constructor
|
||||
OptionsNotification(NotificationPosition p, bool s, Color c)
|
||||
{
|
||||
pos = p;
|
||||
sound = s;
|
||||
color = c;
|
||||
}
|
||||
|
||||
// Método que devuelve la posición horizontal
|
||||
std::string getHorizontalPosition() const
|
||||
{
|
||||
switch (pos)
|
||||
{
|
||||
case NotificationPosition::UPPER_LEFT:
|
||||
case NotificationPosition::MIDDLE_LEFT:
|
||||
case NotificationPosition::BOTTOM_LEFT:
|
||||
return "LEFT";
|
||||
case NotificationPosition::UPPER_CENTER:
|
||||
case NotificationPosition::BOTTOM_CENTER:
|
||||
return "CENTER";
|
||||
case NotificationPosition::UPPER_RIGHT:
|
||||
case NotificationPosition::MIDDLE_RIGHT:
|
||||
case NotificationPosition::BOTTOM_RIGHT:
|
||||
return "RIGHT";
|
||||
}
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
// Método que devuelve la posición vertical
|
||||
std::string getVerticalPosition() const
|
||||
{
|
||||
switch (pos)
|
||||
{
|
||||
case NotificationPosition::UPPER_LEFT:
|
||||
case NotificationPosition::UPPER_CENTER:
|
||||
case NotificationPosition::UPPER_RIGHT:
|
||||
return "UPPER";
|
||||
case NotificationPosition::MIDDLE_LEFT:
|
||||
case NotificationPosition::MIDDLE_RIGHT:
|
||||
return "MIDDLE";
|
||||
case NotificationPosition::BOTTOM_LEFT:
|
||||
case NotificationPosition::BOTTOM_CENTER:
|
||||
case NotificationPosition::BOTTOM_RIGHT:
|
||||
return "BOTTOM";
|
||||
}
|
||||
return "UNKNOWN";
|
||||
}
|
||||
};
|
||||
|
||||
// Estructura para saber la seccion y subseccion del programa
|
||||
struct section_t
|
||||
struct SectionState
|
||||
{
|
||||
Uint8 name;
|
||||
Uint8 subsection;
|
||||
Section section;
|
||||
Subsection subsection;
|
||||
|
||||
// Constructor por defecto
|
||||
SectionState()
|
||||
{
|
||||
section = Section::LOGO;
|
||||
subsection = Subsection::LOGO_TO_INTRO;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
SectionState(Section s, Subsection ss)
|
||||
{
|
||||
section = s;
|
||||
subsection = ss;
|
||||
}
|
||||
};
|
||||
|
||||
// Estructura para albergar trucos
|
||||
struct cheat_t
|
||||
struct Cheat
|
||||
{
|
||||
bool infiniteLives; // Indica si el jugador dispone de vidas infinitas
|
||||
bool invincible; // Indica si el jugador puede morir
|
||||
bool jailEnabled; // Indica si la Jail está abierta
|
||||
bool altSkin; // Indicxa si se usa una skin diferente para el jugador
|
||||
enum class CheatState : bool
|
||||
{
|
||||
DISABLED = false,
|
||||
ENABLED = true
|
||||
};
|
||||
|
||||
CheatState infinite_lives; // Indica si el jugador dispone de vidas infinitas
|
||||
CheatState invincible; // Indica si el jugador puede morir
|
||||
CheatState jail_is_open; // Indica si la Jail está abierta
|
||||
CheatState alternate_skin; // Indica si se usa una skin diferente para el jugador
|
||||
|
||||
// Constructor por defecto
|
||||
Cheat()
|
||||
: infinite_lives(CheatState::DISABLED),
|
||||
invincible(CheatState::DISABLED),
|
||||
jail_is_open(CheatState::DISABLED),
|
||||
alternate_skin(CheatState::DISABLED)
|
||||
{
|
||||
}
|
||||
|
||||
// Constructor
|
||||
Cheat(CheatState il, CheatState i, CheatState je, CheatState as)
|
||||
: infinite_lives(il),
|
||||
invincible(i),
|
||||
jail_is_open(je),
|
||||
alternate_skin(as)
|
||||
{
|
||||
}
|
||||
|
||||
// Método para comprobar si alguno de los tres primeros trucos está activo
|
||||
bool enabled() const
|
||||
{
|
||||
return infinite_lives == CheatState::ENABLED ||
|
||||
invincible == CheatState::ENABLED ||
|
||||
jail_is_open == CheatState::ENABLED;
|
||||
}
|
||||
};
|
||||
|
||||
// Estructura para almacenar estadísticas
|
||||
struct op_stats_t
|
||||
struct OptionsStats
|
||||
{
|
||||
int rooms; // Cantidad de habitaciones visitadas
|
||||
int items; // Cantidad de items obtenidos
|
||||
std::string worstNightmare; // Habitación con más muertes acumuladas
|
||||
int rooms; // Cantidad de habitaciones visitadas
|
||||
int items; // Cantidad de items obtenidos
|
||||
std::string worst_nightmare; // Habitación con más muertes acumuladas
|
||||
|
||||
// Constructor por defecto
|
||||
OptionsStats()
|
||||
{
|
||||
rooms = 0;
|
||||
items = 0;
|
||||
worst_nightmare = "";
|
||||
}
|
||||
|
||||
// Constructor
|
||||
OptionsStats(int r, int i, std::string wn)
|
||||
{
|
||||
rooms = r;
|
||||
items = i;
|
||||
worst_nightmare = wn;
|
||||
}
|
||||
};
|
||||
|
||||
// Estructura con opciones de la pantalla
|
||||
struct op_screen_t
|
||||
struct OptionsWindows
|
||||
{
|
||||
int windowWidth; // Ancho de la ventana
|
||||
int windowHeight; // Alto de la ventana
|
||||
int width; // Ancho de la ventana
|
||||
int height; // Alto de la ventana
|
||||
int zoom; // Zoom de la ventana
|
||||
|
||||
// Constructor por defecto
|
||||
OptionsWindows()
|
||||
{
|
||||
width = DEFAULT_WINDOW_WIDTH;
|
||||
height = DEFAULT_WINDOW_HEIGHT;
|
||||
zoom = DEFAULT_WINDOW_ZOOM;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
OptionsWindows(int w, int h, int z)
|
||||
{
|
||||
width = w;
|
||||
height = h;
|
||||
zoom = z;
|
||||
}
|
||||
};
|
||||
|
||||
// Estructura para gestionar el borde de la pantalla
|
||||
struct Border
|
||||
{
|
||||
bool enabled; // Indica si se ha de mostrar el borde
|
||||
int width; // Ancho del borde
|
||||
int height; // Alto del borde
|
||||
|
||||
// Constructor por defecto
|
||||
Border()
|
||||
{
|
||||
enabled = true;
|
||||
width = DEFAULT_BORDER_WIDTH;
|
||||
height = DEFAULT_BORDER_HEIGHT;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
Border(bool e, int w, int h)
|
||||
{
|
||||
enabled = e;
|
||||
width = w;
|
||||
height = h;
|
||||
}
|
||||
};
|
||||
|
||||
// Estructura para las opciones de video
|
||||
struct OptionsVideo
|
||||
{
|
||||
Uint32 mode; // Contiene el valor del modo de pantalla completa
|
||||
ScreenFilter filter; // Filtro usado para el escalado de la imagen
|
||||
bool vertical_sync; // Indica si se quiere usar vsync o no
|
||||
bool shaders; // Indica si se van a usar shaders o no
|
||||
bool integer_scale; // Indica si el escalado de la imagen ha de ser entero en el modo a pantalla completa
|
||||
bool keep_aspect; // Indica si se ha de mantener la relación de aspecto al poner el modo a pantalla completa
|
||||
Border border; // Borde de la pantalla
|
||||
Palette palette; // Paleta de colores a usar en el juego
|
||||
|
||||
// Constructor por defecto
|
||||
OptionsVideo()
|
||||
{
|
||||
mode = DEFAULT_VIDEO_MODE;
|
||||
filter = ScreenFilter::NEAREST;
|
||||
vertical_sync = true;
|
||||
shaders = false;
|
||||
integer_scale = true;
|
||||
keep_aspect = true;
|
||||
border = Border();
|
||||
palette = DEFAULT_PALETTE;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
OptionsVideo(Uint32 m, ScreenFilter f, bool vs, bool s, bool is, bool ka, Border b, Palette p)
|
||||
{
|
||||
mode = m;
|
||||
filter = f;
|
||||
vertical_sync = vs;
|
||||
shaders = s;
|
||||
integer_scale = is;
|
||||
keep_aspect = ka;
|
||||
border = b;
|
||||
palette = p;
|
||||
}
|
||||
};
|
||||
|
||||
// Estructura para las opciones de juego
|
||||
struct OptionsGame
|
||||
{
|
||||
int width; // Ancho de la resolucion nativa del juego
|
||||
int height; // Alto de la resolucion nativa del juego
|
||||
|
||||
// Constructor por defecto
|
||||
OptionsGame()
|
||||
{
|
||||
width = 320;
|
||||
height = 240;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
OptionsGame(int w, int h)
|
||||
{
|
||||
width = w;
|
||||
height = h;
|
||||
}
|
||||
};
|
||||
|
||||
// Estructura con todas las opciones de configuración del programa
|
||||
struct options_t
|
||||
struct Options
|
||||
{
|
||||
std::string configVersion; // Versión del programa. Sirve para saber si las opciones son compatibles
|
||||
Uint32 videoMode; // Contiene el valor del modo de pantalla completa
|
||||
int windowSize; // Contiene el valor por el que se multiplica el tamaño de la ventana
|
||||
Uint32 filter; // Filtro usado para el escalado de la imagen
|
||||
bool vSync; // Indica si se quiere usar vsync o no
|
||||
bool shaders; // Indica si se van a usar shaders o no
|
||||
int gameWidth; // Ancho de la resolucion nativa del juego
|
||||
int gameHeight; // Alto de la resolucion nativa del juego
|
||||
bool integerScale; // Indica si el escalado de la imagen ha de ser entero en el modo a pantalla completa
|
||||
bool keepAspect; // Indica si se ha de mantener la relación de aspecto al poner el modo a pantalla completa
|
||||
bool borderEnabled; // Indica si ha de mostrar el borde en el modo de ventana
|
||||
int borderWidth; // Cantidad de pixels que se añade en el borde de la ventana
|
||||
int borderHeight; // Cantidad de pixels que se añade en el borde de la ventana
|
||||
palette_e palette; // Paleta de colores a usar en el juego
|
||||
bool console; // Indica si ha de mostrar información por la consola de texto
|
||||
cheat_t cheat; // Contiene trucos y ventajas para el juego
|
||||
op_stats_t stats; // Datos con las estadisticas de juego
|
||||
op_notification_t notifications; // Opciones relativas a las notificaciones;
|
||||
op_screen_t screen; // Opciones relativas a la clase screen
|
||||
ctrl_schem_e keys; // Teclas usadas para jugar
|
||||
section_t section; // Sección actual del programa
|
||||
std::string version; // Versión del fichero de configuración. Sirve para saber si las opciones son compatibles
|
||||
bool console; // Indica si ha de mostrar información por la consola de texto
|
||||
Cheat cheats; // Contiene trucos y ventajas para el juego
|
||||
OptionsGame game; // Opciones de juego
|
||||
OptionsVideo video; // Opciones de video
|
||||
OptionsStats stats; // Datos con las estadisticas de juego
|
||||
OptionsNotification notifications; // Opciones relativas a las notificaciones;
|
||||
OptionsWindows window; // Opciones relativas a la ventana
|
||||
ControlScheme keys; // Teclas usadas para jugar
|
||||
SectionState section; // Sección actual del programa
|
||||
|
||||
// Constructor por defecto
|
||||
Options()
|
||||
{
|
||||
version = "v1.07";
|
||||
console = false;
|
||||
cheats = Cheat();
|
||||
game = OptionsGame();
|
||||
video = OptionsVideo();
|
||||
stats = OptionsStats();
|
||||
notifications = OptionsNotification();
|
||||
window = OptionsWindows();
|
||||
keys = ControlScheme::CURSOR;
|
||||
section = SectionState();
|
||||
}
|
||||
|
||||
// Constructor
|
||||
Options(std::string cv, bool c, Cheat ch, OptionsGame g, OptionsVideo v, OptionsStats s, OptionsNotification n, OptionsWindows sw, ControlScheme k, SectionState sec)
|
||||
{
|
||||
version = cv;
|
||||
console = c;
|
||||
cheats = ch;
|
||||
game = g;
|
||||
video = v;
|
||||
stats = s;
|
||||
notifications = n;
|
||||
window = sw;
|
||||
keys = k;
|
||||
section = sec;
|
||||
}
|
||||
};
|
||||
|
||||
extern options_t options;
|
||||
extern Options options;
|
||||
|
||||
// Crea e inicializa las opciones del programa
|
||||
void initOptions();
|
||||
|
||||
Reference in New Issue
Block a user