UIWFConditionList.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using wf;
  5. [RequireComponent(typeof(UITable))]
  6. public class UIWFConditionList : MonoBehaviour
  7. {
  8. public int height { get; private set; }
  9. public int width { get; private set; }
  10. private void Awake()
  11. {
  12. if (this.condition_label_list_ != null)
  13. {
  14. return;
  15. }
  16. this.condition_label_list_ = new List<UILabel>();
  17. UITable component = base.GetComponent<UITable>();
  18. List<Transform> childList = component.GetChildList();
  19. foreach (Transform transform in childList)
  20. {
  21. UILabel component2 = UTY.GetChildObject(transform.gameObject, "Message", false).GetComponent<UILabel>();
  22. this.condition_label_list_.Add(component2);
  23. this.defaultFontSize = component2.fontSize;
  24. this.widthMargin = (int)(component2.transform.localPosition.x - (float)(UTY.GetChildObject(transform.gameObject, "No", false).GetComponent<UIWidget>().width / -2));
  25. transform.gameObject.SetActive(false);
  26. }
  27. }
  28. public void SetTexts(string[] texts, int limitTextWidth = -1)
  29. {
  30. KeyValuePair<string, Color>[] array = new KeyValuePair<string, Color>[texts.Length];
  31. for (int i = 0; i < texts.Length; i++)
  32. {
  33. array[i] = new KeyValuePair<string, Color>(texts[i], Color.white);
  34. }
  35. this.SetTexts(array, limitTextWidth);
  36. }
  37. public void SetTexts(KeyValuePair<string, Color>[] texts, int limitTextWidth = -1)
  38. {
  39. if (this.condition_label_list_ == null)
  40. {
  41. this.Awake();
  42. }
  43. this.width = 0;
  44. float num = 0f;
  45. float num2 = 0f;
  46. for (int i = 0; i < this.condition_label_list_.Count; i++)
  47. {
  48. if (i < texts.Length)
  49. {
  50. Transform parent = this.condition_label_list_[i].transform.parent;
  51. if (i == 0)
  52. {
  53. num = Mathf.Abs(parent.localPosition.y);
  54. }
  55. this.condition_label_list_[i].transform.parent.gameObject.SetActive(true);
  56. this.condition_label_list_[i].text = texts[i].Key;
  57. this.condition_label_list_[i].color = texts[i].Value;
  58. this.condition_label_list_[i].fontSize = this.defaultFontSize;
  59. this.condition_label_list_[i].width = 0;
  60. this.condition_label_list_[i].MakePixelPerfect();
  61. if (0 <= limitTextWidth)
  62. {
  63. Utility.ResizeUILabelFontSize(this.condition_label_list_[i], limitTextWidth);
  64. }
  65. this.width = Mathf.Max(this.width, this.condition_label_list_[i].width);
  66. num2 = Mathf.Abs(parent.localPosition.y) + (float)parent.gameObject.GetComponent<UIWidget>().height;
  67. }
  68. else
  69. {
  70. this.condition_label_list_[i].transform.parent.gameObject.SetActive(false);
  71. }
  72. }
  73. this.height = (int)(num2 - num);
  74. this.width += this.widthMargin;
  75. }
  76. private int widthMargin;
  77. private List<UILabel> condition_label_list_;
  78. private int defaultFontSize;
  79. }