Explorar o código

Minor Adjustments:
- UI elements text size is small
- UI elements are smaller
- UI elements are centered and should not cover any of the normal in-game elements
- Small performance increase.

Stephen Damm %!s(int64=6) %!d(string=hai) anos
pai
achega
b1085ae2f5
Modificáronse 2 ficheiros con 50 adicións e 50 borrados
  1. 30 30
      SongBrowserPlugin/SongBrowser.cs
  2. 20 20
      SongBrowserPlugin/UIBuilder.cs

+ 30 - 30
SongBrowserPlugin/SongBrowser.cs

@@ -30,7 +30,7 @@ namespace SongBrowserPlugin
         private SongListViewController _songListViewController;
         private MainMenuViewController _mainMenuViewController;
 
-        private List<Sprite> _icons = new List<Sprite>();
+        private Dictionary<String, Sprite> _icons;
 
         private Button _buttonInstance;
 
@@ -39,8 +39,6 @@ namespace SongBrowserPlugin
         private Button _addFavoriteButton;
         private String _addFavoriteButtonText = null;
     
-        private RectTransform _songSelectRectTransform;
-
         private SongBrowserSettings _settings;
 
         /// <summary>
@@ -77,9 +75,14 @@ namespace SongBrowserPlugin
         /// </summary>
         public void AcquireUIElements()
         {
+            _icons = new Dictionary<String, Sprite>();
             foreach (Sprite sprite in Resources.FindObjectsOfTypeAll<Sprite>())
             {
-                _icons.Add(sprite);
+                if (_icons.ContainsKey(sprite.name))
+                {
+                    continue;
+                }
+                _icons.Add(sprite.name, sprite);
             }
 
             try
@@ -89,7 +92,6 @@ namespace SongBrowserPlugin
                 _songSelectionMasterView = Resources.FindObjectsOfTypeAll<SongSelectionMasterViewController>().First();                
                 _songDetailViewController = Resources.FindObjectsOfTypeAll<SongDetailViewController>().First();
                 _songListViewController = Resources.FindObjectsOfTypeAll<SongListViewController>().First();
-                _songSelectRectTransform = _songListViewController.transform as RectTransform;
             }
             catch (Exception e)
             {
@@ -107,21 +109,23 @@ namespace SongBrowserPlugin
             // _icons.ForEach(i => Console.WriteLine(i.ToString()));
 
             try
-            {
+            {                               
+                RectTransform rect = _songSelectionMasterView.transform as RectTransform;
+
                 // Create Sorting Songs By-Buttons
-                
-                RectTransform rect = _songDetailViewController.transform as RectTransform;
-                _sortButtonGroup = new List<SongSortButton>();
-                _sortButtonGroup.Add(CreateSortButton(rect, "PlayButton", "Fav", "AllDirectionsIcon", 30f, 75f, 15f, 8f, SongSortMode.Favorites));
-                _sortButtonGroup.Add(CreateSortButton(rect, "PlayButton", "Def", "AllDirectionsIcon", 15f, 75f, 15f, 8f, SongSortMode.Default));
-                _sortButtonGroup.Add(CreateSortButton(rect, "PlayButton", "Org", "AllDirectionsIcon", 0f, 75f, 15f, 8f, SongSortMode.Original));
-                _sortButtonGroup.Add(CreateSortButton(rect, "PlayButton", "New", "AllDirectionsIcon", -15f, 75f, 15f, 10f, SongSortMode.Newest));
+                _sortButtonGroup = new List<SongSortButton>
+                {
+                    CreateSortButton(rect, "PlayButton", "Fav", 3, "AllDirectionsIcon", 30f, 77.5f, 15f, 5f, SongSortMode.Favorites),
+                    CreateSortButton(rect, "PlayButton", "Def", 3, "AllDirectionsIcon", 15f, 77.5f, 15f, 5f, SongSortMode.Default),
+                    CreateSortButton(rect, "PlayButton", "Org", 3, "AllDirectionsIcon", 0f, 77.5f, 15f, 5f, SongSortMode.Original),
+                    CreateSortButton(rect, "PlayButton", "New", 3, "AllDirectionsIcon", -15f, 77.5f, 15f, 5f, SongSortMode.Newest)
+                };
 
                 // Creaate Add to Favorites Button
                 RectTransform transform = _songDetailViewController.transform as RectTransform;
                 _addFavoriteButton = UIBuilder.CreateUIButton(transform, "QuitButton", _buttonInstance);
-                (_addFavoriteButton.transform as RectTransform).anchoredPosition = new Vector2(40f, 0f);
-                (_addFavoriteButton.transform as RectTransform).sizeDelta = new Vector2(25f, 10f);
+                (_addFavoriteButton.transform as RectTransform).anchoredPosition = new Vector2(45f, 5f);
+                (_addFavoriteButton.transform as RectTransform).sizeDelta = new Vector2(10f, 10f);                
 
                 if (_addFavoriteButtonText == null)
                 {
@@ -130,7 +134,9 @@ namespace SongBrowserPlugin
                 }
                 
                 UIBuilder.SetButtonText(ref _addFavoriteButton, _addFavoriteButtonText);
-                UIBuilder.SetButtonIcon(ref _addFavoriteButton, _icons.First(x => (x.name == "AllDirectionsIcon")));
+                //UIBuilder.SetButtonIcon(ref _addFavoriteButton, _icons["AllDirectionsIcon"]);
+                UIBuilder.SetButtonTextSize(ref _addFavoriteButton, 3);
+                UIBuilder.SetButtonIconEnabled(ref _addFavoriteButton, false);
 
                 _addFavoriteButton.onClick.RemoveAllListeners();
                 _addFavoriteButton.onClick.AddListener(delegate () {                    
@@ -157,7 +163,7 @@ namespace SongBrowserPlugin
         /// <param name="w"></param>
         /// <param name="h"></param>
         /// <param name="action"></param>
-        private SongSortButton CreateSortButton(RectTransform rect, string templateButtonName, string buttonText, string iconName, float x, float y, float w, float h, SongSortMode sortMode)
+        private SongSortButton CreateSortButton(RectTransform rect, string templateButtonName, string buttonText, float fontSize, string iconName, float x, float y, float w, float h, SongSortMode sortMode)
         {
             SongSortButton sortButton = new SongSortButton();
             Button newButton = UIBuilder.CreateUIButton(rect, templateButtonName, _buttonInstance);
@@ -168,12 +174,14 @@ namespace SongBrowserPlugin
 
             UIBuilder.SetButtonText(ref newButton, buttonText);
             //UIBuilder.SetButtonIconEnabled(ref _originalButton, false);
-            UIBuilder.SetButtonIcon(ref newButton, _icons.First(icon => (icon.name == iconName)));
+            UIBuilder.SetButtonIcon(ref newButton, _icons[iconName]);
+            UIBuilder.SetButtonTextSize(ref newButton, fontSize);
 
             newButton.onClick.RemoveAllListeners();
             newButton.onClick.AddListener(delegate () {
                 _log.Debug("Sort button - {0} - pressed.", sortMode.ToString());
                 _settings.sortMode = sortMode;
+                _settings.Save();
                 List<LevelStaticData> sortedSongList = ProcessSongList();
                 RefreshSongList(sortedSongList);
             });
@@ -201,10 +209,6 @@ namespace SongBrowserPlugin
                     AcquireUIElements();
                     CreateUI();
                                                             
-                    //SongListTableView tableView = _songListViewController.GetComponentInChildren<SongListTableView>();
-                    //MainMenuViewController _mainMenuViewController = Resources.FindObjectsOfTypeAll<MainMenuViewController>().First();
-                    //tableView.songListTableViewDidSelectRow += TableView_songListTableViewDidSelectRow;
-
                     _songListViewController.didSelectSongEvent += OnDidSelectSongEvent;
                 }
             }
@@ -260,7 +264,6 @@ namespace SongBrowserPlugin
             }
 
             int selectedIndex = _songSelectionMasterView.GetSelectedSongIndex();
-            //_log.Debug("Selected song index: " + selectedIndex);
             if (selectedIndex < 0)
             {
                 return null;
@@ -336,7 +339,7 @@ namespace SongBrowserPlugin
         }
 
         /// <summary>
-        /// Helper to overwrite the existing song list and refresh it.
+        /// Helper to overwrite the existing song list.
         /// </summary>
         /// <param name="newSongList"></param>
         public void OverwriteSongList(List<LevelStaticData> newSongList)
@@ -368,7 +371,7 @@ namespace SongBrowserPlugin
             weights["Level8"] = 1;
 
             List<LevelStaticData> songList = AcquireSongList();
-            //songList.ForEach(x => _log.Debug(x.levelId));
+
             switch(_settings.sortMode)
             {
                 case SongSortMode.Favorites:
@@ -377,7 +380,8 @@ namespace SongBrowserPlugin
                         .AsQueryable()
                         .OrderBy(x => x.authorName)
                         .OrderBy(x => x.songName)
-                        .OrderBy(x => _settings.favorites.Contains(x.levelId) == false).ThenBy(x => x.songName)
+                        .OrderBy(x => _settings.favorites.Contains(x.levelId) == false)
+                        .ThenBy(x => x.songName)
                         .ToList();
                     break;
                 case SongSortMode.Original:
@@ -396,8 +400,6 @@ namespace SongBrowserPlugin
                         var customSongInfos = ReflectionUtil.InvokeMethod<SongLoaderPlugin.SongLoader>(SongLoaderPlugin.SongLoader.Instance, "RetrieveAllSongs", null) as List<SongLoaderPlugin.CustomSongInfo>;
                         var levelIdToCustomSongInfo = customSongInfos.ToDictionary(x => x.GetIdentifier(), x => x);
 
-                        //customSongInfos.ForEach(x => _log.Debug("{0} @ {1}", x.path, File.GetLastWriteTimeUtc(levelIdToCustomSongInfo[x.levelId].path)));
-                        
                         songList = songList
                             .AsQueryable()
                             .OrderBy(x => weights.ContainsKey(x.levelId) ? weights[x.levelId] : 0)
@@ -418,8 +420,6 @@ namespace SongBrowserPlugin
                     break;
             }
 
-            //songList.ForEach(x => _log.Debug(x.songName));
-
             OverwriteSongList(songList);
 
             return songList;

+ 20 - 20
SongBrowserPlugin/UIBuilder.cs

@@ -7,9 +7,9 @@ namespace SongBrowserPlugin
 {
     public static class UIBuilder
     {
-        static public Button CreateUIButton(RectTransform parent, string buttonTemplate, Button _buttonInstance)
+        static public Button CreateUIButton(RectTransform parent, string buttonTemplate, Button buttonInstance)
         {
-            if (_buttonInstance == null)
+            if (buttonInstance == null)
             {
                 return null;
             }
@@ -37,56 +37,56 @@ namespace SongBrowserPlugin
             return textMesh;
         }
 
-        static public void SetButtonText(ref Button _button, string _text)
+        static public void SetButtonText(ref Button button, string text)
         {
-            if (_button.GetComponentInChildren<TextMeshProUGUI>() != null)
+            if (button.GetComponentInChildren<TextMeshProUGUI>() != null)
             {
 
-                _button.GetComponentInChildren<TextMeshProUGUI>().text = _text;
+                button.GetComponentInChildren<TextMeshProUGUI>().text = text;
             }
 
         }
 
-        static public void SetButtonTextSize(ref Button _button, float _fontSize)
+        static public void SetButtonTextSize(ref Button button, float fontSize)
         {
-            if (_button.GetComponentInChildren<TextMeshProUGUI>() != null)
+            if (button.GetComponentInChildren<TextMeshProUGUI>() != null)
             {
-                _button.GetComponentInChildren<TextMeshProUGUI>().fontSize = _fontSize;
+                button.GetComponentInChildren<TextMeshProUGUI>().fontSize = fontSize;
             }
 
 
         }
 
-        static public void SetButtonIcon(ref Button _button, Sprite _icon)
+        static public void SetButtonIcon(ref Button button, Sprite icon)
         {
-            if (_button.GetComponentsInChildren<UnityEngine.UI.Image>().Count() > 1)
+            if (button.GetComponentsInChildren<UnityEngine.UI.Image>().Count() > 1)
             {
-                _button.GetComponentsInChildren<UnityEngine.UI.Image>()[1].sprite = _icon;
+                button.GetComponentsInChildren<UnityEngine.UI.Image>()[1].sprite = icon;
             }            
         }
 
-        static public void SetButtonIconEnabled(ref Button _button, bool enabled)
+        static public void SetButtonIconEnabled(ref Button button, bool enabled)
         {
-            if (_button.GetComponentsInChildren<UnityEngine.UI.Image>().Count() > 1)
+            if (button.GetComponentsInChildren<UnityEngine.UI.Image>().Count() > 1)
             {
-                _button.GetComponentsInChildren<UnityEngine.UI.Image>()[1].enabled = enabled;
+                button.GetComponentsInChildren<UnityEngine.UI.Image>()[1].enabled = enabled;
             }
         }
 
-        static public void SetButtonBackground(ref Button _button, Sprite _background)
+        static public void SetButtonBackground(ref Button button, Sprite background)
         {
-            if (_button.GetComponentsInChildren<Image>().Any())
+            if (button.GetComponentsInChildren<Image>().Any())
             {
-                _button.GetComponentsInChildren<UnityEngine.UI.Image>()[0].sprite = _background;
+                button.GetComponentsInChildren<UnityEngine.UI.Image>()[0].sprite = background;
             }
 
         }
 
-        static public void SetButtonBorder(ref Button _button, Color color)
+        static public void SetButtonBorder(ref Button button, Color color)
         {
-            if (_button.GetComponentsInChildren<Image>().Any())
+            if (button.GetComponentsInChildren<Image>().Any())
             {
-                _button.GetComponentsInChildren<UnityEngine.UI.Image>()[0].color = color;
+                button.GetComponentsInChildren<UnityEngine.UI.Image>()[0].color = color;
             }
         }
     }