Skip to content

Commit

Permalink
Changed some of the new localization method naming to favour to local…
Browse files Browse the repository at this point in the history
…ized version
  • Loading branch information
EliteAsian123 committed Jul 29, 2024
1 parent eff1609 commit 8191357
Showing 1 changed file with 34 additions and 20 deletions.
54 changes: 34 additions & 20 deletions Assets/Script/Menu/MusicLibrary/PopupMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,25 +99,25 @@ private void CreateMainMenu()
{
SetHeader(null);

CreateLocalizedItem("RandomSong", () =>
CreateItem("RandomSong", () =>
{
_musicLibrary.SelectRandomSong();
gameObject.SetActive(false);
});

CreateLocalizedItem("BackToTop", () =>
CreateItem("BackToTop", () =>
{
_musicLibrary.SelectedIndex = 0;
gameObject.SetActive(false);
});

CreateLocalizedItem("SortBy", SettingsManager.Settings.LibrarySort.ToLocalizedName(), () =>
CreateItem("SortBy", SettingsManager.Settings.LibrarySort.ToLocalizedName(), () =>
{
_menuState = State.SortSelect;
UpdateForState();
});

CreateLocalizedItem("GoToSection", () =>
CreateItem("GoToSection", () =>
{
_menuState = State.GoToSection;
UpdateForState();
Expand All @@ -131,7 +131,7 @@ private void CreateMainMenu()
{
if (!favoriteInfo.IsFavorited)
{
CreateLocalizedItem("AddToFavorites", () =>
CreateItem("AddToFavorites", () =>
{
viewType.FavoriteClick();
_musicLibrary.RefreshViewsObjects();
Expand All @@ -141,7 +141,7 @@ private void CreateMainMenu()
}
else
{
CreateLocalizedItem("RemoveFromFavorites", () =>
CreateItem("RemoveFromFavorites", () =>
{
viewType.FavoriteClick();
_musicLibrary.RefreshViewsObjects();
Expand All @@ -157,14 +157,14 @@ private void CreateMainMenu()
{
var song = songViewType.SongEntry;

CreateLocalizedItem("ViewSongFolder", () =>
CreateItem("ViewSongFolder", () =>
{
FileExplorerHelper.OpenFolder(song.Directory);

gameObject.SetActive(false);
});

CreateLocalizedItem("CopySongChecksum", () =>
CreateItem("CopySongChecksum", () =>
{
GUIUtility.systemCopyBuffer = song.Hash.ToString();

Expand All @@ -181,12 +181,16 @@ private void CreateSortSelect()
{
// Skip theses because they don't make sense
if (sort == SortAttribute.Unspecified)
{
continue;
}

if (sort >= SortAttribute.Instrument)
{
break;
}

CreateItem(sort.ToLocalizedName(), () =>
CreateItemUnlocalized(sort.ToLocalizedName(), () =>
{
_musicLibrary.ChangeSort(sort);
gameObject.SetActive(false);
Expand All @@ -198,7 +202,7 @@ private void CreateSortSelect()
if (SongContainer.HasInstrument(instrument))
{
var attribute = instrument.ToSortAttribute();
CreateItem(attribute.ToLocalizedName(), () =>
CreateItemUnlocalized(attribute.ToLocalizedName(), () =>
{
_musicLibrary.ChangeSort(attribute);
gameObject.SetActive(false);
Expand All @@ -216,11 +220,13 @@ is SortAttribute.Artist
or SortAttribute.Album
or SortAttribute.Artist_Album)
{

foreach (var (header, index) in _musicLibrary.GetSections()
.GroupBy(x => SortString.RemoveArticle(((SortHeaderViewType) x.Item1).HeaderText)[0].ToAsciiUpper())
.GroupBy(x => GetGroupChar(x.Item1).ToAsciiUpper())
.Select(g => g.First()))
{
CreateItem(SortString.RemoveArticle(((SortHeaderViewType) header).HeaderText)[0].ToString(), () =>

CreateItemUnlocalized(GetGroupChar(header).ToString(), () =>
{
_musicLibrary.SelectedIndex = index;
gameObject.SetActive(false);
Expand All @@ -231,20 +237,27 @@ or SortAttribute.Album
{
foreach (var (header, index) in _musicLibrary.GetSections())
{
CreateItem(((SortHeaderViewType) header).HeaderText, () =>
CreateItemUnlocalized(((SortHeaderViewType) header).HeaderText, () =>
{
_musicLibrary.SelectedIndex = index;
gameObject.SetActive(false);
});
}
}

return;

static char GetGroupChar(ViewType header)
{
return SortString.RemoveArticle(((SortHeaderViewType) header).HeaderText)[0];
}
}

private void SetLocalizedHeader(string localizeKey)
{
SetHeader(Localize.Key("Menu.MusicLibrary.Popup.Header", localizeKey));
}

private void SetHeader(string text)
{
if (string.IsNullOrEmpty(text))
Expand All @@ -258,18 +271,19 @@ private void SetHeader(string text)
}
}

private void CreateLocalizedItem(string localizeKey, UnityAction a)
private void CreateItem(string localizeKey, UnityAction a)
{
CreateItem(Localize.Key("Menu.MusicLibrary.Popup.Item", localizeKey), a);
var localized = Localize.Key("Menu.MusicLibrary.Popup.Item", localizeKey);
CreateItemUnlocalized(localized, a);
}


private void CreateLocalizedItem(string localizeKey, string formatArg, UnityAction a)
private void CreateItem(string localizeKey, string formatArg, UnityAction a)
{
CreateItem(Localize.KeyFormat(("Menu.MusicLibrary.Popup.Item", localizeKey), formatArg), a);
var localized = Localize.KeyFormat(("Menu.MusicLibrary.Popup.Item", localizeKey), formatArg);
CreateItemUnlocalized(localized, a);
}

private void CreateItem(string body, UnityAction a)
private void CreateItemUnlocalized(string body, UnityAction a)
{
var btn = Instantiate(_menuItemPrefab, _container);
btn.Initialize(body, a);
Expand Down

0 comments on commit 8191357

Please sign in to comment.