Skip to content

Commit

Permalink
add putter strength to power bar when putting
Browse files Browse the repository at this point in the history
  • Loading branch information
fallahn committed Jul 28, 2023
1 parent 17267f7 commit a05afab
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 5 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 986
#define BUILDNUMBER_STR "986"
#define BUILDNUMBER 993
#define BUILDNUMBER_STR "993"

#endif /* BUILD_NUMBER_H_ */
3 changes: 2 additions & 1 deletion samples/golf/src/golf/CommandIDs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ struct CommandID final
WaitMessage = 0x200000,
FastForward = 0x400000,
WindHidden = 0x800000, //I can't think of a better name - basically when the wind indicator is hidden during putting
WindEffect = 0x1000000
WindEffect = 0x1000000,
PuttPower = 0x2000000
};
};

Expand Down
46 changes: 46 additions & 0 deletions samples/golf/src/golf/GolfState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,29 @@ void GolfState::handleMessage(const cro::Message& msg)
};
m_uiScene.getSystem<cro::CommandSystem>()->sendCommand(cmd);

cmd.targetFlags = CommandID::UI::PuttPower;
cmd.action = [&](cro::Entity e, float)
{
if (m_currentPlayer.client == m_sharedData.clientConnection.connectionID)
{
auto club = getClub();
if (club == ClubID::Putter)
{
auto str = Clubs[ClubID::Putter].getName(m_sharedData.imperialMeasurements, m_distanceToHole);
e.getComponent<cro::Text>().setString(str.substr(str.find_last_of(' ') + 1));
}
else
{
e.getComponent<cro::Text>().setString(" ");
}
}
else
{
e.getComponent<cro::Text>().setString(" ");
}
};
m_uiScene.getSystem<cro::CommandSystem>()->sendCommand(cmd);

//hide wind indicator if club is less than min wind distance to hole
cmd.targetFlags = CommandID::UI::WindHidden;
cmd.action = [&](cro::Entity e, float)
Expand Down Expand Up @@ -1416,6 +1439,29 @@ void GolfState::handleMessage(const cro::Message& msg)
};
m_uiScene.getSystem<cro::CommandSystem>()->sendCommand(cmd);

cmd.targetFlags = CommandID::UI::PuttPower;
cmd.action = [&](cro::Entity e, float)
{
if (m_currentPlayer.client == m_sharedData.clientConnection.connectionID)
{
auto club = getClub();
if (club == ClubID::Putter)
{
auto str = Clubs[ClubID::Putter].getName(m_sharedData.imperialMeasurements, m_distanceToHole);
e.getComponent<cro::Text>().setString(str.substr(str.find_last_of(' ') + 1));
}
else
{
e.getComponent<cro::Text>().setString(" ");
}
}
else
{
e.getComponent<cro::Text>().setString(" ");
}
};
m_uiScene.getSystem<cro::CommandSystem>()->sendCommand(cmd);

cmd.targetFlags = CommandID::UI::PinDistance;
cmd.action =
[&](cro::Entity e, float)
Expand Down
11 changes: 10 additions & 1 deletion samples/golf/src/golf/GolfStateUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -728,9 +728,18 @@ void GolfState::buildUI()
bounds = entity.getComponent<cro::Sprite>().getTextureBounds();
entity.getComponent<cro::Transform>().setOrigin(glm::vec3(bounds.width / 2.f, bounds.height / 2.f, -0.05f));
rootNode.getComponent<cro::Transform>().addChild(entity.getComponent<cro::Transform>());
auto barEnt = entity;

const auto& smallFont = m_sharedData.sharedResources->fonts.get(FontID::Info);
entity = m_uiScene.createEntity();
entity.addComponent<cro::Transform>().setPosition({ bounds.width + 2.f, 12.f, 0.f });
entity.addComponent<cro::Drawable2D>();
entity.addComponent<cro::Text>(smallFont).setFillColour(TextNormalColour);
entity.getComponent<cro::Text>().setCharacterSize(InfoTextSize);
entity.addComponent<cro::CommandTarget>().ID = CommandID::UI::PuttPower;
barEnt.getComponent<cro::Transform>().addChild(entity.getComponent<cro::Transform>());

//power bar
auto barEnt = entity;
const auto BarCentre = bounds.width / 2.f;
const auto BarWidth = bounds.width - 8.f;
const auto BarHeight = bounds.height;
Expand Down
2 changes: 1 addition & 1 deletion samples/golf/src/golf/MenuCreation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2385,7 +2385,7 @@ void MenuState::createLobbyMenu(cro::Entity parent, std::uint32_t mouseEnter, st
//continue message
messageEnt.getComponent<cro::Text>().setFillColour(cro::Colour::Transparent);

messageTitleEnt.getComponent<cro::Text>().setString("Ready?");
messageTitleEnt.getComponent<cro::Text>().setString("Start Game?");
centreText(messageTitleEnt);
}
m_audioEnts[AudioID::Back].getComponent<cro::AudioEmitter>().play();
Expand Down

0 comments on commit a05afab

Please sign in to comment.