99using System . Linq ;
1010using System . Reflection ;
1111using UnityEngine ;
12+ using UnityEngine . EventSystems ;
1213using UnityEngine . UI ;
1314
1415namespace NebulaPatcher . Patches . Dynamic
1516{
1617 [ HarmonyPatch ( typeof ( UIOptionWindow ) ) ]
1718 internal class UIOptionWindow_Patch
1819 {
20+ public class Tooltip : MonoBehaviour , IPointerEnterHandler , IPointerExitHandler
21+ {
22+ public string Title = null ;
23+ public string Text = null ;
24+ UIButtonTip tip = null ;
25+
26+ public void OnPointerEnter ( PointerEventData eventData )
27+ {
28+ tip = UIButtonTip . Create ( true , Title , Text , 2 , new Vector2 ( 0 , 0 ) , 508 , this . gameObject . transform , "" , "" ) ;
29+ }
30+
31+ public void OnPointerExit ( PointerEventData eventData )
32+ {
33+ if ( tip != null )
34+ {
35+ Destroy ( tip . gameObject ) ;
36+ }
37+ }
38+
39+ public void OnDisable ( )
40+ {
41+ if ( tip != null )
42+ {
43+ Destroy ( tip . gameObject ) ;
44+ }
45+ }
46+ }
47+
1948 private static RectTransform multiplayerTab ;
2049
2150 // Templates
@@ -159,23 +188,24 @@ private static void AddMultiplayerOptionsProperties(RectTransform container)
159188 foreach ( PropertyInfo prop in properties )
160189 {
161190 DisplayNameAttribute displayAttr = prop . GetCustomAttribute < DisplayNameAttribute > ( ) ;
191+ DescriptionAttribute descriptionAttr = prop . GetCustomAttribute < DescriptionAttribute > ( ) ;
162192 if ( displayAttr != null )
163193 {
164194 if ( prop . PropertyType == typeof ( bool ) )
165195 {
166- CreateBooleanControl ( displayAttr , prop , anchorPosition , container ) ;
196+ CreateBooleanControl ( displayAttr , descriptionAttr , prop , anchorPosition , container ) ;
167197 }
168198 else if ( prop . PropertyType == typeof ( int ) || prop . PropertyType == typeof ( float ) || prop . PropertyType == typeof ( ushort ) )
169199 {
170- CreateNumberControl ( displayAttr , prop , anchorPosition , container ) ;
200+ CreateNumberControl ( displayAttr , descriptionAttr , prop , anchorPosition , container ) ;
171201 }
172202 else if ( prop . PropertyType == typeof ( string ) )
173203 {
174- CreateStringControl ( displayAttr , prop , anchorPosition , container ) ;
204+ CreateStringControl ( displayAttr , descriptionAttr , prop , anchorPosition , container ) ;
175205 }
176206 else if ( prop . PropertyType . IsEnum )
177207 {
178- CreateEnumControl ( displayAttr , prop , anchorPosition , container ) ;
208+ CreateEnumControl ( displayAttr , descriptionAttr , prop , anchorPosition , container ) ;
179209 }
180210 else
181211 {
@@ -190,10 +220,10 @@ private static void AddMultiplayerOptionsProperties(RectTransform container)
190220 container . sizeDelta = new Vector2 ( container . sizeDelta . x , - anchorPosition . y + 40 ) ;
191221 }
192222
193- private static void CreateBooleanControl ( DisplayNameAttribute control , PropertyInfo prop , Vector2 anchorPosition , RectTransform container )
223+ private static void CreateBooleanControl ( DisplayNameAttribute control , DescriptionAttribute descriptionAttr , PropertyInfo prop , Vector2 anchorPosition , RectTransform container )
194224 {
195225 RectTransform element = Object . Instantiate ( checkboxTemplate , container , false ) ;
196- SetupUIElement ( element , control , prop , anchorPosition ) ;
226+ SetupUIElement ( element , control , descriptionAttr , prop , anchorPosition ) ;
197227 UIToggle toggle = element . GetComponentInChildren < UIToggle > ( ) ;
198228 toggle . toggle . onValueChanged . RemoveAllListeners ( ) ;
199229 toggle . toggle . onValueChanged . AddListener ( ( value ) => {
@@ -219,13 +249,13 @@ private static void CreateBooleanControl(DisplayNameAttribute control, PropertyI
219249 } ;
220250 }
221251
222- private static void CreateNumberControl ( DisplayNameAttribute control , PropertyInfo prop , Vector2 anchorPosition , RectTransform container )
252+ private static void CreateNumberControl ( DisplayNameAttribute control , DescriptionAttribute descriptionAttr , PropertyInfo prop , Vector2 anchorPosition , RectTransform container )
223253 {
224254 UIRangeAttribute rangeAttr = prop . GetCustomAttribute < UIRangeAttribute > ( ) ;
225255 bool sliderControl = rangeAttr != null && rangeAttr . Slider ;
226256
227257 RectTransform element = Object . Instantiate ( sliderControl ? sliderTemplate : inputTemplate , container , false ) ;
228- SetupUIElement ( element , control , prop , anchorPosition ) ;
258+ SetupUIElement ( element , control , descriptionAttr , prop , anchorPosition ) ;
229259
230260 bool isFloatingPoint = prop . PropertyType == typeof ( float ) || prop . PropertyType == typeof ( double ) ;
231261
@@ -294,10 +324,10 @@ private static void CreateNumberControl(DisplayNameAttribute control, PropertyIn
294324 }
295325 }
296326
297- private static void CreateStringControl ( DisplayNameAttribute control , PropertyInfo prop , Vector2 anchorPosition , RectTransform container )
327+ private static void CreateStringControl ( DisplayNameAttribute control , DescriptionAttribute descriptionAttr , PropertyInfo prop , Vector2 anchorPosition , RectTransform container )
298328 {
299329 RectTransform element = Object . Instantiate ( inputTemplate , container , false ) ;
300- SetupUIElement ( element , control , prop , anchorPosition ) ;
330+ SetupUIElement ( element , control , descriptionAttr , prop , anchorPosition ) ;
301331
302332 InputField input = element . GetComponentInChildren < InputField > ( ) ;
303333 input . onValueChanged . RemoveAllListeners ( ) ;
@@ -309,10 +339,10 @@ private static void CreateStringControl(DisplayNameAttribute control, PropertyIn
309339 } ;
310340 }
311341
312- private static void CreateEnumControl ( DisplayNameAttribute control , PropertyInfo prop , Vector2 anchorPosition , RectTransform container )
342+ private static void CreateEnumControl ( DisplayNameAttribute control , DescriptionAttribute descriptionAttr , PropertyInfo prop , Vector2 anchorPosition , RectTransform container )
313343 {
314344 RectTransform element = Object . Instantiate ( comboBoxTemplate , container , false ) ;
315- SetupUIElement ( element , control , prop , anchorPosition ) ;
345+ SetupUIElement ( element , control , descriptionAttr , prop , anchorPosition ) ;
316346 UIComboBox combo = element . GetComponentInChildren < UIComboBox > ( ) ;
317347 combo . Items = System . Enum . GetNames ( prop . PropertyType ) . ToList ( ) ;
318348 combo . ItemsData = System . Enum . GetValues ( prop . PropertyType ) . OfType < int > ( ) . ToList ( ) ;
@@ -325,11 +355,17 @@ private static void CreateEnumControl(DisplayNameAttribute control, PropertyInfo
325355 } ;
326356 }
327357
328- private static void SetupUIElement ( RectTransform element , DisplayNameAttribute display , PropertyInfo prop , Vector2 anchorPosition )
358+ private static void SetupUIElement ( RectTransform element , DisplayNameAttribute display , DescriptionAttribute descriptionAttr , PropertyInfo prop , Vector2 anchorPosition )
329359 {
330360 element . gameObject . SetActive ( true ) ;
331361 element . name = prop . Name ;
332362 element . anchoredPosition = anchorPosition ;
363+ if ( descriptionAttr != null )
364+ {
365+ element . gameObject . AddComponent < Tooltip > ( ) ;
366+ element . gameObject . GetComponent < Tooltip > ( ) . Title = display . DisplayName ;
367+ element . gameObject . GetComponent < Tooltip > ( ) . Text = descriptionAttr . Description ;
368+ }
333369 element . GetComponent < Localizer > ( ) . enabled = false ;
334370 element . GetComponent < Text > ( ) . text = display . DisplayName ;
335371 }
0 commit comments