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

Commit 57afc40

Browse files
authored
Merge pull request #29 from Minty-Labs/master
Allow a component's Tooltip to be modified
2 parents d77be37 + 9800af4 commit 57afc40

File tree

3 files changed

+47
-12
lines changed

3 files changed

+47
-12
lines changed

UI/QuickMenu/ReMenuButton.cs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ public string Text
3333
get => _text.text;
3434
set => _text.SetText(value);
3535
}
36+
37+
private VRC.UI.Elements.Tooltips.UiTooltip _tooltip;
38+
39+
public string Tooltip {
40+
get => _tooltip != null ? _tooltip.field_Public_String_0 : "";
41+
set
42+
{
43+
if (_tooltip == null) return;
44+
_tooltip.field_Public_String_0 = value;
45+
_tooltip.field_Public_String_1 = value;
46+
}
47+
}
3648

3749
private readonly StyleElement _styleElement;
3850
private readonly Button _button;
@@ -99,20 +111,19 @@ public ReMenuButton(string text, string tooltip, Action onClick, Transform paren
99111
Object.DestroyImmediate(RectTransform.Find("Badge_MMJump").gameObject);
100112

101113
var uiTooltips = GameObject.GetComponents<VRC.UI.Elements.Tooltips.UiTooltip>();
102-
VRC.UI.Elements.Tooltips.UiTooltip uiTooltip = null;
103114
if (uiTooltips.Length > 0)
104115
{
105116
//Fuck tooltips, all my friends hate tooltips
106-
uiTooltip = uiTooltips[0];
117+
_tooltip = uiTooltips[0];
107118

108-
for(int i=1; i<uiTooltips.Length; i++)
119+
for(int i = 1; i < uiTooltips.Length; i++)
109120
Object.DestroyImmediate(uiTooltips[i]);
110121
}
111122

112-
if (uiTooltip != null)
123+
if (_tooltip != null)
113124
{
114-
uiTooltip.field_Public_String_0 = tooltip;
115-
uiTooltip.field_Public_String_1 = tooltip;
125+
_tooltip.field_Public_String_0 = tooltip;
126+
_tooltip.field_Public_String_1 = tooltip;
116127
}
117128

118129
if (onClick != null)

UI/QuickMenu/ReMenuSlider.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ namespace ReMod.Core.UI.QuickMenu
1111
public class ReMenuSlider : UiElement
1212
{
1313
private readonly Slider _sliderComponent;
14+
15+
private VRC.UI.Elements.Tooltips.UiTooltip _tooltip;
16+
17+
public string Tooltip {
18+
get => _tooltip != null ? _tooltip.field_Public_String_0 : "";
19+
set
20+
{
21+
if (_tooltip == null) return;
22+
_tooltip.field_Public_String_0 = value;
23+
_tooltip.field_Public_String_1 = value;
24+
}
25+
}
1426

1527
public ReMenuSlider(string text, string tooltip, Action<float> onSlide, Transform parent, float defaultValue = 0, float minValue = 0, float maxValue = 10) : base(QuickMenuEx.SliderPrefab, parent, $"Slider_{text}")
1628
{
@@ -35,9 +47,9 @@ public ReMenuSlider(string text, string tooltip, Action<float> onSlide, Transfor
3547
_sliderComponent.maxValue = maxValue;
3648
_sliderComponent.value = defaultValue;
3749

38-
var uiTooltip = GameObject.GetComponent<VRC.UI.Elements.Tooltips.UiTooltip>();
39-
uiTooltip.field_Public_String_0 = tooltip;
40-
uiTooltip.field_Public_String_1 = tooltip;
50+
_tooltip = GameObject.GetComponent<VRC.UI.Elements.Tooltips.UiTooltip>();
51+
_tooltip.field_Public_String_0 = tooltip;
52+
_tooltip.field_Public_String_1 = tooltip;
4153

4254
Slide(defaultValue,false);
4355

UI/QuickMenu/ReMenuToggle.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ public string Text
4343
get => _textComponent.text;
4444
set => _textComponent.text = value;
4545
}
46+
47+
private VRC.UI.Elements.Tooltips.UiToggleTooltip _tooltip;
48+
49+
public string Tooltip {
50+
get => _tooltip != null ? _tooltip.field_Public_String_0 : "";
51+
set
52+
{
53+
if (_tooltip == null) return;
54+
_tooltip.field_Public_String_0 = value;
55+
_tooltip.field_Public_String_1 = value;
56+
}
57+
}
4658

4759
public ReMenuToggle(string text, string tooltip, Action<bool> onToggle, Transform parent, bool defaultValue = false) : base(QuickMenuEx.TogglePrefab, parent, $"Button_Toggle{text}")
4860
{
@@ -67,9 +79,9 @@ public ReMenuToggle(string text, string tooltip, Action<bool> onToggle, Transfor
6779
_textComponent.m_fontColor = new Color(0.4157f, 0.8902f, 0.9765f, 1f);
6880
_textComponent.m_htmlColor = new Color(0.4157f, 0.8902f, 0.9765f, 1f);
6981

70-
var uiTooltip = GameObject.GetComponent<VRC.UI.Elements.Tooltips.UiToggleTooltip>();
71-
uiTooltip.field_Public_String_0 = tooltip;
72-
uiTooltip.field_Public_String_1 = tooltip;
82+
_tooltip = GameObject.GetComponent<VRC.UI.Elements.Tooltips.UiToggleTooltip>();
83+
_tooltip.field_Public_String_0 = tooltip;
84+
_tooltip.field_Public_String_1 = tooltip;
7385

7486
Toggle(defaultValue,false);
7587

0 commit comments

Comments
 (0)