Qt: simplify zero padding in trophy icon path

This commit is contained in:
Megamouse 2021-06-06 10:00:43 +02:00
parent 568af756cc
commit 4ab2e40d8a

View file

@ -372,28 +372,19 @@ bool trophy_manager_dialog::LoadTrophyFolderToDB(const std::string& trop_name)
if (trophy_count == 0) if (trophy_count == 0)
{ {
gui_log.error("Warning game %s in trophy folder %s usr file reports zero trophies. Cannot load in trophy manager.", game_trophy_data->game_name, game_trophy_data->path); gui_log.error("Warning game %s in trophy folder %s usr file reports zero trophies. Cannot load in trophy manager.", game_trophy_data->game_name, game_trophy_data->path);
return false; return false;
} }
for (u32 trophy_id = 0; trophy_id < trophy_count; ++trophy_id) for (u32 trophy_id = 0; trophy_id < trophy_count; ++trophy_id)
{ {
// Figure out how many zeros are needed for padding. (either 0, 1, or 2) // A trophy icon has 3 digits from 000 to 999, for example TROP001.PNG
QString padding = ""; const QString path = qstr(fmt::format("%sTROP%03d.PNG", game_trophy_data->path, trophy_id));
if (trophy_id < 10)
{
padding = "00";
}
else if (trophy_id < 100)
{
padding = "0";
}
QPixmap trophy_icon; QPixmap trophy_icon;
const QString path = qstr(game_trophy_data->path) + "TROP" + padding + QString::number(trophy_id) + ".PNG";
if (!trophy_icon.load(path)) if (!trophy_icon.load(path))
{ {
gui_log.error("Failed to load trophy icon for trophy %d %s", trophy_id, game_trophy_data->path); gui_log.error("Failed to load trophy icon for trophy %d %s", trophy_id, sstr(path));
} }
game_trophy_data->trophy_images.emplace_back(std::move(trophy_icon)); game_trophy_data->trophy_images.emplace_back(std::move(trophy_icon));
} }