ActivityHuaRongDaoEntryView.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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("gf_pjxq_bj");
  24. _ui.m_btnStart.onClick.Add(OnBtnStartClick);
  25. _ui.m_btnBack.onClick.Add(OnBtnBackClick);
  26. _ui.m_btnClose.onClick.Add(OnBtnBackClick);
  27. InitBtnRule();
  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. _activityID = (int)viewData;
  46. InitIDList();
  47. _ui.m_activityID.selectedPage = _activityID.ToString();
  48. isReturnView = _ui.m_btnBack.touchable;
  49. await UpdateUIAsync();
  50. if (!isShowing)
  51. {
  52. return;
  53. }
  54. _ui.m_show.Play();
  55. UpdateTime(null);
  56. Timers.inst.Remove(UpdateTime);
  57. Timers.inst.Add(1, 0, UpdateTime);
  58. }
  59. protected override void OnHide()
  60. {
  61. base.OnHide();
  62. Timers.inst.Remove(UpdateTime);
  63. }
  64. protected override void AddEventListener()
  65. {
  66. base.AddEventListener();
  67. EventAgent.AddEventListener(ConstMessage.ACTIVITY_HUARONGDAO_UPDATE, UpdateUI);
  68. }
  69. protected override void RemoveEventListener()
  70. {
  71. base.RemoveEventListener();
  72. EventAgent.RemoveEventListener(ConstMessage.ACTIVITY_HUARONGDAO_UPDATE, UpdateUI);
  73. }
  74. /// <summary>
  75. /// 初始化关卡列表
  76. /// </summary>
  77. private void InitIDList()
  78. {
  79. IDList = new List<int>();
  80. string gameID = ActivityOpenCfgArray.Instance.GetCfg(_activityID).params5Arr[0];
  81. int gameTypeID = int.Parse(gameID.Split('_')[1]);
  82. HuarongRoadGame[] cfgs = HuarongRoadGameArray.Instance.dataArray;
  83. foreach (var t in cfgs)
  84. {
  85. if(t.subType == gameTypeID)
  86. {
  87. IDList.Add(t.id);
  88. }
  89. }
  90. }
  91. private void UpdateUI()
  92. {
  93. UpdateUIAsync();
  94. }
  95. private async Task<bool> UpdateUIAsync()
  96. {
  97. await InitInfo();
  98. UpdateRedDots();
  99. return true;
  100. }
  101. private async Task InitInfo()
  102. {
  103. curLevel = await GetCurLevel(_activityID);
  104. RoleLimitData limitData;
  105. _ui.m_curLevel.text = curLevel.ToString();
  106. // 所有关卡都通关了
  107. if (curLevel == IDList.Count)
  108. {
  109. _ui.m_challengeTimes.SetVar("have", "0").SetVar("sum", "0").FlushVars();
  110. }
  111. else
  112. {
  113. limitData = RoleLimitDataManager.GetLimitData(HuarongRoadGameArray.Instance.GetCfg(IDList[curLevel]).comsumeLimit);
  114. int times = limitData.TotalPlayMax - limitData.PlayTimes;
  115. _ui.m_challengeTimes.SetVar("have", times.ToString())
  116. .SetVar("sum", limitData.TotalPlayMax.ToString()).FlushVars();
  117. }
  118. InitProgress();
  119. ProgressAutoLocate();
  120. }
  121. private void InitProgress()
  122. {
  123. _ui.m_scrollPane.m_listBar.numItems = curLevel;
  124. _ui.m_scrollPane.m_listBg.numItems = IDList.Count;
  125. _ui.m_scrollPane.m_listItems.numItems = IDList.Count;
  126. _ui.m_scrollPane.m_listBg.ResizeToFit();
  127. }
  128. private void ProgressAutoLocate()
  129. {
  130. _ui.m_scrollPane.target.scrollPane.posX
  131. = curLevel * (_ui.m_scrollPane.m_listBg.GetChildAt(0).width + _ui.m_scrollPane.m_listBg.columnGap)
  132. + (curLevel > 0 ? -150 : 0);
  133. }
  134. private void RenderListItem(int index, GObject gObject)
  135. {
  136. gObject.data = index;
  137. UI_progressBgItem item = UI_progressBgItem.Proxy(gObject);
  138. item.m_levelNum.text = (index + 1).ToString();
  139. UI_progressBgItem.ProxyEnd();
  140. }
  141. private void RenderRewardListItem(int index, GObject gObject)
  142. {
  143. gObject.data = index;
  144. UI_reward reward = UI_reward.Proxy(gObject);
  145. int id = HuarongRoadGameArray.Instance.GetCfg(IDList[index]).bonusWinArr[0][0];
  146. reward.m_loaIcon.url = ResPathUtil.GetIconPath(ItemCfgArray.Instance.GetCfg(id));
  147. reward.m_c1.SetSelectedIndex(curLevel > index ? 1 : 0);
  148. reward.target.touchable = (curLevel <= index);
  149. reward.target.data = index;
  150. reward.target.onClick.Add(OnClickReward);
  151. UI_reward.ProxyEnd();
  152. }
  153. private void OnClickReward(EventContext eventContext)
  154. {
  155. GObject obj = (GObject)eventContext.sender;
  156. int id = (int)obj.data;
  157. //ViewManager.Show<GiftDetailView>(HuarongRoadGameArray.Instance.GetCfg(IDList[id]).bonusWinArr);
  158. GoodsItemTipsController.ShowItemTips(HuarongRoadGameArray.Instance.GetCfg(IDList[id]).bonusWinArr[0][0]);
  159. }
  160. private void OnBtnBackClick()
  161. {
  162. Hide();
  163. }
  164. private void InitBtnRule()
  165. {
  166. if (_ui.m_btnRule.data == null)
  167. {
  168. _ui.m_btnRule.onClick.Add(RuleController.ShowRuleView);
  169. _ui.m_btnRule.data = 300025;
  170. }
  171. }
  172. private async void OnBtnStartClick()
  173. {
  174. // 通关了所有
  175. if(curLevel == IDList.Count)
  176. {
  177. PromptController.Instance.ShowFloatTextPrompt("已通关所有关卡");
  178. return;
  179. }
  180. HuarongRoadGame cfg = HuarongRoadGameArray.Instance.GetCfg(IDList[curLevel]);
  181. var result = await MiniGameProxy.ReqMiniGameStart(cfg.id, cfg.type, _activityID);
  182. if (!result || !isShowing) return;
  183. ViewManager.Show<ActivityHuaRongDaoView>(new object[] { cfg, _activityID });
  184. }
  185. private async Task<int> GetCurLevel(int id)
  186. {
  187. var result = await MiniGameProxy.ReqGetActivityGameInfos(id);
  188. if (!result)
  189. {
  190. return -1;
  191. }
  192. int i;
  193. for (i = 0; i < MiniGameDateManager.Instance.gameinfoList.Count; i++)
  194. {
  195. if (!MiniGameDateManager.Instance.gameinfoList[i].IsCleared)
  196. {
  197. return i;
  198. }
  199. }
  200. return i;
  201. }
  202. private void UpdateTime(object param)
  203. {
  204. long curTime = TimeHelper.ServerNow();
  205. var activityInfo = ActivityGlobalDataManager.Instance.GetActivityInfo(_activityID);
  206. if (activityInfo != null)
  207. {
  208. long endTime = activityInfo.EndTime;
  209. _ui.m_txtTime.text = "剩余" + TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime);
  210. }
  211. }
  212. private void UpdateRedDots()
  213. {
  214. RedDotController.Instance.SetComRedDot(_ui.m_btnStart, RedDotDataManager.Instance.GetActivityFYJYRed(), "", -16, -8, false);
  215. EventAgent.DispatchEvent(ConstMessage.ACTIVITY_RED_CHANGE, ActivityType.AfternoonLeisure);
  216. }
  217. }
  218. }