clang-tidy readability
This commit is contained in:
@@ -123,8 +123,9 @@ class ListOption : public MenuOption {
|
||||
return value_list_.empty() ? "" : value_list_[list_index_];
|
||||
}
|
||||
void adjustValue(bool adjust_up) override {
|
||||
if (value_list_.empty())
|
||||
if (value_list_.empty()) {
|
||||
return;
|
||||
}
|
||||
size_t size = value_list_.size();
|
||||
list_index_ = (adjust_up) ? (list_index_ + 1) % size
|
||||
: (list_index_ + size - 1) % size;
|
||||
@@ -164,8 +165,9 @@ class ActionOption : public MenuOption {
|
||||
|
||||
[[nodiscard]] auto getBehavior() const -> Behavior override { return Behavior::SELECT; }
|
||||
void executeAction() override {
|
||||
if (action_)
|
||||
if (action_) {
|
||||
action_();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -103,10 +103,10 @@ void MenuRenderer::setAnchors(const ServiceMenu *menu_state) {
|
||||
auto MenuRenderer::calculateNewRect(const ServiceMenu *menu_state) -> SDL_FRect {
|
||||
width_ = getMenuWidthForGroup(menu_state->getCurrentGroup());
|
||||
const auto &display_options = menu_state->getDisplayOptions();
|
||||
lower_height_ = ((display_options.size() > 0 ? display_options.size() - 1 : 0) * (options_height_ + options_padding_)) + options_height_ + (lower_padding_ * 2);
|
||||
lower_height_ = ((!display_options.empty() ? display_options.size() - 1 : 0) * (options_height_ + options_padding_)) + options_height_ + (lower_padding_ * 2);
|
||||
height_ = upper_height_ + lower_height_;
|
||||
|
||||
return {(param.game.width - width_) / 2.0f, (param.game.height - height_) / 2.0f, (float)width_, (float)height_};
|
||||
return {(param.game.width - width_) / 2.0F, (param.game.height - height_) / 2.0F, (float)width_, (float)height_};
|
||||
}
|
||||
|
||||
void MenuRenderer::resize(const ServiceMenu *menu_state) {
|
||||
@@ -131,11 +131,12 @@ void MenuRenderer::setSize(const ServiceMenu *menu_state) {
|
||||
}
|
||||
|
||||
void MenuRenderer::updateResizeAnimation() {
|
||||
if (!resizing_)
|
||||
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_ = setRect(rect_anim_to_);
|
||||
resizing_ = false;
|
||||
return;
|
||||
@@ -150,15 +151,17 @@ void MenuRenderer::updateResizeAnimation() {
|
||||
}
|
||||
|
||||
void MenuRenderer::precalculateMenuWidths(const std::vector<std::unique_ptr<MenuOption>> &all_options, const ServiceMenu *menu_state) {
|
||||
for (int &w : group_menu_widths_)
|
||||
for (int &w : group_menu_widths_) {
|
||||
w = ServiceMenu::MIN_WIDTH;
|
||||
}
|
||||
for (int group = 0; group < 5; ++group) {
|
||||
auto sg = static_cast<ServiceMenu::SettingsGroup>(group);
|
||||
int max_option_width = 0;
|
||||
int max_value_width = 0;
|
||||
for (const auto &option : all_options) {
|
||||
if (option->getGroup() != sg)
|
||||
if (option->getGroup() != sg) {
|
||||
continue;
|
||||
}
|
||||
max_option_width = std::max(max_option_width, element_text_->lenght(option->getCaption(), -2));
|
||||
if (menu_state->getCurrentGroupAlignment() == ServiceMenu::GroupAlignment::LEFT) {
|
||||
max_value_width = std::max(max_value_width, option->getMaxValueWidth(element_text_.get()));
|
||||
@@ -185,7 +188,7 @@ void MenuRenderer::updateColorCounter() {
|
||||
}
|
||||
}
|
||||
|
||||
auto MenuRenderer::getAnimatedSelectedColor() -> Color {
|
||||
auto MenuRenderer::getAnimatedSelectedColor() const -> Color {
|
||||
static auto color_cycle_ = generateMirroredCycle(param.service_menu.selected_color, ColorCycleStyle::HUE_WAVE);
|
||||
return color_cycle_.at(color_counter_ % color_cycle_.size());
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ class MenuRenderer {
|
||||
void updateResizeAnimation();
|
||||
void precalculateMenuWidths(const std::vector<std::unique_ptr<MenuOption>> &all_options, const ServiceMenu *menu_state);
|
||||
[[nodiscard]] auto getMenuWidthForGroup(ServiceMenu::SettingsGroup group) const -> int;
|
||||
auto getAnimatedSelectedColor() -> Color;
|
||||
auto getAnimatedSelectedColor() const -> Color;
|
||||
void updateColorCounter();
|
||||
auto setRect(SDL_FRect rect) -> SDL_FRect;
|
||||
};
|
||||
|
||||
@@ -40,20 +40,22 @@ void ServiceMenu::toggle() {
|
||||
}
|
||||
|
||||
void ServiceMenu::render() {
|
||||
if (!enabled_)
|
||||
if (!enabled_) {
|
||||
return;
|
||||
}
|
||||
renderer_->render(this);
|
||||
|
||||
// El mensaje de reinicio se dibuja por encima, así que lo gestionamos aquí
|
||||
const float MSG_X = param.game.game_area.center_x;
|
||||
const float MSG_Y = renderer_->getRect().y + 39.0f;
|
||||
const float MSG_Y = renderer_->getRect().y + 39.0F;
|
||||
restart_message_ui_->setPosition(MSG_X, MSG_Y);
|
||||
restart_message_ui_->render();
|
||||
}
|
||||
|
||||
void ServiceMenu::update() {
|
||||
if (!enabled_)
|
||||
if (!enabled_) {
|
||||
return;
|
||||
}
|
||||
|
||||
renderer_->update(this);
|
||||
|
||||
@@ -77,22 +79,25 @@ void ServiceMenu::reset() {
|
||||
|
||||
// --- Lógica de Navegación ---
|
||||
void ServiceMenu::setSelectorUp() {
|
||||
if (display_options_.empty())
|
||||
if (display_options_.empty()) {
|
||||
return;
|
||||
}
|
||||
selected_ = (selected_ > 0) ? selected_ - 1 : display_options_.size() - 1;
|
||||
playMoveSound();
|
||||
}
|
||||
|
||||
void ServiceMenu::setSelectorDown() {
|
||||
if (display_options_.empty())
|
||||
if (display_options_.empty()) {
|
||||
return;
|
||||
}
|
||||
selected_ = (selected_ + 1) % display_options_.size();
|
||||
playMoveSound();
|
||||
}
|
||||
|
||||
void ServiceMenu::adjustOption(bool adjust_up) {
|
||||
if (display_options_.empty())
|
||||
if (display_options_.empty()) {
|
||||
return;
|
||||
}
|
||||
auto &selected_option = display_options_.at(selected_);
|
||||
if (selected_option->getBehavior() == MenuOption::Behavior::ADJUST) {
|
||||
selected_option->adjustValue(adjust_up);
|
||||
@@ -102,18 +107,20 @@ void ServiceMenu::adjustOption(bool adjust_up) {
|
||||
}
|
||||
|
||||
void ServiceMenu::selectOption() {
|
||||
if (display_options_.empty())
|
||||
if (display_options_.empty()) {
|
||||
return;
|
||||
if (current_settings_group_ == SettingsGroup::MAIN)
|
||||
}
|
||||
if (current_settings_group_ == SettingsGroup::MAIN) {
|
||||
main_menu_selected_ = selected_;
|
||||
|
||||
}
|
||||
|
||||
auto *selected_option = display_options_.at(selected_);
|
||||
if (!selected_option) {
|
||||
if (selected_option == nullptr) {
|
||||
// This shouldn't happen in normal operation, but protects against null pointer
|
||||
return;
|
||||
}
|
||||
|
||||
if (auto folder = dynamic_cast<FolderOption *>(selected_option)) {
|
||||
|
||||
if (auto *folder = dynamic_cast<FolderOption *>(selected_option)) {
|
||||
previous_settings_group_ = current_settings_group_;
|
||||
current_settings_group_ = folder->getTargetGroup();
|
||||
selected_ = 0;
|
||||
@@ -166,12 +173,15 @@ void ServiceMenu::updateMenu() {
|
||||
}
|
||||
|
||||
void ServiceMenu::applySettings() {
|
||||
if (current_settings_group_ == SettingsGroup::VIDEO)
|
||||
if (current_settings_group_ == SettingsGroup::VIDEO) {
|
||||
applyVideoSettings();
|
||||
if (current_settings_group_ == SettingsGroup::AUDIO)
|
||||
}
|
||||
if (current_settings_group_ == SettingsGroup::AUDIO) {
|
||||
applyAudioSettings();
|
||||
if (current_settings_group_ == SettingsGroup::SETTINGS)
|
||||
}
|
||||
if (current_settings_group_ == SettingsGroup::SETTINGS) {
|
||||
applySettingsSettings();
|
||||
}
|
||||
|
||||
// Actualiza los valores de las opciones
|
||||
updateOptionPairs();
|
||||
@@ -262,7 +272,7 @@ void ServiceMenu::initializeOptions() {
|
||||
// Sincroniza los valores de las opciones tipo lista
|
||||
void ServiceMenu::adjustListValues() {
|
||||
for (auto &option : options_) {
|
||||
if (auto list_option = dynamic_cast<ListOption *>(option.get())) {
|
||||
if (auto *list_option = dynamic_cast<ListOption *>(option.get())) {
|
||||
list_option->sync();
|
||||
}
|
||||
}
|
||||
@@ -275,7 +285,7 @@ void ServiceMenu::playSelectSound() { Audio::get()->playSound("service_menu_sele
|
||||
void ServiceMenu::playBackSound() { Audio::get()->playSound("service_menu_select.wav", Audio::Group::INTERFACE); }
|
||||
|
||||
// Devuelve el nombre del grupo como string para el título
|
||||
auto ServiceMenu::settingsGroupToString(SettingsGroup group) const -> std::string {
|
||||
auto ServiceMenu::settingsGroupToString(SettingsGroup group) -> std::string {
|
||||
switch (group) {
|
||||
case SettingsGroup::MAIN:
|
||||
return Lang::getText("[SERVICE_MENU] TITLE");
|
||||
@@ -295,15 +305,17 @@ auto ServiceMenu::settingsGroupToString(SettingsGroup group) const -> std::strin
|
||||
// Establece el estado de oculto de ciertas opciones
|
||||
void ServiceMenu::setHiddenOptions() {
|
||||
{
|
||||
auto option = getOptionByCaption(Lang::getText("[SERVICE_MENU] WINDOW_SIZE"));
|
||||
if (option)
|
||||
auto *option = getOptionByCaption(Lang::getText("[SERVICE_MENU] WINDOW_SIZE"));
|
||||
if (option != nullptr) {
|
||||
option->setHidden(Options::video.fullscreen);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto option = getOptionByCaption(Lang::getText("[SERVICE_MENU] SHUTDOWN"));
|
||||
if (option)
|
||||
auto *option = getOptionByCaption(Lang::getText("[SERVICE_MENU] SHUTDOWN"));
|
||||
if (option != nullptr) {
|
||||
option->setHidden(!Options::settings.shutdown_enabled);
|
||||
}
|
||||
}
|
||||
|
||||
updateMenu(); // El menú debe refrescarse si algo se oculta
|
||||
|
||||
@@ -89,15 +89,15 @@ private:
|
||||
void updateMenu();
|
||||
void applySettings();
|
||||
void applyVideoSettings();
|
||||
void applyAudioSettings();
|
||||
static void applyAudioSettings();
|
||||
void applySettingsSettings();
|
||||
[[nodiscard]] auto getOptionByCaption(const std::string &caption) const -> MenuOption *;
|
||||
void adjustListValues();
|
||||
void playMoveSound();
|
||||
void playAdjustSound();
|
||||
void playSelectSound();
|
||||
void playBackSound();
|
||||
[[nodiscard]] auto settingsGroupToString(SettingsGroup group) const -> std::string;
|
||||
static void playMoveSound();
|
||||
static void playAdjustSound();
|
||||
static void playSelectSound();
|
||||
static void playBackSound();
|
||||
[[nodiscard]] static auto settingsGroupToString(SettingsGroup group) -> std::string;
|
||||
void setHiddenOptions();
|
||||
|
||||
// --- Constructores y destructor privados (singleton) ---
|
||||
|
||||
@@ -11,11 +11,12 @@ UIMessage::UIMessage(std::shared_ptr<Text> text_renderer, std::string message_te
|
||||
|
||||
// Muestra el mensaje en la posición base_x, base_y con animación de entrada desde arriba
|
||||
void UIMessage::show() {
|
||||
if (visible_ && target_y_ == 0.0f)
|
||||
if (visible_ && target_y_ == 0.0F) {
|
||||
return; // Ya está visible y quieto
|
||||
}
|
||||
|
||||
start_y_ = DESP; // Empieza 8 píxeles arriba de la posición base
|
||||
target_y_ = 0.0f; // La posición final es la base
|
||||
target_y_ = 0.0F; // La posición final es la base
|
||||
y_offset_ = start_y_;
|
||||
anim_step_ = 0;
|
||||
animating_ = true;
|
||||
@@ -24,8 +25,9 @@ void UIMessage::show() {
|
||||
|
||||
// Oculta el mensaje con animación de salida hacia arriba
|
||||
void UIMessage::hide() {
|
||||
if (!visible_)
|
||||
if (!visible_) {
|
||||
return;
|
||||
}
|
||||
|
||||
start_y_ = y_offset_; // Comienza desde la posición actual
|
||||
target_y_ = DESP; // Termina 8 píxeles arriba de la base
|
||||
@@ -58,8 +60,9 @@ void UIMessage::updateAnimation() {
|
||||
if (anim_step_ >= ANIMATION_STEPS) {
|
||||
y_offset_ = target_y_;
|
||||
animating_ = false;
|
||||
if (target_y_ < 0.0f)
|
||||
if (target_y_ < 0.0F) {
|
||||
visible_ = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,16 +40,16 @@ class UIMessage {
|
||||
// --- Estado ---
|
||||
bool visible_ = false; // Indica si el mensaje está visible
|
||||
bool animating_ = false; // Indica si el mensaje está en proceso de animación
|
||||
float base_x_ = 0.0f; // Posición X base donde se muestra el mensaje
|
||||
float base_y_ = 0.0f; // Posición Y base donde se muestra el mensaje
|
||||
float y_offset_ = 0.0f; // Desplazamiento vertical actual del mensaje (para animación)
|
||||
float base_x_ = 0.0F; // Posición X base donde se muestra el mensaje
|
||||
float base_y_ = 0.0F; // Posición Y base donde se muestra el mensaje
|
||||
float y_offset_ = 0.0F; // Desplazamiento vertical actual del mensaje (para animación)
|
||||
|
||||
// --- Animación ---
|
||||
float start_y_ = 0.0f; // Posición Y inicial de la animación
|
||||
float target_y_ = 0.0f; // Posición Y objetivo de la animación
|
||||
float start_y_ = 0.0F; // Posición Y inicial de la animación
|
||||
float target_y_ = 0.0F; // Posición Y objetivo de la animación
|
||||
int anim_step_ = 0; // Paso actual de la animación
|
||||
static constexpr int ANIMATION_STEPS = 8; // Número total de pasos de la animación
|
||||
static constexpr float DESP = -8.0f; // Distancia a desplazarse
|
||||
static constexpr float DESP = -8.0F; // Distancia a desplazarse
|
||||
|
||||
// Actualiza la interpolación de la animación (ease out/in cubic)
|
||||
void updateAnimation();
|
||||
|
||||
Reference in New Issue
Block a user