瀏覽代碼

Create page button.
Fix fast scroll button on hover glow.

Halsafar 4 年之前
父節點
當前提交
7012c9ab90
共有 2 個文件被更改,包括 34 次插入12 次删除
  1. 26 1
      SongBrowserPlugin/Internals/BeatSaberUI.cs
  2. 8 11
      SongBrowserPlugin/UI/Browser/SongBrowserUI.cs

+ 26 - 1
SongBrowserPlugin/Internals/BeatSaberUI.cs

@@ -1,4 +1,5 @@
-using HMUI;
+using BeatSaberMarkupLanguage.Components;
+using HMUI;
 using IPA.Utilities;
 using System;
 using System.Linq;
@@ -110,6 +111,30 @@ namespace SongBrowser.Internals
             return btn;
         }
 
+        public static Button CreatePageButton(String name, RectTransform parent, String buttonTemplate, Vector2 anchoredPosition, Vector2 sizeDelta, UnityAction onClick, Sprite icon)
+        {
+            Logger.Debug("CreatePageButton({0}, {1}, {2}, {3}, {4}", name, parent, buttonTemplate, anchoredPosition, sizeDelta);
+            Button btn = UnityEngine.Object.Instantiate(Resources.FindObjectsOfTypeAll<Button>().Last(x => (x.name == buttonTemplate)), parent, false);
+            btn.name = name;
+            btn.interactable = true;
+
+            (btn.transform as RectTransform).anchorMin = new Vector2(0.5f, 0.5f);
+            (btn.transform as RectTransform).anchorMax = new Vector2(0.5f, 0.5f);
+            (btn.transform as RectTransform).anchoredPosition = anchoredPosition;
+            (btn.transform as RectTransform).sizeDelta = sizeDelta;
+            (btn.transform as RectTransform).pivot = new Vector2(0.5f, 0.5f);
+
+            ButtonIconImage btnIcon = btn.gameObject.AddComponent<ButtonIconImage>();
+            btnIcon.image = btn.gameObject.GetComponentsInChildren<Image>(true).Where(x => x.gameObject.name == "Icon").FirstOrDefault();
+            btnIcon.image.sprite = icon;
+
+            btn.onClick.RemoveAllListeners();
+            if (onClick != null)
+                btn.onClick.AddListener(onClick);
+
+            return btn;
+        }
+
         /// <summary>
         /// Creates a copy of a template button and returns it.
         /// </summary>

+ 8 - 11
SongBrowserPlugin/UI/Browser/SongBrowserUI.cs

@@ -358,26 +358,23 @@ namespace SongBrowser.UI
         private void CreateFastPageButtons()
         {
             Logger.Debug("Creating fast scroll button...");
-            _pageUpFastButton = BeatSaberUI.CreateIconButton("PageUpFast",
-                _beatUi.LevelCollectionNavigationController.transform as RectTransform, "PracticeButton",
-                new Vector2(1f, 24f),
-                new Vector2(10f, 10f),
+            _pageUpFastButton = BeatSaberUI.CreatePageButton("PageUpFast",
+                _beatUi.LevelCollectionNavigationController.transform as RectTransform, "UpButton",
+                new Vector2(2.0f, 24f),
+                new Vector2(8f, 8f),
                 delegate ()
                 {
                     this.JumpSongList(-1, SEGMENT_PERCENT);
                 }, Base64Sprites.DoubleArrow);
-            _pageUpFastButton.SetButtonBackgroundActive(false);
-            (_pageUpFastButton.transform as RectTransform).Rotate(new Vector3(0, 0, 180));
 
-            _pageDownFastButton = BeatSaberUI.CreateIconButton("PageDownFast",
-                _beatUi.LevelCollectionNavigationController.transform as RectTransform, "PracticeButton",
-                new Vector2(1f, -24f),
-                new Vector2(10f, 10f),
+            _pageDownFastButton = BeatSaberUI.CreatePageButton("PageDownFast",
+                _beatUi.LevelCollectionNavigationController.transform as RectTransform, "DownButton",
+                new Vector2(2.0f, -24f),
+                new Vector2(8f, 8f),
                 delegate ()
                 {
                     this.JumpSongList(1, SEGMENT_PERCENT);
                 }, Base64Sprites.DoubleArrow);
-            _pageDownFastButton.SetButtonBackgroundActive(false);
         }
 
         /// <summary>