SuitSyntheticView.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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 : BaseView
  9. {
  10. private UI_ClothingSyntheticListUI _ui;
  11. private List<int> _suitListIds;
  12. public override void Dispose()
  13. {
  14. if (_ui != null)
  15. {
  16. _ui.Dispose();
  17. _ui = null;
  18. }
  19. base.Dispose();
  20. }
  21. protected override void OnInit()
  22. {
  23. base.OnInit();
  24. packageName = UI_ClothingSyntheticListUI.PACKAGE_NAME;
  25. _ui = UI_ClothingSyntheticListUI.Create();
  26. this.viewCom = _ui.target;
  27. isfullScreen = true;
  28. isReturnView = true;
  29. _ui.m_listSuit.itemRenderer = ListSuitItemRenderer;
  30. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  31. _ui.m_listMenu.onClickItem.Add(OnClickListMenuItem);
  32. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("hz_bjbj");
  33. }
  34. protected override void AddEventListener()
  35. {
  36. base.AddEventListener();
  37. EventAgent.AddEventListener(ConstMessage.SUIT_BOX_STATUS_CHANGED, UpdateSuitBoxStatus);
  38. EventAgent.AddEventListener(ConstMessage.RED_CHANGE, UpdateRedDot);
  39. EventAgent.AddEventListener(ConstMessage.CLOTHING_SYNTHETIC_SUCCESS, UpdateSuitList);
  40. }
  41. protected override void OnShown()
  42. {
  43. base.OnShown();
  44. _ui.m_listMenu.selectedIndex = 0;
  45. if (this.viewData != null)
  46. {
  47. int suitId = (int)this.viewData;
  48. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(suitId);
  49. _ui.m_listMenu.selectedIndex = suitCfg.syntheticType - 1;
  50. }
  51. // _ui.m_listMenu.GetChildAt(1).visible = false;
  52. UpdateSuitList();
  53. UpdateRedDot();
  54. //Timers.inst.AddUpdate(CheckGuide);
  55. }
  56. protected override void OnHide()
  57. {
  58. base.OnHide();
  59. //Timers.inst.Remove(CheckGuide);
  60. }
  61. protected override void RemoveEventListener()
  62. {
  63. base.RemoveEventListener();
  64. EventAgent.RemoveEventListener(ConstMessage.SUIT_BOX_STATUS_CHANGED, UpdateSuitBoxStatus);
  65. EventAgent.RemoveEventListener(ConstMessage.RED_CHANGE, UpdateRedDot);
  66. EventAgent.RemoveEventListener(ConstMessage.CLOTHING_SYNTHETIC_SUCCESS, UpdateSuitList);
  67. }
  68. private void OnClickBtnBack()
  69. {
  70. ViewManager.GoBackFrom(typeof(SuitSyntheticView).FullName);
  71. }
  72. private void OnClickListMenuItem()
  73. {
  74. UpdateSuitList();
  75. }
  76. private void UpdateSuitList()
  77. {
  78. if (_suitListIds == null)
  79. {
  80. _suitListIds = new List<int>();
  81. }
  82. else
  83. {
  84. _suitListIds.Clear();
  85. }
  86. int index = _ui.m_listMenu.selectedIndex;
  87. var suitCfgs = SuitCfgArray.Instance.GetCfgsBysyntheticType(index + 1);
  88. foreach (var suitCfg in suitCfgs)
  89. {
  90. _suitListIds.Add(suitCfg.id);
  91. }
  92. _ui.m_listSuit.numItems = _suitListIds.Count;
  93. }
  94. private void ListSuitItemRenderer(int index, GObject item)
  95. {
  96. UI_SuitListItem listItem = UI_SuitListItem.Proxy(item);
  97. int suitId = _suitListIds[index];
  98. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(suitId);
  99. listItem.m_txtName.text = suitCfg.name;
  100. listItem.m_loaderPic.url = ResPathUtil.GetFieldGuideIconPath(suitCfg.res);
  101. int count = 0;
  102. int totalCount = 0;
  103. DressUpMenuSuitDataManager.GetSuitProgressBySuitId(suitId, out count, out totalCount);
  104. listItem.m_progBar.max = totalCount;
  105. listItem.m_progBar.value = count;
  106. RarityIconController.UpdateRarityIcon(listItem.m_rarity, suitId, false, true);
  107. bool haveSuit = DressUpMenuSuitDataManager.CheckHaveSuit(suitId);
  108. bool isLock = false;
  109. // SuitCfg suitSyntheticCfg = SuitCfgArray.Instance.GetCfg(suitId);
  110. if (suitCfg.syntheticStoryLevelId > 0)
  111. {
  112. //int chapter = 0;
  113. //int level = 0;
  114. //CalculateHelper.GetStoryChapterLevel(suitSyntheticCfg.storyLevelId, out var chapter, out var level);
  115. bool isLevelPass = InstanceZonesDataManager.CheckLevelPass(suitCfg.syntheticStoryLevelId);
  116. if (!isLevelPass)
  117. {
  118. isLock = true;
  119. var levelCfg = StoryLevelCfgArray.Instance.GetCfg(suitCfg.syntheticStoryLevelId);
  120. string str = "";
  121. if (levelCfg.type == ConstInstanceZonesType.Studio && levelCfg.subType == ConstInstanceZonesSubType.Hard3)
  122. {
  123. StoryLevelCfg cfg = StoryLevelCfgArray.Instance.GetCfg(suitCfg.syntheticStoryLevelId);
  124. str = string.Format("通关查阅建档 {0}", cfg.name);
  125. }
  126. else
  127. {
  128. var chapterCfg = StoryChapterCfgArray.Instance.GetCfg(levelCfg.chapterId);
  129. str = string.Format("通关第{0}章第{1}关", chapterCfg.order, levelCfg.order);
  130. }
  131. listItem.m_txtLockDesc.text = str;
  132. }
  133. }
  134. if (suitCfg.syntheticPreSuitId > 0)
  135. {
  136. bool hasPreSuit = DressUpMenuSuitDataManager.CheckHaveSuit(suitCfg.syntheticPreSuitId);
  137. if (!hasPreSuit)
  138. {
  139. isLock = true;
  140. string preSuitName = SuitUtil.GetSuitName(suitCfg.syntheticPreSuitId);
  141. listItem.m_txtLockDesc.text = string.Format("集齐{0}套装", preSuitName);
  142. }
  143. }
  144. listItem.m_groupLock.visible = isLock;
  145. listItem.target.data = suitId;
  146. UpdateSuitBoxStatusView(listItem);
  147. int status = DressUpMenuSuitDataManager.GetSuitSyntheticBonusStatus(suitId);
  148. listItem.m_bonusGift.m_loaderBonusBox.onClick.Clear();
  149. listItem.m_bonusGift.m_loaderBonusBox.onClick.Add(() =>
  150. {
  151. SuitUtil.ShowSuitSyntheticBonus(suitId);
  152. });
  153. listItem.m_bg.onClick.Clear();
  154. listItem.m_bg.onClick.Add(() =>
  155. {
  156. if (!isLock)
  157. {
  158. ViewManager.Show<ClothingSyntheticView>(new object[] { suitId }, new object[] { typeof(SuitSyntheticView).FullName, suitId });
  159. }
  160. });
  161. // 提示合成物品的红点
  162. RedDotController.Instance.SetComRedDot(listItem.target, RedDotDataManager.Instance.GetClothingSyntheticRed(suitId), "", 0, 0);
  163. // 奖励红点
  164. RedDotController.Instance.SetComRedDot(listItem.m_bonusGift.target, status == ConstBonusStatus.CAN_GET && !isLock, "", -13, -7);
  165. UI_SuitListItem.ProxyEnd();
  166. }
  167. private void UpdateSuitBoxStatus(EventContext eventContext)
  168. {
  169. int suitId = (int)eventContext.data;
  170. int num = _ui.m_listSuit.numChildren;
  171. for (int i = 0; i < num; i++)
  172. {
  173. UI_SuitListItem listItem = UI_SuitListItem.Proxy(_ui.m_listSuit.GetChildAt(i));
  174. int tempSuitId = (int)listItem.target.data;
  175. if (tempSuitId == suitId)
  176. {
  177. UpdateSuitBoxStatusView(listItem);
  178. }
  179. UI_SuitListItem.ProxyEnd();
  180. }
  181. }
  182. private void UpdateSuitBoxStatusView(UI_SuitListItem listItem)
  183. {
  184. UI_BonusGift bonusGift = UI_BonusGift.Proxy(listItem.m_bonusGift.target);
  185. bonusGift.m_iconGot.visible = false;
  186. int suitId = (int)listItem.target.data;
  187. int status = DressUpMenuSuitDataManager.GetSuitSyntheticBonusStatus(suitId);
  188. if (status == ConstBonusStatus.CAN_GET)
  189. {
  190. bonusGift.m_loaderBonusBox.grayed = false;
  191. }
  192. else
  193. {
  194. bonusGift.m_loaderBonusBox.grayed = true;
  195. if (status == ConstBonusStatus.GOT)
  196. {
  197. bonusGift.m_iconGot.visible = true;
  198. }
  199. RedDotController.Instance.SetComRedDot(listItem.m_bonusGift.target, false, "");
  200. }
  201. UI_BonusGift.ProxyEnd();
  202. }
  203. private void UpdateRedDot()
  204. {
  205. RedDotController.Instance.SetComRedDot(_ui.m_listMenu.GetChildAt(0).asCom, RedDotDataManager.Instance.GetClothingSyntheticTabRed(1), "", 0, -6);
  206. RedDotController.Instance.SetComRedDot(_ui.m_listMenu.GetChildAt(1).asCom, RedDotDataManager.Instance.GetClothingSyntheticTabRed(2), "", 0, -6);
  207. RedDotController.Instance.SetComRedDot(_ui.m_listMenu.GetChildAt(2).asCom, RedDotDataManager.Instance.GetClothingSyntheticTabRed(3), "", 0, -6);
  208. }
  209. private void CheckGuide(object param)
  210. {
  211. if (GuideDataManager.IsGuideFinish(ConstGuideId.CLOTHING_SYNTHETIC) <= 0)
  212. {
  213. UpdateToCheckGuide(null);
  214. }
  215. else
  216. {
  217. Timers.inst.Remove(CheckGuide);
  218. }
  219. }
  220. protected override void UpdateToCheckGuide(object param)
  221. {
  222. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  223. int suitId = 200042;
  224. int suitIndex = 0;
  225. for (int i = 0; i < _suitListIds.Count; i++)
  226. {
  227. if (_suitListIds[i] == suitId)
  228. {
  229. suitIndex = i;
  230. break;
  231. }
  232. }
  233. //GuideController.TryGuide(_ui.m_listSuit, ConstGuideId.CLOTHING_SYNTHETIC, 3, "查看已解锁的图谱。", suitIndex);
  234. }
  235. }
  236. }