LuckyBoxView.cs 13 KB

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