Complete fix to arena selection menu (handle random arenas)

This commit is contained in:
Benau 2015-12-10 15:49:47 +08:00
parent cebefcf374
commit 8f6a529531
2 changed files with 27 additions and 6 deletions

View File

@ -116,6 +116,7 @@ void ArenasScreen::beforeAddingWidget()
void ArenasScreen::init()
{
m_unsupported_arena.clear();
Screen::init();
buildTrackList();
DynamicRibbonWidget* w = this->getWidget<DynamicRibbonWidget>("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<int>::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,8 +250,12 @@ 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
// ------------------------------------------------------------------------------------------------------

View File

@ -34,6 +34,9 @@ class ArenasScreen : public GUIEngine::Screen, public GUIEngine::ScreenSingleton
ArenasScreen();
void buildTrackList();
private:
std::set<int> m_unsupported_arena;
public:
/** \brief implement callback from parent class GUIEngine::Screen */