11#include " cbase.h"
2+
3+ #include " asw_util_shared.h"
24#include " rd_challenge_selection.h"
35#include " rd_challenges_shared.h"
46#include < vgui_controls/ImagePanel.h>
57#include < vgui/ILocalize.h>
68#include < vgui/ISurface.h>
79#include " nb_header_footer.h"
810#include " nb_button.h"
11+ #include " strtools.h"
912#include " vfooterpanel.h"
1013#include " rd_workshop.h"
1114#include " filesystem.h"
1417// memdbgon must be the last include file in a .cpp file!!!
1518#include " tier0/memdbgon.h"
1619
20+ bool NameHasSearch ( const char *szTitle, const char *szSearch )
21+ {
22+ if ( szSearch[0 ] == ' \0 ' )
23+ {
24+ return true ;
25+ }
26+
27+ if ( szTitle[0 ] == ' #' )
28+ {
29+ wchar_t wszLocalized[RD_CHALLENGE_TITLE_LEN ];
30+ char szLocalized[RD_CHALLENGE_TITLE_LEN ];
31+
32+ TryLocalize ( szTitle, wszLocalized, RD_CHALLENGE_TITLE_LEN );
33+ V_UnicodeToUTF8 ( wszLocalized, szLocalized, RD_CHALLENGE_TITLE_LEN );
34+
35+ return Q_stristr ( szLocalized, szSearch ) != NULL ;
36+ }
37+
38+ return Q_stristr ( szTitle, szSearch ) != NULL ;
39+ }
40+
41+ BaseModUI::ReactiveDropChallengeSelectionSearch::ReactiveDropChallengeSelectionSearch ( vgui::Panel *parent, const char *panelName, ReactiveDropChallengeSelection *pSelection ) : BaseClass( parent, panelName )
42+ {
43+ SetMaximumCharCount ( RD_CHALLENGE_TITLE_LEN );
44+ m_pSelection = pSelection;
45+ }
46+
47+ void BaseModUI::ReactiveDropChallengeSelectionSearch::OnKeyTyped ( wchar_t unichar )
48+ {
49+ const int nBefore = GetTextLength ();
50+ BaseClass::OnKeyTyped ( unichar );
51+ const int nAfter = GetTextLength ();
52+
53+ char szSearchText[RD_CHALLENGE_TITLE_LEN ];
54+ GetText ( szSearchText, RD_CHALLENGE_TITLE_LEN );
55+
56+ const bool bIncrSearch = nBefore != 0 && nAfter > nBefore;
57+
58+ m_pSelection->PopulateChallenges ( szSearchText, bIncrSearch );
59+ }
60+
1761BaseModUI::ReactiveDropChallengeSelectionListItem::ReactiveDropChallengeSelectionListItem ( vgui::Panel *parent, const char *panelName ) : BaseClass( parent, panelName )
1862{
1963 SetProportional ( true );
@@ -219,6 +263,13 @@ const CReactiveDropWorkshop::WorkshopItem_t &BaseModUI::ReactiveDropChallengeSel
219263BaseModUI::ReactiveDropChallengeSelection::ReactiveDropChallengeSelection ( vgui::Panel *parent, const char *panelName, bool bDeathmatch ) : BaseClass( parent, panelName )
220264{
221265 SetProportional ( true );
266+ SetMouseInputEnabled ( true );
267+ SetKeyBoardInputEnabled ( true );
268+
269+ if ( engine->IsConnected () )
270+ {
271+ MakePopup ( false );
272+ }
222273
223274 m_pHeaderFooter = new CNB_Header_Footer ( this , " HeaderFooter" );
224275 m_pHeaderFooter->SetTitle ( " " );
@@ -237,6 +288,8 @@ BaseModUI::ReactiveDropChallengeSelection::ReactiveDropChallengeSelection( vgui:
237288 m_lblDescription = new vgui::Label ( this , " LblDescription" , " " );
238289 m_lblAuthor = new vgui::Label ( this , " LblAuthor" , " " );
239290
291+ m_pTxtSearch = new ReactiveDropChallengeSelectionSearch ( this , " TxtSearch" , this );
292+
240293 m_bIgnoreSelectionChange = false ;
241294
242295 m_bDeathmatch = bDeathmatch;
@@ -309,7 +362,7 @@ void BaseModUI::ReactiveDropChallengeSelection::OnMessage( const KeyValues *para
309362 }
310363}
311364
312- void BaseModUI::ReactiveDropChallengeSelection::PopulateChallenges ()
365+ void BaseModUI::ReactiveDropChallengeSelection::PopulateChallenges ( const char * szSearch, bool bIncrSearch )
313366{
314367 m_gplChallenges->RemoveAllPanelItems ();
315368 ReactiveDropChallengeSelectionListItem *pDisabled = m_gplChallenges->AddPanelItem <ReactiveDropChallengeSelectionListItem>( " ReactiveDropChallengeSelectionListItem" );
@@ -319,16 +372,55 @@ void BaseModUI::ReactiveDropChallengeSelection::PopulateChallenges()
319372 Assert ( g_ReactiveDropWorkshop.m_bStartingUp == false );
320373 g_ReactiveDropWorkshop.m_bStartingUp = true ;
321374
322- int iCount = ReactiveDropChallenges::Count ();
323- for ( int i = 0 ; i < iCount; i++ )
375+ const char * szChallenges[RD_MAX_CHALLENGES ];
376+ int nChallenges = 0 ;
377+
378+ // Find valid challenges
379+ if ( bIncrSearch )
324380 {
325- const RD_Challenge_t *pChallenge = ReactiveDropChallenges::GetSummary ( i );
326- if ( m_bDeathmatch ? pChallenge->AllowDeathmatch : pChallenge->AllowCoop )
381+ for ( int i = 0 ; i < m_nChallengesPrev; i++ )
327382 {
328- ReactiveDropChallengeSelectionListItem *pItem = m_gplChallenges->AddPanelItem <ReactiveDropChallengeSelectionListItem>( " ReactiveDropChallengeSelectionListItem" );
329- pItem->PopulateChallenge ( ReactiveDropChallenges::Name ( i ) );
330- GetControllerFocus ()->AddToFocusList ( pItem, true , true );
383+ const char *pChallengeName = m_szChallengesPrev[i];
384+ const char *szTitle = ReactiveDropChallenges::DisplayName (pChallengeName);
385+
386+ if ( NameHasSearch (szTitle, szSearch) )
387+ {
388+ szChallenges[nChallenges] = pChallengeName;
389+ m_szChallengesPrev[nChallenges] = pChallengeName;
390+ nChallenges++;
391+ }
331392 }
393+ m_nChallengesPrev = nChallenges;
394+ }
395+ else
396+ {
397+ const int nRDChallenges = ReactiveDropChallenges::Count ();
398+ Assert ( nRDChallenges <= RD_MAX_CHALLENGES );
399+ for ( int i = 0 ; i < nRDChallenges; i++ )
400+ {
401+ const RD_Challenge_t *pChallenge = ReactiveDropChallenges::GetSummary ( i );
402+ if ( m_bDeathmatch ? pChallenge->AllowDeathmatch : pChallenge->AllowCoop )
403+ {
404+ const char *pChallengeName = ReactiveDropChallenges::Name ( i );
405+ const char *szTitle = pChallenge->Title ;
406+
407+ if ( !szSearch || NameHasSearch (szTitle, szSearch) )
408+ {
409+ szChallenges[nChallenges] = pChallengeName;
410+ m_szChallengesPrev[nChallenges] = pChallengeName;
411+ nChallenges++;
412+ }
413+ }
414+ }
415+ m_nChallengesPrev = nChallenges;
416+ }
417+
418+ // Add valid challenges to the panel list
419+ for ( int j = 0 ; j < nChallenges; j++ )
420+ {
421+ ReactiveDropChallengeSelectionListItem *pItem = m_gplChallenges->AddPanelItem <ReactiveDropChallengeSelectionListItem>( " ReactiveDropChallengeSelectionListItem" );
422+ pItem->PopulateChallenge ( szChallenges[j] );
423+ GetControllerFocus ()->AddToFocusList ( pItem, true , true );
332424 }
333425
334426 g_ReactiveDropWorkshop.m_bStartingUp = false ;
0 commit comments