ServiceMenu: ja es pot canviar la dificultat
This commit is contained in:
@@ -116,6 +116,29 @@ namespace Lang
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza los nombres de las dificultades
|
||||
void updateDifficultyNames()
|
||||
{
|
||||
for (auto &difficulty : Options::difficulties)
|
||||
{
|
||||
switch (difficulty.code)
|
||||
{
|
||||
case Options::DifficultyCode::EASY:
|
||||
difficulty.name = Lang::getText("[SERVICE_MENU] EASY");
|
||||
break;
|
||||
case Options::DifficultyCode::NORMAL:
|
||||
difficulty.name = Lang::getText("[SERVICE_MENU] NORMAL");
|
||||
break;
|
||||
case Options::DifficultyCode::HARD:
|
||||
difficulty.name = Lang::getText("[SERVICE_MENU] HARD");
|
||||
break;
|
||||
default:
|
||||
difficulty.name = "Unknown";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Obtiene una fichero a partir de un lang::Code
|
||||
std::string getLanguageFileName(Lang::Code code)
|
||||
{
|
||||
@@ -134,5 +157,6 @@ namespace Lang
|
||||
Options::settings.language = lang;
|
||||
loadFromFile(Asset::get()->get(getLanguage(lang).file_name));
|
||||
updateLanguageNames();
|
||||
updateDifficultyNames();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Options
|
||||
{DifficultyCode::HARD, "Hard"}};
|
||||
|
||||
// Declaraciones
|
||||
bool setOptions(const std::string &var, const std::string &value);
|
||||
bool set(const std::string &var, const std::string &value);
|
||||
|
||||
// Inicializa las opciones del programa
|
||||
void init()
|
||||
@@ -97,7 +97,7 @@ namespace Options
|
||||
// Encuentra la posición del carácter '='
|
||||
int pos = line.find("=");
|
||||
// Procesa las dos subcadenas
|
||||
if (!setOptions(line.substr(0, pos), line.substr(pos + 1, line.length())))
|
||||
if (!set(line.substr(0, pos), line.substr(pos + 1, line.length())))
|
||||
{
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Unknown parameter: %s", line.substr(0, pos).c_str());
|
||||
success = false;
|
||||
@@ -200,7 +200,7 @@ namespace Options
|
||||
}
|
||||
|
||||
// Asigna variables a partir de dos cadenas
|
||||
bool setOptions(const std::string &var, const std::string &value)
|
||||
bool set(const std::string &var, const std::string &value)
|
||||
{
|
||||
// Indicador de éxito en la asignación
|
||||
auto success = true;
|
||||
@@ -420,4 +420,15 @@ namespace Options
|
||||
pending_changes.has_pending_changes = false;
|
||||
}
|
||||
}
|
||||
|
||||
DifficultyCode getDifficultyCodeFromName(const std::string &name)
|
||||
{
|
||||
for (const auto &difficulty : difficulties)
|
||||
{
|
||||
if (difficulty.name == name)
|
||||
return difficulty.code;
|
||||
}
|
||||
// Si no se encuentra, devuelve el primero por defecto
|
||||
return difficulties[0].code;
|
||||
}
|
||||
} // namespace Options
|
||||
@@ -126,6 +126,7 @@ namespace Options
|
||||
extern AudioOptions audio; // Opciones de audio
|
||||
extern std::vector<GamepadOptions> controllers; // Opciones de mando para cada jugador
|
||||
extern PendingChanges pending_changes; // Opciones que se aplican al cerrar
|
||||
extern std::vector<Difficulty> difficulties;
|
||||
|
||||
// --- Funciones de configuración ---
|
||||
void init(); // Inicializa las opciones del programa
|
||||
@@ -137,4 +138,5 @@ namespace Options
|
||||
int getPlayerWhoUsesKeyboard(); // Averigua quién está usando el teclado
|
||||
void applyPendingChanges(); // Aplica los cambios pendientes copiando los valores a sus variables
|
||||
void checkPendingChanges();
|
||||
DifficultyCode getDifficultyCodeFromName(const std::string& name);
|
||||
} // namespace Options
|
||||
@@ -526,16 +526,28 @@ ServiceMenu::OptionEntry *ServiceMenu::getOptionEntryByCaption(const std::string
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Ajusta los valores de las opciones tipo lista
|
||||
// Pone el texto que corresponde al valor de la variable en las opciones de tipo lista
|
||||
void ServiceMenu::AdjustListValues()
|
||||
{
|
||||
// Idioma
|
||||
auto option = getOptionEntryByCaption(Lang::getText("[SERVICE_MENU] LANGUAGE"));
|
||||
for (size_t i = 0; i < option->value_list.size(); ++i)
|
||||
{
|
||||
if (Lang::getCodeFromName(option->value_list[i]) == Options::settings.language)
|
||||
{ // Idioma
|
||||
auto option = getOptionEntryByCaption(Lang::getText("[SERVICE_MENU] LANGUAGE"));
|
||||
for (size_t i = 0; i < option->value_list.size(); ++i)
|
||||
{
|
||||
option->list_index = i;
|
||||
if (Lang::getCodeFromName(option->value_list[i]) == Options::settings.language)
|
||||
{
|
||||
option->list_index = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{ // Dificultad
|
||||
auto option = getOptionEntryByCaption(Lang::getText("[SERVICE_MENU] DIFFICULTY"));
|
||||
for (size_t i = 0; i < option->value_list.size(); ++i)
|
||||
{
|
||||
if (Options::getDifficultyCodeFromName(option->value_list[i]) == Options::settings.difficulty)
|
||||
{
|
||||
option->list_index = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ private:
|
||||
// Dificultad
|
||||
if (linked_variable == &Options::pending_changes.new_difficulty)
|
||||
{
|
||||
// Options::pending_changes.new_difficulty =
|
||||
Options::pending_changes.new_difficulty = Options::getDifficultyCodeFromName(value_list[list_index]);
|
||||
Options::checkPendingChanges();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user