LuckyBoxNewDressView.cs 9.0 KB

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