vaig a fer un commit per si de cas petara algo ...
This commit is contained in:
@@ -253,7 +253,7 @@ namespace globalInputs
|
||||
{
|
||||
if (Screen::get()->decWindowZoom())
|
||||
{
|
||||
Notifier::get()->show({lang::getText(131) + " x" + std::to_string(options.window.zoom)});
|
||||
Notifier::get()->show({lang::getText(131) + " x" + std::to_string(options.window.size)});
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -263,7 +263,7 @@ namespace globalInputs
|
||||
{
|
||||
if (Screen::get()->incWindowZoom())
|
||||
{
|
||||
Notifier::get()->show({lang::getText(131) + " x" + std::to_string(options.window.zoom)});
|
||||
Notifier::get()->show({lang::getText(131) + " x" + std::to_string(options.window.size)});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ bool setOptions(const std::string &var, const std::string &value);
|
||||
void initOptions()
|
||||
{
|
||||
options.window.caption = "Coffee Crisis Arcade Edition";
|
||||
options.window.zoom = 2;
|
||||
options.window.size = 2;
|
||||
|
||||
// Opciones de video
|
||||
options.video.fullscreen = false;
|
||||
@@ -120,7 +120,7 @@ bool saveOptionsFile(std::string file_path)
|
||||
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=" << options.window.zoom << "\n";
|
||||
file << "window.zoom=" << options.window.size << "\n";
|
||||
file << "video.fullscreen=" << boolToString(options.video.fullscreen) << "\n";
|
||||
file << "video.scale_mode=" << static_cast<int>(options.video.scale_mode) << "\n";
|
||||
file << "video.v_sync=" << boolToString(options.video.v_sync) << "\n";
|
||||
@@ -188,7 +188,7 @@ bool setOptions(const std::string &var, const std::string &value)
|
||||
}
|
||||
else if (var == "window.zoom")
|
||||
{
|
||||
options.window.zoom = std::stoi(value);
|
||||
options.window.size = std::stoi(value);
|
||||
}
|
||||
else if (var == "video.scale_mode")
|
||||
{
|
||||
|
||||
@@ -24,8 +24,8 @@ enum class GameDifficulty
|
||||
struct WindowOptions
|
||||
{
|
||||
std::string caption; // Texto que aparece en la barra de título de la ventana
|
||||
int zoom = 1; // Valor por el que se multiplica el tamaño de la ventana
|
||||
int max_zoom = 1; // Tamaño máximo para que la ventana no sea mayor que la pantalla
|
||||
int size = 1; // Valor por el que se multiplica el tamaño de la ventana
|
||||
int max_size = 1; // Tamaño máximo para que la ventana no sea mayor que la pantalla
|
||||
};
|
||||
|
||||
// --- Opciones de vídeo ---
|
||||
|
||||
@@ -125,7 +125,7 @@ void Screen::toggleFullscreen()
|
||||
// Cambia el tamaño de la ventana
|
||||
void Screen::setWindowZoom(int zoom)
|
||||
{
|
||||
options.window.zoom = zoom;
|
||||
options.window.size = zoom;
|
||||
adjustWindowSize();
|
||||
}
|
||||
|
||||
@@ -134,11 +134,11 @@ bool Screen::decWindowZoom()
|
||||
{
|
||||
if (!options.video.fullscreen)
|
||||
{
|
||||
const int PREVIOUS_ZOOM = options.window.zoom;
|
||||
--options.window.zoom;
|
||||
options.window.zoom = std::max(options.window.zoom, 1);
|
||||
const int PREVIOUS_ZOOM = options.window.size;
|
||||
--options.window.size;
|
||||
options.window.size = std::max(options.window.size, 1);
|
||||
|
||||
if (options.window.zoom != PREVIOUS_ZOOM)
|
||||
if (options.window.size != PREVIOUS_ZOOM)
|
||||
{
|
||||
adjustWindowSize();
|
||||
return true;
|
||||
@@ -153,11 +153,11 @@ bool Screen::incWindowZoom()
|
||||
{
|
||||
if (!options.video.fullscreen)
|
||||
{
|
||||
const int PREVIOUS_ZOOM = options.window.zoom;
|
||||
++options.window.zoom;
|
||||
options.window.zoom = std::min(options.window.zoom, options.window.max_zoom);
|
||||
const int PREVIOUS_ZOOM = options.window.size;
|
||||
++options.window.size;
|
||||
options.window.size = std::min(options.window.size, options.window.max_size);
|
||||
|
||||
if (options.window.zoom != PREVIOUS_ZOOM)
|
||||
if (options.window.size != PREVIOUS_ZOOM)
|
||||
{
|
||||
adjustWindowSize();
|
||||
return true;
|
||||
@@ -253,8 +253,8 @@ void Screen::adjustWindowSize()
|
||||
// Establece el nuevo tamaño
|
||||
if (!options.video.fullscreen)
|
||||
{
|
||||
const int WIDTH = param.game.width * options.window.zoom;
|
||||
const int HEIGHT = param.game.height * options.window.zoom;
|
||||
const int WIDTH = param.game.width * options.window.size;
|
||||
const int HEIGHT = param.game.height * options.window.size;
|
||||
|
||||
int old_width, old_height;
|
||||
SDL_GetWindowSize(window_, &old_width, &old_height);
|
||||
@@ -320,7 +320,7 @@ bool Screen::initSDL()
|
||||
}
|
||||
|
||||
// Crea la ventana
|
||||
window_ = SDL_CreateWindow(options.window.caption.c_str(), param.game.width * options.window.zoom, param.game.height * options.window.zoom, SDL_WINDOW_OPENGL);
|
||||
window_ = SDL_CreateWindow(options.window.caption.c_str(), param.game.width * options.window.size, param.game.height * options.window.size, SDL_WINDOW_OPENGL);
|
||||
if (!window_)
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Window could not be created! SDL Error: %s", SDL_GetError());
|
||||
@@ -368,15 +368,15 @@ void Screen::getDisplayInfo()
|
||||
auto DM = SDL_GetCurrentDisplayMode(displays[0]);
|
||||
|
||||
// Calcula el máximo factor de zoom que se puede aplicar a la pantalla
|
||||
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);
|
||||
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);
|
||||
|
||||
// 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.zoom);
|
||||
static_cast<int>(param.game.width), static_cast<int>(param.game.height), options.window.size);
|
||||
|
||||
options.video.info = std::to_string(static_cast<int>(DM->w)) + "x" +
|
||||
std::to_string(static_cast<int>(DM->h)) + " @ " +
|
||||
@@ -386,7 +386,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.zoom = std::min(options.window.zoom, MAX_ZOOM);
|
||||
options.window.size = std::min(options.window.size, MAX_ZOOM);
|
||||
|
||||
SDL_free(displays);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <string>
|
||||
#include "text.h"
|
||||
#include "resource.h"
|
||||
#include "options.h
|
||||
|
||||
// Singleton
|
||||
ServiceMenu *ServiceMenu::instance_ = nullptr;
|
||||
@@ -24,6 +25,7 @@ ServiceMenu::ServiceMenu()
|
||||
titleText_(Resource::get()->getText("04b_25_flat_2x"))
|
||||
{
|
||||
setAnchors();
|
||||
initializeOptions();
|
||||
}
|
||||
|
||||
void ServiceMenu::toggle()
|
||||
@@ -182,3 +184,28 @@ void ServiceMenu::acceptSelection()
|
||||
void ServiceMenu::cancelSelection()
|
||||
{
|
||||
}
|
||||
|
||||
void ServiceMenu::initializeOptions()
|
||||
{
|
||||
// Video
|
||||
options_.emplace_back("FULLSCREEN", SettingsGroup::VIDEO, OptionBehavior::ADJUST, &options.video.fullscreen, ValueType::BOOL);
|
||||
options_.emplace_back("WINDOW SIZE", SettingsGroup::VIDEO, OptionBehavior::ADJUST, &options.window.size, ValueType::INT);
|
||||
options_.emplace_back("SHADERS", SettingsGroup::VIDEO, OptionBehavior::ADJUST, &options.video.shaders, ValueType::BOOL);
|
||||
options_.emplace_back("VSYNC", SettingsGroup::VIDEO, OptionBehavior::ADJUST, &options.video.v_sync, ValueType::BOOL);
|
||||
options_.emplace_back("INTEGER SCALE", SettingsGroup::VIDEO, OptionBehavior::ADJUST, &options.video.integer_scale, ValueType::BOOL);
|
||||
|
||||
// Audio
|
||||
options_.emplace_back("AUDIO", SettingsGroup::AUDIO, OptionBehavior::ADJUST, &options.audio.enabled, ValueType::BOOL);
|
||||
options_.emplace_back("MAIN VOLUME", SettingsGroup::AUDIO, OptionBehavior::ADJUST, &options.audio.volume, ValueType::INT);
|
||||
options_.emplace_back("MUSIC VOLUME", SettingsGroup::AUDIO, OptionBehavior::ADJUST, &options.audio.music.volume, ValueType::INT);
|
||||
options_.emplace_back("SFX VOLUME", SettingsGroup::AUDIO, OptionBehavior::ADJUST, &options.audio.sound.volume, ValueType::INT);
|
||||
|
||||
// Game
|
||||
options_.emplace_back("AUTOFIRE", SettingsGroup::GAME, OptionBehavior::ADJUST, &options.game.autofire, ValueType::BOOL);
|
||||
//options_.emplace_back("LANG", SettingsGroup::GAME, OptionBehavior::ADJUST, &options.game.language, ValueType::BOOL);
|
||||
|
||||
// System
|
||||
options_.emplace_back("RESET", SettingsGroup::SYSTEM, OptionBehavior::SELECT, nullptr, ValueType::NONE);
|
||||
options_.emplace_back("QUIT", SettingsGroup::SYSTEM, OptionBehavior::SELECT, nullptr, ValueType::NONE);
|
||||
options_.emplace_back("SHUTDOWN", SettingsGroup::SYSTEM, OptionBehavior::SELECT, nullptr, ValueType::NONE);
|
||||
}
|
||||
@@ -31,6 +31,51 @@ public:
|
||||
bool isEnabled() const { return enabled_; }
|
||||
|
||||
private:
|
||||
enum class SettingsGroup
|
||||
{
|
||||
VIDEO, // Configuraciones relacionadas con la calidad y resolución de imagen
|
||||
AUDIO, // Opciones de sonido y volumen
|
||||
GAME, // Ajustes de jugabilidad y mecánicas
|
||||
SYSTEM // Preferencias generales y configuraciones del sistema
|
||||
};
|
||||
|
||||
enum class OptionBehavior
|
||||
{
|
||||
ADJUST, // Modificable con izquierda/derecha
|
||||
SELECT // Activable con ENTER
|
||||
};
|
||||
|
||||
enum class ValueType
|
||||
{
|
||||
BOOL,
|
||||
INT,
|
||||
NONE
|
||||
};
|
||||
|
||||
struct OptionEntry
|
||||
{
|
||||
std::string caption; // Texto visible en el menú
|
||||
SettingsGroup group; // Categoría de la opción
|
||||
OptionBehavior behavior; // Cómo se interactúa con la opción
|
||||
void *linkedVariable; // Puntero a la variable que controla la opción
|
||||
ValueType type; // Tipo de la variable (bool o int)
|
||||
|
||||
// Constructor para inicializar los valores fácilmente
|
||||
OptionEntry(std::string cap, SettingsGroup grp, OptionBehavior beh, void *var, ValueType t)
|
||||
: caption(cap), group(grp), behavior(beh), linkedVariable(var), type(t) {}
|
||||
|
||||
// Método para obtener el valor como string
|
||||
std::string getValueAsString() const
|
||||
{
|
||||
if (type == ValueType::BOOL)
|
||||
return (*(static_cast<bool *>(linkedVariable))) ? "ON" : "OFF";
|
||||
else if (type == ValueType::INT)
|
||||
return std::to_string(*(static_cast<int *>(linkedVariable)));
|
||||
|
||||
return "Unknown";
|
||||
}
|
||||
};
|
||||
|
||||
// -- Variables internas ---
|
||||
bool enabled_ = false; // Indica si el menú de servicio está activo
|
||||
SDL_FRect rect_; // Rectangulo para definir el area del menú de servicio
|
||||
@@ -38,6 +83,7 @@ private:
|
||||
std::shared_ptr<Text> titleText_; // Objeto para escribir texto;
|
||||
size_t selected_ = 2; // Elemento del menú seleccionado
|
||||
Uint32 counter_ = 0; // Contador interno
|
||||
std::vector<OptionEntry> options_; // Listado con todas las opciones del menú de servicio
|
||||
|
||||
// -- Aspecto --
|
||||
Color bgColor_ = SERV_MENU_BG_COLOR; // Color de fondo
|
||||
@@ -52,6 +98,7 @@ private:
|
||||
void setAnchors(); // Establece el valor de las variables de anclaje
|
||||
void updateCounter(); // Actualiza el contador interno
|
||||
Color getSelectedColor(); // Devuelve el color del elemento seleccionado
|
||||
void initializeOptions(); // Crea todas las opciones del menú de servicio
|
||||
|
||||
// --- Patrón Singleton ---
|
||||
ServiceMenu(); // Constructor privado
|
||||
|
||||
Reference in New Issue
Block a user