14 constexpr
float SlideSpeed = 400.f;
15 constexpr
float BarRate = 0.45f;
16 constexpr glm::vec2 BarSize(96.f, 6.f);
18 constexpr glm::vec2 XpBarPos(52.f, 88.f);
19 constexpr glm::vec2 XpBarSize(192.f, 4.f);
21 constexpr glm::vec2 OpBoxPos(0.f, 0.f);
22 constexpr glm::vec2 OpBarPos(100.f, 50.f);
24 constexpr glm::vec2 LpBoxPos(540.f, 357.f);
25 constexpr glm::vec2 LpBarPos(148.f, 54.f);
27 constexpr
float NameSize = 18.f;
28 constexpr
float LevelSize = 15.f;
29 const sf::Color LevelColor(20.f, 20.f, 140.f);
31 std::string makeHpStr(
unsigned int cur,
unsigned int max) {
33 ss << cur <<
"/" << max;
41 , localPlayer(nullptr)
43 , pState(State::Hidden)
44 , oState(State::Hidden)
47 , lpXpBarTarget(0.f) {}
50 constexpr
auto join = bl::util::FileUtil::joinPath;
53 opBoxTxtr = engine.renderer().texturePool().getOrLoadTexture(join(ImgPath,
"Battle/opBox.png"));
54 opBox.create(engine, opBoxTxtr);
55 opBox.getTransform().setPosition(-opBoxTxtr->size().x, OpBoxPos.y);
56 opBox.addToScene(scene, bl::rc::UpdateSpeed::Static);
58 lpBoxTxtr = engine.renderer().texturePool().getOrLoadTexture(join(ImgPath,
"Battle/pBox.png"));
59 lpBox.create(engine, lpBoxTxtr);
61 lpBox.addToScene(scene, bl::rc::UpdateSpeed::Static);
63 lpXpBar.create(engine, {100.f, 100.f});
64 lpXpBar.setFillColor(sf::Color::Blue);
65 lpXpBar.addToScene(scene, bl::rc::UpdateSpeed::Dynamic);
68 opName.addToScene(scene, bl::rc::UpdateSpeed::Static);
71 opLevel.addToScene(scene, bl::rc::UpdateSpeed::Static);
74 lpName.addToScene(scene, bl::rc::UpdateSpeed::Static);
77 lpLevel.addToScene(scene, bl::rc::UpdateSpeed::Static);
80 lpHp.addToScene(scene, bl::rc::UpdateSpeed::Static);
82 lpHpBar.create(engine, {100.f, 100.f});
83 lpHpBar.addToScene(scene, bl::rc::UpdateSpeed::Dynamic);
85 opHpBar.create(engine, {100.f, 100.f});
86 opHpBar.addToScene(scene, bl::rc::UpdateSpeed::Dynamic);
88 opAil.create(engine, engine.renderer().texturePool().getBlankTexture());
89 opAil.addToScene(scene, bl::rc::UpdateSpeed::Static);
91 lpAil.create(engine, engine.renderer().texturePool().getBlankTexture());
92 lpAil.addToScene(scene, bl::rc::UpdateSpeed::Static);
95 opHpBar.getTransform().setPosition(OpBarPos);
96 opHpBar.setParent(opBox);
97 opAil.getTransform().setPosition(glm::vec2(10.f, 46.f));
98 opAil.setParent(opBox);
99 opName.getTransform().setPosition(glm::vec2(5.f, 18.f));
100 opName.setParent(opBox);
101 opLevel.getTransform().setPosition(glm::vec2(168.f, 21.f));
102 opLevel.setParent(opBox);
105 lpAil.getTransform().setPosition(glm::vec2(33.f, 61.f));
106 lpAil.setParent(lpBox);
107 lpName.getTransform().setPosition(glm::vec2(41.f, 22.f));
108 lpName.setParent(lpBox);
109 lpLevel.getTransform().setPosition(glm::vec2(218.f, 24.f));
110 lpLevel.setParent(lpBox);
111 lpHp.getTransform().setPosition(glm::vec2(131.f, 66.f));
112 lpHp.setParent(lpBox);
113 lpHpBar.getTransform().setPosition(LpBarPos);
114 lpHpBar.setParent(lpBox);
115 lpXpBar.getTransform().setPosition(XpBarPos);
116 lpXpBar.setParent(lpBox);
119 lpHpBar.scaleToSize({0.f, BarSize.y});
120 opHpBar.scaleToSize({0.f, BarSize.y});
121 lpXpBar.scaleToSize({0.f, XpBarSize.y});
126 opHpBar.scaleToSize({0.f, BarSize.y});
127 if (oState == State::Hidden) { oState = State::Sliding; }
133 lpHpBar.scaleToSize({0.f, BarSize.y});
134 lpXpBar.scaleToSize({0.f, XpBarSize.y});
135 if (pState == State::Hidden) { pState = State::Sliding; }
141 lpName.getSection().setString(localPlayer->
base().
name());
142 lpLevel.getSection().setString(std::to_string(localPlayer->
base().
currentLevel()));
143 lpHp.getSection().setString(
146 lpHpBarTarget = (
static_cast<float>(localPlayer->
base().
currentHp()) /
149 lpXpBarTarget = (
static_cast<float>(localPlayer->
base().
currentXP()) /
152 if (fromSwitch) { lpXpBar.scaleToSize({lpXpBarTarget, XpBarSize.y}); }
155 BL_LOG_WARN <<
"sync() called with null player peoplemon";
158 lpName.getSection().setString(
"");
162 opName.getSection().setString(opponent->
base().
name());
163 opLevel.getSection().setString(std::to_string(opponent->
base().
currentLevel()));
165 opHpBarTarget = (
static_cast<float>(opponent->
base().
currentHp()) /
170 BL_LOG_WARN <<
"sync() called with null opponent peoplemon";
172 opName.getSection().setString(
"");
177 const float change = dt * BarRate * BarSize.x;
180 if (oState == State::Sliding) {
181 const float dx = SlideSpeed * dt;
182 opBox.getTransform().move({dx, 0.f});
183 if (opBox.getTransform().getLocalPosition().x > OpBoxPos.x) {
184 opBox.getTransform().setPosition(OpBoxPos);
185 oState = State::Showing;
188 else if (oState == State::Showing) {
190 if (opHpBar.getGlobalSize().x < opHpBarTarget) {
191 const float nw = std::min(opHpBarTarget, opHpBar.getGlobalSize().x + change);
192 opHpBar.scaleToSize({nw, BarSize.y});
194 else if (opHpBar.getGlobalSize().x > opHpBarTarget) {
195 const float nw = std::max(opHpBarTarget, opHpBar.getGlobalSize().x - change);
196 opHpBar.scaleToSize({nw, BarSize.y});
200 const float opHp = opHpBar.getSize().x / BarSize.x;
205 if (pState == State::Sliding) {
206 const float dx = SlideSpeed * dt;
207 lpBox.getTransform().move({-dx, 0.f});
208 if (lpBox.getTransform().getLocalPosition().x < LpBoxPos.x) {
209 lpBox.getTransform().setPosition(LpBoxPos);
210 pState = State::Showing;
213 else if (pState == State::Showing) {
215 if (lpHpBar.getGlobalSize().x < lpHpBarTarget) {
216 const float nw = std::min(lpHpBarTarget, lpHpBar.getGlobalSize().x + change);
217 lpHpBar.scaleToSize({nw, BarSize.y});
219 else if (lpHpBar.getGlobalSize().x > lpHpBarTarget) {
220 const float nw = std::max(lpHpBarTarget, lpHpBar.getGlobalSize().x - change);
221 lpHpBar.scaleToSize({nw, BarSize.y});
225 const float lphp = lpHpBar.getGlobalSize().x / BarSize.x;
229 const float xpChange = dt * BarRate * XpBarSize.x;
230 if (lpXpBar.getGlobalSize().x < lpXpBarTarget) {
231 const float nw = std::min(lpXpBarTarget, lpXpBar.getGlobalSize().x + xpChange);
232 lpXpBar.scaleToSize({nw, XpBarSize.y});
234 else if (lpXpBar.getGlobalSize().x > lpXpBarTarget) {
236 lpXpBar.scaleToSize({lpXpBarTarget, XpBarSize.y});
242 return opHpBar.getGlobalSize().x == opHpBarTarget &&
243 lpHpBar.getGlobalSize().x == lpHpBarTarget && lpXpBar.getGlobalSize().x == lpXpBarTarget;
247 if (oState != State::Hidden) {
255 if (pState != State::Hidden) {
266 bl::rc::res::TextureRef StatBoxes::ailmentTexture(
pplmn::Ailment ail) {
268 return src.empty() ? engine.renderer().texturePool().getBlankTexture() :
269 engine.renderer().texturePool().getOrLoadTexture(src);
Ailment
Represents an ailment that a Peoplemon can have.
Core classes and functionality for both the editor and game.
StatBoxes(bl::engine::Engine &engine)
Construct a new Stat Boxes component.
void sync(bool fromSwitch=false)
Updates the UI to reflect the current peoplemon state.
void init(bl::rc::scene::CodeScene *scene)
Creates entities and adds them to the scene.
void update(float dt)
Updates bar sizes if they need to change.
void setOpponent(pplmn::BattlePeoplemon *ppl)
Sets the opponent's peoplemon. Syncs right away.
void setPlayer(pplmn::BattlePeoplemon *ppl)
Sets the player's peoplemon. Syncs right away.
bool synced() const
Returns true if the view is in sync, false if an animation is in progress.
void render(bl::rc::scene::CodeScene::RenderContext &ctx)
Renders the boxes.
Represents a Peoplemon in battle. Stores some extra state that only exists in battle....
OwnedPeoplemon & base()
Returns the wrapped peoplemon.
const Stats & currentStats() const
Returns the current stats of the peoplemon, including changes.
Ailment & currentAilment()
Access the current ailment of this peoplemon.
unsigned int nextLevelXP() const
Returns the xp required to level up.
std::uint16_t & currentHp()
Access the current HP.
unsigned int currentLevel() const
Returns the current level of this peoplemon.
unsigned int currentXP() const
Returns the current XP of this peoplemon.
const std::string & name() const
Returns the name of this peoplemon, custom or defualt.
static const sf::VulkanFont & MenuFont()
static std::string AilmentTexture(pplmn::Ailment ailment)
static sf::Color HPBarColor(float percent)
static const std::string & ImagePath()