Skip to content

Commit

Permalink
Display Active Challenges On Screen
Browse files Browse the repository at this point in the history
The active challenges, aka the primed achievements, are displayed on screen as a series of icons in the bottom right corner of the screen via OnScreenUI.
  • Loading branch information
LillyJadeKatrin committed Oct 24, 2023
1 parent 2d3d8ae commit c4b4361
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
67 changes: 67 additions & 0 deletions Source/Core/VideoCommon/OnScreenUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "Common/Profiler.h"
#include "Common/Timer.h"

#include "Core/AchievementManager.h"
#include "Core/Config/MainSettings.h"
#include "Core/Config/NetplaySettings.h"
#include "Core/Movie.h"
Expand Down Expand Up @@ -36,6 +37,7 @@ bool OnScreenUI::Initialize(u32 width, u32 height, float scale)
{
std::unique_lock<std::mutex> imgui_lock(m_imgui_mutex);


if (!IMGUI_CHECKVERSION())
{
PanicAlertFmt("ImGui version check failed");
Expand Down Expand Up @@ -326,13 +328,78 @@ void OnScreenUI::DrawDebugText()
ImGui::TextUnformatted(profile_output.c_str());
}

#ifdef USE_RETRO_ACHIEVEMENTS
void OnScreenUI::DrawChallenges()
{
std::lock_guard lg{*AchievementManager::GetInstance()->GetLock()};
const std::map<std::string, std::unique_ptr<OSD::Icon>>& challenge_icons =
AchievementManager::GetInstance()->GetChallengeIcons();

const std::string window_name = "Challenges";

u32 sum_of_icon_heights = 0;
u32 max_icon_width = 0;
for (const auto& [name, icon] : challenge_icons)
{
// These *should* all be the same square size but you never know.
if (icon->width > max_icon_width)
max_icon_width = icon->width;
sum_of_icon_heights += icon->height;
}
ImGui::SetNextWindowPos(
ImVec2(ImGui::GetIO().DisplaySize.x - 20.f * m_backbuffer_scale - max_icon_width,
ImGui::GetIO().DisplaySize.y - 20.f * m_backbuffer_scale - sum_of_icon_heights));
ImGui::SetNextWindowSize(ImVec2(0.0f, 0.0f));
if (ImGui::Begin(window_name.c_str(), nullptr,
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoInputs |
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings |
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoNav |
ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoFocusOnAppearing))
{
for (const auto& [name, icon] : challenge_icons)
{
if (m_challenge_texture_map.find(name) != m_challenge_texture_map.end())
continue;
const u32 width = icon->width;
const u32 height = icon->height;
TextureConfig tex_config(width, height, 1, 1, 1, AbstractTextureFormat::RGBA8, 0);
m_challenge_texture_map[name] = g_gfx->CreateTexture(tex_config);
if (m_challenge_texture_map[name] != nullptr)
{
m_challenge_texture_map[name]->Load(0, width, height, width, icon->rgba_data.data(),
sizeof(u32) * width * height);
}
}
for (auto& [name, texture] : m_challenge_texture_map)
{
auto icon_itr = challenge_icons.find(name);
if (icon_itr == challenge_icons.end())
{
m_challenge_texture_map.erase(name);
continue;
}
if (texture)
{
ImGui::Image(texture.get(), ImVec2(static_cast<float>(icon_itr->second->width),
static_cast<float>(icon_itr->second->height)));
}
}
}

ImGui::End();
}
#endif // USE_RETRO_ACHIEVEMENTS

void OnScreenUI::Finalize()
{
auto lock = GetImGuiLock();

g_perf_metrics.DrawImGuiStats(m_backbuffer_scale);
DrawDebugText();
OSD::DrawMessages();
#ifdef USE_RETRO_ACHIEVEMENTS
DrawChallenges();
#endif // USE_RETRO_ACHIEVEMENTS
ImGui::Render();
}

Expand Down
7 changes: 7 additions & 0 deletions Source/Core/VideoCommon/OnScreenUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class OnScreenUI

private:
void DrawDebugText();
#ifdef USE_RETRO_ACHIEVEMENTS
void DrawChallenges();
#endif // USE_RETRO_ACHIEVEMENTS

// ImGui resources.
std::unique_ptr<NativeVertexFormat> m_imgui_vertex_format;
Expand All @@ -74,6 +77,10 @@ class OnScreenUI
u32 m_backbuffer_height = 1;
float m_backbuffer_scale = 1.0;

#ifdef USE_RETRO_ACHIEVEMENTS
std::map<std::string, std::unique_ptr<AbstractTexture>> m_challenge_texture_map;
#endif // USE_RETRO_ACHIEVEMENTS

bool m_ready = false;
};
} // namespace VideoCommon

0 comments on commit c4b4361

Please sign in to comment.