LuckyBoxNewDressView.cs 7.9 KB

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