Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions profiles/chlcc/hud/trophymenu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ root.TrophyMenu = {
BronzeTrophySprite = "BronzeTrophy",
BronzeTrophyPos = { X = 777, Y = 91 },

RarityCountOffset = { X = 32, Y = 8 },
RarityCountFontSize = 12,
RarityCountOffset = { X = 32, Y = 0 },
RarityCountFontSize = 32,

DefaultTrophyIconSprite = "DefaultTrophyIcon",
TrophyEntryCardSprite = "TrophyEntryCard",
Expand All @@ -37,12 +37,14 @@ root.TrophyMenu = {
EntryHeight = 74,
EntryCardOffset = { X = 91, Y = 1 },
EntryNameOffset = { X = 218, Y = 12 },
EntryNameFontSize = 26,
EntryNameFontSize = 32,
EntryDescriptionOffset = { X = 218, Y = 42 },
EntryDescriptionFontSize = 18,
EntryDescriptionFontSize = 24,
EntryIconOffset = { X = 112, Y = 4 },
EntryRarityIconOffset = { X = 161, Y = 42 },
EntryDefaultNameTextTableId = 0,
EntryDefaultNameStringNum = 19,
EntryLockedTextColorIndex = 60,

CurrentPageNumPos = { X = 1133, Y = 65 },
PageNumSeparatorSlashSprite = "PageNumSeparatorSlash",
Expand All @@ -53,8 +55,8 @@ root.TrophyMenu = {

TrophyCountHintTextTableId = 0,
TrophyCountHintStringNum = 20,
TrophyCountHintLabelPos = { X = 297, Y = 97 },
TrophyCountFontSize = 20
TrophyCountHintLabelPos = { X = 297, Y = 90 },
TrophyCountFontSize = 30
};

root.Sprites["CircleTrophy"] = {
Expand Down
42 changes: 25 additions & 17 deletions src/games/chlcc/trophymenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,39 +49,43 @@ void TrophyMenu::UpdateRarityCounts() {
using namespace Impacto::AchievementSystem;

magic_enum::containers::array<AchievementRarity, size_t> unlockedCounts{};
magic_enum::containers::array<AchievementRarity, size_t> totalCounts{};
size_t totalUnlocked = 0;
const size_t totalCount = GetAchievementCount();

switch (Profile::AchievementSystem::Type) {
case AchievementDataType::Common: {
auto* commonImpl = static_cast<AchievementSystemCommon*>(Implementation);
const size_t count = GetAchievementCount();
for (size_t id = 0; id < count; id++) {
const CommonAchievement* ach =
commonImpl->GetAchievement(static_cast<int>(id));
for (size_t id = 0; id < totalCount; id++) {
const Achievement* ach = GetAchievement(static_cast<int>(id));
if (ach == nullptr) continue;
const AchievementRarity rarity = ach->GetRarity();
totalCounts[rarity]++;
if (IsAchievementUnlocked(static_cast<int>(id)))
unlockedCounts[rarity]++;
if (!IsAchievementUnlocked(static_cast<int>(id))) continue;
totalUnlocked++;
const CommonAchievement* commonAch =
static_cast<const CommonAchievement*>(ach);
unlockedCounts[commonAch->GetRarity()]++;
}
break;
}
case AchievementDataType::None:
break;
}

const auto setCount = [&unlockedCounts, &totalCounts](
Label& label, AchievementRarity rarity) {
label.SetText(
fmt::format("{:d}/{:d}", unlockedCounts[rarity], totalCounts[rarity]),
label.Bounds.GetPos(), RarityCountFontSize, RendererOutlineMode::Full,
0);
const auto setCount = [&unlockedCounts](Label& label,
AchievementRarity rarity) {
label.SetText(fmt::format("{:d}", unlockedCounts[rarity]),
label.Bounds.GetPos(), RarityCountFontSize,
RendererOutlineMode::Full, 0);
};

setCount(BronzeCountLabel, AchievementRarity::Bronze);
setCount(SilverCountLabel, AchievementRarity::Silver);
setCount(GoldCountLabel, AchievementRarity::Gold);
setCount(PlatinumCountLabel, AchievementRarity::Platinum);

TrophyCountLabel.SetText(
fmt::format("{:d}/{:d}", totalUnlocked, totalCount),
TrophyCountHintLabelPos +
glm::vec2(TrophyCountHintLabel.Bounds.Width, 0.0f),
RarityCountFontSize, RendererOutlineMode::Full, 0);
}

void TrophyMenu::Show() {
Expand All @@ -107,7 +111,6 @@ void TrophyMenu::Show() {
}
}
MainItems[CurrentPage].Show();
UpdateRarityCounts();
if (!TrophyCountHintLabel.Enabled) {
TrophyCountHintLabel.Enabled = true;
TrophyCountHintLabel.SetText(
Expand All @@ -116,6 +119,7 @@ void TrophyMenu::Show() {
TrophyCountHintLabelPos, TrophyCountFontSize,
RendererOutlineMode::Full, 0);
}
UpdateRarityCounts();
}
}
void TrophyMenu::Hide() {
Expand Down Expand Up @@ -150,6 +154,10 @@ void TrophyMenu::Render() {
TrophyCountHintLabel.Render();
TrophyCountHintLabel.Move(-offset);

TrophyCountLabel.Move(offset);
TrophyCountLabel.Render();
TrophyCountLabel.Move(-offset);

Renderer->DrawSprite(PlatinumTrophySprite, offset + PlatinumTrophyPos);
Renderer->DrawSprite(GoldTrophySprite, offset + GoldTrophyPos);
Renderer->DrawSprite(SilverTrophySprite, offset + SilverTrophyPos);
Expand Down
1 change: 1 addition & 0 deletions src/games/chlcc/trophymenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class TrophyMenu : public Menu, public CommonMenu {
int CurrentPage = 0;

Widgets::Label TrophyCountHintLabel;
Widgets::Label TrophyCountLabel;

Widgets::Label PlatinumCountLabel;
Widgets::Label GoldCountLabel;
Expand Down
3 changes: 3 additions & 0 deletions src/profile/games/chlcc/trophymenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,13 @@ void Configure() {
EntryDescriptionOffset = EnsureGetMember<glm::vec2>("EntryDescriptionOffset");
EntryDescriptionFontSize = EnsureGetMember<float>("EntryDescriptionFontSize");
EntryIconOffset = EnsureGetMember<glm::vec2>("EntryIconOffset");
EntryRarityIconOffset = EnsureGetMember<glm::vec2>("EntryRarityIconOffset");
EntryDefaultNameTextTableId =
EnsureGetMember<uint32_t>("EntryDefaultNameTextTableId");
EntryDefaultNameStringNum =
EnsureGetMember<uint32_t>("EntryDefaultNameStringNum");
EntryLockedTextColorIndex =
EnsureGetMember<size_t>("EntryLockedTextColorIndex");

CurrentPageNumPos = EnsureGetMember<glm::vec2>("CurrentPageNumPos");
PageNumSeparatorSlash =
Expand Down
2 changes: 2 additions & 0 deletions src/profile/games/chlcc/trophymenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ inline float EntryNameFontSize;
inline glm::vec2 EntryDescriptionOffset;
inline float EntryDescriptionFontSize;
inline glm::vec2 EntryIconOffset;
inline glm::vec2 EntryRarityIconOffset;
inline uint32_t EntryDefaultNameTextTableId;
inline uint32_t EntryDefaultNameStringNum;
inline size_t EntryLockedTextColorIndex;

inline glm::vec2 CurrentPageNumPos;
inline Sprite PageNumSeparatorSlash;
Expand Down
55 changes: 46 additions & 9 deletions src/ui/widgets/chlcc/trophymenuentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#include <cassert>

#include "../../../data/achievementsystem.h"
#include "../../../data/achievementsystemcommon.h"
#include "../../../games/chlcc/trophymenu.h"
#include "../../../profile/data/achievementsystem.h"
#include "../../../profile/games/chlcc/trophymenu.h"

namespace Impacto {
Expand All @@ -23,33 +25,67 @@ TrophyMenuEntry::TrophyMenuEntry(int achievementId)
const auto* ach = GetAchievement(AchievementId);
assert(ach != nullptr);
const bool unlocked = IsAchievementUnlocked(AchievementId);
if (ach == nullptr || !unlocked) {
const bool revealed = unlocked || !ach->Hidden();
const size_t textColorIndex = unlocked ? 0 : EntryLockedTextColorIndex;
if (!revealed) {
NameLabel =
Label(Vm::ScriptGetTextTableStrAddress(EntryDefaultNameTextTableId,
EntryDefaultNameStringNum),
Bounds.GetPos() + EntryNameOffset, EntryNameFontSize,
RendererOutlineMode::BottomRight, 0);
DescriptionLabel =
Label("", Bounds.GetPos() + EntryDescriptionOffset,
EntryDescriptionFontSize, RendererOutlineMode::BottomRight, 0);
RendererOutlineMode::BottomRight, textColorIndex);
DescriptionLabel = Label("", Bounds.GetPos() + EntryDescriptionOffset,
EntryDescriptionFontSize,
RendererOutlineMode::BottomRight, textColorIndex);
Icon = DefaultTrophyIconSprite;
} else {
NameLabel = Label(ach->Name(), Bounds.GetPos() + EntryNameOffset,
EntryNameFontSize, RendererOutlineMode::BottomRight, 0);
NameLabel =
Label(ach->Name(), Bounds.GetPos() + EntryNameOffset, EntryNameFontSize,
RendererOutlineMode::BottomRight, textColorIndex);
DescriptionLabel =
Label(ach->Description(), Bounds.GetPos() + EntryDescriptionOffset,
EntryDescriptionFontSize, RendererOutlineMode::BottomRight, 0);
Icon = ach->Icon();
EntryDescriptionFontSize, RendererOutlineMode::BottomRight,
textColorIndex);
Icon = unlocked ? ach->Icon() : DefaultTrophyIconSprite;
}
IconDest = RectF{Bounds.X, Bounds.Y, DefaultTrophyIconSprite.ScaledWidth(),
DefaultTrophyIconSprite.ScaledHeight()} +
EntryIconOffset;

AchievementRarity rarity = AchievementRarity::Bronze;
if (Profile::AchievementSystem::Type == AchievementDataType::Common) {
if (const CommonAchievement* commonAch =
static_cast<AchievementSystemCommon*>(Implementation)
->GetAchievement(AchievementId)) {
rarity = commonAch->GetRarity();
}
}
switch (rarity) {
case AchievementRarity::Platinum:
RarityIcon = PlatinumTrophySprite;
break;
case AchievementRarity::Gold:
RarityIcon = GoldTrophySprite;
break;
case AchievementRarity::Silver:
RarityIcon = SilverTrophySprite;
break;
case AchievementRarity::Bronze:
default:
RarityIcon = BronzeTrophySprite;
break;
}
RarityIconDest = RectF{Bounds.X, Bounds.Y, RarityIcon.ScaledWidth(),
RarityIcon.ScaledHeight()} +
EntryRarityIconOffset;
RarityIconTint = revealed ? glm::vec4{1.0f, 1.0f, 1.0f, 1.0f}
: glm::vec4{0.0f, 0.0f, 0.0f, 1.0f};
};

void TrophyMenuEntry::Render() {
Renderer->DrawSprite(TrophyEntryCardSprite,
Bounds.GetPos() + EntryCardOffset);
Renderer->DrawSprite(Icon, IconDest);
Renderer->DrawSprite(RarityIcon, RarityIconDest, RarityIconTint);

NameLabel.Render();
DescriptionLabel.Render();
Expand All @@ -61,6 +97,7 @@ void TrophyMenuEntry::Move(glm::vec2 relativePosition) {
NameLabel.Move(relativePosition);
DescriptionLabel.Move(relativePosition);
IconDest += relativePosition;
RarityIconDest += relativePosition;
}

} // namespace CHLCC
Expand Down
4 changes: 4 additions & 0 deletions src/ui/widgets/chlcc/trophymenuentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class TrophyMenuEntry : public Widget {

Sprite Icon;
RectF IconDest;

Sprite RarityIcon;
RectF RarityIconDest;
glm::vec4 RarityIconTint;
};

} // namespace CHLCC
Expand Down
Loading