Show remaining time in progress bar

This commit is contained in:
Benau 2018-12-21 12:52:51 +08:00
parent 1799fe834f
commit 0e17839136
4 changed files with 50 additions and 14 deletions

View File

@ -37,9 +37,7 @@ void NetworkKartSelectionScreen::init()
m_timer = getWidget<GUIEngine::ProgressBarWidget>("timer"); m_timer = getWidget<GUIEngine::ProgressBarWidget>("timer");
m_timer->showLabel(false); m_timer->showLabel(false);
// I18N: Time in seconds (before the voting period in network ends). updateProgressBarText();
// I18N: %s specifes where the number is placed
core::stringw seconds = _("%s seconds", "%d");
// change the back button image (because it makes the game quit) // change the back button image (because it makes the game quit)
IconButtonWidget* back_button = getWidget<IconButtonWidget>("back"); IconButtonWidget* back_button = getWidget<IconButtonWidget>("back");
@ -71,10 +69,7 @@ void NetworkKartSelectionScreen::init()
void NetworkKartSelectionScreen::onUpdate(float dt) void NetworkKartSelectionScreen::onUpdate(float dt)
{ {
KartSelectionScreen::onUpdate(dt); KartSelectionScreen::onUpdate(dt);
auto lp = LobbyProtocol::get<LobbyProtocol>(); updateProgressBarText();
float new_value = lp->getRemainingVotingTime() / lp->getMaxVotingTime();
if(new_value < 0) new_value = 0;
m_timer->setValue(new_value*100.0f);
} // onUpdate } // onUpdate
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -124,3 +119,22 @@ bool NetworkKartSelectionScreen::onEscapePressed()
STKHost::get()->shutdown(); STKHost::get()->shutdown();
return true; // remove the screen return true; // remove the screen
} // onEscapePressed } // onEscapePressed
// ----------------------------------------------------------------------------
void NetworkKartSelectionScreen::updateProgressBarText()
{
if (auto lp = LobbyProtocol::get<LobbyProtocol>())
{
float new_value =
lp->getRemainingVotingTime() / lp->getMaxVotingTime();
if (new_value < 0.0f)
new_value = 0.0f;
m_timer->setValue(new_value * 100.0f);
int remaining_time = (int)(lp->getRemainingVotingTime());
if (remaining_time < 0)
remaining_time = 0;
//I18N: In kart screen, show before the voting period in network ends.
core::stringw message = _("Remaining time: %d", remaining_time);
m_timer->setText(message);
}
} // updateProgressBarText

View File

@ -53,6 +53,8 @@ private:
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
virtual bool isIgnored(const std::string& ident) const OVERRIDE virtual bool isIgnored(const std::string& ident) const OVERRIDE
{ return m_available_karts.find(ident) == m_available_karts.end(); } { return m_available_karts.find(ident) == m_available_karts.end(); }
// ------------------------------------------------------------------------
void updateProgressBarText();
public: public:
/** \brief Implement per-frame callback. */ /** \brief Implement per-frame callback. */

View File

@ -339,6 +339,9 @@ void TracksScreen::beforeAddingWidget()
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void TracksScreen::init() void TracksScreen::init()
{ {
if (m_network_tracks)
updateProgressBarText();
// change the back button image (because it makes the game quit) // change the back button image (because it makes the game quit)
if (m_quit_server) if (m_quit_server)
{ {
@ -643,14 +646,10 @@ void TracksScreen::voteForPlayer()
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void TracksScreen::onUpdate(float dt) void TracksScreen::onUpdate(float dt)
{ {
// The following code if (!m_network_tracks)
if(!m_network_tracks) return; return;
auto lp = LobbyProtocol::get<LobbyProtocol>();
float new_value = lp->getRemainingVotingTime() / lp->getMaxVotingTime();
if (new_value < 0) new_value = 0;
m_timer->setValue(new_value * 100.0f);
updateProgressBarText();
} // onUpdate } // onUpdate
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -839,3 +838,22 @@ void TracksScreen::updatePlayerVotes()
} }
} }
} // updatePlayerVotes } // updatePlayerVotes
// ----------------------------------------------------------------------------
void TracksScreen::updateProgressBarText()
{
if (auto lp = LobbyProtocol::get<LobbyProtocol>())
{
float new_value =
lp->getRemainingVotingTime() / lp->getMaxVotingTime();
if (new_value < 0.0f)
new_value = 0.0f;
m_timer->setValue(new_value * 100.0f);
int remaining_time = (int)(lp->getRemainingVotingTime());
if (remaining_time < 0)
remaining_time = 0;
//I18N: In kart screen, show before the voting period in network ends.
core::stringw message = _("Remaining time: %d", remaining_time);
m_timer->setText(message);
}
} // updateProgressBarText

View File

@ -91,6 +91,8 @@ private:
m_bottom_box_height = -1; m_bottom_box_height = -1;
m_track_icons = NULL; m_track_icons = NULL;
} }
// ------------------------------------------------------------------------
void updateProgressBarText();
public: public: