Afegits nous textos als json

This commit is contained in:
2025-06-13 21:12:59 +02:00
parent ac2e2687a2
commit c83d58aaa3
5 changed files with 90 additions and 62 deletions

View File

@@ -68,7 +68,7 @@ void ServiceMenu::render()
SDL_RenderRect(Screen::get()->getRenderer(), &rect_);
// Si está animando el resize, no pintar el contenido
//if (resizing_) return;
// if (resizing_) return;
// TITULO
y += title_padding_;
@@ -104,7 +104,8 @@ void ServiceMenu::render()
// Actualiza el estado del menú de servicio (colores, animaciones, etc.)
void ServiceMenu::update()
{
if (resizing_) {
if (resizing_)
{
updateResizeAnimation();
// No actualizar colores ni animaciones mientras se redimensiona
return;
@@ -146,7 +147,7 @@ void ServiceMenu::setAnchors()
void ServiceMenu::setOptionsPosition()
{
resize();
//options_y_ = rect_.y + upper_height_ + lower_padding_;
// options_y_ = rect_.y + upper_height_ + lower_padding_;
SDL_FRect new_rect = {
(param.game.width - width_) / 2,
@@ -154,7 +155,6 @@ void ServiceMenu::setOptionsPosition()
static_cast<float>(width_),
static_cast<float>(height_)};
options_y_ = new_rect.y + upper_height_ + lower_padding_;
}
// Cambia el tamaño de la ventana de menu
@@ -172,12 +172,15 @@ void ServiceMenu::resize()
static_cast<float>(height_)};
// Si el rect actual es diferente al nuevo, inicia animación
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_to_ = new_rect;
resize_anim_step_ = 0;
resizing_ = true;
} else {
}
else
{
rect_ = new_rect;
resizing_ = false;
}
@@ -185,10 +188,12 @@ void ServiceMenu::resize()
void ServiceMenu::updateResizeAnimation()
{
if (!resizing_) return;
if (!resizing_)
return;
++resize_anim_step_;
float t = static_cast<float>(resize_anim_step_) / resize_anim_steps_;
if (t >= 1.0f) {
if (t >= 1.0f)
{
rect_ = rect_anim_to_;
resizing_ = false;
return;
@@ -366,9 +371,9 @@ void ServiceMenu::initializeOptions()
OptionBehavior::ADJUST,
&options.pending_changes.new_language,
std::vector<std::string>{
lang::getText("[SERVICE_MENU] LANG ES"),
lang::getText("[SERVICE_MENU] LANG BA"),
lang::getText("[SERVICE_MENU] LANG EN")});
lang::getText("[SERVICE_MENU] LANG_ES"),
lang::getText("[SERVICE_MENU] LANG_BA"),
lang::getText("[SERVICE_MENU] LANG_EN")});
// System
options_.emplace_back(lang::getText("[SERVICE_MENU] RESET"), SettingsGroup::SYSTEM, OptionBehavior::SELECT, nullptr, ValueType::NONE);
@@ -379,7 +384,7 @@ void ServiceMenu::initializeOptions()
// Menu principal
options_.emplace_back(lang::getText("[SERVICE_MENU] VIDEO"), SettingsGroup::MAIN, OptionBehavior::SELECT, SettingsGroup::VIDEO);
options_.emplace_back(lang::getText("[SERVICE_MENU] AUDIO"), SettingsGroup::MAIN, OptionBehavior::SELECT, SettingsGroup::AUDIO);
options_.emplace_back(lang::getText("[SERVICE_MENU] GAME"), SettingsGroup::MAIN, OptionBehavior::SELECT, SettingsGroup::GAME);
options_.emplace_back(lang::getText("[SERVICE_MENU] SETTINGS"), SettingsGroup::MAIN, OptionBehavior::SELECT, SettingsGroup::GAME);
options_.emplace_back(lang::getText("[SERVICE_MENU] SYSTEM"), SettingsGroup::MAIN, OptionBehavior::SELECT, SettingsGroup::SYSTEM);
// Al terminar de inicializar las opciones, recalcula los anchos de menú
@@ -518,38 +523,43 @@ void ServiceMenu::AdjustListValues()
void ServiceMenu::precalculateMenuWidths()
{
// Inicializa todos los anchos al mínimo
for (int &w : group_menu_widths_) w = MIN_WIDTH_;
for (int &w : group_menu_widths_)
w = MIN_WIDTH_;
// Para cada grupo
for (int group = 0; group < 5; ++group) {
for (int group = 0; group < 5; ++group)
{
SettingsGroup sg = static_cast<SettingsGroup>(group);
int max_option_width = 0;
int max_value_width = 0;
for (const auto &option : options_) {
if (option.group != sg) continue;
for (const auto &option : options_)
{
if (option.group != sg)
continue;
// Opción más larga
max_option_width = std::max(max_option_width, element_text_->lenght(option.caption, -2));
// Valor más largo de todos los posibles valores de todas las opciones
switch (option.type) {
case ValueType::BOOL:
max_value_width = std::max({max_value_width,
element_text_->lenght(lang::getText("[SERVICE_MENU] ON"), -2),
element_text_->lenght(lang::getText("[SERVICE_MENU] OFF"), -2)});
break;
case ValueType::INT:
max_value_width = std::max({max_value_width,
element_text_->lenght(std::to_string(option.min_value), -2),
element_text_->lenght(std::to_string(option.max_value), -2)});
break;
case ValueType::LIST:
for (const auto &val : option.value_list)
max_value_width = std::max(max_value_width, element_text_->lenght(val, -2));
break;
default:
break;
switch (option.type)
{
case ValueType::BOOL:
max_value_width = std::max({max_value_width,
element_text_->lenght(lang::getText("[SERVICE_MENU] ON"), -2),
element_text_->lenght(lang::getText("[SERVICE_MENU] OFF"), -2)});
break;
case ValueType::INT:
max_value_width = std::max({max_value_width,
element_text_->lenght(std::to_string(option.min_value), -2),
element_text_->lenght(std::to_string(option.max_value), -2)});
break;
case ValueType::LIST:
for (const auto &val : option.value_list)
max_value_width = std::max(max_value_width, element_text_->lenght(val, -2));
break;
default:
break;
}
}
size_t total_width = max_option_width + MIN_GAP_OPTION_VALUE_ + max_value_width + OPTIONS_HORIZONTAL_PADDING_*2;
size_t total_width = max_option_width + MIN_GAP_OPTION_VALUE_ + max_value_width + (OPTIONS_HORIZONTAL_PADDING_ * 2);
group_menu_widths_[group] = std::max(MIN_WIDTH_, total_width);
}
}