LuckyBoxNewDressView.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. long hasCount = ItemDataManager.GetItemNum(_rewardList[i].id);
  82. int thisCount = GetThisCount(_rewardList[i].id, _rewardList);
  83. bool isAddToNew = IsAddToNewRewardList(_rewardList[i].id);
  84. if (thisCount == hasCount && !isAddToNew)
  85. {
  86. _newRewardList.Add(_rewardList[i]);
  87. }
  88. else
  89. {
  90. _oldRewardList.Add(_rewardList[i]);
  91. }
  92. }
  93. UpdateView();
  94. }
  95. private void UpdateView()
  96. {
  97. _ui.m_btnPass.visible = _newRewardList.Count <= 1;
  98. _rewardList = _newRewardList.Count > 0 ? _newRewardList : _oldRewardList;
  99. if (_rewardList.Count - 1 < 0) return;
  100. ItemData itemdata = _rewardList[_rewardList.Count - 1];
  101. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemdata.id);
  102. string resPath = "";
  103. string resPath1 = "";
  104. switch (itemCfg.rarity)
  105. {
  106. case ConstDressRarity.Rarity_TIANYI:
  107. resPath = ResPathUtil.GetViewEffectPath("ui_LuckyBox", "CK_Yellow_01");
  108. SceneController.AddObjectToView(gameObject1, wrapper1, _ui.m_comCard.m_holder, resPath, out gameObject1, out wrapper1);
  109. _ui.m_comCard.m_holder.visible = true;
  110. resPath1 = ResPathUtil.GetViewEffectPath("ui_LuckyBox", "CK_Yellow_01_top");
  111. SceneController.AddObjectToView(gameObject2, wrapper2, _ui.m_comCard.m_holder1, resPath1, out gameObject2, out wrapper2);
  112. _ui.m_comCard.m_holder1.visible = true;
  113. break;
  114. case ConstDressRarity.Rarity_DIANCANG:
  115. resPath = ResPathUtil.GetViewEffectPath("ui_LuckyBox", "CK_Purple_02");
  116. SceneController.AddObjectToView(gameObject1, wrapper1, _ui.m_comCard.m_holder, resPath, out gameObject1, out wrapper1);
  117. _ui.m_comCard.m_holder.visible = true;
  118. resPath1 = ResPathUtil.GetViewEffectPath("ui_LuckyBox", "CK_Purple_02_top");
  119. SceneController.AddObjectToView(gameObject2, wrapper2, _ui.m_comCard.m_holder1, resPath1, out gameObject2, out wrapper2);
  120. _ui.m_comCard.m_holder1.visible = true;
  121. break;
  122. case ConstDressRarity.Rarity_ZHENXI:
  123. resPath = ResPathUtil.GetViewEffectPath("ui_LuckyBox", "CK_Bule_03");
  124. SceneController.AddObjectToView(gameObject1, wrapper1, _ui.m_comCard.m_holder, resPath, out gameObject1, out wrapper1);
  125. _ui.m_comCard.m_holder.visible = true;
  126. break;
  127. case ConstDressRarity.Rarity_FANPIN:
  128. resPath = ResPathUtil.GetViewEffectPath("ui_LuckyBox", "CK_grey_04");
  129. SceneController.AddObjectToView(gameObject1, wrapper1, _ui.m_comCard.m_holder, resPath, out gameObject1, out wrapper1);
  130. _ui.m_comCard.m_holder.visible = true;
  131. break;
  132. }
  133. _ui.m_comCard.m_loaType.url = ResPathUtil.GetCommonGameResPath("hd_sxicon_" + itemCfg.rarity);
  134. _ui.m_comCard.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  135. _ui.m_comCard.m_loaProperty.url = ResPathUtil.GetCommonGameResPath("kp_sx_" + itemCfg.mainScore);
  136. _ui.m_comCard.m_txtName.text = itemCfg.name;
  137. _ui.m_comCard.m_txtDiscribe.text = itemCfg.desc;
  138. if (itemCfg.itemType == ConstItemType.CARD)
  139. {
  140. _ui.m_t_open.Play(() =>
  141. {
  142. ViewManager.Show<LuckyBoxNewCardView>(itemCfg.id);
  143. });
  144. }
  145. else
  146. {
  147. _ui.m_t_open.Play();
  148. }
  149. if (LuckyBoxDataManager.Instance.FirstRewardList.ContainsKey(_rewardList.Count - 1) == true)
  150. {
  151. LuckyBoxDataManager.Instance.FirstRewardList.Remove(_rewardList.Count - 1);
  152. }
  153. _rewardList.RemoveAt(_rewardList.Count - 1);
  154. }
  155. private void OnClickBg()
  156. {
  157. if (_newRewardList.Count == 0 && _oldRewardList.Count == 0)
  158. {
  159. this.Hide();
  160. return;
  161. }
  162. _ui.m_t_close.Play(() =>
  163. {
  164. _ui.m_comCard.m_holder.visible = false;
  165. _ui.m_comCard.m_holder1.visible = false;
  166. _ui.m_t_open.Play();
  167. UpdateView();
  168. });
  169. }
  170. private int GetThisCount(int itemId, List<ItemData> rewards)
  171. {
  172. int count = 0;
  173. for (int i = 0; i < rewards.Count; i++)
  174. {
  175. if (rewards[i].id == itemId)
  176. {
  177. count++;
  178. }
  179. }
  180. return count;
  181. }
  182. private bool IsAddToNewRewardList(int itemId)
  183. {
  184. for (int i = 0; i < _newRewardList.Count; i++)
  185. {
  186. if (itemId == _newRewardList[i].id)
  187. {
  188. return true;
  189. }
  190. }
  191. return false;
  192. }
  193. protected override void OnHide()
  194. {
  195. _ui.m_t_close.Stop(true, false);
  196. _ui.m_t_open.Stop(true, false);
  197. _rewardList.Clear();
  198. base.OnHide();
  199. ViewManager.Show<LuckyBoxBonusShowView>(_rewardParamList);
  200. }
  201. }
  202. }