LuckyBoxView.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. using FairyGUI;
  2. using UI.LuckyBox;
  3. using UI.CommonGame;
  4. using System;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7. using ET;
  8. namespace GFGGame
  9. {
  10. public class LuckyBoxView : BaseWindow
  11. {
  12. private UI_LuckyBoxUI _ui;
  13. private ValueBarController _valueBarController;
  14. private GameObject _gameObject;
  15. private GoWrapper _wrapper;
  16. private GameObject _gameObject1;
  17. private GoWrapper _wrapper1;
  18. private GameObject _gameObject2;
  19. private GoWrapper _wrapper2;
  20. private GameObject _gameObject3;
  21. private GoWrapper _wrapper3;
  22. private bool isActiveBoxOpen = false;
  23. public override void Dispose()
  24. {
  25. _valueBarController.Dispose();
  26. _valueBarController = null;
  27. base.Dispose();
  28. }
  29. protected override void OnInit()
  30. {
  31. base.OnInit();
  32. packageName = UI_LuckyBoxUI.PACKAGE_NAME;
  33. _ui = UI_LuckyBoxUI.Create();
  34. this.viewCom = _ui.target;
  35. isfullScreen = true;
  36. _ui.m_txtRemainTimes.visible = false;
  37. _valueBarController = new ValueBarController(_ui.m_valueBar);
  38. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  39. _ui.m_btnHome.onClick.Add(OnClickBtnHome);
  40. _ui.m_btnBuyOne.target.onClick.Add(OnClickBtnBuyOne);
  41. _ui.m_btnBuyTen.target.onClick.Add(OnClickBtnBuyTen);
  42. _ui.m_btnPreview.target.onClick.Add(OnClickBtnPreview);
  43. _ui.m_btnExchange.target.onClick.Add(OnClickBtnExChange);
  44. _ui.m_btnLeft.onClick.Add(() => { onClickChange(-1); });
  45. _ui.m_btnRight.onClick.Add(() => { onClickChange(1); });
  46. _ui.m_listBg.itemRenderer = RenderListBgItem;
  47. _ui.m_c1.onChanged.Add(OnListBgScroll);//分页控制器
  48. // Reset();//初始默认值
  49. }
  50. protected override void OnShown()
  51. {
  52. base.OnShown();
  53. EventAgent.AddEventListener(ConstMessage.ITEM_CHANGED, UpdateNormal);
  54. EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateNormal);
  55. int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[0];
  56. if (this.viewData != null)
  57. {
  58. object[] datas = (this.viewData as object[]);
  59. if (datas != null && datas.Length > 1)
  60. {
  61. boxId = (int)datas[1];
  62. }
  63. else
  64. {
  65. boxId = (int)this.viewData;
  66. }
  67. }
  68. LuckyBoxDataManager.Instance.currentBoxId = boxId;
  69. isActiveBoxOpen = Array.IndexOf(LuckyBoxDataManager.Instance.luckyBoxIds, LuckyBoxDataManager.BOX_ID_1) >= 0;
  70. int index = Array.IndexOf(LuckyBoxDataManager.Instance.luckyBoxIds, LuckyBoxDataManager.Instance.currentBoxId);
  71. _ui.m_listBg.numItems = LuckyBoxDataManager.Instance.luckyBoxIds.Length;
  72. _ui.m_listBg.ScrollToView(index);
  73. _ui.m_listBg.scrollPane.decelerationRate = 0.8f;
  74. Timers.inst.Add(1, 0, CheckTime);
  75. _valueBarController.OnShown();
  76. _valueBarController.Controller(4);
  77. // onClickChange(0);
  78. // UpdateNormal();
  79. OnListBgScroll();
  80. updateBoxEffect();
  81. }
  82. private void RenderListBgItem(int index, GObject obj)
  83. {
  84. UI_ComListBgItem item = UI_ComListBgItem.Proxy(obj);
  85. LuckyBoxCfg cfg = LuckyBoxCfgArray.Instance.GetCfg(LuckyBoxDataManager.Instance.luckyBoxIds[index]);
  86. item.m_loaBg.url = string.Format("ui://LuckyBox/{0}", cfg.res);
  87. }
  88. private void CheckTime(object param = null)
  89. {
  90. if (!isActiveBoxOpen)
  91. {
  92. //活动未开启
  93. LuckyBoxDataManager.Instance.currentBoxId = LuckyBoxDataManager.Instance.luckyBoxIds[0];
  94. Timers.inst.Remove(CheckTime);
  95. return;
  96. }
  97. int endTime = LuckyBoxDataManager.Instance.endTime;
  98. int curTime = TimeHelper.ServerNowSecs;
  99. TimeUtil.FormattingTime(curTime, endTime, out int num, out string str);
  100. UI_ComListBgItem.Proxy(_ui.m_listBg.GetChildAt(0)).m_txtTime.text = string.Format("{0}", num);
  101. UI_ComListBgItem.Proxy(_ui.m_listBg.GetChildAt(0)).m_txtTimeStr.text = string.Format("{0}", str);
  102. }
  103. private void OnListBgScroll()
  104. {
  105. UI_ComListBgItem item = UI_ComListBgItem.Proxy(_ui.m_listBg.GetChildAt(_ui.m_c1.selectedIndex));
  106. LuckyBoxDataManager.Instance.currentBoxId = LuckyBoxDataManager.Instance.luckyBoxIds[_ui.m_c1.selectedIndex];
  107. item.m_grpTime.visible = LuckyBoxDataManager.Instance.currentBoxId == LuckyBoxDataManager.BOX_ID_1;
  108. item.m_imgTitle.visible = LuckyBoxDataManager.Instance.currentBoxId == LuckyBoxDataManager.BOX_ID_1;
  109. item.m_holder.visible = isActiveBoxOpen && LuckyBoxDataManager.Instance.currentBoxId == LuckyBoxDataManager.BOX_ID_1;
  110. item.m_holder1.visible = isActiveBoxOpen && LuckyBoxDataManager.Instance.currentBoxId == LuckyBoxDataManager.BOX_ID_1;
  111. item.m_loaImg.visible = LuckyBoxDataManager.Instance.currentBoxId == LuckyBoxDataManager.BOX_ID_3;
  112. onClickChange(0);
  113. UpdateNormal();
  114. }
  115. private void UpdateNormal()
  116. {
  117. LuckyBoxCfg luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(LuckyBoxDataManager.Instance.currentBoxId);
  118. _valueBarController.UpdateCJ(LuckyBoxDataManager.Instance.currentBoxId);
  119. _ui.m_comCostOne.m_txtCost.text = luckyBoxCfg.costNum.ToString();
  120. _ui.m_comCostTen.m_txtCost.text = luckyBoxCfg.costNumTen.ToString();
  121. _ui.m_comCostOne.m_loaCost.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(luckyBoxCfg.costID).res);
  122. _ui.m_comCostTen.m_loaCost.url = ResPathUtil.GetCommonGameResPath(ItemCfgArray.Instance.GetCfg(luckyBoxCfg.costID).res);
  123. _ui.m_btnPreview.m_c1.selectedIndex = _ui.m_c1.selectedIndex;
  124. _ui.m_btnExchange.m_c1.selectedIndex = _ui.m_c1.selectedIndex;
  125. int count = LuckyBoxDataManager.Instance.GetOwnedCount();
  126. _ui.m_txtOwned.SetVar("v1", "" + count).FlushVars();
  127. }
  128. private void onClickChange(int count)
  129. {
  130. _ui.m_c1.selectedIndex = _ui.m_c1.selectedIndex + count;
  131. _ui.m_imgSpecial.visible = LuckyBoxDataManager.Instance.currentBoxId == LuckyBoxDataManager.BOX_ID_1;
  132. _ui.m_btnRight.visible = _ui.m_c1.selectedIndex != _ui.m_listBg.numItems - 1;
  133. _ui.m_btnLeft.visible = _ui.m_c1.selectedIndex != 0;
  134. _ui.m_btnBuyOne.m_holder.visible = LuckyBoxDataManager.Instance.currentBoxId == LuckyBoxDataManager.BOX_ID_1;
  135. _ui.m_btnBuyTen.m_holder.visible = LuckyBoxDataManager.Instance.currentBoxId == LuckyBoxDataManager.BOX_ID_1;
  136. }
  137. private void updateBoxEffect()
  138. {
  139. if (isActiveBoxOpen)
  140. {
  141. int index = Array.IndexOf(LuckyBoxDataManager.Instance.luckyBoxIds, LuckyBoxDataManager.BOX_ID_1);
  142. UI_ComListBgItem item = UI_ComListBgItem.Proxy(_ui.m_listBg.GetChildAt(index));
  143. string resPath = ResPathUtil.GetViewEffectPath("ui_cj", "ui_cj_bt");
  144. SceneController.AddObjectToView(_gameObject, _wrapper, item.m_holder, resPath, out _gameObject, out _wrapper);
  145. string resPath3 = ResPathUtil.GetDressUpAnimationPath("dz_jiyuet");
  146. SceneController.AddObjectToView(_gameObject3, _wrapper3, item.m_holder1, resPath3, out _gameObject3, out _wrapper3, 120);
  147. string resPath1 = ResPathUtil.GetViewEffectPath("ui_cj", "ui_cj_sl");
  148. SceneController.AddObjectToView(_gameObject1, _wrapper1, _ui.m_btnBuyOne.m_holder, resPath1, out _gameObject1, out _wrapper1);
  149. SceneController.AddObjectToView(_gameObject2, _wrapper2, _ui.m_btnBuyTen.m_holder, resPath1, out _gameObject2, out _wrapper2);
  150. }
  151. }
  152. private void OnClickBtnExChange()
  153. {
  154. int storeId = LuckyBoxDataManager.Instance.currentBoxId == LuckyBoxDataManager.BOX_ID_1 ? ConstStoreId.LUCKY_BOX_ACTIVITY_STORE_ID : ConstStoreId.LUCKY_BOX_STORE_ID;
  155. ViewManager.Show(ViewName.CLOTHING_SHOP_VIEW, new object[] { storeId }, new object[] { ViewName.LUCKY_BOX_VIEW, LuckyBoxDataManager.Instance.currentBoxId });
  156. this.Hide();
  157. }
  158. private void OnClickBtnPreview()
  159. {
  160. ViewManager.Show(ViewName.LUCKY_BOX_PRE_SHOW_VIEW);
  161. }
  162. private void OnClickBtnBuyOne()
  163. {
  164. LuckyBoxDataManager.Instance.CheckItemEnough(LuckyBoxDataManager.Instance.currentBoxId, LuckyBoxDataManager.ONCE_TIME, async () =>
  165. {
  166. bool result = await LuckyBoxSProxy.ReqGetBonus(LuckyBoxDataManager.Instance.currentBoxId, LuckyBoxDataManager.ONCE_TIME);
  167. if (result)
  168. {
  169. ViewManager.Show(ViewName.LUCKY_BOX_STAR_VIEW, null, new object[] { ViewName.LUCKY_BOX_VIEW, LuckyBoxDataManager.Instance.currentBoxId });
  170. LogServerHelper.SendNodeLog((int)PlayParticipationEnum.ZAI_XING, 2);
  171. }
  172. });
  173. }
  174. private void OnClickBtnBuyTen()
  175. {
  176. LuckyBoxDataManager.Instance.CheckItemEnough(LuckyBoxDataManager.Instance.currentBoxId, LuckyBoxDataManager.TEN_TIME, async () =>
  177. {
  178. bool result = await LuckyBoxSProxy.ReqGetBonus(LuckyBoxDataManager.Instance.currentBoxId, LuckyBoxDataManager.TEN_TIME);
  179. if (result)
  180. {
  181. ViewManager.Show(ViewName.LUCKY_BOX_STAR_VIEW, null, new object[] { ViewName.LUCKY_BOX_VIEW, LuckyBoxDataManager.Instance.currentBoxId });
  182. LogServerHelper.SendNodeLog((int)PlayParticipationEnum.ZAI_XING, 2);
  183. }
  184. });
  185. }
  186. protected override void OnHide()
  187. {
  188. base.OnHide();
  189. _valueBarController.OnHide();
  190. Timers.inst.Remove(CheckTime);
  191. EventAgent.RemoveEventListener(ConstMessage.ITEM_CHANGED, UpdateNormal);
  192. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateNormal);
  193. }
  194. private void OnClickBtnBack()
  195. {
  196. this.Hide();
  197. Reset();
  198. ViewManager.GoBackFrom(ViewName.LUCKY_BOX_VIEW);
  199. }
  200. private void OnClickBtnHome()
  201. {
  202. GameController.GoBackToMainView();
  203. // Reset();
  204. }
  205. private void Reset()
  206. {
  207. LuckyBoxDataManager.Instance.currentBoxId = LuckyBoxDataManager.BOX_ID_1;
  208. }
  209. protected override void UpdateToCheckGuide(object param)
  210. {
  211. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  212. GuideController.TryGuide(_ui.m_btnBuyTen.target, ConstGuideId.LUCKY_BOX, 3, "点击摘取十次");
  213. GuideController.TryGuide(_ui.m_btnBack, ConstGuideId.FREEDOM_DRESS, 1, "获得一套完整的服装啦,马上去试穿一下");
  214. }
  215. }
  216. }