mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-11 01:08:39 +12:00
Qt: minor optimizations in trophy_manager_dialog
This commit is contained in:
parent
8d955cfb8c
commit
91ad3d371f
1 changed files with 58 additions and 45 deletions
|
@ -212,7 +212,10 @@ trophy_manager_dialog::trophy_manager_dialog(std::shared_ptr<gui_settings> gui_s
|
||||||
connect(m_icon_slider, &QSlider::valueChanged, this, [=](int val)
|
connect(m_icon_slider, &QSlider::valueChanged, this, [=](int val)
|
||||||
{
|
{
|
||||||
m_icon_height = val;
|
m_icon_height = val;
|
||||||
trophy_slider_label->setText(tr("Trophy Icon Size: %0x%1").arg(val).arg(val));
|
if (trophy_slider_label)
|
||||||
|
{
|
||||||
|
trophy_slider_label->setText(tr("Trophy Icon Size: %0x%1").arg(val).arg(val));
|
||||||
|
}
|
||||||
ResizeTrophyIcons();
|
ResizeTrophyIcons();
|
||||||
if (m_save_icon_height)
|
if (m_save_icon_height)
|
||||||
{
|
{
|
||||||
|
@ -237,8 +240,11 @@ trophy_manager_dialog::trophy_manager_dialog(std::shared_ptr<gui_settings> gui_s
|
||||||
connect(m_game_icon_slider, &QSlider::valueChanged, this, [=](int val)
|
connect(m_game_icon_slider, &QSlider::valueChanged, this, [=](int val)
|
||||||
{
|
{
|
||||||
m_game_icon_size_index = val;
|
m_game_icon_size_index = val;
|
||||||
m_game_icon_size = gui_settings::SizeFromSlider(val);;
|
m_game_icon_size = gui_settings::SizeFromSlider(val);
|
||||||
game_slider_label->setText(tr("Game Icon Size: %0x%1").arg(m_game_icon_size.width()).arg(m_game_icon_size.height()));
|
if (game_slider_label)
|
||||||
|
{
|
||||||
|
game_slider_label->setText(tr("Game Icon Size: %0x%1").arg(m_game_icon_size.width()).arg(m_game_icon_size.height()));
|
||||||
|
}
|
||||||
ResizeGameIcons();
|
ResizeGameIcons();
|
||||||
if (m_save_game_icon_size)
|
if (m_save_game_icon_size)
|
||||||
{
|
{
|
||||||
|
@ -342,16 +348,16 @@ trophy_manager_dialog::~trophy_manager_dialog()
|
||||||
|
|
||||||
bool trophy_manager_dialog::LoadTrophyFolderToDB(const std::string& trop_name)
|
bool trophy_manager_dialog::LoadTrophyFolderToDB(const std::string& trop_name)
|
||||||
{
|
{
|
||||||
std::string trophyPath = m_trophy_dir + trop_name;
|
const std::string trophyPath = m_trophy_dir + trop_name;
|
||||||
|
|
||||||
// Populate GameTrophiesData
|
// Populate GameTrophiesData
|
||||||
std::unique_ptr<GameTrophiesData> game_trophy_data = std::make_unique<GameTrophiesData>();
|
std::unique_ptr<GameTrophiesData> game_trophy_data = std::make_unique<GameTrophiesData>();
|
||||||
|
|
||||||
game_trophy_data->path = vfs::get(trophyPath + "/");
|
game_trophy_data->path = vfs::get(trophyPath + "/");
|
||||||
game_trophy_data->trop_usr.reset(new TROPUSRLoader());
|
game_trophy_data->trop_usr.reset(new TROPUSRLoader());
|
||||||
std::string trophyUsrPath = trophyPath + "/TROPUSR.DAT";
|
const std::string trophyUsrPath = trophyPath + "/TROPUSR.DAT";
|
||||||
std::string trophyConfPath = trophyPath + "/TROPCONF.SFM";
|
const std::string trophyConfPath = trophyPath + "/TROPCONF.SFM";
|
||||||
bool success = game_trophy_data->trop_usr->Load(trophyUsrPath, trophyConfPath);
|
const bool success = game_trophy_data->trop_usr->Load(trophyUsrPath, trophyConfPath);
|
||||||
|
|
||||||
fs::file config(vfs::get(trophyConfPath));
|
fs::file config(vfs::get(trophyConfPath));
|
||||||
|
|
||||||
|
@ -361,13 +367,15 @@ bool trophy_manager_dialog::LoadTrophyFolderToDB(const std::string& trop_name)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (game_trophy_data->trop_usr->GetTrophiesCount() == 0)
|
const u32 trophy_count = game_trophy_data->trop_usr->GetTrophiesCount();
|
||||||
|
|
||||||
|
if (trophy_count == 0)
|
||||||
{
|
{
|
||||||
LOG_ERROR(GENERAL, "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);
|
LOG_ERROR(GENERAL, "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 < game_trophy_data->trop_usr->GetTrophiesCount(); ++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)
|
// Figure out how many zeros are needed for padding. (either 0, 1, or 2)
|
||||||
QString padding = "";
|
QString padding = "";
|
||||||
|
@ -381,7 +389,7 @@ bool trophy_manager_dialog::LoadTrophyFolderToDB(const std::string& trop_name)
|
||||||
}
|
}
|
||||||
|
|
||||||
QPixmap trophy_icon;
|
QPixmap trophy_icon;
|
||||||
QString path = qstr(game_trophy_data->path) + "TROP" + padding + QString::number(trophy_id) + ".PNG";
|
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))
|
||||||
{
|
{
|
||||||
LOG_ERROR(GENERAL, "Failed to load trophy icon for trophy %n %s", trophy_id, game_trophy_data->path);
|
LOG_ERROR(GENERAL, "Failed to load trophy icon for trophy %n %s", trophy_id, game_trophy_data->path);
|
||||||
|
@ -580,10 +588,16 @@ void trophy_manager_dialog::ResizeTrophyIcons()
|
||||||
|
|
||||||
void trophy_manager_dialog::ApplyFilter()
|
void trophy_manager_dialog::ApplyFilter()
|
||||||
{
|
{
|
||||||
if (m_game_combo->count() <= 0)
|
if (!m_game_combo || m_game_combo->count() <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int db_pos = m_game_combo->currentData().toInt();
|
const int db_pos = m_game_combo->currentData().toInt();
|
||||||
|
if (db_pos >= m_trophies_db.size() || !m_trophies_db[db_pos])
|
||||||
|
return;
|
||||||
|
|
||||||
|
const auto trop_usr = m_trophies_db[db_pos]->trop_usr.get();
|
||||||
|
if (!trop_usr)
|
||||||
|
return;
|
||||||
|
|
||||||
for (int i = 0; i < m_trophy_table->rowCount(); ++i)
|
for (int i = 0; i < m_trophy_table->rowCount(); ++i)
|
||||||
{
|
{
|
||||||
|
@ -600,35 +614,35 @@ void trophy_manager_dialog::ApplyFilter()
|
||||||
const QString trophy_type = type_item->text();
|
const QString trophy_type = type_item->text();
|
||||||
|
|
||||||
// I could use boolean logic and reduce this to something much shorter and also much more confusing...
|
// I could use boolean logic and reduce this to something much shorter and also much more confusing...
|
||||||
bool hidden = icon_item->data(Qt::UserRole).toBool();
|
const bool hidden = icon_item->data(Qt::UserRole).toBool();
|
||||||
bool trophy_unlocked = m_trophies_db[db_pos]->trop_usr->GetTrophyUnlockState(trophy_id);
|
const bool trophy_unlocked = trop_usr->GetTrophyUnlockState(trophy_id);
|
||||||
|
|
||||||
bool hide = false;
|
bool hide = false;
|
||||||
if (trophy_unlocked && !m_show_unlocked_trophies)
|
|
||||||
{
|
|
||||||
hide = true;
|
|
||||||
}
|
|
||||||
if (!trophy_unlocked && !m_show_locked_trophies)
|
|
||||||
{
|
|
||||||
hide = true;
|
|
||||||
}
|
|
||||||
if (hidden && !trophy_unlocked && !m_show_hidden_trophies)
|
|
||||||
{
|
|
||||||
hide = true;
|
|
||||||
}
|
|
||||||
if ((trophy_type == Bronze && !m_show_bronze_trophies)
|
|
||||||
|| (trophy_type == Silver && !m_show_silver_trophies)
|
|
||||||
|| (trophy_type == Gold && !m_show_gold_trophies)
|
|
||||||
|| (trophy_type == Platinum && !m_show_platinum_trophies))
|
|
||||||
{
|
|
||||||
hide = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Special override to show *just* hidden trophies.
|
// Special override to show *just* hidden trophies.
|
||||||
if (!m_show_unlocked_trophies && !m_show_locked_trophies && m_show_hidden_trophies)
|
if (!m_show_unlocked_trophies && !m_show_locked_trophies && m_show_hidden_trophies)
|
||||||
{
|
{
|
||||||
hide = !hidden;
|
hide = !hidden;
|
||||||
}
|
}
|
||||||
|
else if (trophy_unlocked && !m_show_unlocked_trophies)
|
||||||
|
{
|
||||||
|
hide = true;
|
||||||
|
}
|
||||||
|
else if (!trophy_unlocked && !m_show_locked_trophies)
|
||||||
|
{
|
||||||
|
hide = true;
|
||||||
|
}
|
||||||
|
else if (hidden && !trophy_unlocked && !m_show_hidden_trophies)
|
||||||
|
{
|
||||||
|
hide = true;
|
||||||
|
}
|
||||||
|
else if ((trophy_type == Bronze && !m_show_bronze_trophies)
|
||||||
|
|| (trophy_type == Silver && !m_show_silver_trophies)
|
||||||
|
|| (trophy_type == Gold && !m_show_gold_trophies)
|
||||||
|
|| (trophy_type == Platinum && !m_show_platinum_trophies))
|
||||||
|
{
|
||||||
|
hide = true;
|
||||||
|
}
|
||||||
|
|
||||||
m_trophy_table->setRowHidden(i, hide);
|
m_trophy_table->setRowHidden(i, hide);
|
||||||
}
|
}
|
||||||
|
@ -803,14 +817,14 @@ void trophy_manager_dialog::PopulateTrophyTable()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 trophy_id = atoi(n->GetAttribute("id").c_str());
|
|
||||||
|
|
||||||
// Don't show hidden trophies
|
|
||||||
bool hidden = n->GetAttribute("hidden")[0] == 'y';
|
|
||||||
|
|
||||||
// Get data (stolen graciously from sceNpTrophy.cpp)
|
// Get data (stolen graciously from sceNpTrophy.cpp)
|
||||||
SceNpTrophyDetails details;
|
SceNpTrophyDetails details;
|
||||||
|
|
||||||
|
// Get trophy id
|
||||||
|
const s32 trophy_id = atoi(n->GetAttribute("id").c_str());
|
||||||
details.trophyId = trophy_id;
|
details.trophyId = trophy_id;
|
||||||
|
|
||||||
|
// Get trophy type
|
||||||
QString trophy_type = "";
|
QString trophy_type = "";
|
||||||
|
|
||||||
switch (n->GetAttribute("ttype")[0])
|
switch (n->GetAttribute("ttype")[0])
|
||||||
|
@ -821,12 +835,11 @@ void trophy_manager_dialog::PopulateTrophyTable()
|
||||||
case 'P': details.trophyGrade = SCE_NP_TROPHY_GRADE_PLATINUM; trophy_type = Platinum; break;
|
case 'P': details.trophyGrade = SCE_NP_TROPHY_GRADE_PLATINUM; trophy_type = Platinum; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (n->GetAttribute("hidden")[0])
|
// Get hidden state
|
||||||
{
|
const bool hidden = n->GetAttribute("hidden")[0] == 'y';
|
||||||
case 'y': details.hidden = true; break;
|
details.hidden = hidden;
|
||||||
case 'n': details.hidden = false; break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Get name and detail
|
||||||
for (std::shared_ptr<rXmlNode> n2 = n->GetChildren(); n2; n2 = n2->GetNext())
|
for (std::shared_ptr<rXmlNode> n2 = n->GetChildren(); n2; n2 = n2->GetNext())
|
||||||
{
|
{
|
||||||
if (n2->GetName() == "name")
|
if (n2->GetName() == "name")
|
||||||
|
@ -841,7 +854,7 @@ void trophy_manager_dialog::PopulateTrophyTable()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString unlockstate = data->trop_usr->GetTrophyUnlockState(trophy_id) ? tr("Unlocked") : tr("Locked");
|
const QString unlockstate = data->trop_usr->GetTrophyUnlockState(trophy_id) ? tr("Unlocked") : tr("Locked");
|
||||||
|
|
||||||
custom_table_widget_item* icon_item = new custom_table_widget_item();
|
custom_table_widget_item* icon_item = new custom_table_widget_item();
|
||||||
icon_item->setData(Qt::UserRole, hidden, true);
|
icon_item->setData(Qt::UserRole, hidden, true);
|
||||||
|
@ -910,7 +923,7 @@ bool trophy_manager_dialog::eventFilter(QObject *object, QEvent *event)
|
||||||
|
|
||||||
if (wheelEvent->modifiers() & Qt::ControlModifier && (is_trophy_scroll || is_game_scroll))
|
if (wheelEvent->modifiers() & Qt::ControlModifier && (is_trophy_scroll || is_game_scroll))
|
||||||
{
|
{
|
||||||
QPoint numSteps = wheelEvent->angleDelta() / 8 / 15; // http://doc.qt.io/qt-5/qwheelevent.html#pixelDelta
|
const QPoint numSteps = wheelEvent->angleDelta() / 8 / 15; // http://doc.qt.io/qt-5/qwheelevent.html#pixelDelta
|
||||||
zoom_val = numSteps.y();
|
zoom_val = numSteps.y();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue