LuckyBoxView.cs 12 KB

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