Allow track screen searching with name

This commit is contained in:
Benau 2020-07-10 22:12:45 +08:00
parent 04cd0208e2
commit 296b38ea51
3 changed files with 26 additions and 4 deletions

View File

@ -20,9 +20,12 @@
</box>
</div>
<header width="8%" I18N="In the track and grand prix selection screen" text="All Tracks"
align="center" text_align="center" />
<spacer width="100%" height="1%" />
<spacer width="100%" height="1%"/>
<div width="100%" proportion="1" layout="horizontal-row" >
<header width="30%" I18N="In the track and grand prix selection screen" text="All Tracks"
align="center" text_align="center" />
<textbox width="60%" id="search"/>
</div>
<box proportion="8" width="100%" layout="vertical-row" padding="1">
<ribbon_grid id="tracks" proportion="1" width="100%" square_items="true"

View File

@ -167,6 +167,10 @@ void TracksAndGPScreen::init()
DynamicRibbonWidget* tracks_widget = getWidget<DynamicRibbonWidget>("tracks");
assert(tracks_widget != NULL);
m_search_box = getWidget<TextBoxWidget>("search");
m_search_box->clearListeners();
m_search_box->addListener(this);
// Reset GP list everytime (accounts for locking changes, etc.)
gps_widget->clearItems();
gps_widget->setMaxLabelLength(30);
@ -255,6 +259,11 @@ void TracksAndGPScreen::buildTrackList()
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;
if (curr->isArena() || curr->isSoccer()||curr->isInternal()) continue;
if (curr_group_name != ALL_TRACK_GROUPS_ID &&
!curr->isInGroup(curr_group_name)) continue;

View File

@ -19,6 +19,7 @@
#define HEADER_TRACKS_AND_GP_SCREEN_HPP
#include "guiengine/screen.hpp"
#include "guiengine/widgets/text_box_widget.hpp"
#include <deque>
namespace GUIEngine { class Widget; }
@ -28,11 +29,13 @@ namespace GUIEngine { class Widget; }
* \ingroup states_screens
*/
class TracksAndGPScreen : public GUIEngine::Screen,
public GUIEngine::ScreenSingleton<TracksAndGPScreen>
public GUIEngine::ScreenSingleton<TracksAndGPScreen>,
public GUIEngine::ITextBoxWidgetListener
{
friend class GUIEngine::ScreenSingleton<TracksAndGPScreen>;
private:
GUIEngine::TextBoxWidget* m_search_box;
TracksAndGPScreen() : Screen("tracks_and_gp.stkgui") {}
@ -57,6 +60,13 @@ public:
/** \brief implement callback from parent class GUIEngine::Screen */
virtual void beforeAddingWidget() OVERRIDE;
/** Rebuild the list of tracks based on search text */
virtual void onTextUpdated() OVERRIDE
{
buildTrackList();
// After buildTrackList the m_search_box may be unfocused
m_search_box->focused(0);
}
void setFocusOnTrack(const std::string& trackName);
void setFocusOnGP(const std::string& gpName);