Skip to content

Commit

Permalink
Song select polish
Browse files Browse the repository at this point in the history
  • Loading branch information
EliteAsian123 committed Mar 18, 2023
1 parent 9cef452 commit df15d18
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 28 deletions.
67 changes: 62 additions & 5 deletions Assets/Scenes/MenuScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -3296,9 +3296,9 @@ MonoBehaviour:
m_OnClick:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 874813134}
m_TargetAssemblyTypeName: YARG.UI.MainMenu, Assembly-CSharp
m_MethodName: ShowMainMenu
- m_Target: {fileID: 1458336824}
m_TargetAssemblyTypeName: YARG.UI.SongSelect, Assembly-CSharp
m_MethodName: Back
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
Expand Down Expand Up @@ -13279,7 +13279,7 @@ MonoBehaviour:
m_enableAutoSizing: 0
m_fontSizeMin: 18
m_fontSizeMax: 72
m_fontStyle: 0
m_fontStyle: 4
m_HorizontalAlignment: 1
m_VerticalAlignment: 256
m_textAlignment: 65535
Expand Down Expand Up @@ -18413,6 +18413,7 @@ GameObject:
- component: {fileID: 1886399723}
- component: {fileID: 1886399726}
- component: {fileID: 1886399725}
- component: {fileID: 1886399727}
- component: {fileID: 1886399724}
m_Layer: 5
m_Name: Support Text
Expand Down Expand Up @@ -18515,7 +18516,7 @@ MonoBehaviour:
m_enableAutoSizing: 0
m_fontSizeMin: 18
m_fontSizeMax: 72
m_fontStyle: 1
m_fontStyle: 5
m_HorizontalAlignment: 4
m_VerticalAlignment: 256
m_textAlignment: 65535
Expand Down Expand Up @@ -18559,6 +18560,62 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1886399722}
m_CullTransparentMesh: 1
--- !u!114 &1886399727
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1886399722}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Navigation:
m_Mode: 3
m_WrapAround: 0
m_SelectOnUp: {fileID: 0}
m_SelectOnDown: {fileID: 0}
m_SelectOnLeft: {fileID: 0}
m_SelectOnRight: {fileID: 0}
m_Transition: 0
m_Colors:
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
m_ColorMultiplier: 1
m_FadeDuration: 0.1
m_SpriteState:
m_HighlightedSprite: {fileID: 0}
m_PressedSprite: {fileID: 0}
m_SelectedSprite: {fileID: 0}
m_DisabledSprite: {fileID: 0}
m_AnimationTriggers:
m_NormalTrigger: Normal
m_HighlightedTrigger: Highlighted
m_PressedTrigger: Pressed
m_SelectedTrigger: Selected
m_DisabledTrigger: Disabled
m_Interactable: 1
m_TargetGraphic: {fileID: 1290299072}
m_OnClick:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 2044165076}
m_TargetAssemblyTypeName: YARG.UI.SelectedSongView, Assembly-CSharp
m_MethodName: SearchSource
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
--- !u!1 &1887177691
GameObject:
m_ObjectHideFlags: 0
Expand Down
4 changes: 4 additions & 0 deletions Assets/Script/Input/FiveFretInputStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ public override void UpdateNavigationMode() {
if (MappingAsButton("red")?.wasPressedThisFrame ?? false) {
CallGenericNavigationEvent(NavigationType.SECONDARY, true);
}

if (MappingAsButton("yellow")?.wasPressedThisFrame ?? false) {
CallGenericNavigationEvent(NavigationType.TERTIARY, true);
}
}

public override string[] GetAllowedInstruments() {
Expand Down
3 changes: 2 additions & 1 deletion Assets/Script/Input/NavigationType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ public enum NavigationType {
UP,
DOWN,
PRIMARY,
SECONDARY
SECONDARY,
TERTIARY
}
}
2 changes: 2 additions & 0 deletions Assets/Script/UI/DifficultySelect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ private void OnGenericNavigation(NavigationType navigationType, bool firstPresse
MoveOption(1);
} else if (navigationType == NavigationType.PRIMARY) {
Next();
} else if (navigationType == NavigationType.SECONDARY) {
MainMenu.Instance.ShowSongSelect();
}
}

Expand Down
4 changes: 4 additions & 0 deletions Assets/Script/UI/SelectedSongView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,9 @@ public void PlaySong() {
public void SearchArtist() {
SongSelect.Instance.searchField.text = $"artist:{songInfo.ArtistName}";
}

public void SearchSource() {
SongSelect.Instance.searchField.text = $"source:{songInfo.source}";
}
}
}
80 changes: 58 additions & 22 deletions Assets/Script/UI/SongSelect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,18 @@ private void OnGenericNavigation(NavigationType navigationType, bool firstPresse
}
}

if (!firstPressed) {
return;
}

if (navigationType == NavigationType.PRIMARY) {
selectedSongView.PlaySong();
} else if (navigationType == NavigationType.SECONDARY) {
Back();
} else if (navigationType == NavigationType.TERTIARY) {
if (songs.Count > 0) {
searchField.text = $"artist:{songs[selectedSongIndex].song.ArtistName}";
}
}
}

Expand Down Expand Up @@ -247,11 +257,11 @@ private void MoveView(int amount) {
UpdateSongViews();
}

private int FuzzySearch(SongInfo song) {
private int FuzzySearch(string text, SongInfo song) {
if (dropdown.value == 0) {
return Fuzz.Ratio(song.SongName, searchField.text);
return Fuzz.PartialRatio(song.SongName, text);
} else {
return Fuzz.Ratio(song.ArtistName, searchField.text);
return Fuzz.PartialRatio(song.ArtistName, text);
}
}

Expand Down Expand Up @@ -339,26 +349,43 @@ public void UpdateSearch() {
songs.Insert(0, new SongOrHeader {
header = ("Recommended Songs", $"{recommendedSongs.Count} random songs")
});
} else if (searchField.text.StartsWith("artist:")) {
// Search by artist
var artist = searchField.text[7..];
songs = SongLibrary.Songs
.Where(i => i.ArtistName.ToLower() == artist.ToLower())
.OrderBy(song => song.SongNameNoParen)
.Select(i => new SongOrHeader { song = i })
.ToList();
songs.Insert(0, new SongOrHeader { header = ($"{artist}'s Songs", $"{songs.Count} songs") });
} else {
// Fuzzy search!
var text = searchField.text.ToLower();
songs = SongLibrary.Songs
.Select(i => new { score = FuzzySearch(i), songInfo = i })
.Where(i => i.score > 55)
.OrderByDescending(i => i.score)
.Select(i => i.songInfo)
.Select(i => new SongOrHeader { song = i })
.ToList();
songs.Insert(0, new SongOrHeader { header = ("Searched Songs", $"{songs.Count} songs") });
// Split up args
var split = searchField.text.Split(';');
IEnumerable<SongInfo> songsOut = SongLibrary.Songs;

// Go through them all
bool fuzzySearched = false;
foreach (var arg in split) {
if (arg.StartsWith("artist:")) {
// Artist filter
var artist = arg[7..];
songsOut = SongLibrary.Songs
.Where(i => i.ArtistName.ToLower() == artist.ToLower());
} else if (arg.StartsWith("source:")) {
// Source filter
var source = arg[7..];
songsOut = SongLibrary.Songs
.Where(i => i.source.ToLower() == source.ToLower());
} else if (!fuzzySearched) {
// Fuzzy search
fuzzySearched = true;
songsOut = songsOut
.Select(i => new { score = FuzzySearch(arg, i), songInfo = i })
.Where(i => i.score > 55)
.OrderByDescending(i => i.score)
.Select(i => i.songInfo);
}
}

// Sort
if (!fuzzySearched) {
songsOut = songsOut.OrderBy(song => song.SongNameNoParen);
}

// Add header
songs = songsOut.Select(i => new SongOrHeader { song = i }).ToList();
songs.Insert(0, new SongOrHeader { header = ($"Filtered Songs", $"{songs.Count} songs") });
}

// Count songs
Expand All @@ -377,5 +404,14 @@ public void UpdateSearch() {
selectedSongIndex = 1;
UpdateSongViews();
}

public void Back() {
if (string.IsNullOrEmpty(searchField.text)) {
MainMenu.Instance.ShowMainMenu();
} else {
searchField.text = "";
UpdateSearch();
}
}
}
}

0 comments on commit df15d18

Please sign in to comment.