|
|
|
|
@@ -28,8 +28,8 @@ ServiceMenu::ServiceMenu()
|
|
|
|
|
current_settings_group_(SettingsGroup::MAIN),
|
|
|
|
|
previous_settings_group_(current_settings_group_)
|
|
|
|
|
{
|
|
|
|
|
setAnchors();
|
|
|
|
|
initializeOptions();
|
|
|
|
|
setAnchors();
|
|
|
|
|
updateMenu(current_settings_group_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -44,7 +44,6 @@ void ServiceMenu::render()
|
|
|
|
|
if (enabled_)
|
|
|
|
|
{
|
|
|
|
|
int y = rect_.y;
|
|
|
|
|
constexpr int H_PADDING = 20;
|
|
|
|
|
|
|
|
|
|
// SOMBRA
|
|
|
|
|
if (aspect_ == Aspect::ASPECT1)
|
|
|
|
|
@@ -70,15 +69,33 @@ void ServiceMenu::render()
|
|
|
|
|
// LINEA
|
|
|
|
|
y += line_height_ * 2;
|
|
|
|
|
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), title_color_.r, title_color_.g, title_color_.b, 255);
|
|
|
|
|
SDL_RenderLine(Screen::get()->getRenderer(), rect_.x + H_PADDING, y, rect_.x + rect_.w - H_PADDING, y);
|
|
|
|
|
SDL_RenderLine(Screen::get()->getRenderer(), rect_.x + OPTIONS_HORIZONTAL_PADDING_, y, rect_.x + rect_.w - OPTIONS_HORIZONTAL_PADDING_, y);
|
|
|
|
|
|
|
|
|
|
// LIST
|
|
|
|
|
for (size_t i = 0; i < option_pairs_.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
y += line_height_;
|
|
|
|
|
element_text_->writeColored(rect_.x + H_PADDING, y, option_pairs_.at(i).first, i == selected_ ? selected_color_ : text_color_, -2);
|
|
|
|
|
element_text_->writeColored(rect_.x + H_PADDING + 100, y, "" + std::string(option_pairs_.at(i).second), i == selected_ ? selected_color_ : text_color_, -2);
|
|
|
|
|
if (getGroupAlignment(current_settings_group_) == GroupAlignment::LEFT)
|
|
|
|
|
{
|
|
|
|
|
// Nombre de la opción
|
|
|
|
|
element_text_->writeColored(rect_.x + OPTIONS_HORIZONTAL_PADDING_, y, option_pairs_.at(i).first, i == selected_ ? selected_color_ : text_color_, -2);
|
|
|
|
|
// Valor de la opción
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Nombre de la opción
|
|
|
|
|
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_);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 255, 0, 255);
|
|
|
|
|
for (int i = rect_.y; i < rect_.y + rect_.h; i += line_height_)
|
|
|
|
|
{
|
|
|
|
|
SDL_RenderLine(Screen::get()->getRenderer(), rect_.x, i, rect_.x + rect_.w, i);
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -93,9 +110,9 @@ void ServiceMenu::update()
|
|
|
|
|
|
|
|
|
|
void ServiceMenu::setAnchors()
|
|
|
|
|
{
|
|
|
|
|
width_ = 220;
|
|
|
|
|
height_ = 200;
|
|
|
|
|
line_height_ = element_text_->getCharacterSize() + 5;
|
|
|
|
|
width_ = 220;
|
|
|
|
|
height_ = calculateMenuHeight();
|
|
|
|
|
rect_ = {
|
|
|
|
|
(param.game.width - width_) / 2,
|
|
|
|
|
(param.game.height - height_) / 2,
|
|
|
|
|
@@ -139,11 +156,13 @@ Color ServiceMenu::getSelectedColor()
|
|
|
|
|
void ServiceMenu::setSelectorUp()
|
|
|
|
|
{
|
|
|
|
|
selected_ = (selected_ > 0) ? --selected_ : display_options_.size() - 1;
|
|
|
|
|
Audio::get()->playSound(MENU_SOUND_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ServiceMenu::setSelectorDown()
|
|
|
|
|
{
|
|
|
|
|
selected_ = (selected_ + 1) % display_options_.size();
|
|
|
|
|
Audio::get()->playSound(MENU_SOUND_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ServiceMenu::adjustOption(bool adjust_up)
|
|
|
|
|
@@ -153,6 +172,7 @@ void ServiceMenu::adjustOption(bool adjust_up)
|
|
|
|
|
display_options_.at(selected_).adjustValue(adjust_up);
|
|
|
|
|
option_pairs_ = getOptionPairs(current_settings_group_);
|
|
|
|
|
applySettings(current_settings_group_);
|
|
|
|
|
Audio::get()->playSound(MENU_SOUND_);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -165,6 +185,7 @@ void ServiceMenu::selectOption()
|
|
|
|
|
current_settings_group_ = display_options_.at(selected_).target_group;
|
|
|
|
|
updateMenu(current_settings_group_);
|
|
|
|
|
selected_ = 0;
|
|
|
|
|
Audio::get()->playSound(MENU_SOUND_);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -205,6 +226,7 @@ void ServiceMenu::moveBack()
|
|
|
|
|
selected_ = 0;
|
|
|
|
|
current_settings_group_ = previous_settings_group_;
|
|
|
|
|
updateMenu(current_settings_group_);
|
|
|
|
|
Audio::get()->playSound(MENU_SOUND_);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -297,4 +319,41 @@ void ServiceMenu::reset()
|
|
|
|
|
selected_ = 0;
|
|
|
|
|
previous_settings_group_ = current_settings_group_ = SettingsGroup::MAIN;
|
|
|
|
|
updateMenu(current_settings_group_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ServiceMenu::calculateMenuHeight()
|
|
|
|
|
{
|
|
|
|
|
return ((4 + findLargestGroupSize() + 1) * line_height_) - 5;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ServiceMenu::findLargestGroupSize()
|
|
|
|
|
{
|
|
|
|
|
int max_size = 0;
|
|
|
|
|
// Recorremos todos los posibles grupos
|
|
|
|
|
for (int group = static_cast<int>(SettingsGroup::VIDEO); group <= static_cast<int>(SettingsGroup::MAIN); ++group)
|
|
|
|
|
{
|
|
|
|
|
int count = 0;
|
|
|
|
|
for (const auto &option : options_)
|
|
|
|
|
{
|
|
|
|
|
if (static_cast<int>(option.group) == group)
|
|
|
|
|
++count;
|
|
|
|
|
}
|
|
|
|
|
if (count > max_size)
|
|
|
|
|
max_size = count;
|
|
|
|
|
}
|
|
|
|
|
return max_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ServiceMenu::GroupAlignment ServiceMenu::getGroupAlignment(SettingsGroup group)
|
|
|
|
|
{
|
|
|
|
|
switch (group)
|
|
|
|
|
{
|
|
|
|
|
case SettingsGroup::VIDEO:
|
|
|
|
|
case SettingsGroup::AUDIO:
|
|
|
|
|
case SettingsGroup::GAME:
|
|
|
|
|
return GroupAlignment::LEFT;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return GroupAlignment::CENTERED;
|
|
|
|
|
}
|
|
|
|
|
}
|