FullscreenUI: Simplify game properties state

Only allow scanned games to be changed like the Qt UI, makes everything
much simpler.
pull/3589/head
Stenzek 5 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
#include "fullscreenui.h"
#include "fullscreenui_private.h"
#include "fullscreenui_widgets.h"
#include "achievements_private.h"
#include "controller.h"
#include "fullscreenui_private.h"
#include "fullscreenui_widgets.h"
#include "game_list.h"
#include "gpu_thread.h"
#include "system.h"
@ -127,7 +127,7 @@ static constexpr std::string_view ABOUT_DIALOG_NAME = "##about_duckstation";
namespace {
struct ALIGN_TO_CACHE_LINE Locals
struct Locals
{
// Main
MainWindowType current_main_window = MainWindowType::None;
@ -154,7 +154,7 @@ struct ALIGN_TO_CACHE_LINE Locals
} // namespace
static Locals s_locals;
ALIGN_TO_CACHE_LINE static Locals s_locals;
} // namespace FullscreenUI
@ -1604,8 +1604,11 @@ void FullscreenUI::DrawPauseMenu()
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(); });
}
if (MenuButtonWithoutSummary(FSUI_ICONVSTR(ICON_FA_TROPHY, "Achievements"),
Achievements::HasAchievementsOrLeaderboards()))

@ -112,7 +112,6 @@ void SwitchToSettings();
bool SwitchToGameSettings(SettingsPage page = SettingsPage::Summary);
void SwitchToGameSettings(const GameList::Entry* entry, 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();
SettingsPage GetCurrentSettingsPage();
bool IsInputBindingDialogOpen();

@ -33,6 +33,7 @@
#include "IconsFontAwesome6.h"
#include "IconsPromptFont.h"
#include <limits>
#include <mutex>
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";
namespace {
struct ALIGN_TO_CACHE_LINE SettingsLocals
struct SettingsLocals
{
float settings_last_bg_alpha = 1.0f;
SettingsPage settings_page = SettingsPage::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::vector<std::pair<std::string, bool>> game_list_directories_cache;
GPUDevice::AdapterInfoList graphics_adapter_list_cache;
@ -213,7 +211,7 @@ struct ALIGN_TO_CACHE_LINE SettingsLocals
} // namespace
static SettingsLocals s_settings_locals;
ALIGN_TO_CACHE_LINE static SettingsLocals s_settings_locals;
} // namespace FullscreenUI
@ -1564,10 +1562,7 @@ void FullscreenUI::ClearSettingsState()
s_settings_locals.input_binding_dialog.ClearState();
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_settings_db_entry = nullptr;
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_changed = false;
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_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.enabled_game_patch_cache = {};
s_settings_locals.game_cheats_list = {};
@ -1609,45 +1601,20 @@ void FullscreenUI::SwitchToSettings()
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)
{
const std::string& serial = GPUThread::GetGameSerial();
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;
}
return SwitchToGameSettingsForPath(GPUThread::GetGamePath());
}
bool FullscreenUI::SwitchToGameSettingsForPath(const std::string& path, SettingsPage page)
{
auto lock = GameList::GetLock();
const GameList::Entry* entry = GameList::GetEntryForPath(path);
if (!entry)
const GameList::Entry* entry = !path.empty() ? GameList::GetEntryForPath(path) : nullptr;
if (!entry || entry->serial.empty())
{
ShowToast({}, FSUI_STR("Game properties is only available for scanned games."));
return false;
}
SwitchToGameSettings(entry, page);
return true;
@ -1655,8 +1622,12 @@ bool FullscreenUI::SwitchToGameSettingsForPath(const std::string& path, Settings
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_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()
@ -1683,10 +1654,10 @@ void FullscreenUI::PopulateGameListDirectoryCache(SettingsInterface* si)
void FullscreenUI::PopulatePatchesAndCheatsList()
{
s_settings_locals.game_patch_list = Cheats::GetCodeInfoList(s_settings_locals.game_settings_serial,
s_settings_locals.game_settings_hash, false, true, true);
s_settings_locals.game_patch_list = Cheats::GetCodeInfoList(
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_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", "SortList", false));
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"));
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
const bool is_first_disc = (s_settings_locals.game_settings_db_entry->serial ==
s_settings_locals.game_settings_db_entry->disc_set->serials.front());
const bool is_first_disc = (s_settings_locals.game_settings_entry->dbentry->serial ==
s_settings_locals.game_settings_entry->dbentry->disc_set->serials.front());
DrawToggleSetting(
GetEditingSettingsInterface(), FSUI_ICONVSTR(ICON_FA_COMPACT_DISC, "Use Separate Disc Settings"),
FSUI_VSTR(
@ -5180,8 +5152,8 @@ void FullscreenUI::DrawPatchesOrCheatsSettingsPage(bool cheats)
bsi->SetBoolValue("Cheats", "SortList", true);
SetSettingsChanged(bsi);
s_settings_locals.game_cheats_list =
Cheats::GetCodeInfoList(s_settings_locals.game_settings_serial, s_settings_locals.game_settings_hash, true,
load_database_cheats, sort_list);
Cheats::GetCodeInfoList(s_settings_locals.game_settings_entry->serial,
s_settings_locals.game_settings_entry->hash, true, load_database_cheats, sort_list);
}
if (code_list.empty())

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

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

Loading…
Cancel
Save