|
@@ -35,74 +35,49 @@ namespace SongBrowser.Internals
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
- /// Clone a Unity Button into a Button we control.
|
|
|
|
- /// </summary>
|
|
|
|
- /// <param name="parent"></param>
|
|
|
|
- /// <param name="buttonTemplate"></param>
|
|
|
|
- /// <param name="buttonInstance"></param>
|
|
|
|
- /// <returns></returns>
|
|
|
|
- static public Button CreateUIButton(RectTransform parent, Button buttonTemplate)
|
|
|
|
- {
|
|
|
|
- Button btn = UnityEngine.Object.Instantiate(buttonTemplate, parent, false);
|
|
|
|
- UnityEngine.Object.DestroyImmediate(btn.GetComponent<SignalOnUIButtonClick>());
|
|
|
|
- btn.onClick = new Button.ButtonClickedEvent();
|
|
|
|
- btn.name = "CustomUIButton";
|
|
|
|
-
|
|
|
|
- return btn;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /// <summary>
|
|
|
|
/// Create an icon button, simple.
|
|
/// Create an icon button, simple.
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <param name="parent"></param>
|
|
/// <param name="parent"></param>
|
|
/// <param name="buttonTemplate"></param>
|
|
/// <param name="buttonTemplate"></param>
|
|
/// <param name="iconSprite"></param>
|
|
/// <param name="iconSprite"></param>
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
- public static Button CreateIconButton(RectTransform parent, Button buttonTemplate, Sprite iconSprite)
|
|
|
|
|
|
+ public static Button CreateIconButton(String name, RectTransform parent, String buttonTemplate, Vector2 anchoredPosition, Vector2 sizeDelta, UnityAction onClick, Sprite icon)
|
|
{
|
|
{
|
|
- Button newButton = BeatSaberUI.CreateUIButton(parent, buttonTemplate);
|
|
|
|
- newButton.interactable = true;
|
|
|
|
-
|
|
|
|
- RectTransform textRect = newButton.GetComponentsInChildren<RectTransform>(true).FirstOrDefault(c => c.name == "Text");
|
|
|
|
- if (textRect != null)
|
|
|
|
|
|
+ Logger.Debug("CreateIconButton({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;
|
|
|
|
+
|
|
|
|
+ UnityEngine.Object.Destroy(btn.GetComponent<HoverHint>());
|
|
|
|
+ GameObject.Destroy(btn.GetComponent<LocalizedHoverHint>());
|
|
|
|
+ btn.gameObject.AddComponent<BeatSaberMarkupLanguage.Components.ExternalComponents>().components.Add(btn.GetComponentsInChildren<LayoutGroup>().First(x => x.name == "Content"));
|
|
|
|
+
|
|
|
|
+ Transform contentTransform = btn.transform.Find("Content");
|
|
|
|
+ GameObject.Destroy(contentTransform.Find("Text").gameObject);
|
|
|
|
+ Image iconImage = new GameObject("Icon").AddComponent<ImageView>();
|
|
|
|
+ iconImage.material = BeatSaberMarkupLanguage.Utilities.ImageResources.NoGlowMat;
|
|
|
|
+ iconImage.rectTransform.SetParent(contentTransform, false);
|
|
|
|
+ iconImage.rectTransform.sizeDelta = new Vector2(10f, 10f);
|
|
|
|
+ iconImage.sprite = icon;
|
|
|
|
+ iconImage.preserveAspect = true;
|
|
|
|
+ if (iconImage != null)
|
|
{
|
|
{
|
|
- UnityEngine.Object.Destroy(textRect.gameObject);
|
|
|
|
|
|
+ BeatSaberMarkupLanguage.Components.ButtonIconImage btnIcon = btn.gameObject.AddComponent<BeatSaberMarkupLanguage.Components.ButtonIconImage>();
|
|
|
|
+ btnIcon.image = iconImage;
|
|
}
|
|
}
|
|
|
|
|
|
- newButton.SetButtonIcon(iconSprite);
|
|
|
|
- newButton.onClick.RemoveAllListeners();
|
|
|
|
|
|
+ GameObject.Destroy(btn.transform.Find("Content").GetComponent<LayoutElement>());
|
|
|
|
+ btn.GetComponentsInChildren<RectTransform>().First(x => x.name == "Underline").gameObject.SetActive(false);
|
|
|
|
|
|
- return newButton;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /// <summary>
|
|
|
|
- /// Creates a copy of a template button and returns it.
|
|
|
|
- /// </summary>
|
|
|
|
- /// <param name="parent">The transform to parent the button to.</param>
|
|
|
|
- /// <param name="buttonTemplate">The name of the button to make a copy of. Example: "QuitButton", "PlayButton", etc.</param>
|
|
|
|
- /// <param name="anchoredPosition">The position the button should be anchored to.</param>
|
|
|
|
- /// <param name="sizeDelta">The size of the buttons RectTransform.</param>
|
|
|
|
- /// <param name="onClick">Callback for when the button is pressed.</param>
|
|
|
|
- /// <param name="buttonText">The text that should be shown on the button.</param>
|
|
|
|
- /// <param name="icon">The icon that should be shown on the button.</param>
|
|
|
|
- /// <returns>The newly created button.</returns>
|
|
|
|
- public static Button CreateUIButton(RectTransform parent, string buttonTemplate, Vector2 anchoredPosition, Vector2 sizeDelta, UnityAction onClick = null, string buttonText = "BUTTON", Sprite icon = null)
|
|
|
|
- {
|
|
|
|
- Button btn = UnityEngine.Object.Instantiate(Resources.FindObjectsOfTypeAll<Button>().Last(x => (x.name == buttonTemplate)), parent, false);
|
|
|
|
- btn.onClick = new Button.ButtonClickedEvent();
|
|
|
|
- if (onClick != null)
|
|
|
|
- btn.onClick.AddListener(onClick);
|
|
|
|
- btn.name = "CustomUIButton";
|
|
|
|
|
|
+ ContentSizeFitter buttonSizeFitter = btn.gameObject.AddComponent<ContentSizeFitter>();
|
|
|
|
+ buttonSizeFitter.verticalFit = ContentSizeFitter.FitMode.Unconstrained;
|
|
|
|
+ buttonSizeFitter.horizontalFit = ContentSizeFitter.FitMode.Unconstrained;
|
|
|
|
|
|
(btn.transform as RectTransform).anchorMin = new Vector2(0.5f, 0.5f);
|
|
(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).anchorMax = new Vector2(0.5f, 0.5f);
|
|
(btn.transform as RectTransform).anchoredPosition = anchoredPosition;
|
|
(btn.transform as RectTransform).anchoredPosition = anchoredPosition;
|
|
(btn.transform as RectTransform).sizeDelta = sizeDelta;
|
|
(btn.transform as RectTransform).sizeDelta = sizeDelta;
|
|
|
|
|
|
- btn.SetButtonText(buttonText);
|
|
|
|
- if (icon != null)
|
|
|
|
- btn.SetButtonIcon(icon);
|
|
|
|
-
|
|
|
|
return btn;
|
|
return btn;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -112,81 +87,61 @@ namespace SongBrowser.Internals
|
|
/// <param name="parent">The transform to parent the button to.</param>
|
|
/// <param name="parent">The transform to parent the button to.</param>
|
|
/// <param name="buttonTemplate">The name of the button to make a copy of. Example: "QuitButton", "PlayButton", etc.</param>
|
|
/// <param name="buttonTemplate">The name of the button to make a copy of. Example: "QuitButton", "PlayButton", etc.</param>
|
|
/// <param name="anchoredPosition">The position the button should be anchored to.</param>
|
|
/// <param name="anchoredPosition">The position the button should be anchored to.</param>
|
|
|
|
+ /// <param name="sizeDelta">The size of the buttons RectTransform.</param>
|
|
/// <param name="onClick">Callback for when the button is pressed.</param>
|
|
/// <param name="onClick">Callback for when the button is pressed.</param>
|
|
/// <param name="buttonText">The text that should be shown on the button.</param>
|
|
/// <param name="buttonText">The text that should be shown on the button.</param>
|
|
/// <param name="icon">The icon that should be shown on the button.</param>
|
|
/// <param name="icon">The icon that should be shown on the button.</param>
|
|
/// <returns>The newly created button.</returns>
|
|
/// <returns>The newly created button.</returns>
|
|
- public static Button CreateUIButton(RectTransform parent, string buttonTemplate, Vector2 anchoredPosition, UnityAction onClick = null, string buttonText = "BUTTON", Sprite icon = null)
|
|
|
|
|
|
+ public static Button CreateUIButton(String name, RectTransform parent, string buttonTemplate, Vector2 anchoredPosition, Vector2 sizeDelta, UnityAction onClick = null, string buttonText = "BUTTON", Sprite icon = null)
|
|
{
|
|
{
|
|
|
|
+ Logger.Debug("CreateUIButton({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);
|
|
Button btn = UnityEngine.Object.Instantiate(Resources.FindObjectsOfTypeAll<Button>().Last(x => (x.name == buttonTemplate)), parent, false);
|
|
- btn.onClick = new Button.ButtonClickedEvent();
|
|
|
|
- if (onClick != null)
|
|
|
|
- btn.onClick.AddListener(onClick);
|
|
|
|
- btn.name = "CustomUIButton";
|
|
|
|
|
|
+ btn.gameObject.SetActive(true);
|
|
|
|
+ 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;
|
|
|
|
|
|
+ Polyglot.LocalizedTextMeshProUGUI localizer = btn.GetComponentInChildren<Polyglot.LocalizedTextMeshProUGUI>();
|
|
|
|
+ if (localizer != null)
|
|
|
|
+ {
|
|
|
|
+ GameObject.Destroy(localizer);
|
|
|
|
+ }
|
|
|
|
+ BeatSaberMarkupLanguage.Components.ExternalComponents externalComponents = btn.gameObject.AddComponent<BeatSaberMarkupLanguage.Components.ExternalComponents>();
|
|
|
|
+ TextMeshProUGUI textMesh = btn.GetComponentInChildren<TextMeshProUGUI>();
|
|
|
|
+ textMesh.richText = true;
|
|
|
|
+ externalComponents.components.Add(textMesh);
|
|
|
|
|
|
- btn.SetButtonText(buttonText);
|
|
|
|
- if (icon != null)
|
|
|
|
- btn.SetButtonIcon(icon);
|
|
|
|
|
|
+ var f = btn.transform.Find("Content").GetComponent<LayoutElement>();
|
|
|
|
+ if (f != null)
|
|
|
|
+ {
|
|
|
|
+ GameObject.Destroy(f);
|
|
|
|
+ }
|
|
|
|
|
|
- return btn;
|
|
|
|
- }
|
|
|
|
|
|
+ ContentSizeFitter buttonSizeFitter = btn.gameObject.AddComponent<ContentSizeFitter>();
|
|
|
|
+ buttonSizeFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
|
|
|
|
+ buttonSizeFitter.horizontalFit = ContentSizeFitter.FitMode.Unconstrained;
|
|
|
|
|
|
|
|
+ LayoutGroup stackLayoutGroup = btn.GetComponentInChildren<LayoutGroup>();
|
|
|
|
+ if (stackLayoutGroup != null)
|
|
|
|
+ {
|
|
|
|
+ externalComponents.components.Add(stackLayoutGroup);
|
|
|
|
+ }
|
|
|
|
|
|
- /// <summary>
|
|
|
|
- /// Creates a copy of a template button and returns it.
|
|
|
|
- /// </summary>
|
|
|
|
- /// <param name="parent">The transform to parent the button to.</param>
|
|
|
|
- /// <param name="buttonTemplate">The name of the button to make a copy of. Example: "QuitButton", "PlayButton", etc.</param>
|
|
|
|
- /// <param name="onClick">Callback for when the button is pressed.</param>
|
|
|
|
- /// <param name="buttonText">The text that should be shown on the button.</param>
|
|
|
|
- /// <param name="icon">The icon that should be shown on the button.</param>
|
|
|
|
- /// <returns>The newly created button.</returns>
|
|
|
|
- public static Button CreateUIButton(RectTransform parent, string buttonTemplate, UnityAction onClick = null, string buttonText = "BUTTON", Sprite icon = null)
|
|
|
|
- {
|
|
|
|
- Button btn = UnityEngine.Object.Instantiate(Resources.FindObjectsOfTypeAll<Button>().Last(x => (x.name == buttonTemplate)), parent, false);
|
|
|
|
- btn.onClick = new Button.ButtonClickedEvent();
|
|
|
|
|
|
+ //btn.onClick = new Button.ButtonClickedEvent();
|
|
|
|
+ btn.onClick.RemoveAllListeners();
|
|
if (onClick != null)
|
|
if (onClick != null)
|
|
btn.onClick.AddListener(onClick);
|
|
btn.onClick.AddListener(onClick);
|
|
- btn.name = "CustomUIButton";
|
|
|
|
|
|
+
|
|
|
|
|
|
(btn.transform as RectTransform).anchorMin = new Vector2(0.5f, 0.5f);
|
|
(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).anchorMax = new Vector2(0.5f, 0.5f);
|
|
|
|
+ (btn.transform as RectTransform).anchoredPosition = anchoredPosition;
|
|
|
|
+ (btn.transform as RectTransform).sizeDelta = sizeDelta;
|
|
|
|
+
|
|
btn.SetButtonText(buttonText);
|
|
btn.SetButtonText(buttonText);
|
|
|
|
+
|
|
if (icon != null)
|
|
if (icon != null)
|
|
btn.SetButtonIcon(icon);
|
|
btn.SetButtonIcon(icon);
|
|
- return btn;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /// <summary>
|
|
|
|
- /// Creates a copy of a back button.
|
|
|
|
- /// </summary>
|
|
|
|
- /// <param name="parent">The transform to parent the new button to.</param>
|
|
|
|
- /// <param name="onClick">Callback for when the button is pressed.</param>
|
|
|
|
- /// <returns>The newly created back button.</returns>
|
|
|
|
- public static Button CreateBackButton(RectTransform parent, UnityAction onClick = null)
|
|
|
|
- {
|
|
|
|
- if (_backButtonInstance == null)
|
|
|
|
- {
|
|
|
|
- try
|
|
|
|
- {
|
|
|
|
- _backButtonInstance = Resources.FindObjectsOfTypeAll<Button>().First(x => (x.name == "BackArrowButton"));
|
|
|
|
- }
|
|
|
|
- catch
|
|
|
|
- {
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- Button btn = UnityEngine.GameObject.Instantiate(_backButtonInstance, parent, false);
|
|
|
|
- btn.onClick = new Button.ButtonClickedEvent();
|
|
|
|
- if (onClick != null)
|
|
|
|
- btn.onClick.AddListener(onClick);
|
|
|
|
- btn.name = "CustomUIButton";
|
|
|
|
-
|
|
|
|
|
|
+
|
|
return btn;
|
|
return btn;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -275,34 +230,6 @@ namespace SongBrowser.Internals
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
- /// Adjust button border.
|
|
|
|
- /// </summary>
|
|
|
|
- /// <param name="button"></param>
|
|
|
|
- /// <param name="color"></param>
|
|
|
|
- static public void SetButtonBorder(Button button, Color color)
|
|
|
|
- {
|
|
|
|
- Image img = button.GetComponentsInChildren<Image>().FirstOrDefault(x => x.name == "Stroke");
|
|
|
|
- if (img != null)
|
|
|
|
- {
|
|
|
|
- img.color = color;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /// <summary>
|
|
|
|
- /// Adjust button border.
|
|
|
|
- /// </summary>
|
|
|
|
- /// <param name="button"></param>
|
|
|
|
- /// <param name="color"></param>
|
|
|
|
- static public void SetButtonBorderActive(Button button, bool active)
|
|
|
|
- {
|
|
|
|
- Image img = button.GetComponentsInChildren<Image>().FirstOrDefault(x => x.name == "Stroke");
|
|
|
|
- if (img != null)
|
|
|
|
- {
|
|
|
|
- img.gameObject.SetActive(active);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /// <summary>
|
|
|
|
/// Find and adjust a stat panel item text fields.
|
|
/// Find and adjust a stat panel item text fields.
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <param name="rect"></param>
|
|
/// <param name="rect"></param>
|