Added progress bar (showing remaining time) to kart selection screen.
This commit is contained in:
29
data/gui/screens/online/network_karts.stkgui
Executable file
29
data/gui/screens/online/network_karts.stkgui
Executable file
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<stkgui>
|
||||
<div x="1%" y="1%" width="98%" height="99%" layout="vertical-row" >
|
||||
|
||||
<header width="80%"
|
||||
I18N="In the kart selection (player setup) screen"
|
||||
text="Choose a Kart"
|
||||
align="center" text_align="center" />
|
||||
|
||||
<placeholder id="playerskarts" width="100%" align="center" proportion="5">
|
||||
<!-- Contents is added programatically -->
|
||||
</placeholder>
|
||||
|
||||
<spacer height="15" width="25"/>
|
||||
|
||||
<box proportion="2" width="100%" layout="vertical-row" padding="2">
|
||||
<ribbon_grid id="karts" proportion="1" square_items="true" width="100%" align="center"
|
||||
child_width="90" child_height="90" max_rows="3"/>
|
||||
</box>
|
||||
|
||||
<!-- Groups will be added dynamically at runtime -->
|
||||
<tabs width="98%" x="1%" height="5%" id="kartgroups">
|
||||
</tabs>
|
||||
<spacer width="100%" height="2%"/>
|
||||
<progressbar id="timer" height="4%" width="100%"></progressbar>
|
||||
</div>
|
||||
|
||||
<icon-button id="back" x="0" y="0" height="8%" icon="gui/icons/back.png"/>
|
||||
</stkgui>
|
||||
@@ -67,8 +67,13 @@ namespace GUIEngine
|
||||
|
||||
void add();
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
/** Get the current value of the widget. */
|
||||
int getValue() {return m_value; };
|
||||
// --------------------------------------------------------------------
|
||||
/** Sets if the current fraction is shown as a percentage value
|
||||
* in the progress bar. */
|
||||
void showLabel(bool show_label) { m_show_label = show_label; }
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@@ -155,10 +155,10 @@ void LobbyProtocol::startVotingPeriod(float max_time)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Returns the remaining voting time in seconds. */
|
||||
int LobbyProtocol::getRemainingVotingTime()
|
||||
float LobbyProtocol::getRemainingVotingTime()
|
||||
{
|
||||
uint64_t t = m_end_voting_period.load()- StkTime::getRealTimeMs();
|
||||
return int(t/1000);
|
||||
return t/1000.0f;
|
||||
} // getRemainingVotingTime
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
@@ -135,10 +135,11 @@ public:
|
||||
virtual bool allPlayersReady() const = 0;
|
||||
virtual bool isRacing() const = 0;
|
||||
void startVotingPeriod(float max_time);
|
||||
int getRemainingVotingTime();
|
||||
float getRemainingVotingTime();
|
||||
bool isVotingOver();
|
||||
// ------------------------------------------------------------------------
|
||||
float getMaxVotingTime() { return m_max_voting_time * 1000.0f; }
|
||||
/** Returns the maximum floating time in seconds. */
|
||||
float getMaxVotingTime() { return m_max_voting_time / 1000.0f; }
|
||||
// ------------------------------------------------------------------------
|
||||
GameSetup* getGameSetup() const { return m_game_setup; }
|
||||
|
||||
|
||||
20
src/states_screens/online/network_kart_selection.cpp
Normal file → Executable file
20
src/states_screens/online/network_kart_selection.cpp
Normal file → Executable file
@@ -18,6 +18,7 @@
|
||||
#include "states_screens/online/network_kart_selection.hpp"
|
||||
|
||||
#include "config/user_config.hpp"
|
||||
#include "guiengine/widgets/progress_bar_widget.hpp"
|
||||
#include "input/device_manager.hpp"
|
||||
#include "network/network_config.hpp"
|
||||
#include "network/protocols/lobby_protocol.hpp"
|
||||
@@ -34,6 +35,12 @@ void NetworkKartSelectionScreen::init()
|
||||
m_multiplayer = NetworkConfig::get()->getNetworkPlayers().size() != 1;
|
||||
KartSelectionScreen::init();
|
||||
|
||||
m_timer = getWidget<GUIEngine::ProgressBarWidget>("timer");
|
||||
m_timer->showLabel(false);
|
||||
// I18N: Time in seconds (before the voting period in network ends).
|
||||
// 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)
|
||||
IconButtonWidget* back_button = getWidget<IconButtonWidget>("back");
|
||||
back_button->setImage("gui/icons/main_quit.png");
|
||||
@@ -57,6 +64,19 @@ void NetworkKartSelectionScreen::init()
|
||||
}
|
||||
} // init
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Called once per frame. Updates the timer display.
|
||||
* \param dt Time step size.
|
||||
*/
|
||||
void NetworkKartSelectionScreen::onUpdate(float dt)
|
||||
{
|
||||
KartSelectionScreen::onUpdate(dt);
|
||||
auto lp = LobbyProtocol::get<LobbyProtocol>();
|
||||
float new_value = lp->getRemainingVotingTime() / lp->getMaxVotingTime();
|
||||
if(new_value < 0) new_value = 0;
|
||||
m_timer->moveValue(int(new_value*100));
|
||||
} // onUpdate
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void NetworkKartSelectionScreen::allPlayersDone()
|
||||
{
|
||||
|
||||
@@ -21,16 +21,27 @@
|
||||
#include "states_screens/kart_selection.hpp"
|
||||
#include "guiengine/screen.hpp"
|
||||
|
||||
namespace GUIEngine
|
||||
{
|
||||
class ProgressBarWidget;
|
||||
}
|
||||
|
||||
#include <set>
|
||||
|
||||
class NetworkKartSelectionScreen : public KartSelectionScreen,
|
||||
public GUIEngine::ScreenSingleton<NetworkKartSelectionScreen>
|
||||
{
|
||||
private:
|
||||
/** Pointer to progress bar widget which is used as a timer
|
||||
* (going backwards). */
|
||||
GUIEngine::ProgressBarWidget *m_timer;
|
||||
|
||||
friend class GUIEngine::ScreenSingleton<NetworkKartSelectionScreen>;
|
||||
|
||||
protected:
|
||||
// ------------------------------------------------------------------------
|
||||
NetworkKartSelectionScreen() : KartSelectionScreen("karts.stkgui") {}
|
||||
NetworkKartSelectionScreen()
|
||||
: KartSelectionScreen("online/network_karts.stkgui") {}
|
||||
// ------------------------------------------------------------------------
|
||||
~NetworkKartSelectionScreen() {}
|
||||
// ------------------------------------------------------------------------
|
||||
@@ -44,6 +55,9 @@ private:
|
||||
{ return m_available_karts.find(ident) == m_available_karts.end(); }
|
||||
|
||||
public:
|
||||
/** \brief Implement per-frame callback. */
|
||||
virtual void onUpdate(float dt) OVERRIDE;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
void setAvailableKartsFromServer(const std::set<std::string>& k)
|
||||
{ m_available_karts = k; }
|
||||
|
||||
Reference in New Issue
Block a user