Add achievement progress

This commit is contained in:
schmurger 2024-05-17 15:48:55 +10:00 committed by otavepto
parent 435f9bfd49
commit 4e8f2505b5
3 changed files with 34 additions and 2 deletions

View File

@ -1858,9 +1858,29 @@ bool Steam_User_Stats::GetAchievementProgressLimits( const char *pchName, int32
bool Steam_User_Stats::GetAchievementProgressLimits( const char *pchName, float *pfMinProgress, float *pfMaxProgress ) bool Steam_User_Stats::GetAchievementProgressLimits( const char *pchName, float *pfMinProgress, float *pfMaxProgress )
{ {
PRINT_DEBUG_TODO(); PRINT_DEBUG("'%s'", pchName);
std::lock_guard<std::recursive_mutex> lock(global_mutex); std::lock_guard<std::recursive_mutex> lock(global_mutex);
return false;
if (!pchName) return false;
nlohmann::detail::iter_impl<nlohmann::json> it = defined_achievements.end();
try {
it = defined_achievements_find(pchName);
}
catch (...) {}
if (defined_achievements.end() == it) return false;
try {
std::string pch_name = it->value("name", std::string());
auto ach = user_achievements.find(pch_name);
if (user_achievements.end() != ach) {
if (pfMinProgress) *pfMinProgress = ach->value("progress", static_cast<float>(0));
if (pfMaxProgress) *pfMaxProgress = ach->value("max_progress", static_cast<float>(0));
}
}
catch (...) {}
return true;
} }

View File

@ -85,6 +85,8 @@ struct Overlay_Achievement
std::string description{}; std::string description{};
std::string icon_name{}; std::string icon_name{};
std::string icon_gray_name{}; std::string icon_gray_name{};
float progress{};
float max_progress{};
bool hidden{}; bool hidden{};
bool achieved{}; bool achieved{};
uint32 unlock_time{}; uint32 unlock_time{};

View File

@ -364,6 +364,11 @@ void Steam_Overlay::load_achievements_data()
ach.icon_name = steamUserStats->get_achievement_icon_name(ach.name.c_str(), true); ach.icon_name = steamUserStats->get_achievement_icon_name(ach.name.c_str(), true);
ach.icon_gray_name = steamUserStats->get_achievement_icon_name(ach.name.c_str(), false); ach.icon_gray_name = steamUserStats->get_achievement_icon_name(ach.name.c_str(), false);
float pnMinProgress, pnMaxProgress;
steamUserStats->GetAchievementProgressLimits(ach.name.c_str(), &pnMinProgress, &pnMaxProgress);
ach.progress = pnMinProgress;
ach.max_progress = pnMaxProgress;
achievements.push_back(ach); achievements.push_back(ach);
@ -1453,6 +1458,11 @@ void Steam_Overlay::render_main_window()
ImGui::TextColored(ImVec4(0, 255, 0, 255), translationAchievedOn[current_language], buffer); ImGui::TextColored(ImVec4(0, 255, 0, 255), translationAchievedOn[current_language], buffer);
} else { } else {
ImGui::TextColored(ImVec4(255, 0, 0, 255), "%s", translationNotAchieved[current_language]); ImGui::TextColored(ImVec4(255, 0, 0, 255), "%s", translationNotAchieved[current_language]);
if (x.max_progress > 0) {
char buf[32];
sprintf(buf, "%d/%d", (int)x.progress, (int)x.max_progress);
ImGui::ProgressBar(x.progress / x.max_progress, { -1 , settings->overlay_appearance.font_size }, buf);
}
} }
if (could_create_ach_table_entry) ImGui::EndTable(); if (could_create_ach_table_entry) ImGui::EndTable();