LuckyBoxView.cs 13 KB

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