From ea528ed9d9bdb79489e5a696f8a700dac9e0f153 Mon Sep 17 00:00:00 2001 From: madeline Date: Tue, 28 Apr 2026 03:41:04 -0700 Subject: [PATCH] clear single achievement and fix achievement tab moving around --- include/dusk/achievements.h | 1 + src/dusk/achievements.cpp | 12 ++++++++++++ src/dusk/imgui/ImGuiAchievements.cpp | 18 +++++++++++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/include/dusk/achievements.h b/include/dusk/achievements.h index cd4294b6f1..fb2da89c69 100644 --- a/include/dusk/achievements.h +++ b/include/dusk/achievements.h @@ -40,6 +40,7 @@ public: void save(); void tick(); void clearAll(); + void clearOne(const char* key); std::vector getAchievements() const; bool hasPendingUnlock() const { return !m_pendingUnlocks.empty(); } diff --git a/src/dusk/achievements.cpp b/src/dusk/achievements.cpp index 071332a7c2..99d4648b98 100644 --- a/src/dusk/achievements.cpp +++ b/src/dusk/achievements.cpp @@ -426,6 +426,18 @@ void AchievementSystem::clearAll() { save(); } +void AchievementSystem::clearOne(const char* key) { + for (auto& e : m_entries) { + if (std::string(e.achievement.key) == key) { + e.achievement.progress = 0; + e.achievement.unlocked = false; + e.extra = {}; + break; + } + } + save(); +} + void AchievementSystem::processEntry(Entry& e) { if (e.achievement.unlocked) { return; diff --git a/src/dusk/imgui/ImGuiAchievements.cpp b/src/dusk/imgui/ImGuiAchievements.cpp index 4b844b8386..479e307e30 100644 --- a/src/dusk/imgui/ImGuiAchievements.cpp +++ b/src/dusk/imgui/ImGuiAchievements.cpp @@ -131,7 +131,7 @@ void ImGuiAchievements::draw(bool& open) { continue; } - const std::string tabLabel = fmt::format("{} ({}/{})", catInfo.label, catUnlocked, catTotal); + const std::string tabLabel = fmt::format("{} ({}/{})###{}", catInfo.label, catUnlocked, catTotal, catInfo.label); ImGui::PushStyleColor(ImGuiCol_Text, catInfo.color); const bool tabOpen = ImGui::BeginTabItem(tabLabel.c_str()); @@ -152,6 +152,7 @@ void ImGuiAchievements::draw(bool& open) { continue; } ImGui::PushID(a.key); + ImGui::BeginGroup(); ImGui::PushStyleColor( ImGuiCol_Text, @@ -190,6 +191,21 @@ void ImGuiAchievements::draw(bool& open) { ImGui::PopStyleColor(); } + ImGui::EndGroup(); + + if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(ImGuiMouseButton_Right)) { + ImGui::OpenPopup("##ctx"); + } + + if (ImGui::BeginPopup("##ctx")) { + ImGui::TextDisabled("%s", a.name); + ImGui::Separator(); + if (ImGui::MenuItem("Clear Achievement")) { + AchievementSystem::get().clearOne(a.key); + } + ImGui::EndPopup(); + } + ImGui::Spacing(); ImGui::PopID(); }