ServiceMenu: treballant en les animacions
This commit is contained in:
@@ -160,8 +160,10 @@ void ServiceMenu::setOptionsPosition()
|
||||
// Cambia el tamaño de la ventana de menu
|
||||
void ServiceMenu::resize()
|
||||
{
|
||||
// Usa el ancho precalculado para el grupo actual
|
||||
int menu_width = getMenuWidthForGroup(current_settings_group_);
|
||||
width_ = menu_width;
|
||||
lower_height_ = ((display_options_.size() - 1) * (options_height_ + options_padding_)) + options_height_ + (lower_padding_ * 2);
|
||||
width_ = 240;
|
||||
height_ = upper_height_ + lower_height_;
|
||||
SDL_FRect new_rect = {
|
||||
(param.game.width - width_) / 2,
|
||||
@@ -379,6 +381,9 @@ void ServiceMenu::initializeOptions()
|
||||
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] SYSTEM"), SettingsGroup::MAIN, OptionBehavior::SELECT, SettingsGroup::SYSTEM);
|
||||
|
||||
// Al terminar de inicializar las opciones, recalcula los anchos de menú
|
||||
precalculateMenuWidths();
|
||||
}
|
||||
|
||||
// Devuelve las opciones del grupo como pares (nombre, valor)
|
||||
@@ -435,6 +440,8 @@ void ServiceMenu::updateMenu(SettingsGroup group)
|
||||
AdjustListValues();
|
||||
option_pairs_ = getOptionPairs(group);
|
||||
display_options_ = getOptionsByGroup(group);
|
||||
// Recalcula el ancho del menú al cambiar de grupo
|
||||
resize();
|
||||
}
|
||||
|
||||
// Reinicia el menú al estado inicial (grupo principal y opción seleccionada)
|
||||
@@ -508,3 +515,46 @@ void ServiceMenu::AdjustListValues()
|
||||
}
|
||||
}
|
||||
|
||||
void ServiceMenu::precalculateMenuWidths()
|
||||
{
|
||||
// Inicializa todos los anchos al mínimo
|
||||
for (int &w : group_menu_widths_) w = MIN_WIDTH_;
|
||||
|
||||
// Para cada grupo
|
||||
for (int group = 0; group < 5; ++group) {
|
||||
SettingsGroup sg = static_cast<SettingsGroup>(group);
|
||||
int max_width = MIN_WIDTH_;
|
||||
for (const auto &option : options_) {
|
||||
if (option.group != sg) continue;
|
||||
int option_width = element_text_->lenght(option.caption);
|
||||
int value_width = 0;
|
||||
// Calcular el valor más ancho posible para esta opción
|
||||
switch (option.type) {
|
||||
case ValueType::BOOL:
|
||||
value_width = std::max(element_text_->lenght(lang::getText("[SERVICE_MENU] ON")),
|
||||
element_text_->lenght(lang::getText("[SERVICE_MENU] OFF")));
|
||||
break;
|
||||
case ValueType::INT:
|
||||
// Considera el valor máximo y mínimo como strings
|
||||
value_width = std::max(
|
||||
element_text_->lenght(std::to_string(option.min_value)),
|
||||
element_text_->lenght(std::to_string(option.max_value)));
|
||||
break;
|
||||
case ValueType::LIST:
|
||||
for (const auto &val : option.value_list)
|
||||
value_width = std::max(value_width, element_text_->lenght(val));
|
||||
break;
|
||||
default:
|
||||
value_width = 0;
|
||||
}
|
||||
int total_width = option_width + MIN_GAP_OPTION_VALUE_ + value_width;
|
||||
max_width = std::max(max_width, total_width);
|
||||
}
|
||||
group_menu_widths_[group] = max_width;
|
||||
}
|
||||
}
|
||||
|
||||
int ServiceMenu::getMenuWidthForGroup(SettingsGroup group) const
|
||||
{
|
||||
return group_menu_widths_[static_cast<int>(group)];
|
||||
}
|
||||
Reference in New Issue
Block a user