From 5ff7db155d9476a4a5464f6eacbc16864aa9214a Mon Sep 17 00:00:00 2001 From: Benau Date: Sat, 20 Oct 2018 16:22:51 +0800 Subject: [PATCH] Fix broken network kart selection screen if no addon karts available --- src/states_screens/kart_selection.cpp | 34 ++++++++++++++++++++------- src/states_screens/kart_selection.hpp | 3 +++ 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/states_screens/kart_selection.cpp b/src/states_screens/kart_selection.cpp index ad5b088c4..37a1b6dd6 100644 --- a/src/states_screens/kart_selection.cpp +++ b/src/states_screens/kart_selection.cpp @@ -1459,6 +1459,24 @@ void KartSelectionScreen::renumberKarts() w->updateItemDisplay(); } // renumberKarts +// ---------------------------------------------------------------------------- +PtrVector KartSelectionScreen::getUsableKarts( + const std::string& selected_kart_group) +{ + PtrVector karts; + for(unsigned int i=0; igetNumberOfKarts(); i++) + { + const KartProperties* prop = kart_properties_manager->getKartById(i); + // Ignore karts that are not in the selected group + if((selected_kart_group != ALL_KART_GROUPS_ID && + !prop->isInGroup(selected_kart_group)) || isIgnored(prop->getIdent())) + continue; + karts.push_back(prop); + } + karts.insertionSort(); + return karts; +} // getUsableKarts + // ---------------------------------------------------------------------------- void KartSelectionScreen::setKartsFromCurrentGroup() @@ -1484,18 +1502,16 @@ void KartSelectionScreen::setKartsFromCurrentGroup() w->clearItems(); int usable_kart_count = 0; - PtrVector karts; + PtrVector karts = getUsableKarts(selected_kart_group); - for(unsigned int i=0; igetNumberOfKarts(); i++) + if (karts.empty()) { - const KartProperties* prop = kart_properties_manager->getKartById(i); - // Ignore karts that are not in the selected group - if((selected_kart_group != ALL_KART_GROUPS_ID && - !prop->isInGroup(selected_kart_group)) || isIgnored(prop->getIdent())) - continue; - karts.push_back(prop); + // In network this will happen if no addons kart on server + PtrVector new_karts = + getUsableKarts(DEFAULT_GROUP_NAME); + std::swap(karts.m_contents_vector, new_karts.m_contents_vector); + tabs->select(DEFAULT_GROUP_NAME, PLAYER_ID_GAME_MASTER); } - karts.insertionSort(); for(unsigned int i=0; i getUsableKarts( + const std::string& selected_kart_group); public: /** Returns the current instance */ static KartSelectionScreen* getRunningInstance();