From ee69919366ed09f9c1d121e290f0a9fa4e28adec Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Sun, 23 Dec 2012 12:36:50 +0100 Subject: [PATCH] changed challenge party mode song selection (there are still some bugs) --- PartyModeChallenge/PartyModeChallenge.cs | 85 +++++++-- Vocaluxe/Base/CParty.cs | 10 ++ Vocaluxe/Screens/CScreenSong.cs | 169 +++++++++++------- VocaluxeLib/Menu/IMenu.cs | 2 + .../Menu/SongMenu/CSongMenuFramework.cs | 2 + .../Menu/SongMenu/CSongMenuTileBoard.cs | 11 +- VocaluxeLib/PartyModes/CPartyMode.cs | 8 + VocaluxeLib/PartyModes/CPartyModeNone.cs | 1 + VocaluxeLib/PartyModes/IPartyMode.cs | 13 ++ 9 files changed, 220 insertions(+), 81 deletions(-) diff --git a/PartyModeChallenge/PartyModeChallenge.cs b/PartyModeChallenge/PartyModeChallenge.cs index 77c2126f..b64fdba5 100644 --- a/PartyModeChallenge/PartyModeChallenge.cs +++ b/PartyModeChallenge/PartyModeChallenge.cs @@ -121,6 +121,8 @@ namespace Vocaluxe.PartyModes public List ResultTable; public int CurrentRoundNr; + + public int[] CatSongIndices; } struct Stats @@ -161,7 +163,8 @@ namespace Vocaluxe.PartyModes GameData.NumPlayerAtOnce = 2; GameData.NumRounds = 2; GameData.CurrentRoundNr = 1; - GameData.ProfileIDs = new List(); + GameData.ProfileIDs = new List(); + GameData.CatSongIndices = null; } public override bool Init() @@ -169,8 +172,12 @@ namespace Vocaluxe.PartyModes _Stage = EStage.NotStarted; _ScreenSongOptions.Sorting.IgnoreArticles = _Base.Config.GetIgnoreArticles(); - _ScreenSongOptions.Sorting.SongSorting = ESongSorting.TR_CONFIG_FOLDER; - _ScreenSongOptions.Sorting.Tabs = EOffOn.TR_CONFIG_ON; + _ScreenSongOptions.Sorting.SongSorting = _Base.Config.GetSongSorting(); + _ScreenSongOptions.Sorting.Tabs = EOffOn.TR_CONFIG_OFF; + _ScreenSongOptions.Selection.SongIndex = -1; + + if (_Base.Config.GetTabs() == EOffOn.TR_CONFIG_ON && _ScreenSongOptions.Sorting.SongSorting != ESongSorting.TR_CONFIG_NONE) + _ScreenSongOptions.Sorting.Tabs = EOffOn.TR_CONFIG_ON; ToScreenMain.ResultTable = new List(); GameData.ResultTable = new List(); @@ -250,10 +257,11 @@ namespace Vocaluxe.PartyModes public override void UpdateGame() { - if (_Base.Songs.GetCurrentCategoryIndex() != -1) + /* + if (_Base.Songs.GetCurrentCategoryIndex() != -1 || _ScreenSongOptions.Sorting.Tabs == EOffOn.TR_CONFIG_OFF) _ScreenSongOptions.Selection.RandomOnly = true; else - _ScreenSongOptions.Selection.RandomOnly = false; + _ScreenSongOptions.Selection.RandomOnly = false;*/ } public override CMenuParty GetNextPartyScreen(out EScreens AlternativeScreen) @@ -338,6 +346,48 @@ namespace Vocaluxe.PartyModes return _ScreenSongOptions; } + public override void OnSongChange(int SongIndex, ref ScreenSongOptions ScreenSongOptions) + { + if (_ScreenSongOptions.Selection.SongIndex != -1) + _ScreenSongOptions.Selection.SongIndex = -1; + + if (_ScreenSongOptions.Selection.SelectNextRandomSong && SongIndex != -1) + { + _ScreenSongOptions.Selection.SelectNextRandomSong = false; + CreateCatSongIndices(); + + if (GameData.CatSongIndices != null) + { + if (GameData.CatSongIndices[_Base.Songs.GetCurrentCategoryIndex()] == -1) + GameData.CatSongIndices[_Base.Songs.GetCurrentCategoryIndex()] = SongIndex; + } + } + + ScreenSongOptions = _ScreenSongOptions; + } + + public override void OnCategoryChange(int CategoryIndex, ref ScreenSongOptions ScreenSongOptions) + { + if (GameData.CatSongIndices != null && CategoryIndex != -1) + { + if (GameData.CatSongIndices[CategoryIndex] == -1) + _ScreenSongOptions.Selection.SelectNextRandomSong = true; + else + _ScreenSongOptions.Selection.SongIndex = GameData.CatSongIndices[CategoryIndex]; + } + + if (GameData.CatSongIndices == null && CategoryIndex != -1) + _ScreenSongOptions.Selection.SelectNextRandomSong = true; + + if (CategoryIndex == -1) + _ScreenSongOptions.Selection.RandomOnly = false; + + if (_ScreenSongOptions.Sorting.Tabs == EOffOn.TR_CONFIG_OFF || CategoryIndex != -1) + _ScreenSongOptions.Selection.RandomOnly = true; + + ScreenSongOptions = _ScreenSongOptions; + } + public override void SetSearchString(string SearchString, bool Visible) { _ScreenSongOptions.Sorting.SearchString = SearchString; @@ -377,9 +427,7 @@ namespace Vocaluxe.PartyModes if (TeamNr >= _ScreenSongOptions.Selection.NumJokers.Length) return; - if (!_ScreenSongOptions.Selection.CategoryChangeAllowed) - _ScreenSongOptions.Selection.NumJokers[TeamNr]--; - + _ScreenSongOptions.Selection.NumJokers[TeamNr]--; _ScreenSongOptions.Selection.RandomOnly = true; _ScreenSongOptions.Selection.CategoryChangeAllowed = false; } @@ -429,17 +477,17 @@ namespace Vocaluxe.PartyModes public override void LeavingHighscore() { - //TODO: _Base.Graphics.FadeTo(EScreens.ScreenPartyDummy); } private void StartNextRound() { - _ScreenSongOptions.Selection.RandomOnly = false; - _ScreenSongOptions.Selection.CategoryChangeAllowed = true; + _ScreenSongOptions.Selection.RandomOnly = _ScreenSongOptions.Sorting.Tabs != EOffOn.TR_CONFIG_ON; + _ScreenSongOptions.Selection.CategoryChangeAllowed = _ScreenSongOptions.Sorting.Tabs == EOffOn.TR_CONFIG_ON; GameData.CurrentRoundNr++; SetNumJokers(); SetTeamNames(); + GameData.CatSongIndices = null; _Base.Graphics.FadeTo(EScreens.ScreenSong); } @@ -619,5 +667,20 @@ namespace Vocaluxe.PartyModes return result; } + + private void CreateCatSongIndices() + { + if (GameData.CatSongIndices == null && _Base.Songs.GetNumCategories() > 0 && _ScreenSongOptions.Sorting.Tabs == EOffOn.TR_CONFIG_ON) + { + GameData.CatSongIndices = new int[_Base.Songs.GetNumCategories()]; + for (int i = 0; i < GameData.CatSongIndices.Length; i++) + { + GameData.CatSongIndices[i] = -1; + } + } + + if (_Base.Songs.GetNumCategories() == 0 || _ScreenSongOptions.Sorting.Tabs == EOffOn.TR_CONFIG_OFF) + GameData.CatSongIndices = null; + } } } \ No newline at end of file diff --git a/Vocaluxe/Base/CParty.cs b/Vocaluxe/Base/CParty.cs index 02b65164..b92e5f1c 100644 --- a/Vocaluxe/Base/CParty.cs +++ b/Vocaluxe/Base/CParty.cs @@ -163,6 +163,16 @@ namespace Vocaluxe.Base return _CurrentPartyMode.PartyMode.GetScreenSongOptions(); } + public static void OnSongChange(int SongIndex, ref ScreenSongOptions ScreenSongOptions) + { + _CurrentPartyMode.PartyMode.OnSongChange(SongIndex, ref ScreenSongOptions); + } + + public static void OnCategoryChange(int CategoryIndex, ref ScreenSongOptions ScreenSongOptions) + { + _CurrentPartyMode.PartyMode.OnCategoryChange(CategoryIndex, ref ScreenSongOptions); + } + public static void SetSearchString(string SearchString, bool Visible) { _CurrentPartyMode.PartyMode.SetSearchString(SearchString, Visible); diff --git a/Vocaluxe/Screens/CScreenSong.cs b/Vocaluxe/Screens/CScreenSong.cs index a203fe1c..537153e9 100644 --- a/Vocaluxe/Screens/CScreenSong.cs +++ b/Vocaluxe/Screens/CScreenSong.cs @@ -66,7 +66,10 @@ namespace Vocaluxe.Screens private CStatic DragAndDropCover; private bool DragAndDropActive; private int OldMousePosX; - private int OldMousePosY; + private int OldMousePosY; + + private int SelectedSongID; + private int SelectedCategoryIndex; public CScreenSong() { @@ -183,6 +186,8 @@ namespace Vocaluxe.Screens else { SongMenus[htSongMenus(SongMenu)].HandleInput(ref KeyEvent, _sso); + UpdatePartyModeOptions(); + if (KeyEvent.Handled) return true; @@ -478,6 +483,10 @@ namespace Vocaluxe.Screens } SongMenus[htSongMenus(SongMenu)].HandleMouse(ref MouseEvent, _sso); + UpdatePartyModeOptions(); + + if (MouseEvent.Handled) + return true; if (MouseEvent.LB) { @@ -614,6 +623,9 @@ namespace Vocaluxe.Screens { base.OnShow(); + SelectedSongID = -1; + SelectedCategoryIndex = -2; + _sso = CParty.GetSongSelectionOptions(); CSongs.Sort(_sso.Sorting.SongSorting, _sso.Sorting.Tabs, _sso.Sorting.IgnoreArticles, _sso.Sorting.SearchString, _sso.Sorting.ShowDuetSongs); _SearchActive = _sso.Sorting.SearchStringVisible; @@ -643,19 +655,6 @@ namespace Vocaluxe.Screens public override bool UpdateGame() { - _sso = CParty.GetSongSelectionOptions(); - CSongs.Sort(_sso.Sorting.SongSorting, _sso.Sorting.Tabs, _sso.Sorting.IgnoreArticles, _sso.Sorting.SearchString, _sso.Sorting.ShowDuetSongs); - _SearchActive = _sso.Sorting.SearchStringVisible; - _SearchText = _sso.Sorting.SearchString; - - if (_sso.Selection.PartyMode) - _PlaylistActive = false; - - if (_sso.Selection.PartyMode) - ToggleSongOptions(ESongOptionsView.None); - - SongMenus[htSongMenus(SongMenu)].Update(_sso); - if (SongMenus[htSongMenus(SongMenu)].IsSmallView()) CheckPlaylist(); @@ -694,54 +693,7 @@ namespace Vocaluxe.Screens Statics[htStatics(StaticSearchBar)].Visible = false; } - if (_sso.Selection.RandomOnly && _sso.Selection.NumJokers != null) - { - Buttons[htButtons(ButtonStart)].Visible = true; - - if(!SongMenus[htSongMenus(SongMenu)].IsSmallView()) - SongMenus[htSongMenus(SongMenu)].SetSmallView(true); - - for (int i = 0; i < _Base.Settings.GetMaxNumPlayer(); i++) - { - if (i < _sso.Selection.NumJokers.Length) - { - Buttons[htButtons(ButtonsJoker[i])].Visible = true; - Buttons[htButtons(ButtonsJoker[i])].Text.Text = _sso.Selection.NumJokers[i].ToString(); - Texts[htTexts(TextsPlayer[i])].Visible = true; - - bool NameExists = false; - if (_sso.Selection.TeamNames != null) - { - if (_sso.Selection.TeamNames.Length > i) - { - Texts[htTexts(TextsPlayer[i])].Text = _sso.Selection.TeamNames[i]; - NameExists = true; - } - } - - if (!NameExists) - Texts[htTexts(TextsPlayer[i])].Text = i.ToString(); - } - else - { - Buttons[htButtons(ButtonsJoker[i])].Visible = false; - Texts[htTexts(TextsPlayer[i])].Visible = false; - } - } - } - else - { - if(_sso.Selection.PartyMode && SongMenus[htSongMenus(SongMenu)].IsSmallView()) - SongMenus[htSongMenus(SongMenu)].SetSmallView(false); - - for (int i = 0; i < _Base.Settings.GetMaxNumPlayer(); i++) - { - Buttons[htButtons(ButtonsJoker[i])].Visible = false; - Texts[htTexts(TextsPlayer[i])].Visible = false; - } - - Buttons[htButtons(ButtonStart)].Visible = false; - } + UpdatePartyModeOptions(); return true; } @@ -782,6 +734,93 @@ namespace Vocaluxe.Screens } } + private void UpdatePartyModeOptions() + { + if (CSongs.Category == -1) + SelectedSongID = -1; + + if (SelectedCategoryIndex != CSongs.Category) + { + SelectedCategoryIndex = CSongs.Category; + CParty.OnCategoryChange(SelectedCategoryIndex, ref _sso); + + if (_sso.Selection.SelectNextRandomSong) + SelectNextRandomSong(); + + if (_sso.Selection.SongIndex != -1) + SongMenus[htSongMenus(SongMenu)].SetSelectedSong(_sso.Selection.SongIndex); + } + + if (SelectedSongID != SongMenus[htSongMenus(SongMenu)].GetSelectedSong() && CSongs.Category > -1) + { + SelectedSongID = SongMenus[htSongMenus(SongMenu)].GetSelectedSong(); + CParty.OnSongChange(SelectedSongID, ref _sso); + } + + _sso = CParty.GetSongSelectionOptions(); + CSongs.Sort(_sso.Sorting.SongSorting, _sso.Sorting.Tabs, _sso.Sorting.IgnoreArticles, _sso.Sorting.SearchString, _sso.Sorting.ShowDuetSongs); + _SearchActive = _sso.Sorting.SearchStringVisible; + _SearchText = _sso.Sorting.SearchString; + + + if (_sso.Selection.PartyMode) + { + _PlaylistActive = false; + ToggleSongOptions(ESongOptionsView.None); + } + + SongMenus[htSongMenus(SongMenu)].Update(_sso); + + if (_sso.Selection.RandomOnly && _sso.Selection.NumJokers != null) + { + Buttons[htButtons(ButtonStart)].Visible = true; + + if (!SongMenus[htSongMenus(SongMenu)].IsSmallView()) + SongMenus[htSongMenus(SongMenu)].SetSmallView(true); + + for (int i = 0; i < _Base.Settings.GetMaxNumPlayer(); i++) + { + if (i < _sso.Selection.NumJokers.Length) + { + Buttons[htButtons(ButtonsJoker[i])].Visible = true; + Buttons[htButtons(ButtonsJoker[i])].Text.Text = _sso.Selection.NumJokers[i].ToString(); + Texts[htTexts(TextsPlayer[i])].Visible = true; + + bool NameExists = false; + if (_sso.Selection.TeamNames != null) + { + if (_sso.Selection.TeamNames.Length > i) + { + Texts[htTexts(TextsPlayer[i])].Text = _sso.Selection.TeamNames[i]; + NameExists = true; + } + } + + if (!NameExists) + Texts[htTexts(TextsPlayer[i])].Text = i.ToString(); + } + else + { + Buttons[htButtons(ButtonsJoker[i])].Visible = false; + Texts[htTexts(TextsPlayer[i])].Visible = false; + } + } + } + else + { + if (_sso.Selection.PartyMode && SongMenus[htSongMenus(SongMenu)].IsSmallView()) + SongMenus[htSongMenus(SongMenu)].SetSmallView(false); + + for (int i = 0; i < _Base.Settings.GetMaxNumPlayer(); i++) + { + Buttons[htButtons(ButtonsJoker[i])].Visible = false; + Texts[htTexts(TextsPlayer[i])].Visible = false; + } + + Buttons[htButtons(ButtonStart)].Visible = false; + } + } + private void StartSong(int SongNr) { if ((CSongs.Category >= 0) && (SongNr >= 0)) @@ -910,7 +949,7 @@ namespace Vocaluxe.Screens { if (_sso.Selection.NumJokers[TeamNr] > 0) { - result = SelectNextRandomSong(TeamNr) || SelectNextRandomCategory(); + result = SelectNextRandomSong() || SelectNextRandomCategory(); CParty.JokerUsed(TeamNr); _sso = CParty.GetSongSelectionOptions(); } @@ -919,12 +958,12 @@ namespace Vocaluxe.Screens } if (TeamNr == -1) - return SelectNextRandomSong(TeamNr) || SelectNextRandomCategory(); + return SelectNextRandomSong() || SelectNextRandomCategory(); return false; } - private bool SelectNextRandomSong(int TeamNr) + private bool SelectNextRandomSong() { if (CSongs.Category != -1) { diff --git a/VocaluxeLib/Menu/IMenu.cs b/VocaluxeLib/Menu/IMenu.cs index f8499d5e..f92c2008 100644 --- a/VocaluxeLib/Menu/IMenu.cs +++ b/VocaluxeLib/Menu/IMenu.cs @@ -371,6 +371,7 @@ namespace Vocaluxe.Menu public struct MouseEvent { public ESender Sender; + public bool Handled; public int X; public int Y; public bool LB; //left button click @@ -392,6 +393,7 @@ namespace Vocaluxe.Menu public MouseEvent(ESender sender, bool alt, bool shift, bool ctrl, int x, int y, bool lb, bool ld, bool rb, int wheel, bool lbh, bool rbh, bool mb, bool mbh) { Sender = sender; + Handled = false; X = x; Y = y; LB = lb; diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs index c9d30789..5531b8d6 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs @@ -599,6 +599,7 @@ namespace Vocaluxe.Menu.SongMenu if (Category >= _Base.Songs.GetNumCategories()) return; + Reset(); _Base.Songs.SetCategory(Category); } @@ -610,6 +611,7 @@ namespace Vocaluxe.Menu.SongMenu if (_Base.Songs.GetCurrentCategoryIndex() != -1) Reset(); + Reset(); _Base.Songs.SetCategory(-1); } diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs index 405ad95f..05ec1295 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs @@ -105,6 +105,8 @@ namespace Vocaluxe.Menu.SongMenu { base.Update(SongOptions); + UpdateList(_Offset); + if (SongOptions.Selection.RandomOnly) { _Locked = _PreviewSelected; @@ -382,6 +384,7 @@ namespace Vocaluxe.Menu.SongMenu if ((MouseEvent.RB) && (_Base.Songs.GetNumCategories() > 0) && _Base.Songs.GetCurrentCategoryIndex() >= 0 && _Base.Songs.GetTabs() == EOffOn.TR_CONFIG_ON && SongOptions.Selection.CategoryChangeAllowed) { ShowCategories(); + MouseEvent.Handled = true; return; } else if (MouseEvent.RB && _Base.Songs.GetTabs() == EOffOn.TR_CONFIG_OFF && !SongOptions.Selection.PartyMode) @@ -402,6 +405,7 @@ namespace Vocaluxe.Menu.SongMenu if ((tile.Texture.index != _CoverTexture.index) && CHelper.IsInBounds(tile.Rect, MouseEvent)) { EnterCategory(_PreviewSelected); + MouseEvent.Handled = true; return; } } @@ -662,6 +666,7 @@ namespace Vocaluxe.Menu.SongMenu _Locked = -1; _actualSelection = 0; AfterCategoryChange(); + _Locked = 0; } protected override void ShowCategories() @@ -672,16 +677,15 @@ namespace Vocaluxe.Menu.SongMenu _Locked = -1; _actualSelection = 0; AfterCategoryChange(); + _Locked = 0; } private void NextCategory() { if (_Base.Songs.GetCurrentCategoryIndex() > -1) { - Reset(); _Base.Songs.NextCategory(); EnterCategory(_Base.Songs.GetCurrentCategoryIndex()); - _Locked = 0; } } @@ -689,10 +693,8 @@ namespace Vocaluxe.Menu.SongMenu { if (_Base.Songs.GetCurrentCategoryIndex() > -1) { - Reset(); _Base.Songs.PrevCategory(); EnterCategory(_Base.Songs.GetCurrentCategoryIndex()); - _Locked = 0; } } @@ -827,7 +829,6 @@ namespace Vocaluxe.Menu.SongMenu } UpdateList(_Offset); - } public override bool IsSmallView() diff --git a/VocaluxeLib/PartyModes/CPartyMode.cs b/VocaluxeLib/PartyModes/CPartyMode.cs index d406054a..8540dc27 100644 --- a/VocaluxeLib/PartyModes/CPartyMode.cs +++ b/VocaluxeLib/PartyModes/CPartyMode.cs @@ -67,6 +67,14 @@ namespace Vocaluxe.PartyModes return new ScreenSongOptions(); } + public virtual void OnSongChange(int SongIndex, ref ScreenSongOptions ScreenSongOptions) + { + } + + public virtual void OnCategoryChange(int CategoryIndex, ref ScreenSongOptions ScreenSongOptions) + { + } + public virtual int GetMaxPlayer() { return 6; diff --git a/VocaluxeLib/PartyModes/CPartyModeNone.cs b/VocaluxeLib/PartyModes/CPartyModeNone.cs index 3fbff589..623ac0f8 100644 --- a/VocaluxeLib/PartyModes/CPartyModeNone.cs +++ b/VocaluxeLib/PartyModes/CPartyModeNone.cs @@ -16,6 +16,7 @@ namespace Vocaluxe.PartyModes _ScreenSongOptions.Selection.CategoryChangeAllowed = true; _ScreenSongOptions.Selection.NumJokers = null; _ScreenSongOptions.Selection.TeamNames = null; + _ScreenSongOptions.Selection.SongIndex = -1; _ScreenSongOptions.Sorting.SearchString = String.Empty; _ScreenSongOptions.Sorting.SearchStringVisible = false; diff --git a/VocaluxeLib/PartyModes/IPartyMode.cs b/VocaluxeLib/PartyModes/IPartyMode.cs index 94efc342..4ef1a7f2 100644 --- a/VocaluxeLib/PartyModes/IPartyMode.cs +++ b/VocaluxeLib/PartyModes/IPartyMode.cs @@ -28,6 +28,16 @@ namespace Vocaluxe.PartyModes /// public struct SelectionOptions { + /// + /// If != -1, the SongMenu should set the song selection on the provided song index (visible index) if possible + /// + public int SongIndex; + + /// + /// If true, the SongMenu should perform the select random song method + /// + public bool SelectNextRandomSong; + /// /// Choosing song only by random /// @@ -69,6 +79,9 @@ namespace Vocaluxe.PartyModes EScreens GetMainScreen(); ScreenSongOptions GetScreenSongOptions(); + void OnSongChange(int SongIndex, ref ScreenSongOptions ScreenSongOptions); + void OnCategoryChange(int CategoryIndex, ref ScreenSongOptions ScreenSongOptions); + int GetMaxPlayer(); int GetMinPlayer(); int GetMaxTeams();