ActivityHuaRongDaoEntryView.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. using System.Collections;
  2. using UnityEngine;
  3. using UI.ActivityHuaRongDao;
  4. using System.Collections.Generic;
  5. using FairyGUI;
  6. using System.Threading.Tasks;
  7. using ET;
  8. namespace GFGGame
  9. {
  10. public class ActivityHuaRongDaoEntryView : BaseWindow
  11. {
  12. private UI_ActivityHuaRongDaoEntryUI _ui;
  13. private int curLevel;
  14. private int _activityID;
  15. private List<int> IDList;
  16. protected override void OnInit()
  17. {
  18. base.OnInit();
  19. packageName = UI_ActivityHuaRongDaoEntryUI.PACKAGE_NAME;
  20. _ui = UI_ActivityHuaRongDaoEntryUI.Create();
  21. viewCom = _ui.target;
  22. isfullScreen = true;
  23. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("quanping_moren_bg");
  24. _ui.m_btnStart.onClick.Add(OnBtnStartClick);
  25. _ui.m_btnBack.onClick.Add(OnBtnBackClick);
  26. InitBtnRule();
  27. InitIDList();
  28. _ui.m_scrollPane.m_listBg.itemRenderer = RenderListItem;
  29. _ui.m_scrollPane.m_listItems.itemRenderer = RenderRewardListItem;
  30. //_ui.m_scrollPane.m_listBg.onClickItem.Add(OnClickReward);
  31. }
  32. public override void Dispose()
  33. {
  34. if (_ui != null)
  35. {
  36. _ui.Dispose();
  37. _ui = null;
  38. }
  39. base.Dispose();
  40. }
  41. protected override async void OnShown()
  42. {
  43. base.OnShown();
  44. _ui.m_hide.Play();
  45. InitActivityID();
  46. await InitInfo();
  47. _ui.m_show.Play();
  48. UpdateTime(null);
  49. Timers.inst.Add(1, 0, UpdateTime);
  50. }
  51. protected override void OnHide()
  52. {
  53. base.OnHide();
  54. Timers.inst.Remove(UpdateTime);
  55. }
  56. protected override void AddEventListener()
  57. {
  58. base.AddEventListener();
  59. EventAgent.AddEventListener(ConstMessage.ACTIVITY_HUARONGDAO_UPDATE, UpdateUI);
  60. }
  61. protected override void RemoveEventListener()
  62. {
  63. base.RemoveEventListener();
  64. EventAgent.RemoveEventListener(ConstMessage.ACTIVITY_HUARONGDAO_UPDATE, UpdateUI);
  65. }
  66. private void InitIDList()
  67. {
  68. IDList = new List<int>();
  69. HuarongRoadGame[] cfgs = HuarongRoadGameArray.Instance.dataArray;
  70. foreach (var t in cfgs)
  71. {
  72. IDList.Add(t.id);
  73. }
  74. }
  75. private void UpdateUI()
  76. {
  77. InitInfo();
  78. }
  79. private async Task InitInfo()
  80. {
  81. curLevel = await GetCurLevel(_activityID);
  82. RoleLimitData limitData = RoleLimitDataManager.GetLimitData(HuarongRoadGameArray.Instance.GetCfg(IDList[curLevel]).comsumeLimit);
  83. int times = limitData.TotalPlayMax - limitData.PlayTimes;
  84. _ui.m_curLevel.text = curLevel.ToString();
  85. _ui.m_challengeTimes.SetVar("have", times.ToString())
  86. .SetVar("sum", limitData.TotalPlayMax.ToString()).FlushVars();
  87. InitProgress();
  88. ProgressAutoLocate();
  89. }
  90. private void InitProgress()
  91. {
  92. _ui.m_scrollPane.m_listBar.numItems = curLevel;
  93. _ui.m_scrollPane.m_listBg.numItems = IDList.Count;
  94. _ui.m_scrollPane.m_listItems.numItems = IDList.Count;
  95. _ui.m_scrollPane.m_listBg.ResizeToFit();
  96. }
  97. private void ProgressAutoLocate()
  98. {
  99. _ui.m_scrollPane.target.scrollPane.posX
  100. = curLevel * (_ui.m_scrollPane.m_listBg.GetChildAt(0).width + _ui.m_scrollPane.m_listBg.columnGap)
  101. + (curLevel > 0 ? -100 : 0);
  102. }
  103. private void RenderListItem(int index, GObject gObject)
  104. {
  105. gObject.data = index;
  106. UI_progressBgItem item = UI_progressBgItem.Proxy(gObject);
  107. item.m_levelNum.text = (index + 1).ToString();
  108. UI_progressBgItem.ProxyEnd();
  109. }
  110. private void RenderRewardListItem(int index, GObject gObject)
  111. {
  112. gObject.data = index;
  113. UI_reward reward = UI_reward.Proxy(gObject);
  114. int id = HuarongRoadGameArray.Instance.GetCfg(IDList[index]).bonusWinArr[0][0];
  115. reward.m_loaIcon.url = ResPathUtil.GetIconPath(ItemCfgArray.Instance.GetCfg(id));
  116. reward.m_c1.SetSelectedIndex(curLevel > index ? 1 : 0);
  117. reward.target.touchable = (curLevel <= index);
  118. reward.target.data = index;
  119. reward.target.onClick.Add(OnClickReward);
  120. UI_reward.ProxyEnd();
  121. }
  122. private void OnClickReward(EventContext eventContext)
  123. {
  124. GObject obj = (GObject)eventContext.sender;
  125. int id = (int)obj.data;
  126. //ViewManager.Show<GiftDetailView>(HuarongRoadGameArray.Instance.GetCfg(IDList[id]).bonusWinArr);
  127. GoodsItemTipsController.ShowItemTips(HuarongRoadGameArray.Instance.GetCfg(IDList[id]).bonusWinArr[0][0]);
  128. }
  129. private void OnBtnBackClick()
  130. {
  131. Hide();
  132. }
  133. private void InitBtnRule()
  134. {
  135. if (_ui.m_btnRule.data == null)
  136. {
  137. _ui.m_btnRule.onClick.Add(RuleController.ShowRuleView);
  138. _ui.m_btnRule.data = 300025;
  139. }
  140. }
  141. private async void OnBtnStartClick()
  142. {
  143. HuarongRoadGame cfg = HuarongRoadGameArray.Instance.dataArray[curLevel];
  144. var result = await MiniGameProxy.ReqMiniGameStart(cfg.id, cfg.type, _activityID);
  145. if (!result) return;
  146. ViewManager.Show<ActivityHuaRongDaoView>(new object[] { cfg, _activityID });
  147. }
  148. private async Task<int> GetCurLevel(int id)
  149. {
  150. var result = await MiniGameProxy.ReqGetChallengeReward(id);
  151. if (!result)
  152. {
  153. return -1;
  154. }
  155. for(int i = 0;i < MiniGameDateManager.Instance.gameinfoList.Count; i++)
  156. {
  157. if (!MiniGameDateManager.Instance.gameinfoList[i].IsCleared)
  158. {
  159. return i;
  160. }
  161. }
  162. return -1;
  163. }
  164. private void InitActivityID()
  165. {
  166. _activityID = 5003;
  167. }
  168. private void UpdateTime(object param)
  169. {
  170. long curTime = TimeHelper.ServerNow();
  171. var activityInfo = ActivityGlobalDataManager.Instance.GetActivityInfo(_activityID);
  172. if (activityInfo != null)
  173. {
  174. long endTime = activityInfo.EndTime;
  175. _ui.m_txtTime.text = "剩余" + TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime);
  176. }
  177. }
  178. }
  179. }