diff --git a/data/gui/screens/edit_track.stkgui b/data/gui/screens/edit_track.stkgui index 3845dc3da8..f0180d5ff9 100644 --- a/data/gui/screens/edit_track.stkgui +++ b/data/gui/screens/edit_track.stkgui @@ -2,11 +2,15 @@
-
+
+
+ + +
- + diff --git a/src/states_screens/edit_track_screen.cpp b/src/states_screens/edit_track_screen.cpp index ec2ff89192..356bdc7793 100644 --- a/src/states_screens/edit_track_screen.cpp +++ b/src/states_screens/edit_track_screen.cpp @@ -17,8 +17,8 @@ #include "states_screens/edit_track_screen.hpp" +#include "config/player_manager.hpp" #include "graphics/stk_tex_manager.hpp" - #include "guiengine/widgets/button_widget.hpp" #include "guiengine/widgets/check_box_widget.hpp" #include "guiengine/widgets/dynamic_ribbon_widget.hpp" @@ -92,6 +92,8 @@ void EditTrackScreen::loadedFromFile() DynamicRibbonWidget* tracks_widget = getWidget("tracks"); assert(tracks_widget != NULL); tracks_widget->setMaxLabelLength(MAX_LABEL_LENGTH); + // Avoid too many items shown at the same time + tracks_widget->setItemCountHint(std::min((int)track_manager->getNumberOfTracks()+1, 30)); m_screenshot = getWidget("screenshot"); m_screenshot->setFocusable(false); @@ -101,6 +103,9 @@ void EditTrackScreen::loadedFromFile() // ----------------------------------------------------------------------------- void EditTrackScreen::beforeAddingWidget() { + track_manager->setFavoriteTrackStatus( + PlayerManager::getCurrentPlayer()->getFavoriteTrackStatus()); + RibbonWidget* tabs = getWidget("trackgroups"); assert (tabs != NULL); @@ -118,6 +123,11 @@ void EditTrackScreen::beforeAddingWidget() // ----------------------------------------------------------------------------- void EditTrackScreen::init() { + m_search_box = getWidget("search"); + assert(m_search_box != NULL); + m_search_box->clearListeners(); + m_search_box->addListener(this); + RibbonWidget* tabs = getWidget("trackgroups"); assert (tabs != NULL); SpinnerWidget* laps = getWidget("laps"); @@ -183,24 +193,75 @@ void EditTrackScreen::eventCallback(GUIEngine::Widget* widget, const std::string // ----------------------------------------------------------------------------- void EditTrackScreen::loadTrackList() { + track_manager->setFavoriteTrackStatus( + PlayerManager::getCurrentPlayer()->getFavoriteTrackStatus()); + DynamicRibbonWidget* tracks_widget = getWidget("tracks"); assert(tracks_widget != NULL); tracks_widget->clearItems(); - for (unsigned int i = 0; i < track_manager->getNumberOfTracks(); i++) + // First build a list of all tracks to be displayed + // (e.g. exclude arenas, ...) + PtrVector tracks; + + if (m_track_group == ALL_TRACKS_GROUP_ID) + { + const int track_amount = (int)track_manager->getNumberOfTracks(); + for (int n = 0; n < track_amount; n++) + { + Track* curr = track_manager->getTrack(n); + if (curr->isArena() || curr->isSoccer() || curr->isInternal()) continue; + if (RaceManager::get()->getMinorMode() == RaceManager::MINOR_MODE_EASTER_EGG + && !curr->hasEasterEggs()) + continue; + core::stringw search_text = m_search_box->getText(); + search_text.make_lower(); + if (!search_text.empty() && + curr->getName().make_lower().find(search_text.c_str()) == -1) + continue; + + tracks.push_back(curr); + } // for n& curr_tracks = track_manager->getTracksInGroup(m_track_group); + const int track_amount = (int)curr_tracks.size(); + + for (int n = 0; n < track_amount; n++) + { + Track* curr = track_manager->getTrack(curr_tracks[n]); + if (curr->isArena() || curr->isSoccer() || curr->isInternal()) continue; + if (RaceManager::get()->getMinorMode() == RaceManager::MINOR_MODE_EASTER_EGG + && !curr->hasEasterEggs()) + continue; + core::stringw search_text = m_search_box->getText(); + search_text.make_lower(); + if (!search_text.empty() && + curr->getName().make_lower().find(search_text.c_str()) == -1) + continue; + + tracks.push_back(curr); + } // for ngetTrack(i); - bool belongs_to_group = (m_track_group.empty() || - m_track_group == ALL_TRACKS_GROUP_ID || - t->isInGroup(m_track_group) ); - if (!t->isArena() && !t->isSoccer() && - !t->isInternal() && belongs_to_group ) + Track *curr = tracks.get(i); + if (PlayerManager::getCurrentPlayer()->isFavoriteTrack(curr->getIdent())) + { + tracks_widget->addItem(curr->getName(), curr->getIdent(), + curr->getScreenshotFile(), HEART_BADGE, + IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE); + } + else { - tracks_widget->addItem(t->getName(), - t->getIdent(), - t->getScreenshotFile(), 0, - IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE); + tracks_widget->addItem(curr->getName(), curr->getIdent(), + curr->getScreenshotFile(), 0, + IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE); } } diff --git a/src/states_screens/edit_track_screen.hpp b/src/states_screens/edit_track_screen.hpp index c23ad30e2b..275a5bdea5 100644 --- a/src/states_screens/edit_track_screen.hpp +++ b/src/states_screens/edit_track_screen.hpp @@ -19,6 +19,7 @@ #define HEADER_EDIT_TRACK_SCREEN_HPP #include "guiengine/screen.hpp" +#include "guiengine/widgets/text_box_widget.hpp" namespace GUIEngine { class IconButtonWidget; class Widget; } @@ -32,7 +33,8 @@ class Track; */ class EditTrackScreen : public GUIEngine::Screen, - public GUIEngine::ScreenSingleton + public GUIEngine::ScreenSingleton, + public GUIEngine::ITextBoxWidgetListener { friend class GUIEngine::ScreenSingleton; @@ -51,6 +53,8 @@ class EditTrackScreen : bool m_result; GUIEngine::IconButtonWidget* m_screenshot; + + GUIEngine::TextBoxWidget *m_search_box; public: @@ -74,6 +78,15 @@ class EditTrackScreen : /** \brief implement callback from parent class GUIEngine::Screen */ virtual void init() OVERRIDE; + + /** Rebuild the list of tracks based on search text */ + virtual void onTextUpdated() OVERRIDE + { + loadTrackList(); + // After buildTrackList the m_search_box may be unfocused + m_search_box->focused(0); + } + }; #endif