mirror of
https://github.com/stenzek/duckstation.git
synced 2026-02-13 09:54:32 +00:00
FullscreenUI: Move achievements to its own file
This commit is contained in:
@@ -40,6 +40,7 @@ add_library(core
|
||||
dma.h
|
||||
fullscreenui.cpp
|
||||
fullscreenui.h
|
||||
fullscreenui_achievements.cpp
|
||||
fullscreenui_game_list.cpp
|
||||
fullscreenui_private.h
|
||||
fullscreenui_settings.cpp
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -188,35 +188,9 @@ std::string GetGameBadgePath(std::string_view badge_name);
|
||||
/// Returns 0 if pausing is allowed, otherwise the number of frames until pausing is allowed.
|
||||
u32 GetPauseThrottleFrames();
|
||||
|
||||
/// Clears all cached state used to render the UI.
|
||||
void ClearUIState();
|
||||
|
||||
/// Draws ImGui overlays when not paused.
|
||||
void DrawGameOverlays();
|
||||
|
||||
/// Draws ImGui overlays when paused.
|
||||
void DrawPauseMenuOverlays(float start_pos_y);
|
||||
|
||||
/// Updates the stored most-recent and closest-to-completion achievements.
|
||||
/// Call before calling DrawPauseMenuOverlays() for the first time.
|
||||
void UpdateRecentUnlockAndAlmostThere();
|
||||
|
||||
#ifndef __ANDROID__
|
||||
|
||||
/// Queries the achievement list, and if no achievements are available, returns false.
|
||||
bool PrepareAchievementsWindow();
|
||||
|
||||
/// Renders the achievement list.
|
||||
void DrawAchievementsWindow();
|
||||
|
||||
/// Queries the leaderboard list, and if no leaderboards are available, returns false.
|
||||
bool PrepareLeaderboardsWindow();
|
||||
|
||||
/// Renders the leaderboard list.
|
||||
void DrawLeaderboardsWindow();
|
||||
|
||||
#endif // __ANDROID__
|
||||
|
||||
} // namespace Achievements
|
||||
|
||||
/// Functions implemented in the frontend.
|
||||
|
||||
@@ -7,26 +7,43 @@
|
||||
|
||||
#include "rc_client.h"
|
||||
|
||||
#include <span>
|
||||
#include <string>
|
||||
|
||||
namespace Achievements {
|
||||
|
||||
struct ActiveChallengeIndicator
|
||||
{
|
||||
const rc_client_achievement_t* achievement;
|
||||
std::string badge_path;
|
||||
float time_remaining;
|
||||
float opacity;
|
||||
bool active;
|
||||
};
|
||||
|
||||
/// Returns the rc_client instance. Should have the lock held.
|
||||
rc_client_t* GetClient();
|
||||
|
||||
const rc_client_user_game_summary_t& GetGameSummary();
|
||||
|
||||
std::span<const ActiveChallengeIndicator> GetActiveChallengeIndicators();
|
||||
|
||||
std::string GetAchievementBadgePath(const rc_client_achievement_t* achievement, bool locked,
|
||||
bool download_if_missing = true);
|
||||
std::string GetLeaderboardUserBadgePath(const rc_client_leaderboard_entry_t* entry);
|
||||
|
||||
void OpenLeaderboard(const rc_client_leaderboard_t* lboard);
|
||||
bool OpenLeaderboardById(u32 leaderboard_id);
|
||||
u32 GetOpenLeaderboardId();
|
||||
bool IsShowingAllLeaderboardEntries();
|
||||
void FetchNextLeaderboardEntries();
|
||||
|
||||
const std::vector<rc_client_leaderboard_entry_list_t*>& GetLeaderboardEntryLists();
|
||||
const rc_client_leaderboard_entry_list_t* GetLeaderboardNearbyEntries();
|
||||
|
||||
void CloseLeaderboard();
|
||||
|
||||
} // namespace Achievements
|
||||
|
||||
#ifndef __ANDROID__
|
||||
|
||||
namespace FullscreenUI {
|
||||
|
||||
/// Clears all cached state used to render the UI.
|
||||
void ClearAchievementsState();
|
||||
|
||||
/// Updates cached data for the last progress update.
|
||||
void UpdateAchievementsLastProgressUpdate(const rc_client_achievement_t* achievement);
|
||||
|
||||
} // namespace FullscreenUI
|
||||
|
||||
#endif // __ANDROID__
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
<ClCompile Include="cpu_types.cpp" />
|
||||
<ClCompile Include="ddgo_controller.cpp" />
|
||||
<ClCompile Include="digital_controller.cpp" />
|
||||
<ClCompile Include="fullscreenui_achievements.cpp" />
|
||||
<ClCompile Include="fullscreenui_game_list.cpp" />
|
||||
<ClCompile Include="fullscreenui_settings.cpp" />
|
||||
<ClCompile Include="fullscreenui_widgets.cpp" />
|
||||
|
||||
@@ -71,6 +71,7 @@
|
||||
<ClCompile Include="fullscreenui_widgets.cpp" />
|
||||
<ClCompile Include="fullscreenui_settings.cpp" />
|
||||
<ClCompile Include="fullscreenui_game_list.cpp" />
|
||||
<ClCompile Include="fullscreenui_achievements.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="types.h" />
|
||||
|
||||
@@ -2,53 +2,30 @@
|
||||
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
|
||||
|
||||
#include "fullscreenui.h"
|
||||
#include "achievements.h"
|
||||
#include "bios.h"
|
||||
#include "cheats.h"
|
||||
#include "controller.h"
|
||||
#include "fullscreenui_private.h"
|
||||
#include "fullscreenui_widgets.h"
|
||||
#include "achievements_private.h"
|
||||
#include "controller.h"
|
||||
#include "game_list.h"
|
||||
#include "gpu.h"
|
||||
#include "gpu_backend.h"
|
||||
#include "gpu_presenter.h"
|
||||
#include "gpu_thread.h"
|
||||
#include "gte_types.h"
|
||||
#include "host.h"
|
||||
#include "imgui_overlays.h"
|
||||
#include "settings.h"
|
||||
#include "system.h"
|
||||
#include "system_private.h"
|
||||
|
||||
#include "scmversion/scmversion.h"
|
||||
|
||||
#include "util/cd_image.h"
|
||||
#include "util/gpu_device.h"
|
||||
#include "util/imgui_manager.h"
|
||||
#include "util/ini_settings_interface.h"
|
||||
#include "util/input_manager.h"
|
||||
#include "util/postprocessing.h"
|
||||
#include "util/shadergen.h"
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "common/error.h"
|
||||
#include "common/file_system.h"
|
||||
#include "common/log.h"
|
||||
#include "common/path.h"
|
||||
#include "common/progress_callback.h"
|
||||
#include "common/small_string.h"
|
||||
#include "common/string_util.h"
|
||||
#include "common/timer.h"
|
||||
|
||||
#include "IconsEmoji.h"
|
||||
#include "IconsFontAwesome6.h"
|
||||
#include "IconsPromptFont.h"
|
||||
#include "imgui.h"
|
||||
#include "imgui_internal.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
LOG_CHANNEL(FullscreenUI);
|
||||
|
||||
@@ -66,9 +43,6 @@ enum class PauseSubMenu : u8
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Main
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
static void PauseForMenuOpen(bool set_pause_menu_open);
|
||||
static void ClosePauseMenu();
|
||||
static void ClosePauseMenuImmediately();
|
||||
static void DrawLandingTemplate(ImVec2* menu_pos, ImVec2* menu_size);
|
||||
static void DrawLandingWindow();
|
||||
static void DrawStartGameWindow();
|
||||
@@ -140,12 +114,6 @@ static u32 PopulateSaveStateListEntries(const std::string& serial, std::optional
|
||||
static void DrawSaveStateSelector();
|
||||
static void DrawResumeStateSelector();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Achievements/Leaderboards
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
static void SwitchToAchievements();
|
||||
static void SwitchToLeaderboards();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Constants
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@@ -334,7 +302,7 @@ void FullscreenUI::OpenPauseMenu()
|
||||
PauseForMenuOpen(true);
|
||||
ForceKeyNavEnabled();
|
||||
|
||||
Achievements::UpdateRecentUnlockAndAlmostThere();
|
||||
UpdateAchievementsRecentUnlockAndAlmostThere();
|
||||
BeginTransition(SHORT_TRANSITION_TIME, []() {
|
||||
s_locals.current_pause_submenu = PauseSubMenu::None;
|
||||
SwitchToMainWindow(MainWindowType::PauseMenu);
|
||||
@@ -486,7 +454,7 @@ void FullscreenUI::Shutdown(bool clear_state)
|
||||
s_locals.pause_menu_was_open = false;
|
||||
s_locals.was_paused_on_quick_menu_open = false;
|
||||
|
||||
Achievements::ClearUIState();
|
||||
ClearAchievementsState();
|
||||
ClearSaveStateEntryList();
|
||||
ClearSettingsState();
|
||||
ClearGameListState();
|
||||
@@ -502,18 +470,18 @@ void FullscreenUI::Shutdown(bool clear_state)
|
||||
|
||||
void FullscreenUI::Render()
|
||||
{
|
||||
if (!s_locals.initialized)
|
||||
{
|
||||
RenderLoadingScreen();
|
||||
return;
|
||||
}
|
||||
|
||||
UploadAsyncTextures();
|
||||
|
||||
// draw background before any overlays
|
||||
if (!GPUThread::HasGPUBackend() && s_locals.current_main_window != MainWindowType::None)
|
||||
DrawBackground();
|
||||
|
||||
if (!s_locals.initialized)
|
||||
{
|
||||
RenderLoadingScreen();
|
||||
return;
|
||||
}
|
||||
|
||||
BeginLayout();
|
||||
|
||||
// Primed achievements must come first, because we don't want the pause screen to be behind them.
|
||||
@@ -544,10 +512,10 @@ void FullscreenUI::Render()
|
||||
DrawSaveStateSelector();
|
||||
break;
|
||||
case MainWindowType::Achievements:
|
||||
Achievements::DrawAchievementsWindow();
|
||||
DrawAchievementsWindow();
|
||||
break;
|
||||
case MainWindowType::Leaderboards:
|
||||
Achievements::DrawLeaderboardsWindow();
|
||||
DrawLeaderboardsWindow();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -1587,7 +1555,7 @@ void FullscreenUI::DrawPauseMenu()
|
||||
ImVec2(display_size.x, display_size.x - scaled_top_bar_height - LayoutScale(LAYOUT_FOOTER_HEIGHT)),
|
||||
ImGui::GetColorU32(ModAlpha(UIStyle.BackgroundColor, 0.825f)));
|
||||
|
||||
Achievements::DrawPauseMenuOverlays(scaled_top_bar_height);
|
||||
DrawAchievementsPauseMenuOverlays(scaled_top_bar_height);
|
||||
|
||||
if (BeginFullscreenWindow(window_pos, window_size, "pause_menu", ImVec4(0.0f, 0.0f, 0.0f, 0.0f), 0.0f,
|
||||
ImVec2(10.0f, 10.0f), ImGuiWindowFlags_NoBackground))
|
||||
@@ -2328,74 +2296,4 @@ void FullscreenUI::DrawAboutWindow()
|
||||
EndFixedPopupDialog();
|
||||
}
|
||||
|
||||
void FullscreenUI::OpenAchievementsWindow()
|
||||
{
|
||||
// NOTE: Called from CPU thread.
|
||||
if (!System::IsValid())
|
||||
return;
|
||||
|
||||
const auto lock = Achievements::GetLock();
|
||||
if (!Achievements::IsActive() || !Achievements::HasAchievements())
|
||||
{
|
||||
ShowToast(std::string(), Achievements::IsActive() ? FSUI_STR("This game has no achievements.") :
|
||||
FSUI_STR("Achievements are not enabled."));
|
||||
return;
|
||||
}
|
||||
|
||||
GPUThread::RunOnThread([]() {
|
||||
Initialize();
|
||||
|
||||
PauseForMenuOpen(false);
|
||||
ForceKeyNavEnabled();
|
||||
|
||||
BeginTransition(SHORT_TRANSITION_TIME, &SwitchToAchievements);
|
||||
});
|
||||
}
|
||||
|
||||
void FullscreenUI::SwitchToAchievements()
|
||||
{
|
||||
if (!Achievements::PrepareAchievementsWindow())
|
||||
{
|
||||
ClosePauseMenuImmediately();
|
||||
return;
|
||||
}
|
||||
|
||||
SwitchToMainWindow(MainWindowType::Achievements);
|
||||
}
|
||||
|
||||
void FullscreenUI::OpenLeaderboardsWindow()
|
||||
{
|
||||
if (!System::IsValid())
|
||||
return;
|
||||
|
||||
const auto lock = Achievements::GetLock();
|
||||
if (!Achievements::IsActive() || !Achievements::HasLeaderboards())
|
||||
{
|
||||
ShowToast(std::string(), Achievements::IsActive() ? FSUI_STR("This game has no leaderboards.") :
|
||||
FSUI_STR("Achievements are not enabled."));
|
||||
return;
|
||||
}
|
||||
|
||||
GPUThread::RunOnThread([]() {
|
||||
Initialize();
|
||||
|
||||
PauseForMenuOpen(false);
|
||||
ForceKeyNavEnabled();
|
||||
|
||||
BeginTransition(SHORT_TRANSITION_TIME, &SwitchToLeaderboards);
|
||||
});
|
||||
}
|
||||
|
||||
void FullscreenUI::SwitchToLeaderboards()
|
||||
{
|
||||
if (!Achievements::PrepareLeaderboardsWindow())
|
||||
{
|
||||
ClosePauseMenuImmediately();
|
||||
return;
|
||||
}
|
||||
|
||||
SwitchToMainWindow(MainWindowType::Leaderboards);
|
||||
}
|
||||
|
||||
|
||||
#endif // __ANDROID__
|
||||
|
||||
@@ -34,12 +34,6 @@ void InvalidateCoverCache();
|
||||
|
||||
float GetBackgroundAlpha();
|
||||
|
||||
void OpenLoadingScreen(std::string_view image, std::string_view title, std::string_view caption = {},
|
||||
s32 progress_min = -1, s32 progress_max = -1, s32 progress_value = -1);
|
||||
void UpdateLoadingScreen(std::string_view image, std::string_view title, std::string_view caption = {},
|
||||
s32 progress_min = -1, s32 progress_max = -1, s32 progress_value = -1);
|
||||
void CloseLoadingScreen();
|
||||
|
||||
void UpdateTheme();
|
||||
void UpdateRunIdleState();
|
||||
|
||||
@@ -50,7 +44,6 @@ void OpenCheatsMenu();
|
||||
void OpenDiscChangeMenu();
|
||||
void OpenAchievementsWindow();
|
||||
void OpenLeaderboardsWindow();
|
||||
void ReturnToPreviousWindow();
|
||||
|
||||
class BackgroundProgressCallback final : public ProgressCallback
|
||||
{
|
||||
|
||||
1598
src/core/fullscreenui_achievements.cpp
Normal file
1598
src/core/fullscreenui_achievements.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -57,8 +57,13 @@ enum class SettingsPage : u8
|
||||
void SwitchToMainWindow(MainWindowType type);
|
||||
void ReturnToMainWindow();
|
||||
void ReturnToMainWindow(float transition_time);
|
||||
void ReturnToPreviousWindow();
|
||||
bool AreAnyDialogsOpen();
|
||||
|
||||
void PauseForMenuOpen(bool set_pause_menu_open);
|
||||
void ClosePauseMenu();
|
||||
void ClosePauseMenuImmediately();
|
||||
|
||||
void ExitFullscreenAndOpenURL(std::string_view url);
|
||||
void CopyTextToClipboard(std::string title, std::string_view text);
|
||||
|
||||
@@ -112,6 +117,29 @@ void DrawSettingsWindow();
|
||||
SettingsPage GetCurrentSettingsPage();
|
||||
bool IsInputBindingDialogOpen();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Achievements
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// Draws ImGui overlays when paused.
|
||||
void DrawAchievementsPauseMenuOverlays(float start_pos_y);
|
||||
|
||||
/// Updates the stored most-recent and closest-to-completion achievements.
|
||||
/// Call before calling DrawPauseMenuOverlays() for the first time.
|
||||
void UpdateAchievementsRecentUnlockAndAlmostThere();
|
||||
|
||||
/// Switches to the achievements window.
|
||||
void SwitchToAchievements();
|
||||
|
||||
/// Switches to the leaderboards window.
|
||||
void SwitchToLeaderboards();
|
||||
|
||||
/// Renders the achievement list.
|
||||
void DrawAchievementsWindow();
|
||||
|
||||
/// Renders the leaderboard list.
|
||||
void DrawLeaderboardsWindow();
|
||||
|
||||
} // namespace FullscreenUI
|
||||
|
||||
#endif // __ANDROID__
|
||||
|
||||
@@ -481,11 +481,17 @@ bool IsBackgroundProgressDialogOpen(std::string_view str_id);
|
||||
|
||||
/// Displays a loading screen with the logo, rendered with ImGui. Use when executing possibly-time-consuming tasks
|
||||
/// such as compiling shaders when starting up.
|
||||
|
||||
void OpenLoadingScreen(std::string_view image, std::string_view title, std::string_view caption = {},
|
||||
s32 progress_min = -1, s32 progress_max = -1, s32 progress_value = -1);
|
||||
void UpdateLoadingScreen(std::string_view image, std::string_view title, std::string_view caption = {},
|
||||
s32 progress_min = -1, s32 progress_max = -1, s32 progress_value = -1);
|
||||
void CloseLoadingScreen();
|
||||
|
||||
void RenderLoadingScreen(std::string_view image, std::string_view title, std::string_view caption,
|
||||
s32 progress_min = -1, s32 progress_max = -1, s32 progress_value = -1);
|
||||
|
||||
bool IsLoadingScreenOpen();
|
||||
void CloseLoadingScreen();
|
||||
|
||||
/// Renders a previously-configured loading screen.
|
||||
void RenderLoadingScreen();
|
||||
|
||||
Reference in New Issue
Block a user