Added realtime progress update

This commit is contained in:
schmurger 2024-05-19 13:23:12 +10:00 committed by otavepto
parent 4e8f2505b5
commit b0cffd485b
3 changed files with 44 additions and 24 deletions

View File

@ -1151,6 +1151,10 @@ bool Steam_User_Stats::IndicateAchievementProgress( const char *pchName, uint32
user_achievements[actual_ach_name]["progress"] = nCurProgress; user_achievements[actual_ach_name]["progress"] = nCurProgress;
user_achievements[actual_ach_name]["max_progress"] = nMaxProgress; user_achievements[actual_ach_name]["max_progress"] = nMaxProgress;
save_achievements(); save_achievements();
if (!settings->disable_overlay) {
overlay->AddAchievementNotification(it.value());
overlay->update_achievement_progress(actual_ach_name, nCurProgress);
}
} catch (...) {} } catch (...) {}
{ {
@ -1870,6 +1874,9 @@ bool Steam_User_Stats::GetAchievementProgressLimits( const char *pchName, float
catch (...) {} catch (...) {}
if (defined_achievements.end() == it) return false; if (defined_achievements.end() == it) return false;
if (pfMinProgress) *pfMinProgress = 0;
if (pfMaxProgress) *pfMaxProgress = 0;
try { try {
std::string pch_name = it->value("name", std::string()); std::string pch_name = it->value("name", std::string());
auto ach = user_achievements.find(pch_name); auto ach = user_achievements.find(pch_name);

View File

@ -254,6 +254,7 @@ public:
void FriendDisconnect(Friend _friend); void FriendDisconnect(Friend _friend);
void AddAchievementNotification(nlohmann::json const& ach); void AddAchievementNotification(nlohmann::json const& ach);
void update_achievement_progress(std::string const& ach_name, uint32 nCurProgress);
}; };
#else // EMU_OVERLAY #else // EMU_OVERLAY
@ -288,6 +289,7 @@ public:
void FriendDisconnect(Friend _friend) {} void FriendDisconnect(Friend _friend) {}
void AddAchievementNotification(nlohmann::json const& ach) {} void AddAchievementNotification(nlohmann::json const& ach) {}
void update_achievement_progress(std::string const& ach_name, uint32 nCurProgress);
}; };
#endif // EMU_OVERLAY #endif // EMU_OVERLAY

View File

@ -365,10 +365,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; float pnMinProgress = 0, pnMaxProgress = 0;
steamUserStats->GetAchievementProgressLimits(ach.name.c_str(), &pnMinProgress, &pnMaxProgress); if (steamUserStats->GetAchievementProgressLimits(ach.name.c_str(), &pnMinProgress, &pnMaxProgress)) {
ach.progress = pnMinProgress; ach.progress = pnMinProgress;
ach.max_progress = pnMaxProgress; ach.max_progress = pnMaxProgress;
}
achievements.push_back(ach); achievements.push_back(ach);
@ -379,6 +380,20 @@ void Steam_Overlay::load_achievements_data()
} }
void Steam_Overlay::update_achievement_progress(std::string const& ach_name, uint32 nCurProgress) {
PRINT_DEBUG_ENTRY();
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
for (auto& ach : achievements) {
if (ach.name == ach_name) {
ach.progress = (float)nCurProgress;
break;
}
}
}
void Steam_Overlay::initial_load_achievements_icons() void Steam_Overlay::initial_load_achievements_icons()
{ {
{ {
@ -1459,7 +1474,7 @@ void Steam_Overlay::render_main_window()
} 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) { if (x.max_progress > 0) {
char buf[32]; char buf[32]{};
sprintf(buf, "%d/%d", (int)x.progress, (int)x.max_progress); 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); ImGui::ProgressBar(x.progress / x.max_progress, { -1 , settings->overlay_appearance.font_size }, buf);
} }
@ -1972,29 +1987,25 @@ void Steam_Overlay::AddAchievementNotification(nlohmann::json const &ach)
// otherwise when you open the achievements list/menu you won't see the new unlock status // otherwise when you open the achievements list/menu you won't see the new unlock status
// adjust the local 'is_achieved' and 'unlock_time' // adjust the local 'is_achieved' and 'unlock_time'
std::vector<Overlay_Achievement*> found_achs{}; std::lock_guard<std::recursive_mutex> lock2(global_mutex);
{
std::lock_guard<std::recursive_mutex> lock2(global_mutex);
std::string ach_name = ach.value("name", std::string()); std::string ach_name = ach.value("name", std::string());
for (auto &a : achievements) { for (auto &a : achievements) {
if (a.name == ach_name) { if (a.name == ach_name) {
found_achs.push_back(&a); bool achieved = false;
uint32 unlock_time = 0;
bool achieved = false;
uint32 unlock_time = 0; get_steam_client()->steam_user_stats->GetAchievementAndUnlockTime(a.name.c_str(), &achieved, &unlock_time);
get_steam_client()->steam_user_stats->GetAchievementAndUnlockTime(a.name.c_str(), &achieved, &unlock_time); a.achieved = achieved;
a.achieved = achieved; a.unlock_time = unlock_time;
a.unlock_time = unlock_time;
if (achieved) {
post_achievement_notification(a);
notify_sound_user_achievement();
} }
break;
} }
} }
for (auto found_ach : found_achs) {
post_achievement_notification(*found_ach);
}
notify_sound_user_achievement();
} }
#endif #endif