Add track searching to network track screen

This commit is contained in:
Benau 2021-11-14 16:11:21 +08:00
parent c26b3c989b
commit dfd1912c33
3 changed files with 29 additions and 2 deletions

View File

@ -36,11 +36,13 @@
</box> </box>
</div> </div>
<div id="vote" x="63%" y="1%" width="36%" height="88%" layout="vertical-row"> <div id="vote" x="63%" y="1%" width="36%" height="88%" layout="vertical-row">
<div width="100%" proportion="2" layout="horizontal-row"> <div width="100%" height="92%" layout="horizontal-row">
<box proportion="2" height="100%" layout="vertical-row"> <box proportion="2" height="100%" layout="vertical-row">
<list id="vote-list" width="100%" height="100%" word_wrap="true"/> <list id="vote-list" width="100%" height="100%" word_wrap="true"/>
</box> </box>
</div> </div>
<spacer height="1%"/>
<textbox id="search_track" width="100%" height="fit"/>
</div> </div>
<progressbar x="2%" y="93%" id="timer" height="1f" width="96%"></progressbar> <progressbar x="2%" y="93%" id="timer" height="1f" width="96%"></progressbar>
</stkgui> </stkgui>

View File

@ -219,6 +219,7 @@ void TracksScreen::beforeAddingWidget()
Screen::init(); Screen::init();
m_selected_track = NULL; m_selected_track = NULL;
m_search_track = NULL;
m_timer = getWidget<GUIEngine::ProgressBarWidget>("timer"); m_timer = getWidget<GUIEngine::ProgressBarWidget>("timer");
m_timer->showLabel(false); m_timer->showLabel(false);
@ -367,7 +368,14 @@ void TracksScreen::beforeAddingWidget()
void TracksScreen::init() void TracksScreen::init()
{ {
if (m_network_tracks) if (m_network_tracks)
{
m_search_track = getWidget<TextBoxWidget>("search_track");
m_search_track->setText(L"");
// Add listener for incremental update when search text is changed
m_search_track->clearListeners();
m_search_track->addListener(this);
updateProgressBarText(); updateProgressBarText();
}
// change the back button image (because it makes the game quit) // change the back button image (because it makes the game quit)
if (m_quit_server) if (m_quit_server)
@ -563,6 +571,15 @@ void TracksScreen::buildTrackList()
for (int n = 0; n < track_amount; n++) for (int n = 0; n < track_amount; n++)
{ {
Track* curr = track_manager->getTrack(n); Track* curr = track_manager->getTrack(n);
core::stringw search_text;
if (m_search_track)
{
search_text = m_search_track->getText();
search_text.make_lower();
}
if (!search_text.empty() &&
curr->getName().make_lower().find(search_text.c_str()) == -1)
continue;
if (RaceManager::get()->getMinorMode() == RaceManager::MINOR_MODE_EASTER_EGG if (RaceManager::get()->getMinorMode() == RaceManager::MINOR_MODE_EASTER_EGG
&& !curr->hasEasterEggs()) && !curr->hasEasterEggs())
continue; continue;

View File

@ -19,6 +19,7 @@
#define HEADER_TRACKS_SCREEN_HPP #define HEADER_TRACKS_SCREEN_HPP
#include "guiengine/screen.hpp" #include "guiengine/screen.hpp"
#include "guiengine/widgets/text_box_widget.hpp"
#include <deque> #include <deque>
#include <limits> #include <limits>
@ -50,7 +51,8 @@ namespace irr
* \ingroup states_screens * \ingroup states_screens
*/ */
class TracksScreen : public GUIEngine::Screen, class TracksScreen : public GUIEngine::Screen,
public GUIEngine::ScreenSingleton<TracksScreen> public GUIEngine::ScreenSingleton<TracksScreen>,
public GUIEngine::ITextBoxWidgetListener
{ {
friend class GUIEngine::ScreenSingleton<TracksScreen>; friend class GUIEngine::ScreenSingleton<TracksScreen>;
@ -60,6 +62,7 @@ private:
GUIEngine::CheckBoxWidget* m_reversed; GUIEngine::CheckBoxWidget* m_reversed;
GUIEngine::SpinnerWidget* m_laps; GUIEngine::SpinnerWidget* m_laps;
GUIEngine::ListWidget* m_vote_list; GUIEngine::ListWidget* m_vote_list;
GUIEngine::TextBoxWidget* m_search_track;
/** Pointer to progress bar widget which is used as a timer /** Pointer to progress bar widget which is used as a timer
* (going backwards). */ * (going backwards). */
@ -147,6 +150,11 @@ public:
} }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
void updatePlayerVotes(); void updatePlayerVotes();
// ------------------------------------------------------------------------
virtual void onTextUpdated() OVERRIDE
{
eventCallback(m_search_track, "trackgroups", 0);
}
}; };
#endif #endif