From 26a5086fc878d2e952a622658bf186a8451ab2e4 Mon Sep 17 00:00:00 2001 From: Florian Kuepper Date: Sat, 1 Dec 2012 22:05:45 +0100 Subject: [PATCH] Added function to select a random category. --- Output/Languages/Deutsch.xml | 1 + Output/Languages/English.xml | 1 + Output/Themes/Ambient/Screens/ScreenSong.xml | 49 ++++++++++++++++ .../Themes/Changelog/Changelog_ScreenSong.txt | 2 +- Vocaluxe/Base/CSongs.cs | 30 ++++++++++ Vocaluxe/Menu/SongMenu/CSongMenu.cs | 5 ++ Vocaluxe/Menu/SongMenu/CSongMenuFramework.cs | 6 ++ Vocaluxe/Menu/SongMenu/CSongMenuTileBoard.cs | 56 +++++++++++++++++++ Vocaluxe/Menu/SongMenu/ISongMenu.cs | 1 + Vocaluxe/Screens/CScreenSong.cs | 31 +++++++++- 10 files changed, 179 insertions(+), 3 deletions(-) diff --git a/Output/Languages/Deutsch.xml b/Output/Languages/Deutsch.xml index 8fe726bf..75d96131 100644 --- a/Output/Languages/Deutsch.xml +++ b/Output/Languages/Deutsch.xml @@ -123,6 +123,7 @@ Zur Playlist hinzufügen Schließen Zufälligen Song wählen + Zufällige Kategorie wählen Alle Songs singen Alle sichtbaren Song singen Playlist öffnen diff --git a/Output/Languages/English.xml b/Output/Languages/English.xml index 10b2e4fa..b3e2194f 100644 --- a/Output/Languages/English.xml +++ b/Output/Languages/English.xml @@ -123,6 +123,7 @@ Add to playlist Close Select a random song + Select a random category Sing all songs Sing all visible songs Open playlist diff --git a/Output/Themes/Ambient/Screens/ScreenSong.xml b/Output/Themes/Ambient/Screens/ScreenSong.xml index 3d744951..624cb0e6 100644 --- a/Output/Themes/Ambient/Screens/ScreenSong.xml +++ b/Output/Themes/Ambient/Screens/ScreenSong.xml @@ -473,6 +473,55 @@ + + + Button + + Button + + 40 + 90 + -2,11 + 360 + 40 + + + ButtonColor + + + ButtonSColor + + + 180 + 5 + + 30 + + 350 + + + ButtonTextColor + + + ButtonTextSColor + + Center + + Center + + + + Outline + + TR_SCREENSONG_BUTTON_RANDOMCAT + + + + + + + + Button diff --git a/Output/Themes/Changelog/Changelog_ScreenSong.txt b/Output/Themes/Changelog/Changelog_ScreenSong.txt index c1402b34..7d2e320c 100644 --- a/Output/Themes/Changelog/Changelog_ScreenSong.txt +++ b/Output/Themes/Changelog/Changelog_ScreenSong.txt @@ -6,7 +6,7 @@ Version 3: Add: -, , , , , , , +, , , , , , , , , , and as a new Screen-Element. For details, look at ScreenSong.xml diff --git a/Vocaluxe/Base/CSongs.cs b/Vocaluxe/Base/CSongs.cs index cc33b1ed..147e1c01 100644 --- a/Vocaluxe/Base/CSongs.cs +++ b/Vocaluxe/Base/CSongs.cs @@ -56,6 +56,7 @@ namespace Vocaluxe.Base private static int _CoverLoadIndex = -1; private static int _CatIndex = -1; private static List _Categories = new List(); + private static List _CategoriesForRandom = new List(); private static Stopwatch _CoverLoadTimer = new Stopwatch(); @@ -275,6 +276,35 @@ namespace Vocaluxe.Base _SongsForRandom.AddRange(VisibleSongs); } + public static int GetRandomCategory() + { + if (_CategoriesForRandom.Count == 0) + UpdateRandomCategoryList(); + + if (_CategoriesForRandom.Count == 0) + return -1; + + CCategory category = _CategoriesForRandom[CGame.Rand.Next(0, _CategoriesForRandom.Count - 1)]; + _CategoriesForRandom.Remove(category); + return GetCategoryNumber(category); + } + + public static void UpdateRandomCategoryList() + { + _CategoriesForRandom.Clear(); + _CategoriesForRandom.AddRange(Categories); + } + + private static int GetCategoryNumber(CCategory category) + { + for (int i = 0; i < Categories.Length; i++) + { + if (Categories[i] == category) + return i; + } + return -1; + } + public static CSong[] AllSongs { get { return _Songs.ToArray(); } diff --git a/Vocaluxe/Menu/SongMenu/CSongMenu.cs b/Vocaluxe/Menu/SongMenu/CSongMenu.cs index 7f437ab0..e6a2824e 100644 --- a/Vocaluxe/Menu/SongMenu/CSongMenu.cs +++ b/Vocaluxe/Menu/SongMenu/CSongMenu.cs @@ -98,6 +98,11 @@ namespace Vocaluxe.Menu.SongMenu return _SongMenu.GetSelectedCategory(); } + public void SetSelectedCategory(int CategoryNr) + { + _SongMenu.SetSelectedCategory(CategoryNr); + } + public int GetActualSelection() { return _SongMenu.GetActualSelection(); diff --git a/Vocaluxe/Menu/SongMenu/CSongMenuFramework.cs b/Vocaluxe/Menu/SongMenu/CSongMenuFramework.cs index 5dbfe865..c2fc76ee 100644 --- a/Vocaluxe/Menu/SongMenu/CSongMenuFramework.cs +++ b/Vocaluxe/Menu/SongMenu/CSongMenuFramework.cs @@ -536,6 +536,12 @@ namespace Vocaluxe.Menu.SongMenu return; } + public virtual void SetSelectedCategory(int CategoryNr) + { + if (!_Initialized) + return; + } + public virtual void SetSmallView(bool SmallView) { if (!_Initialized) diff --git a/Vocaluxe/Menu/SongMenu/CSongMenuTileBoard.cs b/Vocaluxe/Menu/SongMenu/CSongMenuTileBoard.cs index 10a86dbb..eda76a62 100644 --- a/Vocaluxe/Menu/SongMenu/CSongMenuTileBoard.cs +++ b/Vocaluxe/Menu/SongMenu/CSongMenuTileBoard.cs @@ -556,6 +556,62 @@ namespace Vocaluxe.Menu.SongMenu } + public override void SetSelectedCategory(int CategoryNr) + { + base.SetSelectedCategory(CategoryNr); + + if (CategoryNr < 0) + return; + + if (CSongs.Categories.Length > CategoryNr) + { + bool sel = false; + foreach (CStatic tile in _Tiles) + { + if (tile.Selected) + { + sel = true; + break; + } + } + + if (_Locked == -1 || !sel) + { + if (_PreviewSelected > -1) + { + _Locked = _PreviewSelected; + } + else + { + _Locked = 0; + _actualSelection = 0; + _PreviewSelected = 0; + SetSelectedNow(); + UpdateList(0); + } + } + + foreach (CStatic tile in _Tiles) + { + tile.Selected = false; + } + + _PreviewSelected = CategoryNr; + SetSelectedNow(); + _Locked = CategoryNr; + + UpdateList((CategoryNr / _NumW) * _NumW - (_NumW * (_NumH - 2))); + + _PreviewSelected = _Locked; + _actualSelection = _Locked; + + for (int i = 0; i < _Tiles.Count; i++) + { + _Tiles[i].Selected = _Locked == i + _Offset; + } + } + } + protected override void EnterCategory(int cat) { base.EnterCategory(cat); diff --git a/Vocaluxe/Menu/SongMenu/ISongMenu.cs b/Vocaluxe/Menu/SongMenu/ISongMenu.cs index a859e84b..dfca5dee 100644 --- a/Vocaluxe/Menu/SongMenu/ISongMenu.cs +++ b/Vocaluxe/Menu/SongMenu/ISongMenu.cs @@ -24,6 +24,7 @@ namespace Vocaluxe.Menu.SongMenu void SetActive(bool Active); int GetSelectedCategory(); + void SetSelectedCategory(int CategoryNr); int GetActualSelection(); bool IsSelected(); diff --git a/Vocaluxe/Screens/CScreenSong.cs b/Vocaluxe/Screens/CScreenSong.cs index f5809c12..a8dbc336 100644 --- a/Vocaluxe/Screens/CScreenSong.cs +++ b/Vocaluxe/Screens/CScreenSong.cs @@ -38,6 +38,7 @@ namespace Vocaluxe.Screens private const string ButtonOptionsPlaylist = "ButtonOptionsPlaylist"; private const string ButtonOptionsClose = "ButtonOptionsClose"; private const string ButtonOptionsRandom = "ButtonOptionsRandom"; + private const string ButtonOptionsRandomCategory = "ButtonOptionsRandomCategory"; private const string ButtonOptionsSingAll = "ButtonOptionsSingAll"; private const string ButtonOptionsSingAllVisible = "ButtonOptionsSingAllVisible"; private const string ButtonOptionsOpenPlaylist = "ButtonOptionsOpenPlaylist"; @@ -73,7 +74,7 @@ namespace Vocaluxe.Screens _ScreenVersion = ScreenVersion; _ThemeStatics = new string[] { StaticSearchBar, StaticOptionsBG }; _ThemeTexts = new string[] { TextCategory, TextSelection, TextSearchBarTitle, TextSearchBar, TextOptionsTitle }; - _ThemeButtons = new string[] { ButtonOptionsClose, ButtonOptionsPlaylist, ButtonOptionsSing, ButtonOptionsRandom, ButtonOptionsSingAll, ButtonOptionsSingAllVisible, ButtonOptionsOpenPlaylist, ButtonOpenOptions }; + _ThemeButtons = new string[] { ButtonOptionsClose, ButtonOptionsPlaylist, ButtonOptionsSing, ButtonOptionsRandom, ButtonOptionsRandomCategory, ButtonOptionsSingAll, ButtonOptionsSingAllVisible, ButtonOptionsOpenPlaylist, ButtonOpenOptions }; _ThemeSelectSlides = new string[] { SelectSlideOptionsMode, SelectSlideOptionsPlaylistAdd, SelectSlideOptionsPlaylistOpen }; _ThemeSongMenus = new string[] { SongMenu }; _ThemePlaylists = new string[] { Playlist }; @@ -89,6 +90,7 @@ namespace Vocaluxe.Screens Buttons[htButtons(ButtonOptionsSing)].Visible = false; Buttons[htButtons(ButtonOptionsPlaylist)].Visible = false; Buttons[htButtons(ButtonOptionsRandom)].Visible = false; + Buttons[htButtons(ButtonOptionsRandomCategory)].Visible = false; Buttons[htButtons(ButtonOptionsSingAll)].Visible = false; Buttons[htButtons(ButtonOptionsSingAllVisible)].Visible = false; Buttons[htButtons(ButtonOptionsOpenPlaylist)].Visible = false; @@ -223,6 +225,10 @@ namespace Vocaluxe.Screens { SongMenus[htSongMenus(SongMenu)].SetSelectedSong(CSongs.GetRandomSong()); } + else if (CSongs.Category == -1 && KeyEvent.Mod == Modifier.Ctrl) + { + SongMenus[htSongMenus(SongMenu)].SetSelectedCategory(CSongs.GetRandomCategory()); + } break; //TODO: Delete that! @@ -259,6 +265,13 @@ namespace Vocaluxe.Screens SongMenus[htSongMenus(SongMenu)].SetSelectedSong(CSongs.GetRandomSong()); } } + else if (Buttons[htButtons(ButtonOptionsRandom)].Selected) + { + if (CSongs.Category == -1) + { + SongMenus[htSongMenus(SongMenu)].SetSelectedCategory(CSongs.GetRandomCategory()); + } + } else if (Buttons[htButtons(ButtonOptionsSingAll)].Selected) { StartRandomAllSongs(); @@ -319,6 +332,11 @@ namespace Vocaluxe.Screens Console.WriteLine("MB pressed"); SongMenus[htSongMenus(SongMenu)].SetSelectedSong(CSongs.GetRandomSong()); } + else if (MouseEvent.MB && CSongs.Category == -1) + { + Console.WriteLine("MB pressed"); + SongMenus[htSongMenus(SongMenu)].SetSelectedCategory(CSongs.GetRandomCategory()); + } else SongMenus[htSongMenus(SongMenu)].HandleMouse(ref MouseEvent); @@ -362,6 +380,13 @@ namespace Vocaluxe.Screens SongMenus[htSongMenus(SongMenu)].SetSelectedSong(CSongs.GetRandomSong()); } } + else if (Buttons[htButtons(ButtonOptionsRandomCategory)].Selected) + { + if (CSongs.Category == -1) + { + SongMenus[htSongMenus(SongMenu)].SetSelectedCategory(CSongs.GetRandomCategory()); + } + } else if (Buttons[htButtons(ButtonOptionsSingAll)].Selected) { ToggleSongOptions(ESongOptionsView.None); @@ -648,8 +673,9 @@ namespace Vocaluxe.Screens else if (view == ESongOptionsView.General) { Buttons[htButtons(ButtonOptionsRandom)].Visible = CSongs.Category != -1; + Buttons[htButtons(ButtonOptionsRandomCategory)].Visible = CSongs.Category == -1; Buttons[htButtons(ButtonOptionsSingAll)].Visible = true; - Buttons[htButtons(ButtonOptionsSingAllVisible)].Visible = true; + Buttons[htButtons(ButtonOptionsSingAllVisible)].Visible = CSongs.Category != -1; ; Buttons[htButtons(ButtonOptionsOpenPlaylist)].Visible = true; SelectSlides[htSelectSlides(SelectSlideOptionsPlaylistOpen)].Visible = true; } @@ -666,6 +692,7 @@ namespace Vocaluxe.Screens Buttons[htButtons(ButtonOptionsSing)].Visible = false; Buttons[htButtons(ButtonOptionsPlaylist)].Visible = false; Buttons[htButtons(ButtonOptionsRandom)].Visible = false; + Buttons[htButtons(ButtonOptionsRandomCategory)].Visible = false; Buttons[htButtons(ButtonOptionsSingAll)].Visible = false; Buttons[htButtons(ButtonOptionsSingAllVisible)].Visible = false; Buttons[htButtons(ButtonOptionsOpenPlaylist)].Visible = false;