mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-14 21:37:52 -07:00
Added player and game badges to Achievements dialog header
Provided badges are turned on, if there's a player logged in their RetroAchievements icon will appear next to their player info in the header of the Achievements dialog. If they're playing a game, so will the icon for the game. Also performed some refactoring and reorganizing to the header as a whole so that it looks consistent whether a game is running or not.
This commit is contained in:
parent
fd50b1fda6
commit
0715da2d68
@ -30,45 +30,44 @@
|
|||||||
|
|
||||||
AchievementHeaderWidget::AchievementHeaderWidget(QWidget* parent) : QWidget(parent)
|
AchievementHeaderWidget::AchievementHeaderWidget(QWidget* parent) : QWidget(parent)
|
||||||
{
|
{
|
||||||
m_user_name = new QLabel();
|
m_user_icon = new QLabel();
|
||||||
m_user_points = new QLabel();
|
m_game_icon = new QLabel();
|
||||||
m_game_name = new QLabel();
|
m_name = new QLabel();
|
||||||
m_game_points = new QLabel();
|
m_points = new QLabel();
|
||||||
m_game_progress_hard = new QProgressBar();
|
m_game_progress_hard = new QProgressBar();
|
||||||
m_game_progress_soft = new QProgressBar();
|
m_game_progress_soft = new QProgressBar();
|
||||||
m_rich_presence = new QLabel();
|
m_rich_presence = new QLabel();
|
||||||
|
|
||||||
QVBoxLayout* m_user_right_col = new QVBoxLayout();
|
QSizePolicy sp_retain = m_game_progress_hard->sizePolicy();
|
||||||
m_user_right_col->addWidget(m_user_name);
|
sp_retain.setRetainSizeWhenHidden(true);
|
||||||
m_user_right_col->addWidget(m_user_points);
|
m_game_progress_hard->setSizePolicy(sp_retain);
|
||||||
QHBoxLayout* m_user_layout = new QHBoxLayout();
|
sp_retain = m_game_progress_soft->sizePolicy();
|
||||||
// TODO: player badge goes here
|
sp_retain.setRetainSizeWhenHidden(true);
|
||||||
m_user_layout->addLayout(m_user_right_col);
|
m_game_progress_soft->setSizePolicy(sp_retain);
|
||||||
m_user_box = new QGroupBox();
|
|
||||||
m_user_box->setLayout(m_user_layout);
|
|
||||||
|
|
||||||
QVBoxLayout* m_game_right_col = new QVBoxLayout();
|
QVBoxLayout* icon_col = new QVBoxLayout();
|
||||||
m_game_right_col->addWidget(m_game_name);
|
icon_col->addWidget(m_user_icon);
|
||||||
m_game_right_col->addWidget(m_game_points);
|
icon_col->addWidget(m_game_icon);
|
||||||
m_game_right_col->addWidget(m_game_progress_hard);
|
QVBoxLayout* text_col = new QVBoxLayout();
|
||||||
m_game_right_col->addWidget(m_game_progress_soft);
|
text_col->addWidget(m_name);
|
||||||
QHBoxLayout* m_game_upper_row = new QHBoxLayout();
|
text_col->addWidget(m_points);
|
||||||
// TODO: player badge and game badge go here
|
text_col->addWidget(m_game_progress_hard);
|
||||||
m_game_upper_row->addLayout(m_game_right_col);
|
text_col->addWidget(m_game_progress_soft);
|
||||||
QVBoxLayout* m_game_layout = new QVBoxLayout();
|
text_col->addWidget(m_rich_presence);
|
||||||
m_game_layout->addLayout(m_game_upper_row);
|
QHBoxLayout* header_layout = new QHBoxLayout();
|
||||||
m_game_layout->addWidget(m_rich_presence);
|
header_layout->addLayout(icon_col);
|
||||||
m_game_box = new QGroupBox();
|
header_layout->addLayout(text_col);
|
||||||
m_game_box->setLayout(m_game_layout);
|
m_header_box = new QGroupBox();
|
||||||
|
m_header_box->setLayout(header_layout);
|
||||||
|
|
||||||
QVBoxLayout* m_total = new QVBoxLayout();
|
QVBoxLayout* m_total = new QVBoxLayout();
|
||||||
m_total->addWidget(m_user_box);
|
m_total->addWidget(m_header_box);
|
||||||
m_total->addWidget(m_game_box);
|
|
||||||
|
|
||||||
m_total->setContentsMargins(0, 0, 0, 0);
|
m_total->setContentsMargins(0, 0, 0, 0);
|
||||||
m_total->setAlignment(Qt::AlignTop);
|
m_total->setAlignment(Qt::AlignTop);
|
||||||
setLayout(m_total);
|
setLayout(m_total);
|
||||||
|
|
||||||
|
std::lock_guard lg{*AchievementManager::GetInstance()->GetLock()};
|
||||||
UpdateData();
|
UpdateData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,38 +75,83 @@ void AchievementHeaderWidget::UpdateData()
|
|||||||
{
|
{
|
||||||
if (!AchievementManager::GetInstance()->IsLoggedIn())
|
if (!AchievementManager::GetInstance()->IsLoggedIn())
|
||||||
{
|
{
|
||||||
m_user_box->setVisible(false);
|
m_header_box->setVisible(false);
|
||||||
m_game_box->setVisible(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString user_name =
|
|
||||||
QString::fromStdString(AchievementManager::GetInstance()->GetPlayerDisplayName());
|
|
||||||
m_user_name->setText(user_name);
|
|
||||||
m_user_points->setText(tr("%1 points").arg(AchievementManager::GetInstance()->GetPlayerScore()));
|
|
||||||
|
|
||||||
if (!AchievementManager::GetInstance()->IsGameLoaded())
|
|
||||||
{
|
|
||||||
m_user_box->setVisible(true);
|
|
||||||
m_game_box->setVisible(false);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
AchievementManager::PointSpread point_spread = AchievementManager::GetInstance()->TallyScore();
|
AchievementManager::PointSpread point_spread = AchievementManager::GetInstance()->TallyScore();
|
||||||
m_game_name->setText(
|
QString user_name =
|
||||||
QString::fromStdString(AchievementManager::GetInstance()->GetGameDisplayName()));
|
QString::fromStdString(AchievementManager::GetInstance()->GetPlayerDisplayName());
|
||||||
m_game_points->setText(GetPointsString(user_name, point_spread));
|
QString game_name =
|
||||||
m_game_progress_hard = new QProgressBar();
|
QString::fromStdString(AchievementManager::GetInstance()->GetGameDisplayName());
|
||||||
m_game_progress_hard->setRange(0, point_spread.total_count);
|
AchievementManager::BadgeStatus player_badge =
|
||||||
m_game_progress_soft->setValue(point_spread.hard_unlocks);
|
AchievementManager::GetInstance()->GetPlayerBadge();
|
||||||
m_game_progress_soft->setRange(0, point_spread.total_count);
|
AchievementManager::BadgeStatus game_badge = AchievementManager::GetInstance()->GetGameBadge();
|
||||||
m_game_progress_soft->setValue(point_spread.hard_unlocks + point_spread.soft_unlocks);
|
|
||||||
m_rich_presence->setText(
|
|
||||||
QString::fromUtf8(AchievementManager::GetInstance()->GetRichPresence().data()));
|
|
||||||
m_rich_presence->setVisible(Config::Get(Config::RA_RICH_PRESENCE_ENABLED));
|
|
||||||
|
|
||||||
m_user_box->setVisible(false);
|
m_user_icon->setVisible(false);
|
||||||
m_game_box->setVisible(true);
|
m_user_icon->clear();
|
||||||
|
m_user_icon->setText({});
|
||||||
|
if (Config::Get(Config::RA_BADGES_ENABLED))
|
||||||
|
{
|
||||||
|
if (player_badge.name != "")
|
||||||
|
{
|
||||||
|
QImage i_user_icon{};
|
||||||
|
if (i_user_icon.loadFromData(&player_badge.badge.front(), (int)player_badge.badge.size()))
|
||||||
|
{
|
||||||
|
m_user_icon->setPixmap(QPixmap::fromImage(i_user_icon)
|
||||||
|
.scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||||
|
m_user_icon->adjustSize();
|
||||||
|
m_user_icon->setStyleSheet(QStringLiteral("border: 4px solid transparent"));
|
||||||
|
m_user_icon->setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_game_icon->setVisible(false);
|
||||||
|
m_game_icon->clear();
|
||||||
|
m_game_icon->setText({});
|
||||||
|
if (Config::Get(Config::RA_BADGES_ENABLED))
|
||||||
|
{
|
||||||
|
if (game_badge.name != "")
|
||||||
|
{
|
||||||
|
QImage i_game_icon{};
|
||||||
|
if (i_game_icon.loadFromData(&game_badge.badge.front(), (int)game_badge.badge.size()))
|
||||||
|
{
|
||||||
|
m_game_icon->setPixmap(QPixmap::fromImage(i_game_icon)
|
||||||
|
.scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||||
|
m_game_icon->adjustSize();
|
||||||
|
m_game_icon->setStyleSheet(QStringLiteral("border: 4px solid transparent"));
|
||||||
|
m_game_icon->setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!game_name.isEmpty())
|
||||||
|
{
|
||||||
|
m_name->setText(tr("%1 is playing %2").arg(user_name).arg(game_name));
|
||||||
|
m_points->setText(GetPointsString(user_name, point_spread));
|
||||||
|
|
||||||
|
m_game_progress_hard->setRange(0, point_spread.total_count);
|
||||||
|
if (!m_game_progress_hard->isVisible())
|
||||||
|
m_game_progress_hard->setVisible(true);
|
||||||
|
m_game_progress_soft->setValue(point_spread.hard_unlocks);
|
||||||
|
m_game_progress_soft->setRange(0, point_spread.total_count);
|
||||||
|
m_game_progress_soft->setValue(point_spread.hard_unlocks + point_spread.soft_unlocks);
|
||||||
|
if (!m_game_progress_soft->isVisible())
|
||||||
|
m_game_progress_soft->setVisible(true);
|
||||||
|
m_rich_presence->setText(
|
||||||
|
QString::fromUtf8(AchievementManager::GetInstance()->GetRichPresence().data()));
|
||||||
|
if (!m_rich_presence->isVisible())
|
||||||
|
m_rich_presence->setVisible(Config::Get(Config::RA_RICH_PRESENCE_ENABLED));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_name->setText(user_name);
|
||||||
|
m_points->setText(tr("%1 points").arg(AchievementManager::GetInstance()->GetPlayerScore()));
|
||||||
|
|
||||||
|
m_game_progress_hard->setVisible(false);
|
||||||
|
m_game_progress_soft->setVisible(false);
|
||||||
|
m_rich_presence->setVisible(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString
|
QString
|
||||||
|
@ -27,16 +27,14 @@ private:
|
|||||||
QGroupBox* m_common_box;
|
QGroupBox* m_common_box;
|
||||||
QVBoxLayout* m_common_layout;
|
QVBoxLayout* m_common_layout;
|
||||||
|
|
||||||
QLabel* m_user_name;
|
QLabel* m_user_icon;
|
||||||
QLabel* m_user_points;
|
QLabel* m_game_icon;
|
||||||
QLabel* m_game_name;
|
QLabel* m_name;
|
||||||
QLabel* m_game_points;
|
QLabel* m_points;
|
||||||
QProgressBar* m_game_progress_hard;
|
QProgressBar* m_game_progress_hard;
|
||||||
QProgressBar* m_game_progress_soft;
|
QProgressBar* m_game_progress_soft;
|
||||||
QLabel* m_rich_presence;
|
QLabel* m_rich_presence;
|
||||||
|
QGroupBox* m_header_box;
|
||||||
QGroupBox* m_user_box;
|
|
||||||
QGroupBox* m_game_box;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // USE_RETRO_ACHIEVEMENTS
|
#endif // USE_RETRO_ACHIEVEMENTS
|
||||||
|
Loading…
Reference in New Issue
Block a user