From 8f6a5295310db0737b6f4945d207cc68e074a178 Mon Sep 17 00:00:00 2001 From: Benau Date: Thu, 10 Dec 2015 15:49:47 +0800 Subject: [PATCH] Complete fix to arena selection menu (handle random arenas) --- src/states_screens/arenas_screen.cpp | 30 ++++++++++++++++++++++------ src/states_screens/arenas_screen.hpp | 3 +++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/states_screens/arenas_screen.cpp b/src/states_screens/arenas_screen.cpp index fbaacbead..227128040 100644 --- a/src/states_screens/arenas_screen.cpp +++ b/src/states_screens/arenas_screen.cpp @@ -116,6 +116,7 @@ void ArenasScreen::beforeAddingWidget() void ArenasScreen::init() { + m_unsupported_arena.clear(); Screen::init(); buildTrackList(); DynamicRibbonWidget* w = this->getWidget("tracks"); @@ -161,6 +162,16 @@ void ArenasScreen::eventCallback(Widget* widget, const std::string& name, const curr_group = track_manager->getArenasInGroup( tabs->getSelectionIDString(PLAYER_ID_GAME_MASTER), soccer_mode ); } + // Remove unsupported arena + if (m_unsupported_arena.size() > 0) + { + for (std::set::iterator it = m_unsupported_arena.begin(); + it != m_unsupported_arena.end(); ++it) + { + curr_group.erase(std::remove(curr_group.begin(), + curr_group.end(), *it), curr_group.end()); + } + } RandomGenerator random; const int randomID = random.get((int)curr_group.size()); @@ -218,7 +229,6 @@ void ArenasScreen::buildTrackList() bool soccer_mode = race_manager->getMinorMode() == RaceManager::MINOR_MODE_SOCCER; bool arenas_have_navmesh = false; - int skipped = 0; if (curr_group_name == ALL_ARENA_GROUPS_ID) { @@ -240,7 +250,11 @@ void ArenasScreen::buildTrackList() (!(curr->hasNavMesh() || race_manager->getNumLocalPlayers() > 1 || UserConfigParams::m_artist_debug_mode))) + { + if (curr->isArena()) + m_unsupported_arena.insert(n); continue; + } } if (PlayerManager::getCurrentPlayer()->isLocked(curr->getIdent())) @@ -278,7 +292,8 @@ void ArenasScreen::buildTrackList() race_manager->getNumLocalPlayers() > 1 || UserConfigParams::m_artist_debug_mode))) { - skipped++; + if (curr->isArena()) + m_unsupported_arena.insert(currArenas[n]); continue; } } @@ -295,13 +310,15 @@ void ArenasScreen::buildTrackList() } } } - if ((arenas_have_navmesh || race_manager->getNumLocalPlayers() > 1 || - UserConfigParams::m_artist_debug_mode) && !skipped) + if (arenas_have_navmesh || race_manager->getNumLocalPlayers() > 1 || + UserConfigParams::m_artist_debug_mode) w->addItem(_("Random Arena"), "random_track", "/gui/track_random.png"); w->updateItemDisplay(); - if (skipped > 0) - w->setText( _("%i arenas unavailable in single player", skipped) ); + if (m_unsupported_arena.size() > 0) + w->setText( _P("%d arena unavailable in single player.", + "%d arenas unavailable in single player.", + m_unsupported_arena.size()) ); } // ------------------------------------------------------------------------------------------------------ @@ -312,6 +329,7 @@ void ArenasScreen::setFocusOnTrack(const std::string& trackName) assert( w != NULL ); w->setSelection(trackName, PLAYER_ID_GAME_MASTER, true); + } // setFOxuOnTrack // ------------------------------------------------------------------------------------------------------ diff --git a/src/states_screens/arenas_screen.hpp b/src/states_screens/arenas_screen.hpp index 097e3c3e1..6f603e768 100644 --- a/src/states_screens/arenas_screen.hpp +++ b/src/states_screens/arenas_screen.hpp @@ -34,6 +34,9 @@ class ArenasScreen : public GUIEngine::Screen, public GUIEngine::ScreenSingleton ArenasScreen(); void buildTrackList(); +private: + std::set m_unsupported_arena; + public: /** \brief implement callback from parent class GUIEngine::Screen */