From 3b77b4dfde7070b045b240be3c51cbc332f6037c Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Fri, 28 Dec 2012 21:05:52 +0100 Subject: [PATCH] fixed search handling --- PartyModeChallenge/PartyModeChallenge.cs | 4 +-- Vocaluxe/Base/CSongs.cs | 12 +++++-- Vocaluxe/Screens/CScreenSong.cs | 46 ++++++++++++------------ VocaluxeLib/PartyModes/CPartyModeNone.cs | 8 +++-- VocaluxeLib/PartyModes/IPartyMode.cs | 2 +- 5 files changed, 41 insertions(+), 31 deletions(-) diff --git a/PartyModeChallenge/PartyModeChallenge.cs b/PartyModeChallenge/PartyModeChallenge.cs index af6f6f22..66c1ab61 100644 --- a/PartyModeChallenge/PartyModeChallenge.cs +++ b/PartyModeChallenge/PartyModeChallenge.cs @@ -152,7 +152,7 @@ namespace Vocaluxe.PartyModes _ScreenSongOptions.Selection.TeamNames = new string[] { "foo", "bar" }; _ScreenSongOptions.Sorting.SearchString = String.Empty; - _ScreenSongOptions.Sorting.SearchStringVisible = false; + _ScreenSongOptions.Sorting.SearchActive = false; _ScreenSongOptions.Sorting.ShowDuetSongs = false; _Stage = EStage.NotStarted; @@ -398,7 +398,7 @@ namespace Vocaluxe.PartyModes public override void SetSearchString(string SearchString, bool Visible) { _ScreenSongOptions.Sorting.SearchString = SearchString; - _ScreenSongOptions.Sorting.SearchStringVisible = Visible; + _ScreenSongOptions.Sorting.SearchActive = Visible; } public override int GetMaxPlayer() diff --git a/Vocaluxe/Base/CSongs.cs b/Vocaluxe/Base/CSongs.cs index 4c2ec4a0..a265098b 100644 --- a/Vocaluxe/Base/CSongs.cs +++ b/Vocaluxe/Base/CSongs.cs @@ -62,7 +62,7 @@ namespace Vocaluxe.Base get { return _SearchFilter; } set { - if (value.Length > 0) + if (value != String.Empty) { _Sort(_SongSorting, EOffOn.TR_CONFIG_OFF, _IgnoreArticles, value, false, _ShowDuetSongs); } @@ -406,7 +406,15 @@ namespace Vocaluxe.Base _SongList.Add(song); else { - if (song.Title.ToUpper().Contains(_SearchFilter.ToUpper()) || song.Artist.ToUpper().Contains(_SearchFilter.ToUpper())) + string search = song.Title.ToUpper() + " " + song.Artist.ToUpper() + " " + song.FolderName.ToUpper() + " " + song.FileName.ToUpper(); + string[] searchStrings = _SearchFilter.ToUpper().Split(new char[]{' '}); + bool contains = searchStrings != null; + + foreach (string str in searchStrings) + { + contains &= search.Contains(str); + } + if (contains) _SongList.Add(song); } } diff --git a/Vocaluxe/Screens/CScreenSong.cs b/Vocaluxe/Screens/CScreenSong.cs index 684ae0d2..c41843b4 100644 --- a/Vocaluxe/Screens/CScreenSong.cs +++ b/Vocaluxe/Screens/CScreenSong.cs @@ -659,7 +659,7 @@ namespace Vocaluxe.Screens _sso = CParty.GetSongSelectionOptions(); CSongs.Sort(_sso.Sorting.SongSorting, _sso.Sorting.Tabs, _sso.Sorting.IgnoreArticles, _sso.Sorting.SearchString, _sso.Sorting.ShowDuetSongs); - _SearchActive = _sso.Sorting.SearchStringVisible; + _SearchActive = _sso.Sorting.SearchActive; _SearchText = _sso.Sorting.SearchString; CGame.EnterNormalGame(); @@ -744,8 +744,6 @@ namespace Vocaluxe.Screens base.OnClose(); CBackgroundMusic.Disabled = false; SongMenus[htSongMenus(SongMenu)].OnHide(); - - CParty.SetSearchString(_SearchText, _SearchActive); } public override void ApplyVolume() @@ -794,7 +792,7 @@ namespace Vocaluxe.Screens if (_sso.Selection.PartyMode) { CSongs.Sort(_sso.Sorting.SongSorting, _sso.Sorting.Tabs, _sso.Sorting.IgnoreArticles, _sso.Sorting.SearchString, _sso.Sorting.ShowDuetSongs); - _SearchActive = _sso.Sorting.SearchStringVisible; + _SearchActive = _sso.Sorting.SearchActive; _SearchText = _sso.Sorting.SearchString; ClosePlaylist(); @@ -1078,31 +1076,31 @@ namespace Vocaluxe.Screens private void ApplyNewSearchFilter(string NewFilterString) { - int song = SongMenus[htSongMenus(SongMenu)].GetSelectedSong(); - int id = -1; - if (song > -1 && song < CSongs.NumVisibleSongs) - { - id = CSongs.VisibleSongs[song].ID; - } - + CParty.SetSearchString(NewFilterString, _SearchActive); + _sso = CParty.GetSongSelectionOptions(); + + bool refresh = false; _SearchText = NewFilterString; - CSongs.SearchFilter = _SearchText; - if (NewFilterString != String.Empty) - CSongs.Category = 0; - else - CSongs.Category = -1; - - if (id > -1) + int SongIndex = SongMenus[htSongMenus(SongMenu)].GetSelectedSong(); + int SongID = -1; + if (SongIndex != -1 && CSongs.NumVisibleSongs > 0 && CSongs.NumVisibleSongs > SongIndex) { - if (CSongs.NumVisibleSongs > 0) - { - if (id != CSongs.VisibleSongs[0].ID) - SongMenus[htSongMenus(SongMenu)].OnHide(); - } + SongID = CSongs.VisibleSongs[SongIndex].ID; } - if (CSongs.NumVisibleSongs == 0) + if (NewFilterString == String.Empty && _sso.Sorting.Tabs == EOffOn.TR_CONFIG_ON) + { + CSongs.Category = -1; + refresh = true; + } + + CSongs.Sort(_sso.Sorting.SongSorting, _sso.Sorting.Tabs, _sso.Sorting.IgnoreArticles, NewFilterString, _sso.Sorting.ShowDuetSongs); + + if (SongID == -1 || CSongs.NumVisibleSongs == 0 || CSongs.NumVisibleSongs <= SongIndex || CSongs.VisibleSongs[SongIndex].ID != SongID) + refresh = true; + + if (refresh) SongMenus[htSongMenus(SongMenu)].OnHide(); SongMenus[htSongMenus(SongMenu)].OnShow(); diff --git a/VocaluxeLib/PartyModes/CPartyModeNone.cs b/VocaluxeLib/PartyModes/CPartyModeNone.cs index 623ac0f8..27436373 100644 --- a/VocaluxeLib/PartyModes/CPartyModeNone.cs +++ b/VocaluxeLib/PartyModes/CPartyModeNone.cs @@ -19,7 +19,7 @@ namespace Vocaluxe.PartyModes _ScreenSongOptions.Selection.SongIndex = -1; _ScreenSongOptions.Sorting.SearchString = String.Empty; - _ScreenSongOptions.Sorting.SearchStringVisible = false; + _ScreenSongOptions.Sorting.SearchActive = false; _ScreenSongOptions.Sorting.ShowDuetSongs = true; } @@ -27,6 +27,10 @@ namespace Vocaluxe.PartyModes { _ScreenSongOptions.Sorting.SongSorting = _Base.Config.GetSongSorting(); _ScreenSongOptions.Sorting.Tabs = _Base.Config.GetTabs(); + + if (_ScreenSongOptions.Sorting.SearchActive) + _ScreenSongOptions.Sorting.Tabs = EOffOn.TR_CONFIG_OFF; + _ScreenSongOptions.Sorting.IgnoreArticles = _Base.Config.GetIgnoreArticles(); return _ScreenSongOptions; @@ -35,7 +39,7 @@ namespace Vocaluxe.PartyModes public override void SetSearchString(string SearchString, bool Visible) { _ScreenSongOptions.Sorting.SearchString = SearchString; - _ScreenSongOptions.Sorting.SearchStringVisible = Visible; + _ScreenSongOptions.Sorting.SearchActive = Visible; } } } diff --git a/VocaluxeLib/PartyModes/IPartyMode.cs b/VocaluxeLib/PartyModes/IPartyMode.cs index 4ef1a7f2..3248db10 100644 --- a/VocaluxeLib/PartyModes/IPartyMode.cs +++ b/VocaluxeLib/PartyModes/IPartyMode.cs @@ -19,7 +19,7 @@ namespace Vocaluxe.PartyModes public EOffOn Tabs; public EOffOn IgnoreArticles; public string SearchString; - public bool SearchStringVisible; + public bool SearchActive; public bool ShowDuetSongs; }