diff --git a/src/bzflag/HUDRenderer.cxx b/src/bzflag/HUDRenderer.cxx index 4b75d9ddb5..11b6c2d75d 100644 --- a/src/bzflag/HUDRenderer.cxx +++ b/src/bzflag/HUDRenderer.cxx @@ -2023,6 +2023,7 @@ void HUDRenderer::renderShots(const Player* target) if (!target) return; + FontManager &fm = FontManager::instance(); const ShotSlot::Vec& slotList = target->getShotSlots(); @@ -2069,6 +2070,41 @@ void HUDRenderer::renderShots(const Player* target) } } glDisable(GL_BLEND); + + // draw the number of shots left + const int& flagLimit = target->getFlagLimit(); + if (flagLimit >= 0) + { + if (!flagLimitShown) + { + flagLimitStartTime = TimeKeeper::getTick(); + flagLimitShown = true; + flagLimitInfo = true; + } + + hudColor4f(1.0f, 1.0f, 1.0f, 0.5f); // 50%-solid white + + std::string flagLimitStr = std::to_string(flagLimit); + float y = (float)indicatorTop + factors.size() * (indicatorHeight + indicatorSpace); + fm.drawString((float)indicatorLeft, y, 0, minorFontFace, minorFontSize, flagLimitStr); + + if (TimeKeeper::getTick() - flagLimitStartTime >= 5.0) + flagLimitInfo = false; + + if (flagLimitInfo) + { + float alpha = float(TimeKeeper::getTick() - flagLimitStartTime); + if (alpha <= 1.0f) + hudColor4f(1.0f, 1.0f, 1.0f, alpha / 2.0f); // white + else if (alpha >= 4.0f) + hudColor4f(1.0f, 1.0f, 1.0f, -(alpha - 5.0f) / 2.0f); // white + fm.drawString((float)indicatorLeft + fm.getStrLength(minorFontFace, minorFontSize, flagLimitStr + " "), y, 0, minorFontFace, minorFontSize, (flagLimit == 1) ? "shot left" : "shots left"); + } + } + else + { + flagLimitShown = false; + } } diff --git a/src/bzflag/HUDRenderer.h b/src/bzflag/HUDRenderer.h index 69f4fe91e5..ce325309dd 100644 --- a/src/bzflag/HUDRenderer.h +++ b/src/bzflag/HUDRenderer.h @@ -267,6 +267,10 @@ class HUDRenderer unsigned int lastTimeChange; int triangleCount; int radarTriangleCount; + + bool flagLimitShown = false; + bool flagLimitInfo = false; + TimeKeeper flagLimitStartTime; }; diff --git a/src/bzflag/LocalPlayer.cxx b/src/bzflag/LocalPlayer.cxx index 11c34a35ad..91bf0af4fd 100644 --- a/src/bzflag/LocalPlayer.cxx +++ b/src/bzflag/LocalPlayer.cxx @@ -1290,21 +1290,6 @@ bool LocalPlayer::fireShot() { // the server is going to drop it for us now.... } - else - { - if (flagLimit % 5 == 0 || flagLimit <= 3) - { - std::string limitMessage; - if (flagLimit > 1) - limitMessage = TextUtils::format("%d shots left", flagLimit); - else if (flagLimit == 1) - limitMessage = "1 shot left"; - else - limitMessage = "The flag is empty and can not be fired anymore"; - - addMessage(nullptr, limitMessage, 0); - } - } } if (gettingSound) diff --git a/src/bzflag/Player.h b/src/bzflag/Player.h index def421c061..f6f9e0889d 100644 --- a/src/bzflag/Player.h +++ b/src/bzflag/Player.h @@ -83,6 +83,10 @@ class Player { return ShotSlots; } + const int& getFlagLimit() const + { + return flagLimit; + } float getAngularVelocity() const; int getPhysicsDriver() const; diff --git a/src/bzflag/playing.cxx b/src/bzflag/playing.cxx index 741cdf4f72..be3374d941 100644 --- a/src/bzflag/playing.cxx +++ b/src/bzflag/playing.cxx @@ -2693,20 +2693,6 @@ static void handleServerMessage(bool human, uint16_t code, // grabbed flag playLocalSound(myTank->getFlag()->endurance != FlagEndurance::Sticky ? SFX_GRAB_FLAG : SFX_GRAB_BAD); updateFlag(myTank->getFlag()); - - if (flagLimit >= 0) - { - std::string limitMessage; - - if (flagLimit > 1) - limitMessage = TextUtils::format("This flag is limited to %d shots", flagLimit); - else if (flagLimit == 1) - limitMessage = "This flag is limited to 1 shot"; - else - limitMessage = "This flag is empty and can not be shot"; - - addMessage(nullptr, limitMessage, 0); - } } else if (isViewTank(tank)) {