modernitzat el sistema d'opcions

This commit is contained in:
2026-04-17 19:36:40 +02:00
parent 1bb0ebdef8
commit 7f703390f9
12 changed files with 690 additions and 553 deletions

View File

@@ -11,7 +11,7 @@
#include "core/locale/lang.h" // for Lang, ba_BA, en_UK, es_ES
#include "core/rendering/animatedsprite.h" // for AnimatedSprite
#include "core/rendering/fade.h" // for Fade
#include "core/rendering/screen.h" // for Screen, FILTER_LINEAL, FILTER_NEAREST
#include "core/rendering/screen.h" // for Screen
#include "core/rendering/smartsprite.h" // for SmartSprite
#include "core/rendering/sprite.h" // for Sprite
#include "core/rendering/text.h" // for Text, TXT_CENTER, TXT_SHADOW
@@ -20,16 +20,16 @@
#include "core/resources/resource.h"
#include "game/defaults.hpp" // for GAMECANVAS_CENTER_X, SECTION_PROG_QUIT
#include "game/game.h" // for Game
#include "game/options.hpp" // for Options
#include "game/ui/menu.h" // for Menu
// Constructor
Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset, options_t *options, Lang *lang, section_t *section) {
Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset, Lang *lang, section_t *section) {
// Copia las direcciones de los punteros
this->renderer = renderer;
this->screen = screen;
this->input = input;
this->asset = asset;
this->options = options;
this->lang = lang;
this->section = section;
@@ -113,18 +113,18 @@ void Title::init() {
demoThenInstructions = false;
// Pone valores por defecto a las opciones de control
options->input.clear();
Options::inputs.clear();
input_t i;
i.id = 0;
i.name = "KEYBOARD";
i.deviceType = INPUT_USE_KEYBOARD;
options->input.push_back(i);
Options::inputs.push_back(i);
i.id = 0;
i.name = "GAME CONTROLLER";
i.deviceType = INPUT_USE_GAMECONTROLLER;
options->input.push_back(i);
Options::inputs.push_back(i);
// Comprueba si hay mandos conectados
checkInputDevices();
@@ -136,9 +136,9 @@ void Title::init() {
// Si ha encontrado un mando se lo asigna al segundo jugador
if (input->gameControllerFound()) {
options->input[1].id = availableInputDevices[deviceIndex[1]].id;
options->input[1].name = availableInputDevices[deviceIndex[1]].name;
options->input[1].deviceType = availableInputDevices[deviceIndex[1]].deviceType;
Options::inputs[1].id = availableInputDevices[deviceIndex[1]].id;
Options::inputs[1].name = availableInputDevices[deviceIndex[1]].name;
Options::inputs[1].deviceType = availableInputDevices[deviceIndex[1]].deviceType;
} else { // Si no ha encontrado un mando, deshabilita la opción de jugar a 2 jugadores
menu.title->setSelectable(1, false);
menu.title->setGreyed(1, true);
@@ -347,7 +347,10 @@ void Title::update() {
case 2: // OPTIONS
menu.active = menu.options;
optionsPrevious = *options;
prevVideo = Options::video;
prevWindow = Options::window;
prevSettings = Options::settings;
prevInputs = Options::inputs;
break;
case 3: // QUIT
@@ -369,13 +372,13 @@ void Title::update() {
case 1: // BAL1
postFade = 0;
options->playerSelected = 0;
Options::settings.player_selected = 0;
fade->activateFade();
break;
case 2: // AROUNDER
postFade = 0;
options->playerSelected = 1;
Options::settings.player_selected = 1;
fade->activateFade();
break;
@@ -393,12 +396,12 @@ void Title::update() {
if (menu.active->getName() == "OPTIONS") {
switch (menu.active->getItemSelected()) {
case 0: // Difficulty
if (options->difficulty == DIFFICULTY_EASY)
options->difficulty = DIFFICULTY_NORMAL;
else if (options->difficulty == DIFFICULTY_NORMAL)
options->difficulty = DIFFICULTY_HARD;
if (Options::settings.difficulty == DIFFICULTY_EASY)
Options::settings.difficulty = DIFFICULTY_NORMAL;
else if (Options::settings.difficulty == DIFFICULTY_NORMAL)
Options::settings.difficulty = DIFFICULTY_HARD;
else
options->difficulty = DIFFICULTY_EASY;
Options::settings.difficulty = DIFFICULTY_EASY;
updateMenuLabels();
break;
@@ -413,15 +416,15 @@ void Title::update() {
break;
case 5: // Language
options->language++;
if (options->language == 3)
options->language = 0;
Options::settings.language++;
if (Options::settings.language == 3)
Options::settings.language = 0;
updateMenuLabels();
break;
case 6: // Display mode
switchFullScreenModeVar();
if (options->videoMode != 0) {
if (Options::video.fullscreen) {
menu.options->setSelectable(8, false);
menu.options->setGreyed(8, true);
} else {
@@ -432,27 +435,23 @@ void Title::update() {
break;
case 8: // Windows size
options->windowSize++;
if (options->windowSize == 5)
options->windowSize = 1;
Options::window.zoom++;
if (Options::window.zoom > Options::window.max_zoom)
Options::window.zoom = 1;
updateMenuLabels();
break;
case 9: // FILTER
if (options->filter == FILTER_LINEAL)
options->filter = FILTER_NEAREST;
else
options->filter = FILTER_LINEAL;
Texture::setGlobalScaleMode(options->filter == FILTER_NEAREST ? SDL_SCALEMODE_NEAREST : SDL_SCALEMODE_LINEAR);
case 9: // Scale mode
Options::video.scale_mode = (Options::video.scale_mode == SDL_SCALEMODE_NEAREST)
? SDL_SCALEMODE_LINEAR
: SDL_SCALEMODE_NEAREST;
Texture::setGlobalScaleMode(Options::video.scale_mode);
reLoadTextures();
updateMenuLabels();
break;
case 10: // VSYNC
if (options->vSync)
options->vSync = false;
else
options->vSync = true;
Options::video.vsync = !Options::video.vsync;
updateMenuLabels();
break;
@@ -467,7 +466,10 @@ void Title::update() {
break;
case 13: // CANCEL
options = &optionsPrevious;
Options::video = prevVideo;
Options::window = prevWindow;
Options::settings = prevSettings;
Options::inputs = prevInputs;
updateMenuLabels();
menu.active->reset();
menu.active = menu.title;
@@ -682,25 +684,14 @@ void Title::updateBG() {
// Cambia el valor de la variable de modo de pantalla completa
void Title::switchFullScreenModeVar() {
switch (options->videoMode) {
case 0:
options->videoMode = SDL_WINDOW_FULLSCREEN;
break;
case SDL_WINDOW_FULLSCREEN:
options->videoMode = 0;
break;
default:
options->videoMode = 0;
break;
}
Options::video.fullscreen = !Options::video.fullscreen;
}
// Actualiza los elementos de los menus
void Title::updateMenuLabels() {
int i = 0;
// DIFFICULTY
switch (options->difficulty) {
switch (Options::settings.difficulty) {
case DIFFICULTY_EASY:
menu.options->setItemCaption(i, lang->getText(59) + ": " + lang->getText(66)); // EASY
break;
@@ -724,7 +715,7 @@ void Title::updateMenuLabels() {
i++;
// PLAYER 1 CONTROLS - OPTIONS
switch (options->input[0].deviceType) {
switch (Options::inputs[0].deviceType) {
case INPUT_USE_KEYBOARD:
menu.options->setItemCaption(i, lang->getText(69)); // KEYBOARD
menu.options->setGreyed(i, false);
@@ -736,7 +727,7 @@ void Title::updateMenuLabels() {
menu.options->setGreyed(i, true);
else {
menu.options->setGreyed(i, false);
menu.options->setItemCaption(i, options->input[0].name);
menu.options->setItemCaption(i, Options::inputs[0].name);
}
break;
@@ -751,7 +742,7 @@ void Title::updateMenuLabels() {
i++;
// PLAYER 2 CONTROLS - OPTIONS
switch (options->input[1].deviceType) {
switch (Options::inputs[1].deviceType) {
case INPUT_USE_KEYBOARD:
menu.options->setItemCaption(i, lang->getText(69)); // KEYBOARD
menu.options->setGreyed(i, false);
@@ -763,7 +754,7 @@ void Title::updateMenuLabels() {
menu.options->setGreyed(i, true);
else {
menu.options->setGreyed(i, false);
menu.options->setItemCaption(i, options->input[1].name);
menu.options->setItemCaption(i, Options::inputs[1].name);
}
break;
@@ -774,7 +765,7 @@ void Title::updateMenuLabels() {
i++;
// LANGUAGE
switch (options->language) {
switch (Options::settings.language) {
case es_ES:
menu.options->setItemCaption(i, lang->getText(8) + ": " + lang->getText(24)); // SPANISH
break;
@@ -798,34 +789,22 @@ void Title::updateMenuLabels() {
i++;
// DISPLAY MODE - OPTIONS
switch (options->videoMode) {
case 0:
menu.options->setItemCaption(i, lang->getText(4)); // WINDOW
break;
case SDL_WINDOW_FULLSCREEN:
menu.options->setItemCaption(i, lang->getText(5)); // FULLSCREEN
break;
default:
menu.options->setItemCaption(i, lang->getText(4)); // WINDOW
break;
}
menu.options->setItemCaption(i, Options::video.fullscreen ? lang->getText(5) : lang->getText(4));
i++;
// WINDOW SIZE
menu.options->setItemCaption(i, lang->getText(7) + " x" + std::to_string(options->windowSize)); // WINDOW SIZE
menu.options->setItemCaption(i, lang->getText(7) + " x" + std::to_string(Options::window.zoom)); // WINDOW SIZE
i++;
// FILTER
if (options->filter == FILTER_LINEAL)
// SCALE MODE
if (Options::video.scale_mode == SDL_SCALEMODE_LINEAR)
menu.options->setItemCaption(i, lang->getText(60) + ": " + lang->getText(71)); // BILINEAL
else
menu.options->setItemCaption(i, lang->getText(60) + ": " + lang->getText(72)); // LINEAL
i++;
// VSYNC
if (options->vSync)
if (Options::video.vsync)
menu.options->setItemCaption(i, lang->getText(61) + ": " + lang->getText(73)); // ON
else
menu.options->setItemCaption(i, lang->getText(61) + ": " + lang->getText(74)); // OFF
@@ -887,9 +866,11 @@ void Title::updateMenuLabels() {
// Aplica las opciones de menu seleccionadas
void Title::applyOptions() {
screen->setVideoMode(options->videoMode != 0);
screen->setVideoMode(Options::video.fullscreen);
screen->setWindowZoom(Options::window.zoom);
screen->setVSync(Options::video.vsync);
lang->setLang(options->language);
lang->setLang(Options::settings.language);
updateMenuLabels();
createTiledBackground();
@@ -1004,7 +985,7 @@ void Title::runDemoGame() {
// Temporalmente ponemos section para que el constructor de Game funcione
section->name = SECTION_PROG_GAME;
section->subsection = SUBSECTION_GAME_PLAY_1P;
demoGame = new Game(1, 0, renderer, screen, asset, lang, input, true, options, section);
demoGame = new Game(1, 0, renderer, screen, asset, lang, input, true, section);
demoGameActive = true;
// Restauramos section para que Director no transicione fuera de Title
section->name = SECTION_PROG_TITLE;
@@ -1018,17 +999,17 @@ bool Title::updatePlayerInputs(int numPlayer) {
deviceIndex[0] = 0;
deviceIndex[1] = 0;
options->input[0].id = -1;
options->input[0].name = "KEYBOARD";
options->input[0].deviceType = INPUT_USE_KEYBOARD;
Options::inputs[0].id = -1;
Options::inputs[0].name = "KEYBOARD";
Options::inputs[0].deviceType = INPUT_USE_KEYBOARD;
options->input[1].id = 0;
options->input[1].name = "GAME CONTROLLER";
options->input[1].deviceType = INPUT_USE_GAMECONTROLLER;
Options::inputs[1].id = 0;
Options::inputs[1].name = "GAME CONTROLLER";
Options::inputs[1].deviceType = INPUT_USE_GAMECONTROLLER;
return true;
} else { // Si hay mas de un dispositivo, se recorre el vector
if (options->console) {
if (Options::settings.console) {
std::cout << "numplayer:" << numPlayer << std::endl;
std::cout << "deviceindex:" << deviceIndex[numPlayer] << std::endl;
}
@@ -1039,7 +1020,7 @@ bool Title::updatePlayerInputs(int numPlayer) {
} else {
deviceIndex[numPlayer] = 0;
}
if (options->console) {
if (Options::settings.console) {
std::cout << "deviceindex:" << deviceIndex[numPlayer] << std::endl;
}
@@ -1053,8 +1034,8 @@ bool Title::updatePlayerInputs(int numPlayer) {
}
// Copia el dispositivo marcado por el indice a la variable de opciones de cada jugador
options->input[0] = availableInputDevices[deviceIndex[0]];
options->input[1] = availableInputDevices[deviceIndex[1]];
Options::inputs[0] = availableInputDevices[deviceIndex[0]];
Options::inputs[1] = availableInputDevices[deviceIndex[1]];
return true;
}
@@ -1068,7 +1049,7 @@ void Title::createTiledBackground() {
SDL_SetTextureScaleMode(background, Texture::currentScaleMode);
}
if (background == nullptr) {
if (options->console) {
if (Options::settings.console) {
std::cout << "TitleSurface could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
}
}
@@ -1105,7 +1086,7 @@ void Title::createTiledBackground() {
// El estado de Input lo mantiene al día Director via eventos SDL_EVENT_GAMEPAD_ADDED/REMOVED,
// así que aquí solo leemos la lista actual sin reescanear.
void Title::checkInputDevices() {
if (options->console) {
if (Options::settings.console) {
std::cout << "Filling devices for options menu..." << std::endl;
}
const int numControllers = input->getNumControllers();
@@ -1119,7 +1100,7 @@ void Title::checkInputDevices() {
temp.name = input->getControllerName(i);
temp.deviceType = INPUT_USE_GAMECONTROLLER;
availableInputDevices.push_back(temp);
if (options->console) {
if (Options::settings.console) {
std::cout << "Device " << (int)availableInputDevices.size() << " - " << temp.name.c_str() << std::endl;
}
}
@@ -1129,7 +1110,7 @@ void Title::checkInputDevices() {
temp.name = "KEYBOARD";
temp.deviceType = INPUT_USE_KEYBOARD;
availableInputDevices.push_back(temp);
if (options->console) {
if (Options::settings.console) {
std::cout << "Device " << (int)availableInputDevices.size() << " - " << temp.name.c_str() << std::endl;
std::cout << std::endl;
}