Skip to content

Commit

Permalink
add random song select to SongSelect
Browse files Browse the repository at this point in the history
  • Loading branch information
dustdustinthewind committed Mar 7, 2020
1 parent 207cd55 commit 010cae5
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 18 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Pulsarc/Pulsarc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<AssemblyName>Pulsarc</AssemblyName>
<ApplicationIcon>Icon.ico</ApplicationIcon>
<StartupObject></StartupObject>
<AssemblyVersion>1.4.2.0</AssemblyVersion>
<FileVersion>1.4.2.0</FileVersion>
<AssemblyVersion>1.4.3.0</AssemblyVersion>
<FileVersion>1.4.3.0</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
25 changes: 21 additions & 4 deletions Pulsarc/UI/Screens/SongSelect/SongSelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ public override void Init()
base.Init();

RefreshBeatmaps();

SelectRandomCard();
}

/// <summary>
Expand Down Expand Up @@ -179,6 +181,20 @@ public List<Beatmap> SortBeatmaps(List<Beatmap> 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();
Expand Down Expand Up @@ -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:
Expand Down
17 changes: 5 additions & 12 deletions Pulsarc/UI/Screens/SongSelect/SongSelectionView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,6 @@ public SongSelectionView(Screen screen, List<Beatmap> 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");

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 010cae5

Please sign in to comment.