FullscreenUI: Simplify game properties state

Only allow scanned games to be changed like the Qt UI, makes everything
much simpler.
pull/3589/head
Stenzek 7 days ago
parent 32aa86a608
commit 45d3c66579
No known key found for this signature in database

@ -2,10 +2,10 @@
// SPDX-License-Identifier: CC-BY-NC-ND-4.0 // SPDX-License-Identifier: CC-BY-NC-ND-4.0
#include "fullscreenui.h" #include "fullscreenui.h"
#include "fullscreenui_private.h"
#include "fullscreenui_widgets.h"
#include "achievements_private.h" #include "achievements_private.h"
#include "controller.h" #include "controller.h"
#include "fullscreenui_private.h"
#include "fullscreenui_widgets.h"
#include "game_list.h" #include "game_list.h"
#include "gpu_thread.h" #include "gpu_thread.h"
#include "system.h" #include "system.h"
@ -127,7 +127,7 @@ static constexpr std::string_view ABOUT_DIALOG_NAME = "##about_duckstation";
namespace { namespace {
struct ALIGN_TO_CACHE_LINE Locals struct Locals
{ {
// Main // Main
MainWindowType current_main_window = MainWindowType::None; MainWindowType current_main_window = MainWindowType::None;
@ -154,7 +154,7 @@ struct ALIGN_TO_CACHE_LINE Locals
} // namespace } // namespace
static Locals s_locals; ALIGN_TO_CACHE_LINE static Locals s_locals;
} // namespace FullscreenUI } // namespace FullscreenUI
@ -1604,8 +1604,11 @@ void FullscreenUI::DrawPauseMenu()
DoToggleAnalogMode(); DoToggleAnalogMode();
} }
if (MenuButtonWithoutSummary(FSUI_ICONVSTR(ICON_FA_WRENCH, "Game Properties"), has_game)) if (MenuButtonWithoutSummary(FSUI_ICONVSTR(ICON_FA_WRENCH, "Game Properties"),
has_game && !GPUThread::GetGameSerial().empty()))
{
BeginTransition([]() { SwitchToGameSettings(); }); BeginTransition([]() { SwitchToGameSettings(); });
}
if (MenuButtonWithoutSummary(FSUI_ICONVSTR(ICON_FA_TROPHY, "Achievements"), if (MenuButtonWithoutSummary(FSUI_ICONVSTR(ICON_FA_TROPHY, "Achievements"),
Achievements::HasAchievementsOrLeaderboards())) Achievements::HasAchievementsOrLeaderboards()))

@ -112,7 +112,6 @@ void SwitchToSettings();
bool SwitchToGameSettings(SettingsPage page = SettingsPage::Summary); bool SwitchToGameSettings(SettingsPage page = SettingsPage::Summary);
void SwitchToGameSettings(const GameList::Entry* entry, SettingsPage page = SettingsPage::Summary); void SwitchToGameSettings(const GameList::Entry* entry, SettingsPage page = SettingsPage::Summary);
bool SwitchToGameSettingsForPath(const std::string& path, SettingsPage page = SettingsPage::Summary); bool SwitchToGameSettingsForPath(const std::string& path, SettingsPage page = SettingsPage::Summary);
void SwitchToGameSettingsForSerial(std::string_view serial, GameHash hash, SettingsPage page = SettingsPage::Summary);
void DrawSettingsWindow(); void DrawSettingsWindow();
SettingsPage GetCurrentSettingsPage(); SettingsPage GetCurrentSettingsPage();
bool IsInputBindingDialogOpen(); bool IsInputBindingDialogOpen();

@ -33,6 +33,7 @@
#include "IconsFontAwesome6.h" #include "IconsFontAwesome6.h"
#include "IconsPromptFont.h" #include "IconsPromptFont.h"
#include <limits>
#include <mutex> #include <mutex>
LOG_CHANNEL(FullscreenUI); LOG_CHANNEL(FullscreenUI);
@ -186,14 +187,11 @@ static constexpr std::string_view ACHIEVEMENTS_LOGIN_DIALOG_NAME = "##achievemen
static constexpr std::string_view COVER_DOWNLOADER_DIALOG_NAME = "##cover_downloader"; static constexpr std::string_view COVER_DOWNLOADER_DIALOG_NAME = "##cover_downloader";
namespace { namespace {
struct ALIGN_TO_CACHE_LINE SettingsLocals struct SettingsLocals
{ {
float settings_last_bg_alpha = 1.0f; float settings_last_bg_alpha = 1.0f;
SettingsPage settings_page = SettingsPage::Interface; SettingsPage settings_page = SettingsPage::Interface;
std::unique_ptr<INISettingsInterface> game_settings_interface; std::unique_ptr<INISettingsInterface> game_settings_interface;
std::string game_settings_serial;
GameHash game_settings_hash = 0;
const GameDatabase::Entry* game_settings_db_entry;
std::unique_ptr<GameList::Entry> game_settings_entry; std::unique_ptr<GameList::Entry> game_settings_entry;
std::vector<std::pair<std::string, bool>> game_list_directories_cache; std::vector<std::pair<std::string, bool>> game_list_directories_cache;
GPUDevice::AdapterInfoList graphics_adapter_list_cache; GPUDevice::AdapterInfoList graphics_adapter_list_cache;
@ -213,7 +211,7 @@ struct ALIGN_TO_CACHE_LINE SettingsLocals
} // namespace } // namespace
static SettingsLocals s_settings_locals; ALIGN_TO_CACHE_LINE static SettingsLocals s_settings_locals;
} // namespace FullscreenUI } // namespace FullscreenUI
@ -1564,10 +1562,7 @@ void FullscreenUI::ClearSettingsState()
s_settings_locals.input_binding_dialog.ClearState(); s_settings_locals.input_binding_dialog.ClearState();
std::memset(s_settings_locals.controller_macro_expanded, 0, sizeof(s_settings_locals.controller_macro_expanded)); std::memset(s_settings_locals.controller_macro_expanded, 0, sizeof(s_settings_locals.controller_macro_expanded));
s_settings_locals.game_list_directories_cache = {}; s_settings_locals.game_list_directories_cache = {};
s_settings_locals.game_settings_db_entry = nullptr;
s_settings_locals.game_settings_entry.reset(); s_settings_locals.game_settings_entry.reset();
s_settings_locals.game_settings_hash = 0;
s_settings_locals.game_settings_serial = {};
s_settings_locals.game_settings_interface.reset(); s_settings_locals.game_settings_interface.reset();
s_settings_locals.game_settings_changed = false; s_settings_locals.game_settings_changed = false;
s_settings_locals.game_patch_list = {}; s_settings_locals.game_patch_list = {};
@ -1585,9 +1580,6 @@ void FullscreenUI::SwitchToSettings()
{ {
s_settings_locals.game_settings_entry.reset(); s_settings_locals.game_settings_entry.reset();
s_settings_locals.game_settings_interface.reset(); s_settings_locals.game_settings_interface.reset();
s_settings_locals.game_settings_serial = {};
s_settings_locals.game_settings_hash = 0;
s_settings_locals.game_settings_db_entry = nullptr;
s_settings_locals.game_patch_list = {}; s_settings_locals.game_patch_list = {};
s_settings_locals.enabled_game_patch_cache = {}; s_settings_locals.enabled_game_patch_cache = {};
s_settings_locals.game_cheats_list = {}; s_settings_locals.game_cheats_list = {};
@ -1609,45 +1601,20 @@ void FullscreenUI::SwitchToSettings()
s_settings_locals.settings_last_bg_alpha = GetBackgroundAlpha(); s_settings_locals.settings_last_bg_alpha = GetBackgroundAlpha();
} }
void FullscreenUI::SwitchToGameSettingsForSerial(std::string_view serial, GameHash hash, SettingsPage page)
{
s_settings_locals.game_settings_serial = serial;
s_settings_locals.game_settings_hash = hash;
s_settings_locals.game_settings_entry.reset();
s_settings_locals.game_settings_db_entry = GameDatabase::GetEntryForSerial(serial);
s_settings_locals.game_settings_interface =
System::GetGameSettingsInterface(s_settings_locals.game_settings_db_entry, serial, true, false);
PopulatePatchesAndCheatsList();
s_settings_locals.settings_page = page;
SwitchToMainWindow(MainWindowType::Settings);
}
bool FullscreenUI::SwitchToGameSettings(SettingsPage page) bool FullscreenUI::SwitchToGameSettings(SettingsPage page)
{ {
const std::string& serial = GPUThread::GetGameSerial(); return SwitchToGameSettingsForPath(GPUThread::GetGamePath());
if (serial.empty())
return false;
auto lock = GameList::GetLock();
const GameList::Entry* entry = GameList::GetEntryForPath(GPUThread::GetGamePath());
if (!entry)
{
SwitchToGameSettingsForSerial(serial, GPUThread::GetGameHash(), page);
return true;
}
else
{
SwitchToGameSettings(entry, page);
return true;
}
} }
bool FullscreenUI::SwitchToGameSettingsForPath(const std::string& path, SettingsPage page) bool FullscreenUI::SwitchToGameSettingsForPath(const std::string& path, SettingsPage page)
{ {
auto lock = GameList::GetLock(); auto lock = GameList::GetLock();
const GameList::Entry* entry = GameList::GetEntryForPath(path); const GameList::Entry* entry = !path.empty() ? GameList::GetEntryForPath(path) : nullptr;
if (!entry) if (!entry || entry->serial.empty())
{
ShowToast({}, FSUI_STR("Game properties is only available for scanned games."));
return false; return false;
}
SwitchToGameSettings(entry, page); SwitchToGameSettings(entry, page);
return true; return true;
@ -1655,8 +1622,12 @@ bool FullscreenUI::SwitchToGameSettingsForPath(const std::string& path, Settings
void FullscreenUI::SwitchToGameSettings(const GameList::Entry* entry, SettingsPage page) void FullscreenUI::SwitchToGameSettings(const GameList::Entry* entry, SettingsPage page)
{ {
SwitchToGameSettingsForSerial(entry->serial, entry->hash, page);
s_settings_locals.game_settings_entry = std::make_unique<GameList::Entry>(*entry); s_settings_locals.game_settings_entry = std::make_unique<GameList::Entry>(*entry);
s_settings_locals.game_settings_interface = System::GetGameSettingsInterface(
s_settings_locals.game_settings_entry->dbentry, s_settings_locals.game_settings_entry->serial, true, false);
PopulatePatchesAndCheatsList();
s_settings_locals.settings_page = page;
SwitchToMainWindow(MainWindowType::Settings);
} }
void FullscreenUI::PopulateGraphicsAdapterList() void FullscreenUI::PopulateGraphicsAdapterList()
@ -1683,10 +1654,10 @@ void FullscreenUI::PopulateGameListDirectoryCache(SettingsInterface* si)
void FullscreenUI::PopulatePatchesAndCheatsList() void FullscreenUI::PopulatePatchesAndCheatsList()
{ {
s_settings_locals.game_patch_list = Cheats::GetCodeInfoList(s_settings_locals.game_settings_serial, s_settings_locals.game_patch_list = Cheats::GetCodeInfoList(
s_settings_locals.game_settings_hash, false, true, true); s_settings_locals.game_settings_entry->serial, s_settings_locals.game_settings_entry->hash, false, true, true);
s_settings_locals.game_cheats_list = Cheats::GetCodeInfoList( s_settings_locals.game_cheats_list = Cheats::GetCodeInfoList(
s_settings_locals.game_settings_serial, s_settings_locals.game_settings_hash, true, s_settings_locals.game_settings_entry->serial, s_settings_locals.game_settings_entry->hash, true,
s_settings_locals.game_settings_interface->GetBoolValue("Cheats", "LoadCheatsFromDatabase", true), s_settings_locals.game_settings_interface->GetBoolValue("Cheats", "LoadCheatsFromDatabase", true),
s_settings_locals.game_settings_interface->GetBoolValue("Cheats", "SortList", false)); s_settings_locals.game_settings_interface->GetBoolValue("Cheats", "SortList", false));
s_settings_locals.game_cheat_groups = Cheats::GetCodeListUniquePrefixes(s_settings_locals.game_cheats_list, true); s_settings_locals.game_cheat_groups = Cheats::GetCodeListUniquePrefixes(s_settings_locals.game_cheats_list, true);
@ -2064,11 +2035,12 @@ void FullscreenUI::DrawSummarySettingsPage(bool show_localized_titles)
MenuHeading(FSUI_VSTR("Options")); MenuHeading(FSUI_VSTR("Options"));
if (s_settings_locals.game_settings_db_entry && s_settings_locals.game_settings_db_entry->disc_set) DebugAssert(s_settings_locals.game_settings_entry);
if (s_settings_locals.game_settings_entry->dbentry && s_settings_locals.game_settings_entry->dbentry->disc_set)
{ {
// only enable for first disc // only enable for first disc
const bool is_first_disc = (s_settings_locals.game_settings_db_entry->serial == const bool is_first_disc = (s_settings_locals.game_settings_entry->dbentry->serial ==
s_settings_locals.game_settings_db_entry->disc_set->serials.front()); s_settings_locals.game_settings_entry->dbentry->disc_set->serials.front());
DrawToggleSetting( DrawToggleSetting(
GetEditingSettingsInterface(), FSUI_ICONVSTR(ICON_FA_COMPACT_DISC, "Use Separate Disc Settings"), GetEditingSettingsInterface(), FSUI_ICONVSTR(ICON_FA_COMPACT_DISC, "Use Separate Disc Settings"),
FSUI_VSTR( FSUI_VSTR(
@ -5180,8 +5152,8 @@ void FullscreenUI::DrawPatchesOrCheatsSettingsPage(bool cheats)
bsi->SetBoolValue("Cheats", "SortList", true); bsi->SetBoolValue("Cheats", "SortList", true);
SetSettingsChanged(bsi); SetSettingsChanged(bsi);
s_settings_locals.game_cheats_list = s_settings_locals.game_cheats_list =
Cheats::GetCodeInfoList(s_settings_locals.game_settings_serial, s_settings_locals.game_settings_hash, true, Cheats::GetCodeInfoList(s_settings_locals.game_settings_entry->serial,
load_database_cheats, sort_list); s_settings_locals.game_settings_entry->hash, true, load_database_cheats, sort_list);
} }
if (code_list.empty()) if (code_list.empty())

@ -297,7 +297,7 @@ public:
void End(); void End();
}; };
struct ALIGN_TO_CACHE_LINE WidgetsState struct WidgetsState
{ {
std::recursive_mutex shared_state_mutex; std::recursive_mutex shared_state_mutex;
@ -370,8 +370,8 @@ struct ALIGN_TO_CACHE_LINE WidgetsState
} // namespace } // namespace
UIStyles UIStyle = {}; ALIGN_TO_CACHE_LINE UIStyles UIStyle = {};
static WidgetsState s_state; ALIGN_TO_CACHE_LINE static WidgetsState s_state;
} // namespace FullscreenUI } // namespace FullscreenUI

@ -945,7 +945,7 @@ static constexpr const char* DATE_TIME_FORMAT =
namespace { namespace {
struct ALIGN_TO_CACHE_LINE State struct State
{ {
std::shared_ptr<GPUTexture> placeholder_texture; std::shared_ptr<GPUTexture> placeholder_texture;
@ -969,7 +969,7 @@ struct ALIGN_TO_CACHE_LINE State
} // namespace } // namespace
static State s_state; ALIGN_TO_CACHE_LINE static State s_state;
} // namespace SaveStateSelectorUI } // namespace SaveStateSelectorUI

Loading…
Cancel
Save