SuitSyntheticView.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. using System.Collections;
  2. using UnityEngine;
  3. using UI.ClothingSynthetic;
  4. using FairyGUI;
  5. using System.Collections.Generic;
  6. namespace GFGGame
  7. {
  8. public class SuitSyntheticView : BaseWindow
  9. {
  10. private UI_ClothingSyntheticListUI _ui;
  11. private List<int> _suitListIds;
  12. public override void Dispose()
  13. {
  14. _ui.m_loaBg.Dispose();
  15. for (int i = 0; i < _ui.m_listSuit.numItems; i++)
  16. {
  17. UI_SuitListItem listItem = UI_SuitListItem.Proxy(_ui.m_listSuit.GetChildAt(i));
  18. listItem.m_loaderPic.Dispose();
  19. UI_SuitListItem.ProxyEnd();
  20. }
  21. if (_ui != null)
  22. {
  23. _ui.Dispose();
  24. _ui = null;
  25. }
  26. base.Dispose();
  27. }
  28. protected override void OnInit()
  29. {
  30. base.OnInit();
  31. packageName = UI_ClothingSyntheticListUI.PACKAGE_NAME;
  32. _ui = UI_ClothingSyntheticListUI.Create();
  33. this.viewCom = _ui.target;
  34. isfullScreen = true;
  35. _ui.m_listSuit.itemRenderer = ListSuitItemRenderer;
  36. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  37. _ui.m_listMenu.onClickItem.Add(OnClickListMenuItem);
  38. }
  39. protected override void AddEventListener()
  40. {
  41. base.AddEventListener();
  42. EventAgent.AddEventListener(ConstMessage.SUIT_BOX_STATUS_CHANGED, UpdateSuitBoxStatus);
  43. }
  44. protected override void OnShown()
  45. {
  46. base.OnShown();
  47. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("hc_bj_1");
  48. _ui.m_listMenu.selectedIndex = 0;
  49. UpdateSuitList();
  50. Timers.inst.AddUpdate(CheckGuide);
  51. }
  52. protected override void OnHide()
  53. {
  54. base.OnHide();
  55. Timers.inst.Remove(CheckGuide);
  56. }
  57. protected override void RemoveEventListener()
  58. {
  59. base.RemoveEventListener();
  60. EventAgent.RemoveEventListener(ConstMessage.SUIT_BOX_STATUS_CHANGED, UpdateSuitBoxStatus);
  61. }
  62. private void OnClickBtnBack()
  63. {
  64. ViewManager.GoBackFrom(ViewName.SUIT_SYNTHETIC_LIST_VIEW);
  65. }
  66. private void OnClickListMenuItem()
  67. {
  68. UpdateSuitList();
  69. }
  70. private void UpdateSuitList()
  71. {
  72. if (_suitListIds == null)
  73. {
  74. _suitListIds = new List<int>();
  75. }
  76. else
  77. {
  78. _suitListIds.Clear();
  79. }
  80. int index = _ui.m_listMenu.selectedIndex;
  81. var suitCfgs = SuitCfgArray.Instance.GetCfgs(index + 1);
  82. foreach (var suitCfg in suitCfgs)
  83. {
  84. _suitListIds.Add(suitCfg.id);
  85. }
  86. _ui.m_listSuit.numItems = _suitListIds.Count;
  87. }
  88. private void ListSuitItemRenderer(int index, GObject item)
  89. {
  90. UI_SuitListItem listItem = UI_SuitListItem.Proxy(item);
  91. int suitId = _suitListIds[index];
  92. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(suitId);
  93. listItem.m_txtName.text = suitCfg.name;
  94. listItem.m_loaderPic.url = ResPathUtil.GetFieldGuideIconPath(suitCfg.res);
  95. int count = 0;
  96. int totalCount = 0;
  97. DressUpMenuSuitDataManager.GetSuitProgressBySuitId(suitId, out count, out totalCount);
  98. listItem.m_progBar.max = totalCount;
  99. listItem.m_progBar.value = count;
  100. RarityIconController.UpdateRarityIcon(listItem.m_rarity, suitId, false, true);
  101. bool haveSuit = DressUpMenuSuitDataManager.CheckHaveSuit(suitId);
  102. bool isLock = false;
  103. SuitCfg suitSyntheticCfg = SuitCfgArray.Instance.GetCfg(suitId);
  104. if (suitSyntheticCfg.syntheticStoryLevelId > 0)
  105. {
  106. //int chapter = 0;
  107. //int level = 0;
  108. //CalculateHelper.GetStoryChapterLevel(suitSyntheticCfg.storyLevelId, out var chapter, out var level);
  109. bool isLevelPass = InstanceZonesDataManager.CheckLevelPass(suitSyntheticCfg.syntheticStoryLevelId);
  110. if (!isLevelPass)
  111. {
  112. isLock = true;
  113. var levelCfg = StoryLevelCfgArray.Instance.GetCfg(suitSyntheticCfg.syntheticStoryLevelId);
  114. var chapterCfg = StoryChapterCfgArray.Instance.GetCfg(levelCfg.chapterId);
  115. listItem.m_txtLockDesc.text = string.Format("通关第{0}章第{1}关", chapterCfg.order, levelCfg.order);
  116. }
  117. }
  118. if (suitSyntheticCfg.syntheticPreSuitId > 0)
  119. {
  120. bool hasPreSuit = DressUpMenuSuitDataManager.CheckHaveSuit(suitSyntheticCfg.syntheticPreSuitId);
  121. if (!hasPreSuit)
  122. {
  123. isLock = true;
  124. string preSuitName = SuitUtil.GetSuitName(suitSyntheticCfg.syntheticPreSuitId);
  125. listItem.m_txtLockDesc.text = string.Format("集齐{0}套装", preSuitName);
  126. }
  127. }
  128. listItem.m_groupLock.visible = isLock;
  129. listItem.target.data = suitId;
  130. UpdateSuitBoxStatusView(listItem);
  131. listItem.m_loaderBonusBox.onClick.Clear();
  132. listItem.m_loaderBonusBox.onClick.Add(() =>
  133. {
  134. SuitUtil.ShowSuitSyntheticBonus(suitId);
  135. });
  136. listItem.m_bg.onClick.Clear();
  137. listItem.m_bg.onClick.Add(() =>
  138. {
  139. if (!isLock)
  140. {
  141. ViewManager.Show(ViewName.CLOTHING_SYNTHETIC_VIEW, new object[] { suitId }, new object[] { ViewName.SUIT_SYNTHETIC_LIST_VIEW, this.viewData });
  142. }
  143. });
  144. UI_SuitListItem.ProxyEnd();
  145. }
  146. private void UpdateSuitBoxStatus(EventContext eventContext)
  147. {
  148. int suitId = (int)eventContext.data;
  149. int num = _ui.m_listSuit.numChildren;
  150. for (int i = 0; i < num; i++)
  151. {
  152. UI_SuitListItem listItem = UI_SuitListItem.Proxy(_ui.m_listSuit.GetChildAt(i));
  153. int tempSuitId = (int)listItem.target.data;
  154. if (tempSuitId == suitId)
  155. {
  156. UpdateSuitBoxStatusView(listItem);
  157. }
  158. UI_SuitListItem.ProxyEnd();
  159. }
  160. }
  161. private void UpdateSuitBoxStatusView(UI_SuitListItem listItem)
  162. {
  163. listItem.m_iconGot.visible = false;
  164. int suitId = (int)listItem.target.data;
  165. int status = DressUpMenuSuitDataManager.GetSuitSyntheticBonusStatus(suitId);
  166. if (status == ConstBonusStatus.CAN_GET)
  167. {
  168. listItem.m_loaderBonusBox.grayed = false;
  169. }
  170. else
  171. {
  172. listItem.m_loaderBonusBox.grayed = true;
  173. if (status == ConstBonusStatus.GOT)
  174. {
  175. listItem.m_iconGot.visible = true;
  176. }
  177. }
  178. }
  179. private void CheckGuide(object param)
  180. {
  181. if (GuideDataManager.IsGuideFinish(ConstGuideId.CLOTHING_SYNTHETIC) <= 0)
  182. {
  183. UpdateToCheckGuide(null);
  184. }
  185. else
  186. {
  187. Timers.inst.Remove(CheckGuide);
  188. }
  189. }
  190. protected override void UpdateToCheckGuide(object param)
  191. {
  192. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  193. int suitId = 200017;
  194. int suitIndex = 0;
  195. for (int i = 0; i < _suitListIds.Count; i++)
  196. {
  197. if (_suitListIds[i] == suitId)
  198. {
  199. suitIndex = i;
  200. break;
  201. }
  202. }
  203. GuideController.TryGuide(_ui.m_listSuit, ConstGuideId.CLOTHING_SYNTHETIC, 3, "查看已解锁的图谱", suitIndex);
  204. }
  205. }
  206. }