Make kart selection screen usable with live join

This commit is contained in:
Benau 2018-12-31 14:40:00 +08:00
parent 2ceeabf882
commit 5410a34f9e
3 changed files with 31 additions and 7 deletions

View File

@ -844,6 +844,7 @@ void ClientLobby::startSelection(Event* event)
NetworkKartSelectionScreen* screen =
NetworkKartSelectionScreen::getInstance();
screen->setAvailableKartsFromServer(m_available_karts);
screen->setLiveJoin(false);
// In case of auto-connect or continue a grand prix, use random karts
// (or previous kart) from server and go to track selection
if (NetworkConfig::get()->isAutoConnect() || skip_kart_screen)

View File

@ -37,7 +37,13 @@ void NetworkKartSelectionScreen::init()
m_timer = getWidget<GUIEngine::ProgressBarWidget>("timer");
m_timer->showLabel(false);
updateProgressBarText();
if (m_live_join)
m_timer->setVisible(false);
else
{
m_timer->setVisible(true);
updateProgressBarText();
}
// change the back button image (because it makes the game quit)
IconButtonWidget* back_button = getWidget<IconButtonWidget>("back");
@ -95,7 +101,14 @@ void NetworkKartSelectionScreen::allPlayersDone()
const uint8_t kart_count = (uint8_t)m_kart_widgets.size();
NetworkString kart(PROTOCOL_LOBBY_ROOM);
kart.addUInt8(LobbyProtocol::LE_KART_SELECTION).addUInt8(kart_count);
if (m_live_join)
{
kart.setSynchronous(true);
kart.addUInt8(LobbyProtocol::LE_LIVE_JOIN);
}
else
kart.addUInt8(LobbyProtocol::LE_KART_SELECTION);
kart.addUInt8(kart_count);
for (unsigned n = 0; n < kart_count; n++)
{
// If server recieve an invalid name, it will auto correct to a random
@ -106,9 +119,11 @@ void NetworkKartSelectionScreen::allPlayersDone()
// ---- Switch to assign mode
input_manager->getDeviceManager()->setAssignMode(ASSIGN);
TracksScreen::getInstance()->setNetworkTracks();
TracksScreen::getInstance()->push();
if (!m_live_join)
{
TracksScreen::getInstance()->setNetworkTracks();
TracksScreen::getInstance()->push();
}
} // allPlayersDone
// ----------------------------------------------------------------------------
@ -123,6 +138,8 @@ bool NetworkKartSelectionScreen::onEscapePressed()
// ----------------------------------------------------------------------------
void NetworkKartSelectionScreen::updateProgressBarText()
{
if (m_live_join)
return;
if (auto lp = LobbyProtocol::get<LobbyProtocol>())
{
float new_value =

View File

@ -38,10 +38,15 @@ private:
friend class GUIEngine::ScreenSingleton<NetworkKartSelectionScreen>;
bool m_live_join;
protected:
// ------------------------------------------------------------------------
NetworkKartSelectionScreen()
: KartSelectionScreen("online/network_karts.stkgui") {}
: KartSelectionScreen("online/network_karts.stkgui")
{
m_live_join = false;
}
// ------------------------------------------------------------------------
~NetworkKartSelectionScreen() {}
// ------------------------------------------------------------------------
@ -70,7 +75,8 @@ public:
// ------------------------------------------------------------------------
virtual bool playerQuit(StateManager::ActivePlayer* player) OVERRIDE
{ return true; }
// ------------------------------------------------------------------------
void setLiveJoin(bool val) { m_live_join = val; }
};
#endif // NETWORK_KART_SELECTION_HPP