From 08e8d22dcebf227ed1886b92b3d8066dac3f1173 Mon Sep 17 00:00:00 2001 From: auria Date: Fri, 22 Apr 2011 23:34:48 +0000 Subject: [PATCH] Better random for the random track button git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@8419 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/states_screens/tracks_screen.cpp | 20 ++++++++++++++++++-- src/states_screens/tracks_screen.hpp | 4 +++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/states_screens/tracks_screen.cpp b/src/states_screens/tracks_screen.cpp index 6cbd856e7..5e159cfb9 100644 --- a/src/states_screens/tracks_screen.cpp +++ b/src/states_screens/tracks_screen.cpp @@ -108,6 +108,9 @@ void TracksScreen::eventCallback(Widget* widget, const std::string& name, const RibbonWidget* tabs = this->getWidget("trackgroups"); assert( tabs != NULL ); + if (m_random_track_list.empty()) return; + + /* const std::vector& curr_group = track_manager->getTracksInGroup( tabs->getSelectionIDString(0) ); RandomGenerator random; @@ -123,6 +126,15 @@ void TracksScreen::eventCallback(Widget* widget, const std::string& name, const while (unlock_manager->isLocked( track_manager->getTrack(curr_group[randomID])->getIdent())); Track* clickedTrack = track_manager->getTrack( curr_group[randomID] ); + */ + + + std::string track = m_random_track_list.front(); + m_random_track_list.pop_front(); + m_random_track_list.push_back(track); + Track* clickedTrack = track_manager->getTrack( track ); + + if (clickedTrack != NULL) { ITexture* screenshot = irr_driver->getTexture( clickedTrack->getScreenshotFile().c_str() ); @@ -243,7 +255,7 @@ void TracksScreen::init() gps_widget->updateItemDisplay(); buildTrackList(); - + // select something for the game master // FIXME: 'setSelection' will not scroll up to the passed track, so if given track is not visible // with current scrolling this fails @@ -265,6 +277,7 @@ void TracksScreen::buildTrackList() // Reset track list everytime (accounts for locking changes, etc.) tracks_widget->clearItems(); + m_random_track_list.clear(); const std::string curr_group_name = tabs->getSelectionIDString(0); @@ -288,6 +301,7 @@ void TracksScreen::buildTrackList() { tracks_widget->addItem(translations->fribidize(curr->getName()), curr->getIdent(), curr->getScreenshotFile(), 0, IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE ); + m_random_track_list.push_back(curr->getIdent()); } } @@ -313,6 +327,7 @@ void TracksScreen::buildTrackList() tracks_widget->addItem(translations->fribidize(curr->getName()), curr->getIdent(), curr->getScreenshotFile(), 0 /* no badge */, IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE ); + m_random_track_list.push_back(curr->getIdent()); } } } @@ -320,7 +335,8 @@ void TracksScreen::buildTrackList() tracks_widget->addItem(_("Random Track"), "random_track", "/gui/track_random.png", 0 /* no badge */, IconButtonWidget::ICON_PATH_TYPE_RELATIVE); - tracks_widget->updateItemDisplay(); + tracks_widget->updateItemDisplay(); + std::random_shuffle( m_random_track_list.begin(), m_random_track_list.end() ); } // ----------------------------------------------------------------------------------------------- diff --git a/src/states_screens/tracks_screen.hpp b/src/states_screens/tracks_screen.hpp index 50e4e36d6..2d351dab2 100644 --- a/src/states_screens/tracks_screen.hpp +++ b/src/states_screens/tracks_screen.hpp @@ -19,7 +19,7 @@ #define HEADER_TRACKS_SCREEN_HPP #include "guiengine/screen.hpp" - +#include namespace GUIEngine { class Widget; } @@ -36,6 +36,8 @@ class TracksScreen : public GUIEngine::Screen, public GUIEngine::ScreenSingleton /** adds the tracks from the current track group into the tracks ribbon */ void buildTrackList(); + std::deque m_random_track_list; + public: /** \brief implement callback from parent class GUIEngine::Screen */