LuckyBoxNewDressView.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. using System.Collections;
  2. using UnityEngine;
  3. using UI.LuckyBox;
  4. using System.Collections.Generic;
  5. using FairyGUI;
  6. using System.Linq;
  7. namespace GFGGame
  8. {
  9. public class LuckyBoxNewDressView : BaseWindow
  10. {
  11. private UI_LuckyBoxNewDressUI _ui;
  12. private List<ItemData> _rewardList = new List<ItemData>();
  13. private List<ItemData> _rewardParamList = new List<ItemData>();
  14. private List<ItemData> _newRewardList = new List<ItemData>();
  15. private List<ItemData> _oldRewardList = new List<ItemData>();
  16. // private List<ItemData> _showRewardList = new List<ItemData>();
  17. // private int _type = 0;//弹窗类型:0可跳过,1:首次获得物品不可跳过,2首次获得物品不可跳过,不弹获得套装界面
  18. private GameObject gameObject;
  19. private GoWrapper wrapper;
  20. private GameObject gameObject1;
  21. private GoWrapper wrapper1;
  22. private GameObject gameObject2;
  23. private GoWrapper wrapper2;
  24. private GameObject _gameObject0;
  25. private GameObject _gameObject1;
  26. private GameObject _gameObject2;
  27. private GoWrapper _wrapper0;
  28. private GoWrapper _wrapper1;
  29. private GoWrapper _wrapper2;
  30. public override void Dispose()
  31. {
  32. base.Dispose();
  33. SceneController.DestroyObjectFromView(gameObject, wrapper);
  34. SceneController.DestroyObjectFromView(gameObject1, wrapper1);
  35. SceneController.DestroyObjectFromView(gameObject2, wrapper2);
  36. SceneController.DestroyObjectFromView(_gameObject0, _wrapper0);
  37. SceneController.DestroyObjectFromView(_gameObject1, _wrapper1);
  38. SceneController.DestroyObjectFromView(_gameObject2, _wrapper2);
  39. if (_ui != null)
  40. {
  41. _ui.Dispose();
  42. _ui = null;
  43. }
  44. }
  45. protected override void OnInit()
  46. {
  47. base.OnInit();
  48. packageName = UI_LuckyBoxNewDressUI.PACKAGE_NAME;
  49. _ui = UI_LuckyBoxNewDressUI.Create();
  50. this.viewCom = _ui.target;
  51. isfullScreen = true;
  52. this.modal = true;
  53. _ui.m_loaBg.onTouchBegin.Add(OnClickBg);
  54. _ui.m_btnPass.onClick.Add(Hide);
  55. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("zx_bg");
  56. UpdateEffect();
  57. }
  58. private void UpdateEffect()
  59. {
  60. string resPath = ResPathUtil.GetViewEffectPath("ui_ck", "ui_ck_zs");
  61. SceneController.AddObjectToView(gameObject, null, _ui.m_comCard.m_holder, resPath, out gameObject, out wrapper);
  62. string resPath0 = ResPathUtil.GetViewEffectPath("ui_LuckyBox", "bg_liuxing");
  63. SceneController.AddObjectToView(null, null, _ui.m_holder_star, resPath0, out _gameObject0, out _wrapper0);
  64. string resPath1 = ResPathUtil.GetViewEffectPath("ui_LuckyBox", "CK_UI");
  65. SceneController.AddObjectToView(null, null, _ui.m_holder_bg, resPath1, out _gameObject1, out _wrapper1);
  66. string resPath2 = ResPathUtil.GetViewEffectPath("ui_LuckyBox", "bg_cloud");
  67. SceneController.AddObjectToView(null, null, _ui.m_holder_cloud, resPath2, out _gameObject2, out _wrapper2);
  68. }
  69. protected override void OnShown()
  70. {
  71. base.OnShown();
  72. _rewardParamList.Clear();
  73. _rewardList.Clear();
  74. _rewardParamList.AddRange(this.viewData as List<ItemData>);
  75. _rewardList = this.viewData as List<ItemData>;
  76. _ui.m_btnPass.visible = false;
  77. _newRewardList.Clear();
  78. _oldRewardList.Clear();
  79. for (int i = 0; i < _rewardList.Count; i++)
  80. {
  81. if (GetThisCount(_rewardList[i].id, _rewardList) == ItemDataManager.GetItemNum(_rewardList[i].id) && !IsAddToNewRewardList(_rewardList[i].id))
  82. {
  83. _newRewardList.Add(_rewardList[i]);
  84. }
  85. else
  86. {
  87. _oldRewardList.Add(_rewardList[i]);
  88. }
  89. }
  90. UpdateView();
  91. }
  92. private void UpdateView()
  93. {
  94. _ui.m_btnPass.visible = _newRewardList.Count <= 1;
  95. _rewardList = _newRewardList.Count > 0 ? _newRewardList : _oldRewardList;
  96. if (_rewardList.Count - 1 < 0) return;
  97. ItemData itemdata = _rewardList[_rewardList.Count - 1];
  98. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemdata.id);
  99. string resPath = "";
  100. string resPath1 = "";
  101. switch (itemCfg.rarity)
  102. {
  103. case ConstDressRarity.Rarity_TIANYI:
  104. resPath = ResPathUtil.GetViewEffectPath("ui_LuckyBox", "CK_Yellow_01");
  105. SceneController.AddObjectToView(gameObject1, wrapper1, _ui.m_comCard.m_holder, resPath, out gameObject1, out wrapper1);
  106. _ui.m_comCard.m_holder.visible = true;
  107. resPath1 = ResPathUtil.GetViewEffectPath("ui_LuckyBox", "CK_Yellow_01_top");
  108. SceneController.AddObjectToView(gameObject2, wrapper2, _ui.m_comCard.m_holder1, resPath1, out gameObject2, out wrapper2);
  109. _ui.m_comCard.m_holder1.visible = true;
  110. break;
  111. case ConstDressRarity.Rarity_DIANCANG:
  112. resPath = ResPathUtil.GetViewEffectPath("ui_LuckyBox", "CK_Purple_02");
  113. SceneController.AddObjectToView(gameObject1, wrapper1, _ui.m_comCard.m_holder, resPath, out gameObject1, out wrapper1);
  114. _ui.m_comCard.m_holder.visible = true;
  115. resPath1 = ResPathUtil.GetViewEffectPath("ui_LuckyBox", "CK_Purple_02_top");
  116. SceneController.AddObjectToView(gameObject2, wrapper2, _ui.m_comCard.m_holder1, resPath1, out gameObject2, out wrapper2);
  117. _ui.m_comCard.m_holder1.visible = true;
  118. break;
  119. case ConstDressRarity.Rarity_ZHENXI:
  120. resPath = ResPathUtil.GetViewEffectPath("ui_LuckyBox", "CK_Bule_03");
  121. SceneController.AddObjectToView(gameObject1, wrapper1, _ui.m_comCard.m_holder, resPath, out gameObject1, out wrapper1);
  122. _ui.m_comCard.m_holder.visible = true;
  123. break;
  124. case ConstDressRarity.Rarity_FANPIN:
  125. resPath = ResPathUtil.GetViewEffectPath("ui_LuckyBox", "CK_grey_04");
  126. SceneController.AddObjectToView(gameObject1, wrapper1, _ui.m_comCard.m_holder, resPath, out gameObject1, out wrapper1);
  127. _ui.m_comCard.m_holder.visible = true;
  128. break;
  129. }
  130. _ui.m_comCard.m_loaType.url = ResPathUtil.GetCommonGameResPath("hd_sxicon_" + itemCfg.rarity);
  131. _ui.m_comCard.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  132. _ui.m_comCard.m_loaProperty.url = ResPathUtil.GetCommonGameResPath("kp_sx_" + itemCfg.mainScore);
  133. _ui.m_comCard.m_txtName.text = itemCfg.name;
  134. _ui.m_comCard.m_txtDiscribe.text = itemCfg.desc;
  135. if (itemCfg.itemType == ConstItemType.CARD)
  136. {
  137. _ui.m_t_open.Play(() =>
  138. {
  139. ViewManager.Show<LuckyBoxNewCardView>(itemCfg.id);
  140. });
  141. }
  142. else
  143. {
  144. _ui.m_t_open.Play();
  145. }
  146. if (LuckyBoxDataManager.Instance.FirstRewardList.ContainsKey(_rewardList.Count - 1) == true)
  147. {
  148. LuckyBoxDataManager.Instance.FirstRewardList.Remove(_rewardList.Count - 1);
  149. }
  150. _rewardList.RemoveAt(_rewardList.Count - 1);
  151. }
  152. private void OnClickBg()
  153. {
  154. if (_newRewardList.Count == 0 && _oldRewardList.Count == 0)
  155. {
  156. this.Hide();
  157. return;
  158. }
  159. _ui.m_t_close.Play(() =>
  160. {
  161. _ui.m_comCard.m_holder.visible = false;
  162. _ui.m_comCard.m_holder1.visible = false;
  163. _ui.m_t_open.Play();
  164. UpdateView();
  165. });
  166. }
  167. private int GetThisCount(int itemId, List<ItemData> rewards)
  168. {
  169. int count = 0;
  170. for (int i = 0; i < rewards.Count; i++)
  171. {
  172. if (rewards[i].id == itemId)
  173. {
  174. count++;
  175. }
  176. }
  177. return count;
  178. }
  179. private bool IsAddToNewRewardList(int itemId)
  180. {
  181. for (int i = 0; i < _rewardList.Count; i++)
  182. {
  183. if (itemId == _rewardList[i].id)
  184. {
  185. return true;
  186. }
  187. }
  188. return false;
  189. }
  190. protected override void OnHide()
  191. {
  192. _ui.m_t_close.Stop(true, false);
  193. _ui.m_t_open.Stop(true, false);
  194. _rewardList.Clear();
  195. base.OnHide();
  196. ViewManager.Show<LuckyBoxBonusShowView>(_rewardParamList);
  197. }
  198. }
  199. }