options: canviat size per zoom i v_sync per vsync
options: moguda la opció de window a la seua seccio
This commit is contained in:
@@ -55,7 +55,7 @@ void toggleIntegerScale() {
|
||||
// Activa / desactiva el vsync
|
||||
void toggleVSync() {
|
||||
Screen::get()->toggleVSync();
|
||||
Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 14") + " " + boolToOnOff(Options::video.v_sync)});
|
||||
Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 14") + " " + boolToOnOff(Options::video.vsync)});
|
||||
}
|
||||
|
||||
// Activa o desactiva los shaders
|
||||
@@ -149,14 +149,14 @@ void toggleFullscreen() {
|
||||
// Reduce el tamaño de la ventana
|
||||
void decWindowSize() {
|
||||
if (Screen::get()->decWindowSize()) {
|
||||
Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 09") + " x" + std::to_string(Options::window.size)});
|
||||
Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 09") + " x" + std::to_string(Options::window.zoom)});
|
||||
}
|
||||
}
|
||||
|
||||
// Aumenta el tamaño de la ventana
|
||||
void incWindowSize() {
|
||||
if (Screen::get()->incWindowSize()) {
|
||||
Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 09") + " x" + std::to_string(Options::window.size)});
|
||||
Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 09") + " x" + std::to_string(Options::window.zoom)});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,7 +283,7 @@ auto checkInputs() -> bool {
|
||||
// Comprueba el teclado para decrementar el tamaño de la ventana
|
||||
if (Input::get()->checkInput(InputAction::WINDOW_DEC_SIZE, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) {
|
||||
if (Screen::get()->decWindowSize()) {
|
||||
Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 09") + " x" + std::to_string(Options::window.size)});
|
||||
Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 09") + " x" + std::to_string(Options::window.zoom)});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -291,7 +291,7 @@ auto checkInputs() -> bool {
|
||||
// Comprueba el teclado para incrementar el tamaño de la ventana
|
||||
if (Input::get()->checkInput(InputAction::WINDOW_INC_SIZE, INPUT_DO_NOT_ALLOW_REPEAT, InputDevice::KEYBOARD)) {
|
||||
if (Screen::get()->incWindowSize()) {
|
||||
Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 09") + " x" + std::to_string(Options::window.size)});
|
||||
Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 09") + " x" + std::to_string(Options::window.zoom)});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "options.h"
|
||||
|
||||
#include <SDL3/SDL.h> // Para SDL_GamepadButton, SDL_ScaleMode, SDL_LogCategory, SDL_LogInfo, SDL_LogError, SDL_LogWarn
|
||||
|
||||
#include <algorithm> // Para clamp, max
|
||||
#include <fstream> // Para basic_ostream, operator<<, basic_ostream::operator<<, basic_ofstream, basic_istream, basic_ifstream, ifstream, ofstream
|
||||
#include <utility> // Para swap
|
||||
@@ -105,15 +106,20 @@ auto saveToFile() -> bool {
|
||||
|
||||
applyPendingChanges();
|
||||
|
||||
// Opciones de ventana
|
||||
file << "## WINDOW\n";
|
||||
file << "\n";
|
||||
|
||||
file << "window.zoom=" << window.zoom << "\n";
|
||||
|
||||
// Opciones de video
|
||||
file << "## VIDEO\n";
|
||||
file << "## video.scale_mode [" << static_cast<int>(SDL_ScaleMode::SDL_SCALEMODE_NEAREST) << ": nearest, " << static_cast<int>(SDL_ScaleMode::SDL_SCALEMODE_LINEAR) << ": lineal]\n";
|
||||
file << "\n";
|
||||
|
||||
file << "window.zoom=" << window.size << "\n";
|
||||
file << "video.fullscreen=" << boolToString(video.fullscreen) << "\n";
|
||||
file << "video.scale_mode=" << static_cast<int>(video.scale_mode) << "\n";
|
||||
file << "video.v_sync=" << boolToString(video.v_sync) << "\n";
|
||||
file << "video.vsync=" << boolToString(video.vsync) << "\n";
|
||||
file << "video.integer_scale=" << boolToString(video.integer_scale) << "\n";
|
||||
file << "video.shaders=" << boolToString(video.shaders) << "\n";
|
||||
|
||||
@@ -168,21 +174,27 @@ auto saveToFile() -> bool {
|
||||
// Asigna variables a partir de dos cadenas
|
||||
auto set(const std::string &var, const std::string &value) -> bool {
|
||||
// Indicador de éxito en la asignación
|
||||
auto success = true;
|
||||
// Lineas vacias o que empiezan por comentario
|
||||
if (var.empty() || var.starts_with("#")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Opciones de ventana
|
||||
if (var == "window.zoom") {
|
||||
window.zoom = std::stoi(value);
|
||||
}
|
||||
|
||||
// Opciones de video
|
||||
if (var == "video.fullscreen") {
|
||||
video.fullscreen = stringToBool(value);
|
||||
} else if (var == "window.zoom") {
|
||||
window.size = std::stoi(value);
|
||||
} else if (var == "video.scale_mode") {
|
||||
video.scale_mode = static_cast<SDL_ScaleMode>(std::stoi(value));
|
||||
} else if (var == "video.shaders") {
|
||||
video.shaders = stringToBool(value);
|
||||
} else if (var == "video.integer_scale") {
|
||||
video.integer_scale = stringToBool(value);
|
||||
} else if (var == "video.v_sync") {
|
||||
video.v_sync = stringToBool(value);
|
||||
} else if (var == "video.vsync") {
|
||||
video.vsync = stringToBool(value);
|
||||
}
|
||||
|
||||
// Opciones de audio
|
||||
@@ -248,13 +260,7 @@ auto set(const std::string &var, const std::string &value) -> bool {
|
||||
controllers.at(1).buttons.at(4) = static_cast<SDL_GamepadButton>(std::stoi(value));
|
||||
}
|
||||
|
||||
// Lineas vacias o que empiezan por comentario
|
||||
else if (var.empty() || var.starts_with("#")) {
|
||||
} else {
|
||||
success = false;
|
||||
}
|
||||
|
||||
return success;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Asigna el teclado al jugador
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h> // Para SDL_GamepadButton, SDL_ScaleMode
|
||||
|
||||
#include <algorithm> // Para copy
|
||||
#include <string> // Para allocator, string
|
||||
#include <utility> // Para move
|
||||
@@ -32,8 +33,8 @@ struct Difficulty {
|
||||
// --- Opciones de ventana ---
|
||||
struct WindowOptions {
|
||||
std::string caption; // Texto que aparece en la barra de título de la ventana
|
||||
int size{2}; // Valor por el que se multiplica el tamaño de la ventana
|
||||
int max_size{2}; // Tamaño máximo para que la ventana no sea mayor que la pantalla
|
||||
int zoom{2}; // Valor por el que se multiplica el tamaño de la ventana
|
||||
int max_zoom{2}; // Tamaño máximo para que la ventana no sea mayor que la pantalla
|
||||
|
||||
// Constructor por defecto con valores iniciales
|
||||
WindowOptions()
|
||||
@@ -44,7 +45,7 @@ struct WindowOptions {
|
||||
struct VideoOptions {
|
||||
SDL_ScaleMode scale_mode{SDL_ScaleMode::SDL_SCALEMODE_NEAREST}; // Filtro usado para el escalado de la imagen
|
||||
bool fullscreen{false}; // Indica si se usa pantalla completa
|
||||
bool v_sync{true}; // Indica si se usa vsync
|
||||
bool vsync{true}; // Indica si se usa vsync
|
||||
bool integer_scale{true}; // Indica si se usa escalado entero
|
||||
bool shaders{false}; // Indica si se usan shaders para los filtros de vídeo
|
||||
std::string info; // Información sobre el modo de vídeo
|
||||
|
||||
@@ -119,18 +119,18 @@ void Screen::toggleFullscreen() {
|
||||
|
||||
// Cambia el tamaño de la ventana
|
||||
void Screen::setWindowZoom(int zoom) {
|
||||
Options::window.size = zoom;
|
||||
Options::window.zoom = zoom;
|
||||
adjustWindowSize();
|
||||
}
|
||||
|
||||
// Reduce el tamaño de la ventana
|
||||
auto Screen::decWindowSize() -> bool {
|
||||
if (!Options::video.fullscreen) {
|
||||
const int PREVIOUS_ZOOM = Options::window.size;
|
||||
--Options::window.size;
|
||||
Options::window.size = std::max(Options::window.size, 1);
|
||||
const int PREVIOUS_ZOOM = Options::window.zoom;
|
||||
--Options::window.zoom;
|
||||
Options::window.zoom = std::max(Options::window.zoom, 1);
|
||||
|
||||
if (Options::window.size != PREVIOUS_ZOOM) {
|
||||
if (Options::window.zoom != PREVIOUS_ZOOM) {
|
||||
adjustWindowSize();
|
||||
return true;
|
||||
}
|
||||
@@ -142,11 +142,11 @@ auto Screen::decWindowSize() -> bool {
|
||||
// Aumenta el tamaño de la ventana
|
||||
auto Screen::incWindowSize() -> bool {
|
||||
if (!Options::video.fullscreen) {
|
||||
const int PREVIOUS_ZOOM = Options::window.size;
|
||||
++Options::window.size;
|
||||
Options::window.size = std::min(Options::window.size, Options::window.max_size);
|
||||
const int PREVIOUS_ZOOM = Options::window.zoom;
|
||||
++Options::window.zoom;
|
||||
Options::window.zoom = std::min(Options::window.zoom, Options::window.max_zoom);
|
||||
|
||||
if (Options::window.size != PREVIOUS_ZOOM) {
|
||||
if (Options::window.zoom != PREVIOUS_ZOOM) {
|
||||
adjustWindowSize();
|
||||
return true;
|
||||
}
|
||||
@@ -241,8 +241,8 @@ void Screen::initShaders() {
|
||||
void Screen::adjustWindowSize() {
|
||||
if (!Options::video.fullscreen) {
|
||||
// Establece el nuevo tamaño
|
||||
const int WIDTH = param.game.width * Options::window.size;
|
||||
const int HEIGHT = param.game.height * Options::window.size;
|
||||
const int WIDTH = param.game.width * Options::window.zoom;
|
||||
const int HEIGHT = param.game.height * Options::window.zoom;
|
||||
|
||||
int old_width;
|
||||
int old_height;
|
||||
@@ -307,8 +307,8 @@ auto Screen::initSDLVideo() -> bool {
|
||||
}
|
||||
window_ = SDL_CreateWindow(
|
||||
Options::window.caption.c_str(),
|
||||
param.game.width * Options::window.size,
|
||||
param.game.height * Options::window.size,
|
||||
param.game.width * Options::window.zoom,
|
||||
param.game.height * Options::window.zoom,
|
||||
window_flags);
|
||||
|
||||
if (window_ == nullptr) {
|
||||
@@ -335,7 +335,7 @@ auto Screen::initSDLVideo() -> bool {
|
||||
SDL_SetRenderDrawColor(renderer_, 0x00, 0x00, 0x00, 0xFF);
|
||||
SDL_SetRenderLogicalPresentation(renderer_, param.game.width, param.game.height, Options::video.integer_scale ? SDL_LOGICAL_PRESENTATION_INTEGER_SCALE : SDL_LOGICAL_PRESENTATION_LETTERBOX);
|
||||
SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_BLEND);
|
||||
SDL_SetRenderVSync(renderer_, Options::video.v_sync ? 1 : SDL_RENDERER_VSYNC_DISABLED);
|
||||
SDL_SetRenderVSync(renderer_, Options::video.vsync ? 1 : SDL_RENDERER_VSYNC_DISABLED);
|
||||
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "** Video system initialized successfully");
|
||||
return true;
|
||||
@@ -357,13 +357,13 @@ void Screen::getDisplayInfo() {
|
||||
const auto *dm = SDL_GetCurrentDisplayMode(displays[0]);
|
||||
|
||||
// Calcula el máximo factor de zoom que se puede aplicar a la pantalla
|
||||
Options::window.max_size = std::min(dm->w / param.game.width, dm->h / param.game.height);
|
||||
Options::window.size = std::min(Options::window.size, Options::window.max_size);
|
||||
Options::window.max_zoom = std::min(dm->w / param.game.width, dm->h / param.game.height);
|
||||
Options::window.zoom = std::min(Options::window.zoom, Options::window.max_zoom);
|
||||
|
||||
// Muestra información sobre el tamaño de la pantalla y de la ventana de juego
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Current display mode: %dx%d @ %dHz", static_cast<int>(dm->w), static_cast<int>(dm->h), static_cast<int>(dm->refresh_rate));
|
||||
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Window resolution: %dx%d x%d", static_cast<int>(param.game.width), static_cast<int>(param.game.height), Options::window.size);
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Window resolution: %dx%d x%d", static_cast<int>(param.game.width), static_cast<int>(param.game.height), Options::window.zoom);
|
||||
|
||||
Options::video.info = std::to_string(static_cast<int>(dm->w)) + "x" +
|
||||
std::to_string(static_cast<int>(dm->h)) + " @ " +
|
||||
@@ -373,7 +373,7 @@ void Screen::getDisplayInfo() {
|
||||
const int MAX_ZOOM = std::min(dm->w / param.game.width, (dm->h - WINDOWS_DECORATIONS) / param.game.height);
|
||||
|
||||
// Normaliza los valores de zoom
|
||||
Options::window.size = std::min(Options::window.size, MAX_ZOOM);
|
||||
Options::window.zoom = std::min(Options::window.zoom, MAX_ZOOM);
|
||||
|
||||
SDL_free(displays);
|
||||
}
|
||||
@@ -393,13 +393,13 @@ void Screen::toggleIntegerScale() {
|
||||
|
||||
// Alterna entre activar y desactivar el V-Sync
|
||||
void Screen::toggleVSync() {
|
||||
Options::video.v_sync = !Options::video.v_sync;
|
||||
SDL_SetRenderVSync(renderer_, Options::video.v_sync ? 1 : SDL_RENDERER_VSYNC_DISABLED);
|
||||
Options::video.vsync = !Options::video.vsync;
|
||||
SDL_SetRenderVSync(renderer_, Options::video.vsync ? 1 : SDL_RENDERER_VSYNC_DISABLED);
|
||||
}
|
||||
|
||||
// Establece el estado del V-Sync
|
||||
void Screen::setVSync(bool enabled) {
|
||||
Options::video.v_sync = enabled;
|
||||
Options::video.vsync = enabled;
|
||||
SDL_SetRenderVSync(renderer_, enabled ? 1 : SDL_RENDERER_VSYNC_DISABLED);
|
||||
}
|
||||
|
||||
@@ -411,7 +411,7 @@ void Screen::getSingletons() {
|
||||
|
||||
// Aplica los valores de las opciones
|
||||
void Screen::applySettings() {
|
||||
SDL_SetRenderVSync(renderer_, Options::video.v_sync ? 1 : SDL_RENDERER_VSYNC_DISABLED);
|
||||
SDL_SetRenderVSync(renderer_, Options::video.vsync ? 1 : SDL_RENDERER_VSYNC_DISABLED);
|
||||
SDL_SetRenderLogicalPresentation(Screen::get()->getRenderer(), param.game.width, param.game.height, Options::video.integer_scale ? SDL_LOGICAL_PRESENTATION_INTEGER_SCALE : SDL_LOGICAL_PRESENTATION_LETTERBOX);
|
||||
setFullscreenMode();
|
||||
adjustWindowSize();
|
||||
|
||||
@@ -31,7 +31,7 @@ class Screen {
|
||||
// --- Configuración de ventana y render ---
|
||||
void setFullscreenMode(); // Establece el modo de pantalla completa
|
||||
void toggleFullscreen(); // Cambia entre pantalla completa y ventana
|
||||
void setWindowZoom(int size); // Cambia el tamaño de la ventana
|
||||
void setWindowZoom(int zoom); // Cambia el tamaño de la ventana
|
||||
auto decWindowSize() -> bool; // Reduce el tamaño de la ventana
|
||||
auto incWindowSize() -> bool; // Aumenta el tamaño de la ventana
|
||||
void applySettings(); // Aplica los valores de las opciones
|
||||
@@ -51,7 +51,7 @@ class Screen {
|
||||
void show() { SDL_ShowWindow(window_); } // Muestra la ventana
|
||||
void hide() { SDL_HideWindow(window_); } // Oculta la ventana
|
||||
void getSingletons(); // Obtiene los punteros a los singletones
|
||||
[[nodiscard]] static auto getVSync() -> bool { return Options::video.v_sync; } // Obtiene el valor de V-Sync
|
||||
[[nodiscard]] static auto getVSync() -> bool { return Options::video.vsync; } // Obtiene el valor de V-Sync
|
||||
[[nodiscard]] auto getText() const -> std::shared_ptr<Text> { return text_; } // Obtiene el puntero al texto de Screen
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
||||
@@ -240,9 +240,9 @@ void ServiceMenu::initializeOptions() {
|
||||
|
||||
// --- Video ---
|
||||
options_.push_back(std::make_unique<BoolOption>(Lang::getText("[SERVICE_MENU] FULLSCREEN"), SettingsGroup::VIDEO, &Options::video.fullscreen));
|
||||
options_.push_back(std::make_unique<IntOption>(Lang::getText("[SERVICE_MENU] WINDOW_SIZE"), SettingsGroup::VIDEO, &Options::window.size, 1, Options::window.max_size, 1));
|
||||
options_.push_back(std::make_unique<IntOption>(Lang::getText("[SERVICE_MENU] WINDOW_SIZE"), SettingsGroup::VIDEO, &Options::window.zoom, 1, Options::window.max_zoom, 1));
|
||||
options_.push_back(std::make_unique<BoolOption>(Lang::getText("[SERVICE_MENU] SHADERS"), SettingsGroup::VIDEO, &Options::video.shaders));
|
||||
options_.push_back(std::make_unique<BoolOption>(Lang::getText("[SERVICE_MENU] VSYNC"), SettingsGroup::VIDEO, &Options::video.v_sync));
|
||||
options_.push_back(std::make_unique<BoolOption>(Lang::getText("[SERVICE_MENU] VSYNC"), SettingsGroup::VIDEO, &Options::video.vsync));
|
||||
options_.push_back(std::make_unique<BoolOption>(Lang::getText("[SERVICE_MENU] INTEGER_SCALE"), SettingsGroup::VIDEO, &Options::video.integer_scale));
|
||||
|
||||
// --- Audio ---
|
||||
|
||||
Reference in New Issue
Block a user