Skip to content

Commit

Permalink
display 'flag type' challenge progress as check boxes
Browse files Browse the repository at this point in the history
  • Loading branch information
fallahn committed Aug 22, 2023
1 parent bfc8791 commit 4e53ac8
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 10 deletions.
9 changes: 8 additions & 1 deletion libsocial/src/MonthlyChallenge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,14 @@ cro::String MonthlyChallenge::getProgressString() const
ret = ChallengeDescriptions[m_month] + "\n";
if (progress.value != progress.target)
{
ret += "Progress: " + std::to_string(progress.value) + "/" + std::to_string(progress.target);
if (m_challenges[m_month].type == Challenge::Counter)
{
ret += "Progress: " + std::to_string(progress.value) + "/" + std::to_string(progress.target);
}
else
{
ret += " "; //leave empty so we can display the 'check' boxes
}

if (remain == 0)
{
Expand Down
4 changes: 2 additions & 2 deletions samples/golf/buildnumber.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#ifndef BUILD_NUMBER_H_
#define BUILD_NUMBER_H_

#define BUILDNUMBER 1313
#define BUILDNUMBER_STR "1313"
#define BUILDNUMBER 1314
#define BUILDNUMBER_STR "1314"

#endif /* BUILD_NUMBER_H_ */
42 changes: 35 additions & 7 deletions samples/golf/src/golf/ClubhouseStateUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,22 +574,51 @@ void ClubhouseState::createMainMenu(cro::Entity parent, std::uint32_t mouseEnter
std::vector<cro::Vertex2D> verts;

entity = m_uiScene.createEntity();
entity.addComponent<cro::Transform>();
entity.addComponent<cro::Transform>().setPosition({ 0.f, -24.f,-0.1f });
entity.addComponent<cro::Drawable2D>().setPrimitiveType(GL_TRIANGLES);

if (flags != std::numeric_limits<std::uint32_t>::max())
{
auto spr = spriteSheet.getSprite("progress_icon");
const auto uvRect = spr.getTextureRectNormalised();
const float IconWidth = spr.getTextureBounds().width;
const float IconHeight = spr.getTextureBounds().height;
static constexpr float IconPadding = 2.f;

const auto addIcon =
[&](glm::vec2 position, bool selected)
{
auto uv = uvRect;
if (selected)
{
uv.bottom += uvRect.height;
}

//GL_TRIANGLES
verts.emplace_back(glm::vec2(position.x, position.y + IconHeight), glm::vec2(uv.left, uv.bottom + uv.height));
verts.emplace_back(position, glm::vec2(uv.left, uv.bottom));
verts.emplace_back(glm::vec2(position.x + IconWidth, position.y + IconHeight), glm::vec2(uv.left + uv.width, uv.bottom + uv.height));

verts.emplace_back(glm::vec2(position.x + IconWidth, position.y + IconHeight), glm::vec2(uv.left + uv.width, uv.bottom + uv.height));
verts.emplace_back(position, glm::vec2(uv.left, uv.bottom));
verts.emplace_back(glm::vec2(position.x + IconWidth, position.y), glm::vec2(uv.left + uv.width, uv.bottom));
};

//we gots flags baybee
CRO_ASSERT(target < 31, "too many flags buddy");
entity.getComponent<cro::Transform>();// .setPosition({ 0.f, -24.f,-0.1f });
verts = {};
//GL_TRIANGLES
float xPos = ((target * (IconWidth + IconPadding)) - IconPadding) / 2.f;
xPos = -std::floor(xPos);

for (auto i = 0; i < target; ++i)
{
addIcon(glm::vec2(xPos, 0.f), (flags & (1 << i)) != 0);
xPos += (IconWidth + IconPadding);
}
entity.getComponent<cro::Drawable2D>().setTexture(spr.getTexture());
}
else
{
//regular progress
entity.getComponent<cro::Transform>().setPosition({ 0.f, -24.f,-0.1f });
verts =
{
cro::Vertex2D(glm::vec2(-BarWidth, BarHeight), LeaderboardTextDark),
Expand Down Expand Up @@ -632,8 +661,7 @@ void ClubhouseState::createMainMenu(cro::Entity parent, std::uint32_t mouseEnter
}

}
entity.addComponent<cro::Drawable2D>().setVertexData(verts);
entity.getComponent<cro::Drawable2D>().setPrimitiveType(GL_TRIANGLES);
entity.getComponent<cro::Drawable2D>().setVertexData(verts);
textEnt.getComponent<cro::Transform>().addChild(entity.getComponent<cro::Transform>());
}
}
Expand Down
10 changes: 10 additions & 0 deletions samples/golf/src/golf/GolfStateUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2688,6 +2688,16 @@ void GolfState::updateScoreboard(bool updateParDiff)
break;
case ScoreType::Stableford:
case ScoreType::StablefordPro:
totalString += " - " + std::to_string(scores[i].total);
if (scores[i].total == 1)
{
totalString += " POINT";
}
else
{
totalString += " POINTS";
}
break;
case ScoreType::Match:
if (scores[i].backNine == 1)
{
Expand Down

0 comments on commit 4e53ac8

Please sign in to comment.