clear single achievement and fix achievement tab moving around

This commit is contained in:
madeline
2026-04-28 03:41:04 -07:00
parent 30b7087f30
commit ea528ed9d9
3 changed files with 30 additions and 1 deletions
+1
View File
@@ -40,6 +40,7 @@ public:
void save();
void tick();
void clearAll();
void clearOne(const char* key);
std::vector<Achievement> getAchievements() const;
bool hasPendingUnlock() const { return !m_pendingUnlocks.empty(); }
+12
View File
@@ -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;
+17 -1
View File
@@ -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();
}