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
|
// Obtiene una fichero a partir de un lang::Code
|
||||||
std::string getLanguageFileName(Lang::Code code)
|
std::string getLanguageFileName(Lang::Code code)
|
||||||
{
|
{
|
||||||
@@ -134,5 +157,6 @@ namespace Lang
|
|||||||
Options::settings.language = lang;
|
Options::settings.language = lang;
|
||||||
loadFromFile(Asset::get()->get(getLanguage(lang).file_name));
|
loadFromFile(Asset::get()->get(getLanguage(lang).file_name));
|
||||||
updateLanguageNames();
|
updateLanguageNames();
|
||||||
|
updateDifficultyNames();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ namespace Options
|
|||||||
{DifficultyCode::HARD, "Hard"}};
|
{DifficultyCode::HARD, "Hard"}};
|
||||||
|
|
||||||
// Declaraciones
|
// 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
|
// Inicializa las opciones del programa
|
||||||
void init()
|
void init()
|
||||||
@@ -97,7 +97,7 @@ namespace Options
|
|||||||
// Encuentra la posición del carácter '='
|
// Encuentra la posición del carácter '='
|
||||||
int pos = line.find("=");
|
int pos = line.find("=");
|
||||||
// Procesa las dos subcadenas
|
// 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());
|
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Unknown parameter: %s", line.substr(0, pos).c_str());
|
||||||
success = false;
|
success = false;
|
||||||
@@ -200,7 +200,7 @@ namespace Options
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Asigna variables a partir de dos cadenas
|
// 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
|
// Indicador de éxito en la asignación
|
||||||
auto success = true;
|
auto success = true;
|
||||||
@@ -420,4 +420,15 @@ namespace Options
|
|||||||
pending_changes.has_pending_changes = false;
|
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
|
} // namespace Options
|
||||||
@@ -126,6 +126,7 @@ namespace Options
|
|||||||
extern AudioOptions audio; // Opciones de audio
|
extern AudioOptions audio; // Opciones de audio
|
||||||
extern std::vector<GamepadOptions> controllers; // Opciones de mando para cada jugador
|
extern std::vector<GamepadOptions> controllers; // Opciones de mando para cada jugador
|
||||||
extern PendingChanges pending_changes; // Opciones que se aplican al cerrar
|
extern PendingChanges pending_changes; // Opciones que se aplican al cerrar
|
||||||
|
extern std::vector<Difficulty> difficulties;
|
||||||
|
|
||||||
// --- Funciones de configuración ---
|
// --- Funciones de configuración ---
|
||||||
void init(); // Inicializa las opciones del programa
|
void init(); // Inicializa las opciones del programa
|
||||||
@@ -137,4 +138,5 @@ namespace Options
|
|||||||
int getPlayerWhoUsesKeyboard(); // Averigua quién está usando el teclado
|
int getPlayerWhoUsesKeyboard(); // Averigua quién está usando el teclado
|
||||||
void applyPendingChanges(); // Aplica los cambios pendientes copiando los valores a sus variables
|
void applyPendingChanges(); // Aplica los cambios pendientes copiando los valores a sus variables
|
||||||
void checkPendingChanges();
|
void checkPendingChanges();
|
||||||
|
DifficultyCode getDifficultyCodeFromName(const std::string& name);
|
||||||
} // namespace Options
|
} // namespace Options
|
||||||
@@ -526,10 +526,10 @@ ServiceMenu::OptionEntry *ServiceMenu::getOptionEntryByCaption(const std::string
|
|||||||
return nullptr;
|
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()
|
void ServiceMenu::AdjustListValues()
|
||||||
{
|
{
|
||||||
// Idioma
|
{ // Idioma
|
||||||
auto option = getOptionEntryByCaption(Lang::getText("[SERVICE_MENU] LANGUAGE"));
|
auto option = getOptionEntryByCaption(Lang::getText("[SERVICE_MENU] LANGUAGE"));
|
||||||
for (size_t i = 0; i < option->value_list.size(); ++i)
|
for (size_t i = 0; i < option->value_list.size(); ++i)
|
||||||
{
|
{
|
||||||
@@ -538,6 +538,18 @@ void ServiceMenu::AdjustListValues()
|
|||||||
option->list_index = i;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServiceMenu::precalculateMenuWidths()
|
void ServiceMenu::precalculateMenuWidths()
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ private:
|
|||||||
// Dificultad
|
// Dificultad
|
||||||
if (linked_variable == &Options::pending_changes.new_difficulty)
|
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();
|
Options::checkPendingChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user