UI: Massive revamp, new features and improvements

This commit is contained in:
Connor McLaughlin
2022-07-11 23:03:29 +10:00
parent 3fb61865e5
commit b42b5501f6
425 changed files with 39701 additions and 29487 deletions

View File

@@ -1,8 +1,8 @@
#include "achievementsettingswidget.h"
#include "achievementlogindialog.h"
#include "common/string_util.h"
#include "core/cheevos.h"
#include "core/system.h"
#include "frontend-common/achievements.h"
#include "mainwindow.h"
#include "qtutils.h"
#include "settingsdialog.h"
@@ -10,20 +10,20 @@
#include <QtCore/QDateTime>
#include <QtWidgets/QMessageBox>
AchievementSettingsWidget::AchievementSettingsWidget(QtHostInterface* host_interface, QWidget* parent,
SettingsDialog* dialog)
: QWidget(parent), m_host_interface(host_interface)
AchievementSettingsWidget::AchievementSettingsWidget(SettingsDialog* dialog, QWidget* parent)
: QWidget(parent), m_dialog(dialog)
{
SettingsInterface* sif = dialog->getSettingsInterface();
m_ui.setupUi(this);
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.richPresence, "Cheevos", "RichPresence", true);
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.testMode, "Cheevos", "TestMode", false);
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.unofficialTestMode, "Cheevos",
"UnofficialTestMode", false);
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.useFirstDiscFromPlaylist, "Cheevos",
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.enable, "Cheevos", "Enabled", true);
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.richPresence, "Cheevos", "RichPresence", true);
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.challengeMode, "Cheevos", "ChallengeMode", false);
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.testMode, "Cheevos", "TestMode", false);
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.unofficialTestMode, "Cheevos", "UnofficialTestMode", false);
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.useFirstDiscFromPlaylist, "Cheevos",
"UseFirstDiscFromPlaylist", true);
m_ui.enable->setChecked(m_host_interface->GetBoolSettingValue("Cheevos", "Enabled", false));
m_ui.challengeMode->setChecked(m_host_interface->GetBoolSettingValue("Cheevos", "ChallengeMode", false));
dialog->registerWidgetHelp(m_ui.enable, tr("Enable Achievements"), tr("Unchecked"),
tr("When enabled and logged in, DuckStation will scan for achievements on startup."));
@@ -45,24 +45,37 @@ AchievementSettingsWidget::AchievementSettingsWidget(QtHostInterface* host_inter
tr("\"Challenge\" mode for achievements. Disables save state, cheats, and slowdown "
"functions, but you receive double the achievement points."));
connect(m_ui.enable, &QCheckBox::toggled, this, &AchievementSettingsWidget::onEnableToggled);
connect(m_ui.loginButton, &QPushButton::clicked, this, &AchievementSettingsWidget::onLoginLogoutPressed);
connect(m_ui.viewProfile, &QPushButton::clicked, this, &AchievementSettingsWidget::onViewProfilePressed);
connect(m_ui.challengeMode, &QCheckBox::toggled, this, &AchievementSettingsWidget::onChallengeModeToggled);
connect(host_interface, &QtHostInterface::achievementsLoaded, this, &AchievementSettingsWidget::onAchievementsLoaded);
connect(m_ui.enable, &QCheckBox::stateChanged, this, &AchievementSettingsWidget::updateEnableState);
if (!m_dialog->isPerGameSettings())
{
connect(m_ui.loginButton, &QPushButton::clicked, this, &AchievementSettingsWidget::onLoginLogoutPressed);
connect(m_ui.viewProfile, &QPushButton::clicked, this, &AchievementSettingsWidget::onViewProfilePressed);
connect(g_emu_thread, &EmuThread::achievementsRefreshed, this, &AchievementSettingsWidget::onAchievementsRefreshed);
updateLoginState();
// force a refresh of game info
Host::RunOnCPUThread(Host::OnAchievementsRefreshed);
}
else
{
// remove login and game info, not relevant for per-game
m_ui.verticalLayout->removeWidget(m_ui.gameInfoBox);
m_ui.gameInfoBox->deleteLater();
m_ui.gameInfoBox = nullptr;
m_ui.verticalLayout->removeWidget(m_ui.loginBox);
m_ui.loginBox->deleteLater();
m_ui.loginBox = nullptr;
}
updateEnableState();
updateLoginState();
// force a refresh of game info
host_interface->OnAchievementsRefreshed();
}
AchievementSettingsWidget::~AchievementSettingsWidget() = default;
void AchievementSettingsWidget::updateEnableState()
{
const bool enabled = m_host_interface->GetBoolSettingValue("Cheevos", "Enabled", false);
const bool enabled = m_dialog->getEffectiveBoolValue("Cheevos", "Enabled", false);
m_ui.testMode->setEnabled(enabled);
m_ui.useFirstDiscFromPlaylist->setEnabled(enabled);
m_ui.richPresence->setEnabled(enabled);
@@ -71,13 +84,13 @@ void AchievementSettingsWidget::updateEnableState()
void AchievementSettingsWidget::updateLoginState()
{
const std::string username(m_host_interface->GetStringSettingValue("Cheevos", "Username"));
const std::string username(Host::GetBaseStringSettingValue("Cheevos", "Username"));
const bool logged_in = !username.empty();
if (logged_in)
{
const u64 login_unix_timestamp =
StringUtil::FromChars<u64>(m_host_interface->GetStringSettingValue("Cheevos", "LoginTimestamp", "0")).value_or(0);
StringUtil::FromChars<u64>(Host::GetBaseStringSettingValue("Cheevos", "LoginTimestamp", "0")).value_or(0);
const QDateTime login_timestamp(QDateTime::fromSecsSinceEpoch(static_cast<qint64>(login_unix_timestamp)));
m_ui.loginStatus->setText(tr("Username: %1\nLogin token generated on %2.")
.arg(QString::fromStdString(username))
@@ -95,9 +108,9 @@ void AchievementSettingsWidget::updateLoginState()
void AchievementSettingsWidget::onLoginLogoutPressed()
{
if (!m_host_interface->GetStringSettingValue("Cheevos", "Username").empty())
if (!Host::GetBaseStringSettingValue("Cheevos", "Username").empty())
{
m_host_interface->executeOnEmulationThread([]() { Cheevos::Logout(); }, true);
Host::RunOnCPUThread([]() { Achievements::Logout(); }, true);
updateLoginState();
return;
}
@@ -112,7 +125,7 @@ void AchievementSettingsWidget::onLoginLogoutPressed()
void AchievementSettingsWidget::onViewProfilePressed()
{
const std::string username(m_host_interface->GetStringSettingValue("Cheevos", "Username"));
const std::string username(Host::GetBaseStringSettingValue("Cheevos", "Username"));
if (username.empty())
return;
@@ -122,63 +135,8 @@ void AchievementSettingsWidget::onViewProfilePressed()
QUrl(QStringLiteral("https://retroachievements.org/user/%1").arg(QString::fromUtf8(encoded_username))));
}
void AchievementSettingsWidget::onEnableToggled(bool checked)
{
const bool challenge_mode = m_host_interface->GetBoolSettingValue("Cheevos", "ChallengeMode", false);
const bool challenge_mode_active = checked && challenge_mode;
if (challenge_mode_active && !confirmChallengeModeEnable())
{
QSignalBlocker sb(m_ui.challengeMode);
m_ui.challengeMode->setChecked(false);
return;
}
m_host_interface->SetBoolSettingValue("Cheevos", "Enabled", checked);
m_host_interface->applySettings(false);
if (challenge_mode)
m_host_interface->getMainWindow()->onAchievementsChallengeModeToggled(challenge_mode_active);
updateEnableState();
}
void AchievementSettingsWidget::onChallengeModeToggled(bool checked)
{
if (checked && !confirmChallengeModeEnable())
{
QSignalBlocker sb(m_ui.challengeMode);
m_ui.challengeMode->setChecked(false);
return;
}
m_host_interface->SetBoolSettingValue("Cheevos", "ChallengeMode", checked);
m_host_interface->applySettings(false);
m_host_interface->getMainWindow()->onAchievementsChallengeModeToggled(checked);
}
void AchievementSettingsWidget::onAchievementsLoaded(quint32 id, const QString& game_info_string, quint32 total,
quint32 points)
void AchievementSettingsWidget::onAchievementsRefreshed(quint32 id, const QString& game_info_string, quint32 total,
quint32 points)
{
m_ui.gameInfo->setText(game_info_string);
}
bool AchievementSettingsWidget::confirmChallengeModeEnable()
{
if (!System::IsValid())
return true;
QString message = tr("Enabling hardcore mode will shut down your current game.\n\n");
if (m_host_interface->ShouldSaveResumeState())
{
message +=
tr("The current state will be saved, but you will be unable to load it until you disable hardcore mode.\n\n");
}
message += tr("Do you want to continue?");
if (QMessageBox::question(QtUtils::GetRootWidget(this), tr("Enable Hardcore Mode"), message) != QMessageBox::Yes)
return false;
m_host_interface->synchronousPowerOffSystem();
return true;
}