ServiceMenu: trastejant cosetes
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <algorithm> // para std::clamp
|
#include <algorithm> // para std::clamp
|
||||||
#include "service_menu.h" // Necesitamos las enums como SettingsGroup
|
#include "service_menu.h" // Necesitamos las enums como SettingsGroup
|
||||||
#include "options.h" // Para acceder a las variables de configuración
|
#include "options.h" // Para acceder a las variables de configuración
|
||||||
#include "lang.h" // Para las traducciones
|
#include "lang.h" // Para las traducciones
|
||||||
@@ -13,16 +13,21 @@
|
|||||||
|
|
||||||
// --- Interfaz Base para todas las Opciones del Menú ---
|
// --- Interfaz Base para todas las Opciones del Menú ---
|
||||||
|
|
||||||
class MenuOption {
|
class MenuOption
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
enum class Behavior { ADJUST, SELECT };
|
enum class Behavior
|
||||||
|
{
|
||||||
|
ADJUST,
|
||||||
|
SELECT
|
||||||
|
};
|
||||||
|
|
||||||
MenuOption(std::string caption, ServiceMenu::SettingsGroup group, bool hidden = false)
|
MenuOption(std::string caption, ServiceMenu::SettingsGroup group, bool hidden = false)
|
||||||
: caption_(std::move(caption)), group_(group), hidden_(hidden) {}
|
: caption_(std::move(caption)), group_(group), hidden_(hidden) {}
|
||||||
|
|
||||||
virtual ~MenuOption() = default;
|
virtual ~MenuOption() = default;
|
||||||
|
|
||||||
const std::string& getCaption() const { return caption_; }
|
const std::string &getCaption() const { return caption_; }
|
||||||
ServiceMenu::SettingsGroup getGroup() const { return group_; }
|
ServiceMenu::SettingsGroup getGroup() const { return group_; }
|
||||||
bool isHidden() const { return hidden_; }
|
bool isHidden() const { return hidden_; }
|
||||||
void setHidden(bool hidden) { hidden_ = hidden; }
|
void setHidden(bool hidden) { hidden_ = hidden; }
|
||||||
@@ -33,10 +38,8 @@ public:
|
|||||||
virtual ServiceMenu::SettingsGroup getTargetGroup() const { return ServiceMenu::SettingsGroup::MAIN; }
|
virtual ServiceMenu::SettingsGroup getTargetGroup() const { return ServiceMenu::SettingsGroup::MAIN; }
|
||||||
virtual void executeAction() {}
|
virtual void executeAction() {}
|
||||||
|
|
||||||
// --- AÑADIDO ---
|
|
||||||
// Método virtual para que cada opción calcule el ancho de su valor más largo.
|
// Método virtual para que cada opción calcule el ancho de su valor más largo.
|
||||||
virtual int getMaxValueWidth(Text* text_renderer) const { return 0; }
|
virtual int getMaxValueWidth(Text *text_renderer) const { return 0; }
|
||||||
// --- FIN AÑADIDO ---
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string caption_;
|
std::string caption_;
|
||||||
@@ -44,63 +47,73 @@ protected:
|
|||||||
bool hidden_;
|
bool hidden_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// --- Clases Derivadas ---
|
// --- Clases Derivadas ---
|
||||||
|
|
||||||
class BoolOption : public MenuOption {
|
class BoolOption : public MenuOption
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
BoolOption(const std::string& cap, ServiceMenu::SettingsGroup grp, bool* var)
|
BoolOption(const std::string &cap, ServiceMenu::SettingsGroup grp, bool *var)
|
||||||
: MenuOption(cap, grp), linked_variable_(var) {}
|
: MenuOption(cap, grp), linked_variable_(var) {}
|
||||||
|
|
||||||
Behavior getBehavior() const override { return Behavior::ADJUST; }
|
Behavior getBehavior() const override { return Behavior::ADJUST; }
|
||||||
std::string getValueAsString() const override {
|
std::string getValueAsString() const override
|
||||||
|
{
|
||||||
return *linked_variable_ ? Lang::getText("[SERVICE_MENU] ON") : Lang::getText("[SERVICE_MENU] OFF");
|
return *linked_variable_ ? Lang::getText("[SERVICE_MENU] ON") : Lang::getText("[SERVICE_MENU] OFF");
|
||||||
}
|
}
|
||||||
void adjustValue(bool /*adjust_up*/) override {
|
void adjustValue(bool /*adjust_up*/) override
|
||||||
|
{
|
||||||
*linked_variable_ = !*linked_variable_;
|
*linked_variable_ = !*linked_variable_;
|
||||||
}
|
}
|
||||||
// --- AÑADIDO ---
|
int getMaxValueWidth(Text *text_renderer) const override
|
||||||
int getMaxValueWidth(Text* text_renderer) const override {
|
{
|
||||||
return std::max(
|
return std::max(
|
||||||
text_renderer->lenght(Lang::getText("[SERVICE_MENU] ON"), -2),
|
text_renderer->lenght(Lang::getText("[SERVICE_MENU] ON"), -2),
|
||||||
text_renderer->lenght(Lang::getText("[SERVICE_MENU] OFF"), -2)
|
text_renderer->lenght(Lang::getText("[SERVICE_MENU] OFF"), -2));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
// --- FIN AÑADIDO ---
|
|
||||||
private:
|
private:
|
||||||
bool* linked_variable_;
|
bool *linked_variable_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class IntOption : public MenuOption {
|
class IntOption : public MenuOption
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
IntOption(const std::string& cap, ServiceMenu::SettingsGroup grp, int* var, int min, int max, int step)
|
IntOption(const std::string &cap, ServiceMenu::SettingsGroup grp, int *var, int min, int max, int step)
|
||||||
: MenuOption(cap, grp), linked_variable_(var), min_value_(min), max_value_(max), step_value_(step) {}
|
: MenuOption(cap, grp), linked_variable_(var), min_value_(min), max_value_(max), step_value_(step) {}
|
||||||
|
|
||||||
Behavior getBehavior() const override { return Behavior::ADJUST; }
|
Behavior getBehavior() const override { return Behavior::ADJUST; }
|
||||||
std::string getValueAsString() const override { return std::to_string(*linked_variable_); }
|
std::string getValueAsString() const override { return std::to_string(*linked_variable_); }
|
||||||
void adjustValue(bool adjust_up) override {
|
void adjustValue(bool adjust_up) override
|
||||||
|
{
|
||||||
int newValue = *linked_variable_ + (adjust_up ? step_value_ : -step_value_);
|
int newValue = *linked_variable_ + (adjust_up ? step_value_ : -step_value_);
|
||||||
*linked_variable_ = std::clamp(newValue, min_value_, max_value_);
|
*linked_variable_ = std::clamp(newValue, min_value_, max_value_);
|
||||||
}
|
}
|
||||||
// --- AÑADIDO ---
|
int getMaxValueWidth(Text *text_renderer) const override
|
||||||
int getMaxValueWidth(Text* text_renderer) const override {
|
{
|
||||||
return std::max(
|
int max_width = 0;
|
||||||
text_renderer->lenght(std::to_string(min_value_), -2),
|
|
||||||
text_renderer->lenght(std::to_string(max_value_), -2)
|
// Iterar por todos los valores posibles en el rango
|
||||||
);
|
for (int value = min_value_; value <= max_value_; value += step_value_)
|
||||||
|
{
|
||||||
|
int width = text_renderer->lenght(std::to_string(value), -2);
|
||||||
|
max_width = std::max(max_width, width);
|
||||||
|
}
|
||||||
|
|
||||||
|
return max_width;
|
||||||
}
|
}
|
||||||
// --- FIN AÑADIDO ---
|
|
||||||
private:
|
private:
|
||||||
int* linked_variable_;
|
int *linked_variable_;
|
||||||
int min_value_, max_value_, step_value_;
|
int min_value_, max_value_, step_value_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ListOption : public MenuOption {
|
class ListOption : public MenuOption
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
ListOption(const std::string& cap, ServiceMenu::SettingsGroup grp,
|
ListOption(const std::string &cap, ServiceMenu::SettingsGroup grp,
|
||||||
std::vector<std::string> values,
|
std::vector<std::string> values,
|
||||||
std::function<std::string()> current_value_getter,
|
std::function<std::string()> current_value_getter,
|
||||||
std::function<void(const std::string&)> new_value_setter)
|
std::function<void(const std::string &)> new_value_setter)
|
||||||
: MenuOption(cap, grp),
|
: MenuOption(cap, grp),
|
||||||
value_list_(std::move(values)),
|
value_list_(std::move(values)),
|
||||||
getter_(std::move(current_value_getter)),
|
getter_(std::move(current_value_getter)),
|
||||||
@@ -109,11 +122,14 @@ public:
|
|||||||
{
|
{
|
||||||
sync();
|
sync();
|
||||||
}
|
}
|
||||||
|
|
||||||
void sync() {
|
void sync()
|
||||||
|
{
|
||||||
std::string current_value = getter_();
|
std::string current_value = getter_();
|
||||||
for (size_t i = 0; i < value_list_.size(); ++i) {
|
for (size_t i = 0; i < value_list_.size(); ++i)
|
||||||
if (value_list_[i] == current_value) {
|
{
|
||||||
|
if (value_list_[i] == current_value)
|
||||||
|
{
|
||||||
list_index_ = i;
|
list_index_ = i;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -121,52 +137,61 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
Behavior getBehavior() const override { return Behavior::ADJUST; }
|
Behavior getBehavior() const override { return Behavior::ADJUST; }
|
||||||
std::string getValueAsString() const override {
|
std::string getValueAsString() const override
|
||||||
|
{
|
||||||
return value_list_.empty() ? "" : value_list_[list_index_];
|
return value_list_.empty() ? "" : value_list_[list_index_];
|
||||||
}
|
}
|
||||||
void adjustValue(bool adjust_up) override {
|
void adjustValue(bool adjust_up) override
|
||||||
if (value_list_.empty()) return;
|
{
|
||||||
|
if (value_list_.empty())
|
||||||
|
return;
|
||||||
size_t size = value_list_.size();
|
size_t size = value_list_.size();
|
||||||
list_index_ = (adjust_up) ? (list_index_ + 1) % size
|
list_index_ = (adjust_up) ? (list_index_ + 1) % size
|
||||||
: (list_index_ + size - 1) % size;
|
: (list_index_ + size - 1) % size;
|
||||||
setter_(value_list_[list_index_]);
|
setter_(value_list_[list_index_]);
|
||||||
}
|
}
|
||||||
// --- AÑADIDO ---
|
int getMaxValueWidth(Text *text_renderer) const override
|
||||||
int getMaxValueWidth(Text* text_renderer) const override {
|
{
|
||||||
int max_w = 0;
|
int max_w = 0;
|
||||||
for (const auto& val : value_list_) {
|
for (const auto &val : value_list_)
|
||||||
|
{
|
||||||
max_w = std::max(max_w, text_renderer->lenght(val, -2));
|
max_w = std::max(max_w, text_renderer->lenght(val, -2));
|
||||||
}
|
}
|
||||||
return max_w;
|
return max_w;
|
||||||
}
|
}
|
||||||
// --- FIN AÑADIDO ---
|
|
||||||
private:
|
private:
|
||||||
std::vector<std::string> value_list_;
|
std::vector<std::string> value_list_;
|
||||||
std::function<std::string()> getter_;
|
std::function<std::string()> getter_;
|
||||||
std::function<void(const std::string&)> setter_;
|
std::function<void(const std::string &)> setter_;
|
||||||
size_t list_index_;
|
size_t list_index_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FolderOption : public MenuOption {
|
class FolderOption : public MenuOption
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
FolderOption(const std::string& cap, ServiceMenu::SettingsGroup grp, ServiceMenu::SettingsGroup target)
|
FolderOption(const std::string &cap, ServiceMenu::SettingsGroup grp, ServiceMenu::SettingsGroup target)
|
||||||
: MenuOption(cap, grp), target_group_(target) {}
|
: MenuOption(cap, grp), target_group_(target) {}
|
||||||
|
|
||||||
Behavior getBehavior() const override { return Behavior::SELECT; }
|
Behavior getBehavior() const override { return Behavior::SELECT; }
|
||||||
ServiceMenu::SettingsGroup getTargetGroup() const override { return target_group_; }
|
ServiceMenu::SettingsGroup getTargetGroup() const override { return target_group_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ServiceMenu::SettingsGroup target_group_;
|
ServiceMenu::SettingsGroup target_group_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ActionOption : public MenuOption {
|
class ActionOption : public MenuOption
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
ActionOption(const std::string& cap, ServiceMenu::SettingsGroup grp, std::function<void()> action, bool hidden = false)
|
ActionOption(const std::string &cap, ServiceMenu::SettingsGroup grp, std::function<void()> action, bool hidden = false)
|
||||||
: MenuOption(cap, grp, hidden), action_(std::move(action)) {}
|
: MenuOption(cap, grp, hidden), action_(std::move(action)) {}
|
||||||
|
|
||||||
Behavior getBehavior() const override { return Behavior::SELECT; }
|
Behavior getBehavior() const override { return Behavior::SELECT; }
|
||||||
void executeAction() override {
|
void executeAction() override
|
||||||
if (action_) action_();
|
{
|
||||||
|
if (action_)
|
||||||
|
action_();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::function<void()> action_;
|
std::function<void()> action_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,37 +1,40 @@
|
|||||||
#include "UIMessage.h"
|
#include "UIMessage.h"
|
||||||
#include <cmath> // Para pow
|
#include <cmath> // Para pow
|
||||||
#include "screen.h" // Para param y TEXT_CENTER
|
#include "screen.h" // Para param y TEXT_CENTER
|
||||||
|
|
||||||
// Constructor
|
// Constructor: inicializa el renderizador, el texto y el color del mensaje
|
||||||
UIMessage::UIMessage(std::shared_ptr<Text> text_renderer, const std::string& message_text, const Color& color)
|
UIMessage::UIMessage(std::shared_ptr<Text> text_renderer, const std::string &message_text, const Color &color)
|
||||||
: text_renderer_(text_renderer), text_(message_text), color_(color)
|
: text_renderer_(text_renderer), text_(message_text), color_(color) {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Muestra el mensaje en la posición base_x, base_y con animación de entrada desde arriba
|
||||||
void UIMessage::show(float base_x, float base_y)
|
void UIMessage::show(float base_x, float base_y)
|
||||||
{
|
{
|
||||||
if (visible_ && target_y_ == 0.0f) return; // Ya está visible y quieto
|
if (visible_ && target_y_ == 0.0f)
|
||||||
|
return; // Ya está visible y quieto
|
||||||
|
|
||||||
base_x_ = base_x;
|
base_x_ = base_x;
|
||||||
base_y_ = base_y;
|
base_y_ = base_y;
|
||||||
start_y_ = -8.0f; // Empieza 8 píxeles arriba
|
start_y_ = DESP_; // Empieza 8 píxeles arriba de la posición base
|
||||||
target_y_ = 0.0f; // La posición final es el base_y
|
target_y_ = 0.0f; // La posición final es la base
|
||||||
y_offset_ = start_y_;
|
y_offset_ = start_y_;
|
||||||
anim_step_ = 0;
|
anim_step_ = 0;
|
||||||
animating_ = true;
|
animating_ = true;
|
||||||
visible_ = true;
|
visible_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Oculta el mensaje con animación de salida hacia arriba
|
||||||
void UIMessage::hide()
|
void UIMessage::hide()
|
||||||
{
|
{
|
||||||
if (!visible_) return;
|
if (!visible_)
|
||||||
|
return;
|
||||||
|
|
||||||
start_y_ = y_offset_;
|
start_y_ = y_offset_; // Comienza desde la posición actual
|
||||||
target_y_ = -8.0f; // Sube 8 píxeles para desaparecer
|
target_y_ = DESP_; // Termina 8 píxeles arriba de la base
|
||||||
anim_step_ = 0;
|
anim_step_ = 0;
|
||||||
animating_ = true;
|
animating_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Actualiza el estado de la animación (debe llamarse cada frame)
|
||||||
void UIMessage::update()
|
void UIMessage::update()
|
||||||
{
|
{
|
||||||
if (animating_)
|
if (animating_)
|
||||||
@@ -40,27 +43,35 @@ void UIMessage::update()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Interpola la posición vertical del mensaje usando ease out cubic
|
||||||
void UIMessage::updateAnimation()
|
void UIMessage::updateAnimation()
|
||||||
{
|
{
|
||||||
anim_step_++;
|
anim_step_++;
|
||||||
float t = static_cast<float>(anim_step_) / ANIMATION_STEPS;
|
float t = static_cast<float>(anim_step_) / ANIMATION_STEPS;
|
||||||
|
|
||||||
// Ease Out Cubic para una animación más suave
|
if (target_y_ > start_y_)
|
||||||
t = 1 - pow(1 - t, 3);
|
{
|
||||||
|
// Animación de entrada (ease out cubic)
|
||||||
|
t = 1 - pow(1 - t, 3);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Animación de salida (ease in cubic)
|
||||||
|
t = pow(t, 3);
|
||||||
|
}
|
||||||
|
|
||||||
y_offset_ = start_y_ + (target_y_ - start_y_) * t;
|
y_offset_ = start_y_ + (target_y_ - start_y_) * t;
|
||||||
|
|
||||||
if (anim_step_ >= ANIMATION_STEPS)
|
if (anim_step_ >= ANIMATION_STEPS)
|
||||||
{
|
{
|
||||||
y_offset_ = target_y_;
|
y_offset_ = target_y_;
|
||||||
animating_ = false;
|
animating_ = false;
|
||||||
|
if (target_y_ < 0.0f)
|
||||||
// Si el objetivo era ocultarlo (target_y negativo), lo marcamos como no visible
|
|
||||||
if (target_y_ < 0.0f) {
|
|
||||||
visible_ = false;
|
visible_ = false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Dibuja el mensaje en pantalla si está visible
|
||||||
void UIMessage::render()
|
void UIMessage::render()
|
||||||
{
|
{
|
||||||
if (visible_)
|
if (visible_)
|
||||||
@@ -75,7 +86,14 @@ void UIMessage::render()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Devuelve true si el mensaje está visible actualmente
|
||||||
bool UIMessage::isVisible() const
|
bool UIMessage::isVisible() const
|
||||||
{
|
{
|
||||||
return visible_;
|
return visible_;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Permite actualizar la posición base Y del mensaje (por ejemplo, si el menú se mueve)
|
||||||
|
void UIMessage::setBaseY(float new_base_y)
|
||||||
|
{
|
||||||
|
base_y_ = new_base_y;
|
||||||
}
|
}
|
||||||
@@ -5,36 +5,51 @@
|
|||||||
#include "text.h"
|
#include "text.h"
|
||||||
#include "utils.h" // Para Color
|
#include "utils.h" // Para Color
|
||||||
|
|
||||||
|
// Clase para mostrar mensajes animados en la interfaz de usuario
|
||||||
class UIMessage
|
class UIMessage
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UIMessage(std::shared_ptr<Text> text_renderer, const std::string& message_text, const Color& color);
|
// Constructor: recibe el renderizador de texto, el mensaje y el color
|
||||||
|
UIMessage(std::shared_ptr<Text> text_renderer, const std::string &message_text, const Color &color);
|
||||||
|
|
||||||
|
// Muestra el mensaje en la posición base_x, base_y con animación de entrada
|
||||||
void show(float base_x, float base_y);
|
void show(float base_x, float base_y);
|
||||||
|
|
||||||
|
// Oculta el mensaje con animación de salida
|
||||||
void hide();
|
void hide();
|
||||||
|
|
||||||
|
// Actualiza el estado de la animación (debe llamarse cada frame)
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
|
// Dibuja el mensaje en pantalla si está visible
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
|
// Indica si el mensaje está visible actualmente
|
||||||
bool isVisible() const;
|
bool isVisible() const;
|
||||||
|
|
||||||
|
// Permite actualizar la posición base Y del mensaje (por ejemplo, si el menú se mueve)
|
||||||
|
void setBaseY(float new_base_y);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Configuración
|
// --- Configuración ---
|
||||||
std::shared_ptr<Text> text_renderer_;
|
std::shared_ptr<Text> text_renderer_; // Renderizador de texto
|
||||||
std::string text_;
|
std::string text_; // Texto del mensaje a mostrar
|
||||||
Color color_;
|
Color color_; // Color del texto
|
||||||
|
|
||||||
// Estado
|
// --- Estado ---
|
||||||
bool visible_ = false;
|
bool visible_ = false; // Indica si el mensaje está visible
|
||||||
bool animating_ = false;
|
bool animating_ = false; // Indica si el mensaje está en proceso de animación
|
||||||
float base_x_ = 0.0f;
|
float base_x_ = 0.0f; // Posición X base donde se muestra el mensaje
|
||||||
float base_y_ = 0.0f;
|
float base_y_ = 0.0f; // Posición Y base donde se muestra el mensaje
|
||||||
float y_offset_ = 0.0f;
|
float y_offset_ = 0.0f; // Desplazamiento vertical actual del mensaje (para animación)
|
||||||
|
|
||||||
// Animación
|
// --- Animación ---
|
||||||
float start_y_ = 0.0f;
|
float start_y_ = 0.0f; // Posición Y inicial de la animación
|
||||||
float target_y_ = 0.0f;
|
float target_y_ = 0.0f; // Posición Y objetivo de la animación
|
||||||
int anim_step_ = 0;
|
int anim_step_ = 0; // Paso actual de la animación
|
||||||
static constexpr int ANIMATION_STEPS = 12;
|
static constexpr int ANIMATION_STEPS = 8; // Número total de pasos de la animación
|
||||||
|
static constexpr float DESP_ = -8.0f; // Distancia a desplazarse
|
||||||
|
|
||||||
|
// Actualiza la interpolación de la animación (ease out/in cubic)
|
||||||
void updateAnimation();
|
void updateAnimation();
|
||||||
};
|
};
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#include "service_menu.h"
|
#include "service_menu.h"
|
||||||
#include "MenuOption.h"
|
#include "MenuOption.h"
|
||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include <array>
|
#include <array>
|
||||||
@@ -25,8 +25,7 @@ ServiceMenu::ServiceMenu()
|
|||||||
restart_message_ui_ = std::make_unique<UIMessage>(
|
restart_message_ui_ = std::make_unique<UIMessage>(
|
||||||
element_text_,
|
element_text_,
|
||||||
Lang::getText("[SERVICE_MENU] NEED_RESTART_MESSAGE"),
|
Lang::getText("[SERVICE_MENU] NEED_RESTART_MESSAGE"),
|
||||||
title_color_
|
title_color_);
|
||||||
);
|
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,25 +47,24 @@ void ServiceMenu::initializeOptions()
|
|||||||
options_.push_back(std::make_unique<IntOption>(Lang::getText("[SERVICE_MENU] MAIN_VOLUME"), SettingsGroup::AUDIO, &Options::audio.volume, 0, 100, 5));
|
options_.push_back(std::make_unique<IntOption>(Lang::getText("[SERVICE_MENU] MAIN_VOLUME"), SettingsGroup::AUDIO, &Options::audio.volume, 0, 100, 5));
|
||||||
options_.push_back(std::make_unique<IntOption>(Lang::getText("[SERVICE_MENU] MUSIC_VOLUME"), SettingsGroup::AUDIO, &Options::audio.music.volume, 0, 100, 5));
|
options_.push_back(std::make_unique<IntOption>(Lang::getText("[SERVICE_MENU] MUSIC_VOLUME"), SettingsGroup::AUDIO, &Options::audio.music.volume, 0, 100, 5));
|
||||||
options_.push_back(std::make_unique<IntOption>(Lang::getText("[SERVICE_MENU] SFX_VOLUME"), SettingsGroup::AUDIO, &Options::audio.sound.volume, 0, 100, 5));
|
options_.push_back(std::make_unique<IntOption>(Lang::getText("[SERVICE_MENU] SFX_VOLUME"), SettingsGroup::AUDIO, &Options::audio.sound.volume, 0, 100, 5));
|
||||||
|
|
||||||
// --- Settings ---
|
// --- Settings ---
|
||||||
options_.push_back(std::make_unique<BoolOption>(Lang::getText("[SERVICE_MENU] AUTOFIRE"), SettingsGroup::SETTINGS, &Options::settings.autofire));
|
options_.push_back(std::make_unique<BoolOption>(Lang::getText("[SERVICE_MENU] AUTOFIRE"), SettingsGroup::SETTINGS, &Options::settings.autofire));
|
||||||
options_.push_back(std::make_unique<ListOption>(Lang::getText("[SERVICE_MENU] LANGUAGE"), SettingsGroup::SETTINGS,
|
options_.push_back(std::make_unique<ListOption>(Lang::getText("[SERVICE_MENU] LANGUAGE"), SettingsGroup::SETTINGS, std::vector<std::string>{Lang::getText("[SERVICE_MENU] LANG_ES"), Lang::getText("[SERVICE_MENU] LANG_BA"), Lang::getText("[SERVICE_MENU] LANG_EN")}, []()
|
||||||
std::vector<std::string>{Lang::getText("[SERVICE_MENU] LANG_ES"), Lang::getText("[SERVICE_MENU] LANG_BA"), Lang::getText("[SERVICE_MENU] LANG_EN")},
|
{ return Lang::getNameFromCode(Options::pending_changes.new_language); }, [](const std::string &val)
|
||||||
[](){ return Lang::getNameFromCode(Options::pending_changes.new_language); },
|
{ Options::pending_changes.new_language = Lang::getCodeFromName(val); Options::checkPendingChanges(); }));
|
||||||
[](const std::string& val){ Options::pending_changes.new_language = Lang::getCodeFromName(val); Options::checkPendingChanges(); }
|
options_.push_back(std::make_unique<ListOption>(Lang::getText("[SERVICE_MENU] DIFFICULTY"), SettingsGroup::SETTINGS, std::vector<std::string>{Lang::getText("[SERVICE_MENU] EASY"), Lang::getText("[SERVICE_MENU] NORMAL"), Lang::getText("[SERVICE_MENU] HARD")}, []()
|
||||||
));
|
{ return Options::getDifficultyNameFromCode(Options::pending_changes.new_difficulty); }, [](const std::string &val)
|
||||||
options_.push_back(std::make_unique<ListOption>(Lang::getText("[SERVICE_MENU] DIFFICULTY"), SettingsGroup::SETTINGS,
|
{ Options::pending_changes.new_difficulty = Options::getDifficultyCodeFromName(val); Options::checkPendingChanges(); }));
|
||||||
std::vector<std::string>{Lang::getText("[SERVICE_MENU] EASY"), Lang::getText("[SERVICE_MENU] NORMAL"), Lang::getText("[SERVICE_MENU] HARD")},
|
|
||||||
[](){ return Options::getDifficultyNameFromCode(Options::pending_changes.new_difficulty); },
|
|
||||||
[](const std::string& val){ Options::pending_changes.new_difficulty = Options::getDifficultyCodeFromName(val); Options::checkPendingChanges(); }
|
|
||||||
));
|
|
||||||
options_.push_back(std::make_unique<BoolOption>(Lang::getText("[SERVICE_MENU] ENABLE_SHUTDOWN"), SettingsGroup::SETTINGS, &Options::settings.shutdown_enabled));
|
options_.push_back(std::make_unique<BoolOption>(Lang::getText("[SERVICE_MENU] ENABLE_SHUTDOWN"), SettingsGroup::SETTINGS, &Options::settings.shutdown_enabled));
|
||||||
|
|
||||||
// --- System ---
|
// --- System ---
|
||||||
options_.push_back(std::make_unique<ActionOption>(Lang::getText("[SERVICE_MENU] RESET"), SettingsGroup::SYSTEM, [this](){ Section::name = Section::Name::RESET; toggle(); }));
|
options_.push_back(std::make_unique<ActionOption>(Lang::getText("[SERVICE_MENU] RESET"), SettingsGroup::SYSTEM, [this]()
|
||||||
options_.push_back(std::make_unique<ActionOption>(Lang::getText("[SERVICE_MENU] QUIT"), SettingsGroup::SYSTEM, [](){ Section::name = Section::Name::QUIT; Section::options = Section::Options::NONE; }));
|
{ Section::name = Section::Name::RESET; toggle(); }));
|
||||||
options_.push_back(std::make_unique<ActionOption>(Lang::getText("[SERVICE_MENU] SHUTDOWN"), SettingsGroup::SYSTEM, [](){ Section::name = Section::Name::QUIT; Section::options = Section::Options::SHUTDOWN; }, !Options::settings.shutdown_enabled ));
|
options_.push_back(std::make_unique<ActionOption>(Lang::getText("[SERVICE_MENU] QUIT"), SettingsGroup::SYSTEM, []()
|
||||||
|
{ Section::name = Section::Name::QUIT; Section::options = Section::Options::NONE; }));
|
||||||
|
options_.push_back(std::make_unique<ActionOption>(Lang::getText("[SERVICE_MENU] SHUTDOWN"), SettingsGroup::SYSTEM, []()
|
||||||
|
{ Section::name = Section::Name::QUIT; Section::options = Section::Options::SHUTDOWN; }, !Options::settings.shutdown_enabled));
|
||||||
|
|
||||||
// --- Main Menu ---
|
// --- Main Menu ---
|
||||||
options_.push_back(std::make_unique<FolderOption>(Lang::getText("[SERVICE_MENU] VIDEO"), SettingsGroup::MAIN, SettingsGroup::VIDEO));
|
options_.push_back(std::make_unique<FolderOption>(Lang::getText("[SERVICE_MENU] VIDEO"), SettingsGroup::MAIN, SettingsGroup::VIDEO));
|
||||||
@@ -79,9 +77,10 @@ void ServiceMenu::initializeOptions()
|
|||||||
|
|
||||||
void ServiceMenu::adjustOption(bool adjust_up)
|
void ServiceMenu::adjustOption(bool adjust_up)
|
||||||
{
|
{
|
||||||
if (display_options_.empty() || selected_ >= display_options_.size()) return;
|
if (display_options_.empty() || selected_ >= display_options_.size())
|
||||||
|
return;
|
||||||
auto& selected_option = display_options_.at(selected_);
|
|
||||||
|
auto &selected_option = display_options_.at(selected_);
|
||||||
if (selected_option->getBehavior() == MenuOption::Behavior::ADJUST)
|
if (selected_option->getBehavior() == MenuOption::Behavior::ADJUST)
|
||||||
{
|
{
|
||||||
selected_option->adjustValue(adjust_up);
|
selected_option->adjustValue(adjust_up);
|
||||||
@@ -93,14 +92,15 @@ void ServiceMenu::adjustOption(bool adjust_up)
|
|||||||
|
|
||||||
void ServiceMenu::selectOption()
|
void ServiceMenu::selectOption()
|
||||||
{
|
{
|
||||||
if (display_options_.empty() || selected_ >= display_options_.size()) return;
|
if (display_options_.empty() || selected_ >= display_options_.size())
|
||||||
|
return;
|
||||||
|
|
||||||
if (current_settings_group_ == SettingsGroup::MAIN)
|
if (current_settings_group_ == SettingsGroup::MAIN)
|
||||||
main_menu_selected_ = selected_;
|
main_menu_selected_ = selected_;
|
||||||
|
|
||||||
auto& selected_option = display_options_.at(selected_);
|
auto &selected_option = display_options_.at(selected_);
|
||||||
|
|
||||||
if (auto folder = dynamic_cast<FolderOption*>(selected_option))
|
if (auto folder = dynamic_cast<FolderOption *>(selected_option))
|
||||||
{
|
{
|
||||||
previous_settings_group_ = current_settings_group_;
|
previous_settings_group_ = current_settings_group_;
|
||||||
current_settings_group_ = folder->getTargetGroup();
|
current_settings_group_ = folder->getTargetGroup();
|
||||||
@@ -111,19 +111,18 @@ void ServiceMenu::selectOption()
|
|||||||
playMenuSound();
|
playMenuSound();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selected_option->getBehavior() == MenuOption::Behavior::SELECT)
|
if (selected_option->getBehavior() == MenuOption::Behavior::SELECT)
|
||||||
{
|
{
|
||||||
selected_option->executeAction();
|
selected_option->executeAction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// --- Métodos de Cálculo de Ancho (Reincorporados y adaptados) ---
|
// --- Métodos de Cálculo de Ancho (Reincorporados y adaptados) ---
|
||||||
|
|
||||||
void ServiceMenu::precalculateMenuWidths()
|
void ServiceMenu::precalculateMenuWidths()
|
||||||
{
|
{
|
||||||
for (int& w : group_menu_widths_)
|
for (int &w : group_menu_widths_)
|
||||||
w = MIN_WIDTH_;
|
w = MIN_WIDTH_;
|
||||||
|
|
||||||
for (int group = 0; group < 5; ++group)
|
for (int group = 0; group < 5; ++group)
|
||||||
@@ -131,19 +130,23 @@ void ServiceMenu::precalculateMenuWidths()
|
|||||||
SettingsGroup sg = static_cast<SettingsGroup>(group);
|
SettingsGroup sg = static_cast<SettingsGroup>(group);
|
||||||
int max_option_width = 0;
|
int max_option_width = 0;
|
||||||
int max_value_width = 0;
|
int max_value_width = 0;
|
||||||
|
|
||||||
for (const auto& option : options_)
|
for (const auto &option : options_)
|
||||||
{
|
{
|
||||||
if (option->getGroup() != sg) continue;
|
if (option->getGroup() != sg)
|
||||||
|
continue;
|
||||||
|
|
||||||
max_option_width = std::max(max_option_width, element_text_->lenght(option->getCaption(), -2));
|
max_option_width = std::max(max_option_width, element_text_->lenght(option->getCaption(), -2));
|
||||||
max_value_width = std::max(max_value_width, option->getMaxValueWidth(element_text_.get()));
|
max_value_width = std::max(max_value_width, option->getMaxValueWidth(element_text_.get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getGroupAlignment(sg) == GroupAlignment::LEFT) {
|
if (getGroupAlignment(sg) == GroupAlignment::LEFT)
|
||||||
size_t total_width = max_option_width + MIN_GAP_OPTION_VALUE_ + max_value_width + (OPTIONS_HORIZONTAL_PADDING_ * 2);
|
{
|
||||||
group_menu_widths_[group] = std::max((int)MIN_WIDTH_, (int)total_width);
|
size_t total_width = max_option_width + MIN_GAP_OPTION_VALUE_ + max_value_width + (OPTIONS_HORIZONTAL_PADDING_ * 2);
|
||||||
} else {
|
group_menu_widths_[group] = std::max((int)MIN_WIDTH_, (int)total_width);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
size_t total_width = max_option_width + (OPTIONS_HORIZONTAL_PADDING_ * 2);
|
size_t total_width = max_option_width + (OPTIONS_HORIZONTAL_PADDING_ * 2);
|
||||||
group_menu_widths_[group] = std::max((int)MIN_WIDTH_, (int)total_width);
|
group_menu_widths_[group] = std::max((int)MIN_WIDTH_, (int)total_width);
|
||||||
}
|
}
|
||||||
@@ -155,17 +158,25 @@ int ServiceMenu::getMenuWidthForGroup(SettingsGroup group) const
|
|||||||
return group_menu_widths_[static_cast<int>(group)];
|
return group_menu_widths_[static_cast<int>(group)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// --- Resto de métodos ---
|
// --- Resto de métodos ---
|
||||||
// (Incluyendo el resto de definiciones que ya tenías para que el archivo esté completo)
|
// (Incluyendo el resto de definiciones que ya tenías para que el archivo esté completo)
|
||||||
|
|
||||||
void ServiceMenu::toggle() { enabled_ = !enabled_; if (!enabled_) { reset(); } }
|
void ServiceMenu::toggle()
|
||||||
|
{
|
||||||
|
enabled_ = !enabled_;
|
||||||
|
if (!enabled_)
|
||||||
|
{
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ServiceMenu::render() {
|
void ServiceMenu::render()
|
||||||
|
{
|
||||||
if (enabled_)
|
if (enabled_)
|
||||||
{
|
{
|
||||||
int y = rect_.y;
|
int y = rect_.y;
|
||||||
if (aspect_ == Aspect::ASPECT1) {
|
if (aspect_ == Aspect::ASPECT1)
|
||||||
|
{
|
||||||
SDL_FRect shadowRect = {rect_.x + 5, rect_.y + 5, rect_.w, rect_.h};
|
SDL_FRect shadowRect = {rect_.x + 5, rect_.y + 5, rect_.w, rect_.h};
|
||||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 64);
|
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 64);
|
||||||
SDL_RenderFillRect(Screen::get()->getRenderer(), &shadowRect);
|
SDL_RenderFillRect(Screen::get()->getRenderer(), &shadowRect);
|
||||||
@@ -182,35 +193,53 @@ void ServiceMenu::render() {
|
|||||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), title_color_.r, title_color_.g, title_color_.b, 255);
|
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), title_color_.r, title_color_.g, title_color_.b, 255);
|
||||||
SDL_RenderLine(Screen::get()->getRenderer(), rect_.x + OPTIONS_HORIZONTAL_PADDING_, y, rect_.x + rect_.w - OPTIONS_HORIZONTAL_PADDING_, y);
|
SDL_RenderLine(Screen::get()->getRenderer(), rect_.x + OPTIONS_HORIZONTAL_PADDING_, y, rect_.x + rect_.w - OPTIONS_HORIZONTAL_PADDING_, y);
|
||||||
y = options_y_;
|
y = options_y_;
|
||||||
for (size_t i = 0; i < option_pairs_.size(); ++i) {
|
for (size_t i = 0; i < option_pairs_.size(); ++i)
|
||||||
if (getGroupAlignment(current_settings_group_) == GroupAlignment::LEFT) {
|
{
|
||||||
|
if (getGroupAlignment(current_settings_group_) == GroupAlignment::LEFT)
|
||||||
|
{
|
||||||
element_text_->writeColored(rect_.x + OPTIONS_HORIZONTAL_PADDING_, y, option_pairs_.at(i).first, i == selected_ ? selected_color_ : text_color_, -2);
|
element_text_->writeColored(rect_.x + OPTIONS_HORIZONTAL_PADDING_, y, option_pairs_.at(i).first, i == selected_ ? selected_color_ : text_color_, -2);
|
||||||
const int X = rect_.x + rect_.w - OPTIONS_HORIZONTAL_PADDING_ - element_text_->lenght(std::string(option_pairs_.at(i).second), -2);
|
const int X = rect_.x + rect_.w - OPTIONS_HORIZONTAL_PADDING_ - element_text_->lenght(std::string(option_pairs_.at(i).second), -2);
|
||||||
element_text_->writeColored(X, y, std::string(option_pairs_.at(i).second), i == selected_ ? selected_color_ : text_color_, -2);
|
element_text_->writeColored(X, y, std::string(option_pairs_.at(i).second), i == selected_ ? selected_color_ : text_color_, -2);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
element_text_->writeDX(TEXT_CENTER | TEXT_COLOR, rect_.x + rect_.w / 2, y, option_pairs_.at(i).first, -2, i == selected_ ? selected_color_ : text_color_);
|
element_text_->writeDX(TEXT_CENTER | TEXT_COLOR, rect_.x + rect_.w / 2, y, option_pairs_.at(i).first, -2, i == selected_ ? selected_color_ : text_color_);
|
||||||
}
|
}
|
||||||
y += options_height_ + options_padding_;
|
y += options_height_ + options_padding_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void ServiceMenu::update() {
|
void ServiceMenu::update()
|
||||||
if (resizing_) { updateResizeAnimation(); return; }
|
{
|
||||||
if (enabled_) { updateCounter(); selected_color_ = getSelectedColor(); }
|
if (resizing_)
|
||||||
|
{
|
||||||
|
updateResizeAnimation();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (enabled_)
|
||||||
|
{
|
||||||
|
updateCounter();
|
||||||
|
selected_color_ = getSelectedColor();
|
||||||
|
}
|
||||||
bool now_pending = Options::pending_changes.has_pending_changes;
|
bool now_pending = Options::pending_changes.has_pending_changes;
|
||||||
if (now_pending != last_pending_changes_) {
|
if (now_pending != last_pending_changes_)
|
||||||
if (now_pending) {
|
{
|
||||||
float msg_x = param.game.game_area.center_x;
|
if (now_pending)
|
||||||
float msg_y = rect_.y + 39.0f;
|
{
|
||||||
restart_message_ui_->show(msg_x, msg_y);
|
const float MSG_X = param.game.game_area.center_x;
|
||||||
} else {
|
const float MSG_Y = rect_.y + RESET_TEXT_POS_Y_;
|
||||||
|
restart_message_ui_->show(MSG_X, MSG_Y);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
restart_message_ui_->hide();
|
restart_message_ui_->hide();
|
||||||
}
|
}
|
||||||
last_pending_changes_ = now_pending;
|
last_pending_changes_ = now_pending;
|
||||||
}
|
}
|
||||||
restart_message_ui_->update();
|
restart_message_ui_->update();
|
||||||
}
|
}
|
||||||
void ServiceMenu::reset() {
|
void ServiceMenu::reset()
|
||||||
|
{
|
||||||
selected_ = 0;
|
selected_ = 0;
|
||||||
previous_settings_group_ = current_settings_group_ = SettingsGroup::MAIN;
|
previous_settings_group_ = current_settings_group_ = SettingsGroup::MAIN;
|
||||||
title_ = settingsGroupToString(current_settings_group_);
|
title_ = settingsGroupToString(current_settings_group_);
|
||||||
@@ -218,20 +247,41 @@ void ServiceMenu::reset() {
|
|||||||
updateMenu(current_settings_group_);
|
updateMenu(current_settings_group_);
|
||||||
setAnchors();
|
setAnchors();
|
||||||
}
|
}
|
||||||
void ServiceMenu::setSelectorUp() { if (display_options_.empty()) return; selected_ = (selected_ > 0) ? selected_ - 1 : display_options_.size() - 1; playMenuSound(); }
|
void ServiceMenu::setSelectorUp()
|
||||||
void ServiceMenu::setSelectorDown() { if (display_options_.empty()) return; selected_ = (selected_ + 1) % display_options_.size(); playMenuSound(); }
|
{
|
||||||
void ServiceMenu::moveBack() {
|
if (display_options_.empty())
|
||||||
if (current_settings_group_ == SettingsGroup::MAIN) { enabled_ = false; return; }
|
return;
|
||||||
else {
|
selected_ = (selected_ > 0) ? selected_ - 1 : display_options_.size() - 1;
|
||||||
if (previous_settings_group_ == SettingsGroup::MAIN) selected_ = main_menu_selected_;
|
playMenuSound();
|
||||||
else selected_ = 0;
|
}
|
||||||
|
void ServiceMenu::setSelectorDown()
|
||||||
|
{
|
||||||
|
if (display_options_.empty())
|
||||||
|
return;
|
||||||
|
selected_ = (selected_ + 1) % display_options_.size();
|
||||||
|
playMenuSound();
|
||||||
|
}
|
||||||
|
void ServiceMenu::moveBack()
|
||||||
|
{
|
||||||
|
if (current_settings_group_ == SettingsGroup::MAIN)
|
||||||
|
{
|
||||||
|
enabled_ = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (previous_settings_group_ == SettingsGroup::MAIN)
|
||||||
|
selected_ = main_menu_selected_;
|
||||||
|
else
|
||||||
|
selected_ = 0;
|
||||||
current_settings_group_ = previous_settings_group_;
|
current_settings_group_ = previous_settings_group_;
|
||||||
updateMenu(current_settings_group_);
|
updateMenu(current_settings_group_);
|
||||||
setOptionsPosition();
|
setOptionsPosition();
|
||||||
playMenuSound();
|
playMenuSound();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void ServiceMenu::setAnchors() {
|
void ServiceMenu::setAnchors()
|
||||||
|
{
|
||||||
const size_t MAX_ENTRIES = findLargestGroupSize();
|
const size_t MAX_ENTRIES = findLargestGroupSize();
|
||||||
options_height_ = element_text_->getCharacterSize();
|
options_height_ = element_text_->getCharacterSize();
|
||||||
options_padding_ = 5;
|
options_padding_ = 5;
|
||||||
@@ -245,114 +295,173 @@ void ServiceMenu::setAnchors() {
|
|||||||
rect_ = {(param.game.width - width_) / 2.0f, (param.game.height - height_) / 2.0f, static_cast<float>(width_), static_cast<float>(height_)};
|
rect_ = {(param.game.width - width_) / 2.0f, (param.game.height - height_) / 2.0f, static_cast<float>(width_), static_cast<float>(height_)};
|
||||||
setOptionsPosition();
|
setOptionsPosition();
|
||||||
}
|
}
|
||||||
void ServiceMenu::setOptionsPosition() {
|
void ServiceMenu::setOptionsPosition()
|
||||||
|
{
|
||||||
resize();
|
resize();
|
||||||
SDL_FRect new_rect = {(param.game.width - width_) / 2.0f, (param.game.height - height_) / 2.0f, static_cast<float>(width_), static_cast<float>(height_)};
|
SDL_FRect new_rect = {(param.game.width - width_) / 2.0f, (param.game.height - height_) / 2.0f, static_cast<float>(width_), static_cast<float>(height_)};
|
||||||
options_y_ = new_rect.y + upper_height_ + lower_padding_;
|
options_y_ = new_rect.y + upper_height_ + lower_padding_;
|
||||||
}
|
}
|
||||||
void ServiceMenu::resize() {
|
void ServiceMenu::resize()
|
||||||
|
{
|
||||||
int menu_width = getMenuWidthForGroup(current_settings_group_);
|
int menu_width = getMenuWidthForGroup(current_settings_group_);
|
||||||
width_ = menu_width;
|
width_ = menu_width;
|
||||||
lower_height_ = ((display_options_.size() > 0 ? display_options_.size() - 1 : 0) * (options_height_ + options_padding_)) + options_height_ + (lower_padding_ * 2);
|
lower_height_ = ((display_options_.size() > 0 ? display_options_.size() - 1 : 0) * (options_height_ + options_padding_)) + options_height_ + (lower_padding_ * 2);
|
||||||
height_ = upper_height_ + lower_height_;
|
height_ = upper_height_ + lower_height_;
|
||||||
SDL_FRect new_rect = {(param.game.width - width_) / 2.0f, (param.game.height - height_) / 2.0f, static_cast<float>(width_), static_cast<float>(height_)};
|
SDL_FRect new_rect = {(param.game.width - width_) / 2.0f, (param.game.height - height_) / 2.0f, static_cast<float>(width_), static_cast<float>(height_)};
|
||||||
if (rect_.x != new_rect.x || rect_.y != new_rect.y || rect_.w != new_rect.w || rect_.h != new_rect.h) {
|
if (rect_.x != new_rect.x || rect_.y != new_rect.y || rect_.w != new_rect.w || rect_.h != new_rect.h)
|
||||||
|
{
|
||||||
rect_anim_from_ = rect_;
|
rect_anim_from_ = rect_;
|
||||||
rect_anim_to_ = new_rect;
|
rect_anim_to_ = new_rect;
|
||||||
resize_anim_step_ = 0;
|
resize_anim_step_ = 0;
|
||||||
resizing_ = true;
|
resizing_ = true;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
rect_ = new_rect;
|
rect_ = new_rect;
|
||||||
resizing_ = false;
|
resizing_ = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void ServiceMenu::updateResizeAnimation() {
|
void ServiceMenu::updateResizeAnimation()
|
||||||
if (!resizing_) return;
|
{
|
||||||
|
if (!resizing_)
|
||||||
|
return;
|
||||||
++resize_anim_step_;
|
++resize_anim_step_;
|
||||||
float t = static_cast<float>(resize_anim_step_) / resize_anim_steps_;
|
float t = static_cast<float>(resize_anim_step_) / resize_anim_steps_;
|
||||||
if (t >= 1.0f) { rect_ = rect_anim_to_; resizing_ = false; return; }
|
if (t >= 1.0f)
|
||||||
|
{
|
||||||
|
rect_ = rect_anim_to_;
|
||||||
|
resizing_ = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
float ease = 1 - (1 - t) * (1 - t);
|
float ease = 1 - (1 - t) * (1 - t);
|
||||||
rect_.x = rect_anim_from_.x + (rect_anim_to_.x - rect_anim_from_.x) * ease;
|
rect_.x = rect_anim_from_.x + (rect_anim_to_.x - rect_anim_from_.x) * ease;
|
||||||
rect_.y = rect_anim_from_.y + (rect_anim_to_.y - rect_anim_from_.y) * ease;
|
rect_.y = rect_anim_from_.y + (rect_anim_to_.y - rect_anim_from_.y) * ease;
|
||||||
rect_.w = rect_anim_from_.w + (rect_anim_to_.w - rect_anim_from_.w) * ease;
|
rect_.w = rect_anim_from_.w + (rect_anim_to_.w - rect_anim_from_.w) * ease;
|
||||||
rect_.h = rect_anim_from_.h + (rect_anim_to_.h - rect_anim_from_.h) * ease;
|
rect_.h = rect_anim_from_.h + (rect_anim_to_.h - rect_anim_from_.h) * ease;
|
||||||
|
restart_message_ui_->setBaseY(rect_.y + RESET_TEXT_POS_Y_);
|
||||||
}
|
}
|
||||||
void ServiceMenu::updateCounter() { static Uint64 lastUpdate = SDL_GetTicks(); Uint64 currentTicks = SDL_GetTicks(); if (currentTicks - lastUpdate >= 50) { counter_++; lastUpdate = currentTicks; } }
|
void ServiceMenu::updateCounter()
|
||||||
Color ServiceMenu::getSelectedColor() const {
|
{
|
||||||
static std::array<Color, 12> colors = { Color(0xFF, 0xFB, 0x8A), Color(0xFF, 0xE4, 0x5D), Color(0xFF, 0xD1, 0x3C), Color(0xFF, 0xBF, 0x23), Color(0xFF, 0xAA, 0x12), Color(0xE6, 0x9A, 0x08), Color(0xE6, 0x9A, 0x08), Color(0xFF, 0xAA, 0x12), Color(0xFF, 0xBF, 0x23), Color(0xFF, 0xD1, 0x3C), Color(0xFF, 0xE4, 0x5D), Color(0xFF, 0xFB, 0x8A) };
|
static Uint64 lastUpdate = SDL_GetTicks();
|
||||||
|
Uint64 currentTicks = SDL_GetTicks();
|
||||||
|
if (currentTicks - lastUpdate >= 50)
|
||||||
|
{
|
||||||
|
counter_++;
|
||||||
|
lastUpdate = currentTicks;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Color ServiceMenu::getSelectedColor() const
|
||||||
|
{
|
||||||
|
static std::array<Color, 12> colors = {Color(0xFF, 0xFB, 0x8A), Color(0xFF, 0xE4, 0x5D), Color(0xFF, 0xD1, 0x3C), Color(0xFF, 0xBF, 0x23), Color(0xFF, 0xAA, 0x12), Color(0xE6, 0x9A, 0x08), Color(0xE6, 0x9A, 0x08), Color(0xFF, 0xAA, 0x12), Color(0xFF, 0xBF, 0x23), Color(0xFF, 0xD1, 0x3C), Color(0xFF, 0xE4, 0x5D), Color(0xFF, 0xFB, 0x8A)};
|
||||||
return colors.at(counter_ % colors.size());
|
return colors.at(counter_ % colors.size());
|
||||||
}
|
}
|
||||||
void ServiceMenu::playMenuSound() { Audio::get()->playSound(MENU_SOUND_); }
|
void ServiceMenu::playMenuSound() { Audio::get()->playSound(MENU_SOUND_); }
|
||||||
void ServiceMenu::updateMenu(SettingsGroup group) {
|
void ServiceMenu::updateMenu(SettingsGroup group)
|
||||||
|
{
|
||||||
title_ = settingsGroupToString(group);
|
title_ = settingsGroupToString(group);
|
||||||
AdjustListValues();
|
AdjustListValues();
|
||||||
option_pairs_ = getOptionPairs(group);
|
option_pairs_ = getOptionPairs(group);
|
||||||
display_options_ = getOptionsByGroup(group);
|
display_options_ = getOptionsByGroup(group);
|
||||||
resize();
|
resize();
|
||||||
}
|
}
|
||||||
int ServiceMenu::findLargestGroupSize() const {
|
int ServiceMenu::findLargestGroupSize() const
|
||||||
|
{
|
||||||
std::unordered_map<SettingsGroup, int> group_counts;
|
std::unordered_map<SettingsGroup, int> group_counts;
|
||||||
for (const auto& option : options_) ++group_counts[option->getGroup()];
|
for (const auto &option : options_)
|
||||||
|
++group_counts[option->getGroup()];
|
||||||
int max_size = 0;
|
int max_size = 0;
|
||||||
for (const auto& pair : group_counts) if (pair.second > max_size) max_size = pair.second;
|
for (const auto &pair : group_counts)
|
||||||
|
if (pair.second > max_size)
|
||||||
|
max_size = pair.second;
|
||||||
return max_size;
|
return max_size;
|
||||||
}
|
}
|
||||||
ServiceMenu::GroupAlignment ServiceMenu::getGroupAlignment(SettingsGroup group) const {
|
ServiceMenu::GroupAlignment ServiceMenu::getGroupAlignment(SettingsGroup group) const
|
||||||
switch (group) {
|
{
|
||||||
case SettingsGroup::VIDEO: case SettingsGroup::AUDIO: case SettingsGroup::SETTINGS: return GroupAlignment::LEFT;
|
switch (group)
|
||||||
default: return GroupAlignment::CENTERED;
|
{
|
||||||
|
case SettingsGroup::VIDEO:
|
||||||
|
case SettingsGroup::AUDIO:
|
||||||
|
case SettingsGroup::SETTINGS:
|
||||||
|
return GroupAlignment::LEFT;
|
||||||
|
default:
|
||||||
|
return GroupAlignment::CENTERED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::string ServiceMenu::settingsGroupToString(SettingsGroup group) const {
|
std::string ServiceMenu::settingsGroupToString(SettingsGroup group) const
|
||||||
switch (group) {
|
{
|
||||||
case SettingsGroup::MAIN: return Lang::getText("[SERVICE_MENU] TITLE");
|
switch (group)
|
||||||
case SettingsGroup::VIDEO: return Lang::getText("[SERVICE_MENU] VIDEO");
|
{
|
||||||
case SettingsGroup::AUDIO: return Lang::getText("[SERVICE_MENU] AUDIO");
|
case SettingsGroup::MAIN:
|
||||||
case SettingsGroup::SETTINGS: return Lang::getText("[SERVICE_MENU] SETTINGS");
|
return Lang::getText("[SERVICE_MENU] TITLE");
|
||||||
case SettingsGroup::SYSTEM: return Lang::getText("[SERVICE_MENU] SYSTEM");
|
case SettingsGroup::VIDEO:
|
||||||
default: return Lang::getText("[SERVICE_MENU] TITLE");
|
return Lang::getText("[SERVICE_MENU] VIDEO");
|
||||||
|
case SettingsGroup::AUDIO:
|
||||||
|
return Lang::getText("[SERVICE_MENU] AUDIO");
|
||||||
|
case SettingsGroup::SETTINGS:
|
||||||
|
return Lang::getText("[SERVICE_MENU] SETTINGS");
|
||||||
|
case SettingsGroup::SYSTEM:
|
||||||
|
return Lang::getText("[SERVICE_MENU] SYSTEM");
|
||||||
|
default:
|
||||||
|
return Lang::getText("[SERVICE_MENU] TITLE");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ServiceMenu::OptionPairs ServiceMenu::getOptionPairs(SettingsGroup group) const {
|
ServiceMenu::OptionPairs ServiceMenu::getOptionPairs(SettingsGroup group) const
|
||||||
|
{
|
||||||
OptionPairs option_pairs;
|
OptionPairs option_pairs;
|
||||||
for (const auto& option : options_) {
|
for (const auto &option : options_)
|
||||||
if (option->getGroup() == group && !option->isHidden()) {
|
{
|
||||||
|
if (option->getGroup() == group && !option->isHidden())
|
||||||
|
{
|
||||||
option_pairs.emplace_back(option->getCaption(), option->getValueAsString());
|
option_pairs.emplace_back(option->getCaption(), option->getValueAsString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return option_pairs;
|
return option_pairs;
|
||||||
}
|
}
|
||||||
std::vector<MenuOption*> ServiceMenu::getOptionsByGroup(SettingsGroup group) {
|
std::vector<MenuOption *> ServiceMenu::getOptionsByGroup(SettingsGroup group)
|
||||||
std::vector<MenuOption*> filtered_options;
|
{
|
||||||
for (auto& option : options_) {
|
std::vector<MenuOption *> filtered_options;
|
||||||
if (option->getGroup() == group && !option->isHidden()) {
|
for (auto &option : options_)
|
||||||
|
{
|
||||||
|
if (option->getGroup() == group && !option->isHidden())
|
||||||
|
{
|
||||||
filtered_options.push_back(option.get());
|
filtered_options.push_back(option.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return filtered_options;
|
return filtered_options;
|
||||||
}
|
}
|
||||||
MenuOption* ServiceMenu::getOptionByCaption(const std::string& caption) {
|
MenuOption *ServiceMenu::getOptionByCaption(const std::string &caption)
|
||||||
for (auto& option : options_) {
|
{
|
||||||
if (option->getCaption() == caption) {
|
for (auto &option : options_)
|
||||||
|
{
|
||||||
|
if (option->getCaption() == caption)
|
||||||
|
{
|
||||||
return option.get();
|
return option.get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
void ServiceMenu::applySettings(SettingsGroup group) {
|
void ServiceMenu::applySettings(SettingsGroup group)
|
||||||
if (group == SettingsGroup::VIDEO) Screen::get()->applySettings();
|
{
|
||||||
if (group == SettingsGroup::AUDIO) Audio::get()->applySettings();
|
if (group == SettingsGroup::VIDEO)
|
||||||
if (group == SettingsGroup::SETTINGS) {
|
Screen::get()->applySettings();
|
||||||
|
if (group == SettingsGroup::AUDIO)
|
||||||
|
Audio::get()->applySettings();
|
||||||
|
if (group == SettingsGroup::SETTINGS)
|
||||||
|
{
|
||||||
auto option = getOptionByCaption(Lang::getText("[SERVICE_MENU] SHUTDOWN"));
|
auto option = getOptionByCaption(Lang::getText("[SERVICE_MENU] SHUTDOWN"));
|
||||||
if (option) {
|
if (option)
|
||||||
|
{
|
||||||
option->setHidden(!Options::settings.shutdown_enabled);
|
option->setHidden(!Options::settings.shutdown_enabled);
|
||||||
display_options_ = getOptionsByGroup(group);
|
display_options_ = getOptionsByGroup(group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void ServiceMenu::AdjustListValues() {
|
void ServiceMenu::AdjustListValues()
|
||||||
for (auto& option : options_) {
|
{
|
||||||
if (auto list_option = dynamic_cast<ListOption*>(option.get())) {
|
for (auto &option : options_)
|
||||||
|
{
|
||||||
|
if (auto list_option = dynamic_cast<ListOption *>(option.get()))
|
||||||
|
{
|
||||||
list_option->sync();
|
list_option->sync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ private:
|
|||||||
static constexpr size_t OPTIONS_HORIZONTAL_PADDING_ = 20;
|
static constexpr size_t OPTIONS_HORIZONTAL_PADDING_ = 20;
|
||||||
static constexpr size_t MIN_WIDTH_ = 220;
|
static constexpr size_t MIN_WIDTH_ = 220;
|
||||||
static constexpr size_t MIN_GAP_OPTION_VALUE_ = 20;
|
static constexpr size_t MIN_GAP_OPTION_VALUE_ = 20;
|
||||||
|
static constexpr float RESET_TEXT_POS_Y_ = 39.0f;
|
||||||
|
|
||||||
// --- Tipos internos ---
|
// --- Tipos internos ---
|
||||||
using OptionPairs = std::vector<std::pair<std::string, std::string>>;
|
using OptionPairs = std::vector<std::pair<std::string, std::string>>;
|
||||||
|
|||||||
Reference in New Issue
Block a user