ScoutCharacterSelectCtrl.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. using System;
  2. using System.Collections.Generic;
  3. using Kasizuki;
  4. using UnityEngine;
  5. namespace scoutmode
  6. {
  7. public class ScoutCharacterSelectCtrl : NGUIWindow
  8. {
  9. public ScoutMaidData selectedMaidData { get; private set; }
  10. private void Init()
  11. {
  12. if (this.m_IsInit)
  13. {
  14. return;
  15. }
  16. this.m_IsInit = true;
  17. }
  18. private void Start()
  19. {
  20. this.Init();
  21. }
  22. public void SetData()
  23. {
  24. this.Init();
  25. List<ScoutMaidData> maidList = this.callbackGetScoutMaidList();
  26. this.m_ListViewer.Show<Transform>(maidList.Count, delegate(int i, Transform trans)
  27. {
  28. this.CreateItem(maidList[i], i, trans);
  29. });
  30. UIGrid componentInParent = this.m_ListViewer.parentItemArea.GetComponentInParent<UIGrid>();
  31. if (componentInParent)
  32. {
  33. componentInParent.repositionNow = true;
  34. }
  35. UIScrollView componentInParent2 = this.m_ListViewer.parentItemArea.GetComponentInParent<UIScrollView>();
  36. if (componentInParent2)
  37. {
  38. componentInParent2.ResetPosition();
  39. }
  40. }
  41. public void DeleteItem(ScoutMaidData maid)
  42. {
  43. if (!this.itemDictionary.ContainsKey(maid))
  44. {
  45. return;
  46. }
  47. GameObject gameObject = null;
  48. GameObject[] itemArray = this.m_ListViewer.ItemArray;
  49. for (int i = 0; i < itemArray.Length; i++)
  50. {
  51. GameObject x = itemArray[i];
  52. if (!(x != this.itemDictionary[maid]))
  53. {
  54. if (i + 1 < itemArray.Length)
  55. {
  56. gameObject = itemArray[i + 1];
  57. }
  58. else if (i - 1 >= 0)
  59. {
  60. gameObject = itemArray[i - 1];
  61. }
  62. break;
  63. }
  64. }
  65. this.m_ListViewer.RemoveItem(this.itemDictionary[maid]);
  66. this.selectedMaidData = null;
  67. if (gameObject != null)
  68. {
  69. UIButton componentInChildren = gameObject.GetComponentInChildren<UIButton>();
  70. if (componentInChildren != null && componentInChildren.onClick != null)
  71. {
  72. EventDelegate.Execute(componentInChildren.onClick);
  73. }
  74. }
  75. UIGrid componentInParent = this.m_ListViewer.parentItemArea.GetComponentInParent<UIGrid>();
  76. if (componentInParent)
  77. {
  78. componentInParent.Reposition();
  79. }
  80. }
  81. private void CreateItem(ScoutMaidData maid, int index, Transform item)
  82. {
  83. GameObject itemObj = item.gameObject;
  84. this.itemDictionary[maid] = itemObj;
  85. UIButton componentInChildren = item.GetComponentInChildren<UIButton>(item);
  86. EventDelegate.Add(componentInChildren.onClick, delegate()
  87. {
  88. this.selectedMaidData = maid;
  89. if (this.callbackSelectItem != null)
  90. {
  91. this.callbackSelectItem(maid);
  92. }
  93. this.UpdateListColor(itemObj);
  94. });
  95. UI2DSprite component = UTY.GetChildObject(itemObj, "BG/ThumbnailFrame/Thumbnail", false).GetComponent<UI2DSprite>();
  96. UILabel component2 = UTY.GetChildObject(itemObj, "BG/FirstName", false).GetComponent<UILabel>();
  97. UILabel component3 = UTY.GetChildObject(itemObj, "BG/LastName", false).GetComponent<UILabel>();
  98. Texture2D texture2D = null;
  99. byte[] iconImageBinary = maid.iconImageBinary;
  100. if (iconImageBinary != null)
  101. {
  102. texture2D = new Texture2D(1, 1, TextureFormat.ARGB32, false);
  103. texture2D.LoadImage(iconImageBinary);
  104. }
  105. if (texture2D != null)
  106. {
  107. Sprite sprite2D = Sprite.Create(texture2D, new Rect(0f, 0f, (float)texture2D.width, (float)texture2D.height), default(Vector2));
  108. component.sprite2D = sprite2D;
  109. }
  110. else
  111. {
  112. component.sprite2D = null;
  113. }
  114. if (maid.status != null)
  115. {
  116. component3.text = maid.status.name1;
  117. component2.text = maid.status.name2;
  118. }
  119. }
  120. private void UpdateListColor(GameObject target)
  121. {
  122. if (!this.m_IsInit)
  123. {
  124. return;
  125. }
  126. foreach (GameObject f_goParent in this.m_ListViewer.ItemArray)
  127. {
  128. GameObject childObject = UTY.GetChildObject(f_goParent, "BG/mask", true);
  129. if (childObject)
  130. {
  131. childObject.SetActive(true);
  132. }
  133. }
  134. if (target != null)
  135. {
  136. GameObject childObject = UTY.GetChildObject(target, "BG/mask", true);
  137. if (childObject)
  138. {
  139. childObject.SetActive(false);
  140. }
  141. }
  142. }
  143. public BigThumbnail bigThumbnail
  144. {
  145. get
  146. {
  147. return this.m_BigThumbnail;
  148. }
  149. }
  150. public uGUIListViewer listViewer
  151. {
  152. get
  153. {
  154. return this.m_ListViewer;
  155. }
  156. }
  157. public Func<List<ScoutMaidData>> callbackGetScoutMaidList;
  158. public Action<ScoutMaidData> callbackSelectItem;
  159. private Dictionary<ScoutMaidData, GameObject> itemDictionary = new Dictionary<ScoutMaidData, GameObject>();
  160. private bool m_IsInit;
  161. [SerializeField]
  162. private BigThumbnail m_BigThumbnail;
  163. [SerializeField]
  164. private uGUIListViewer m_ListViewer;
  165. }
  166. }