Skip to content
This repository was archived by the owner on Jan 24, 2023. It is now read-only.

Commit 9d67f2d

Browse files
committed
Added ability to add an empty button with our without a sprite.
1 parent 7ba01a0 commit 9d67f2d

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

UI/QuickMenu/ReMenuButton.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,17 @@ public bool Interactable
4646
}
4747
}
4848

49+
public Image Background { get; }
50+
4951
public ReMenuButton(string text, string tooltip, Action onClick, Transform parent, Sprite sprite = null, bool resizeTextNoSprite = true) : base(ButtonPrefab, parent,
5052
$"Button_{text}")
5153
{
5254
_text = GameObject.GetComponentInChildren<TextMeshProUGUI>();
5355
_text.text = text;
5456
_text.richText = true;
57+
58+
Background = RectTransform.Find("Background").GetComponent<Image>();
59+
5560
if (sprite == null)
5661
{
5762
if (resizeTextNoSprite)
@@ -63,7 +68,7 @@ public ReMenuButton(string text, string tooltip, Action onClick, Transform paren
6368
_text.m_htmlColor = new Color(0.4157f, 0.8902f, 0.9765f, 1f);
6469
_text.transform.localPosition = new Vector3(_text.transform.localPosition.x, -30f);
6570

66-
var layoutElement = RectTransform.Find("Background").gameObject.AddComponent<LayoutElement>();
71+
var layoutElement = Background.gameObject.AddComponent<LayoutElement>();
6772
layoutElement.ignoreLayout = true;
6873

6974
var horizontalLayout = GameObject.AddComponent<HorizontalLayoutGroup>();
@@ -96,17 +101,21 @@ public ReMenuButton(string text, string tooltip, Action onClick, Transform paren
96101
var uiTooltip = GameObject.GetComponent<VRC.UI.Elements.Tooltips.UiTooltip>();
97102
uiTooltip.field_Public_String_0 = tooltip;
98103
uiTooltip.field_Public_String_1 = tooltip;
99-
100-
_button = GameObject.GetComponent<Button>();
101-
_button.onClick = new Button.ButtonClickedEvent();
102-
_button.onClick.AddListener(new Action(onClick));
104+
105+
if (onClick != null)
106+
{
107+
_button = GameObject.GetComponent<Button>();
108+
_button.onClick = new Button.ButtonClickedEvent();
109+
_button.onClick.AddListener(new Action(onClick));
110+
}
103111
}
104112

105113
public ReMenuButton(Transform transform) : base(transform)
106114
{
107115
_text = GameObject.GetComponentInChildren<TextMeshProUGUI>();
108116
_styleElement = GameObject.GetComponent<StyleElement>();
109117
_button = GameObject.GetComponent<Button>();
118+
Background = RectTransform.Find("Background").GetComponent<Image>();
110119
}
111120

112121
public static ReMenuButton Create(string text, string tooltip, Action onClick, Transform parent, Sprite sprite = null)

UI/QuickMenu/ReMenuPage.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,13 @@ public ReMenuButton AddButton(string text, string tooltip, Action onClick, Sprit
145145
return new ReMenuButton(text, tooltip, onClick, _container, sprite);
146146
}
147147

148+
public ReMenuButton AddSpacer(Sprite sprite = null)
149+
{
150+
var spacer = AddButton("Spacer", string.Empty, null, sprite);
151+
spacer.Background.gameObject.SetActive(false);
152+
return spacer;
153+
}
154+
148155
public ReMenuToggle AddToggle(string text, string tooltip, Action<bool> onToggle, bool defaultValue = false)
149156
{
150157
return new ReMenuToggle(text, tooltip, onToggle, _container, defaultValue);

0 commit comments

Comments
 (0)