Skip to content

Commit

Permalink
tidy up driving range UI
Browse files Browse the repository at this point in the history
auto select correct leaderboards based on current options when opening leaderboard browser on driving range
  • Loading branch information
fallahn committed Jul 8, 2023
1 parent 2f79690 commit 10c144c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 37 deletions.
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 646
#define BUILDNUMBER_STR "646"
#define BUILDNUMBER 648
#define BUILDNUMBER_STR "648"

#endif /* BUILD_NUMBER_H_ */
12 changes: 9 additions & 3 deletions samples/golf/src/golf/DrivingState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,10 +494,16 @@ bool DrivingState::handleEvent(const cro::Event& evt)
}
else if (evt.type == SDL_MOUSEBUTTONUP)
{
if (evt.button.button == SDL_BUTTON_RIGHT &&
m_gameScene.getDirector<DrivingRangeDirector>()->roundEnded())
if (evt.button.button == SDL_BUTTON_RIGHT)
{
pauseGame();
#ifdef USE_GNS
closeLeaderboard();
#else
if(m_gameScene.getDirector<DrivingRangeDirector>()->roundEnded())
{
pauseGame();
}
#endif
}
}
else if (evt.type == SDL_CONTROLLERDEVICEREMOVED)
Expand Down
77 changes: 45 additions & 32 deletions samples/golf/src/golf/DrivingStateUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -925,9 +925,8 @@ void DrivingState::createGameOptions()
cro::SpriteSheet spriteSheet;
spriteSheet.loadFromFile("assets/golf/sprites/scoreboard.spt", m_resources.textures);
m_sprites[SpriteID::Stars] = spriteSheet.getSprite("orbs");
//auto bgSprite = spriteSheet.getSprite("border");

auto bounds = cro::FloatRect(glm::vec2(0.f), glm::vec2(tex.getSize()));// bgSprite.getTextureBounds();
auto bounds = cro::FloatRect(glm::vec2(0.f), glm::vec2(tex.getSize()));
auto size = glm::vec2(GolfGame::getActiveTarget()->getSize());
auto position = glm::vec3(size.x / 2.f, size.y / 2.f, 1.5f);

Expand Down Expand Up @@ -1118,6 +1117,8 @@ score based on your overall accuracy. Good Luck!
numberEnt.getComponent<cro::Text>().setString(std::to_string(m_strokeCounts[m_strokeCountIndex]));
centreText(numberEnt);

leaderboardTryCount = m_strokeCountIndex;

if (m_topScores[m_strokeCountIndex] > 0)
{
std::stringstream s;
Expand Down Expand Up @@ -1156,6 +1157,8 @@ score based on your overall accuracy. Good Luck!
numberEnt.getComponent<cro::Text>().setString(std::to_string(m_strokeCounts[m_strokeCountIndex]));
centreText(numberEnt);

leaderboardTryCount = m_strokeCountIndex;

if (m_topScores[m_strokeCountIndex] > 0)
{
std::stringstream s;
Expand Down Expand Up @@ -1314,6 +1317,8 @@ score based on your overall accuracy. Good Luck!
numberEnt.getComponent<cro::Text>().setString(str);
centreText(numberEnt);

leaderboardHoleIndex = m_targetIndex;

m_summaryScreen.audioEnt.getComponent<cro::AudioEmitter>().play();
}
});
Expand All @@ -1331,6 +1336,8 @@ score based on your overall accuracy. Good Luck!
numberEnt.getComponent<cro::Text>().setString(str);
centreText(numberEnt);

leaderboardHoleIndex = m_targetIndex;

m_summaryScreen.audioEnt.getComponent<cro::AudioEmitter>().play();
}
});
Expand Down Expand Up @@ -1442,35 +1449,7 @@ score based on your overall accuracy. Good Luck!
entity.getComponent<cro::Transform>().setOrigin({ b.width / 2.f, b.height / 2.f });
entity.getComponent<cro::Transform>().move({ std::floor(bgBounds.width / 2.f), b.height / 2.f });
entity.addComponent<cro::Callback>().setUserData<LeaderboardData>();
entity.getComponent<cro::Callback>().function =
[&](cro::Entity e, float dt)
{
const float Speed = dt * 4.f;
auto& [progress, direction] = e.getComponent<cro::Callback>().getUserData<LeaderboardData>();
if (direction == 0)
{
//grow
progress = std::min(1.f, progress + Speed);
if (progress == 1)
{
direction = 1;
e.getComponent<cro::Callback>().active = false;
m_uiScene.getSystem<cro::UISystem>()->setActiveGroup(MenuID::Leaderboard);
}
}
else
{
//shrink
progress = std::max(0.f, progress - Speed);
if (progress == 0)
{
direction = 0;
e.getComponent<cro::Callback>().active = false;
m_uiScene.getSystem<cro::UISystem>()->setActiveGroup(MenuID::Options);
}
}
e.getComponent<cro::Transform>().setScale({ cro::Util::Easing::easeOutQuad(progress), 1.f });
};
//callback is added below so we can captch upDisplay lambda
bgEntity.getComponent<cro::Transform>().addChild(entity.getComponent<cro::Transform>());

auto lbEntity = entity;
Expand Down Expand Up @@ -1623,6 +1602,40 @@ score based on your overall accuracy. Good Luck!
};


lbEntity.getComponent<cro::Callback>().function =
[&, updateDisplay](cro::Entity e, float dt) mutable
{
const float Speed = dt * 4.f;
auto& [progress, direction] = e.getComponent<cro::Callback>().getUserData<LeaderboardData>();
if (direction == 0)
{
//grow
progress = std::min(1.f, progress + Speed);
if (progress == 1)
{
direction = 1;
e.getComponent<cro::Callback>().active = false;
m_uiScene.getSystem<cro::UISystem>()->setActiveGroup(MenuID::Leaderboard);

updateDisplay();
}
}
else
{
//shrink
progress = std::max(0.f, progress - Speed);
if (progress == 0)
{
direction = 0;
e.getComponent<cro::Callback>().active = false;
m_uiScene.getSystem<cro::UISystem>()->setActiveGroup(MenuID::Options);
}
}
e.getComponent<cro::Transform>().setScale({ cro::Util::Easing::easeOutQuad(progress), 1.f });
};



//browse leaderboards
textEnt4 = m_uiScene.createEntity();
textEnt4.addComponent<cro::Transform>().setPosition({ (bounds.width / 5.f) * 4.f, 100.f, 0.02f });
Expand Down Expand Up @@ -1901,7 +1914,7 @@ void DrivingState::createSummary()
//background
cro::SpriteSheet spriteSheet;
spriteSheet.loadFromFile("assets/golf/sprites/scoreboard.spt", m_resources.textures);
auto bgSprite = spriteSheet.getSprite("border");
auto bgSprite = cro::Sprite(m_resources.textures.get("assets/golf/images/driving_range_menu.png"));

auto bounds = bgSprite.getTextureBounds();
auto size = glm::vec2(GolfGame::getActiveTarget()->getSize());
Expand Down

0 comments on commit 10c144c

Please sign in to comment.