From 010cae5ae0c1e34d8bffb84cef2243e7ebd9f795 Mon Sep 17 00:00:00 2001 From: FRUP Date: Sat, 7 Mar 2020 12:18:32 -0800 Subject: [PATCH] add random song select to SongSelect --- CHANGELOG.md | 5 ++++ Pulsarc/Pulsarc.csproj | 4 +-- .../UI/Screens/SongSelect/SongSelection.cs | 25 ++++++++++++++++--- .../Screens/SongSelect/SongSelectionView.cs | 17 ++++--------- 4 files changed, 33 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e60425..62f1b86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.4.3-alpha] - 2020-03-07 + +### Added +- Random song selection. Press F2 in the song select to choose a random song. + ## [1.4.2-alpha] - 2020-03-02 ### Added diff --git a/Pulsarc/Pulsarc.csproj b/Pulsarc/Pulsarc.csproj index faad6b0..879fdb5 100644 --- a/Pulsarc/Pulsarc.csproj +++ b/Pulsarc/Pulsarc.csproj @@ -9,8 +9,8 @@ Pulsarc Icon.ico - 1.4.2.0 - 1.4.2.0 + 1.4.3.0 + 1.4.3.0 diff --git a/Pulsarc/UI/Screens/SongSelect/SongSelection.cs b/Pulsarc/UI/Screens/SongSelect/SongSelection.cs index d97ad87..4dcbc5f 100644 --- a/Pulsarc/UI/Screens/SongSelect/SongSelection.cs +++ b/Pulsarc/UI/Screens/SongSelect/SongSelection.cs @@ -83,6 +83,8 @@ public override void Init() base.Init(); RefreshBeatmaps(); + + SelectRandomCard(); } /// @@ -179,6 +181,20 @@ public List SortBeatmaps(List beatmaps, string sort, bool asce } } + public void SelectRandomCard() + { + if (Cards.Count <= 0) { return; } + + Random rd = new Random(); + + FocusedCard?.SetClicked(false); + + FocusedCard = Cards[rd.Next(0, Cards.Count)]; + FocusedCard.OnClick(); + + GetSongSelectionView().FocusCard(FocusedCard); + } + public void DeleteMap(in BeatmapCard card) { AudioManager.Stop(); @@ -261,16 +277,17 @@ private void HandleKeyboardPresses() // If the backspace is pressed, delete the last character case Keys.Back: // If there's nothing in the box, don't do anything - if (GetSongSelectionView().SearchBox.GetText().Length <= 0) - { - break; - } + if (GetSongSelectionView().SearchBox.GetText().Length <= 0) { break; } // Reset the timer RestartSearchBoxKeyPressTimer = true; GetSongSelectionView().SearchBox.DeleteLastCharacter(); break; + // If the random key is pressed, choose a random song + case Keys.F2: + SelectRandomCard(); + break; // If none of the above, type into the search bar // TODO? Ignore keypresses unless clicked on default: diff --git a/Pulsarc/UI/Screens/SongSelect/SongSelectionView.cs b/Pulsarc/UI/Screens/SongSelect/SongSelectionView.cs index e75ea79..1ef8280 100644 --- a/Pulsarc/UI/Screens/SongSelect/SongSelectionView.cs +++ b/Pulsarc/UI/Screens/SongSelect/SongSelectionView.cs @@ -67,16 +67,6 @@ public SongSelectionView(Screen screen, List beatmaps, string search = cards.Add(new BeatmapCard(beatmaps[i], i)); } - // Select a random map by default in the song selection. - if (cards.Count > 0) - { - Random rd = new Random(); - - songSelectScreen.FocusedCard = cards[rd.Next(0, cards.Count)]; - songSelectScreen.FocusedCard.OnClick(); - FocusCard(songSelectScreen.FocusedCard); - } - Anchor searchBoxAnchor = GetSkinnablePropertyAnchor("SearchBarAnchor"); Vector2 searchBarStartPosition = Skin.GetConfigStartPosition("song_select", "Properties", "SearchBarStartPos"); @@ -252,13 +242,16 @@ public override void Update(GameTime gameTime) if (Math.Round(currentFocus, 2) != Math.Round(songSelectScreen.SelectedFocus, 2)) { currentFocus = PulsarcMath.Lerp( - currentFocus, songSelectScreen.SelectedFocus, (float)PulsarcTime.DeltaTime / 100f); + currentFocus, songSelectScreen.SelectedFocus, + (float)PulsarcTime.DeltaTime / 100f); float diff = lastFocus - currentFocus; lastFocus = currentFocus; - + for (int i = 0; i < cards.Count; i++) + { cards[i].Move(new Vector2(0, BeatmapCard.TotalHeight * diff)); + } } // Go back if the back button was clicked.