ActivityAfuGiftView.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. using System.Collections;
  2. using UnityEngine;
  3. using UI.ActivityAFuGift;
  4. using ET;
  5. using FairyGUI;
  6. using System;
  7. using UI.CommonGame;
  8. using static GFGGame.ShopSProxy;
  9. using System.Threading.Tasks;
  10. namespace GFGGame
  11. {
  12. public class ActivityAfuGiftView : BaseWindow
  13. {
  14. private UI_ActivityAFuGiftUI _ui;
  15. private GList _rewardListUI;
  16. private struct GetState
  17. {
  18. public int rewardID;
  19. public bool canGet;
  20. public bool isVip;
  21. }
  22. public override void Dispose()
  23. {
  24. base.Dispose();
  25. }
  26. protected override void OnInit()
  27. {
  28. base.OnInit();
  29. packageName = UI_ActivityAFuGiftUI.PACKAGE_NAME;
  30. _ui = UI_ActivityAFuGiftUI.Create();
  31. viewCom = _ui.target;
  32. viewCom.Center();
  33. modal = true;
  34. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  35. _ui.m_btnClose.onClick.Add(Hide);
  36. _ui.m_btnGet.onClick.Add(OnClickBtnGet);
  37. // Data
  38. ActivityAfuGiftDataManager.Instance.InitActivityInfo();
  39. // UI
  40. _rewardListUI = _ui.m_panel.m_scrollPane.m_list;
  41. _rewardListUI.itemRenderer = RenderListReward;
  42. _rewardListUI.numItems = ActivityAfuGiftDataManager.Instance.RewardCfgs.Count;
  43. InitUI();
  44. }
  45. protected override void OnShown()
  46. {
  47. base.OnShown();
  48. ProgressAutoLocate();
  49. UpdateTime(null);
  50. Timers.inst.Add(1, 0, UpdateTime);
  51. UpdateState();
  52. }
  53. protected override void OnHide()
  54. {
  55. base.OnHide();
  56. Timers.inst.Remove(UpdateTime);
  57. }
  58. protected override void AddEventListener()
  59. {
  60. base.AddEventListener();
  61. EventAgent.AddEventListener(ConstMessage.RED_CHANGE, UpdateState);
  62. }
  63. protected override void RemoveEventListener()
  64. {
  65. base.RemoveEventListener();
  66. EventAgent.RemoveEventListener(ConstMessage.RED_CHANGE, UpdateState);
  67. }
  68. private void InitUI()
  69. {
  70. _ui.m_c1.SetSelectedIndex(ActivityAfuGiftDataManager.Instance.GetIsBuy() ? 1 : 0);
  71. // 使列表宽度等于子节点的总宽度
  72. float itemWidth = _rewardListUI.GetChildAt(0).width;
  73. float columnGap = _rewardListUI.columnGap;
  74. _rewardListUI.width = CalculateListWidth(_rewardListUI.numItems, itemWidth, columnGap);
  75. Timers.inst.StartCoroutine(InitProgressWidth());
  76. }
  77. private IEnumerator InitProgressWidth()
  78. {
  79. GProgressBar gProgressBar = _ui.m_panel.m_scrollPane.m_progress;
  80. gProgressBar.width = 0;
  81. // 等待窗口动画结束
  82. yield return new WaitForSeconds(0.3f);
  83. // 根据列表 初始化进度条长度
  84. float marginLeft = 149;
  85. gProgressBar.width = marginLeft + _rewardListUI.GetChildAt(_rewardListUI.numChildren - 1).position.x - _rewardListUI.GetChildAt(0).position.x;
  86. // 初始化进度条值
  87. int indexDay = ActivityAfuGiftDataManager.Instance.GetIndexDay();
  88. gProgressBar.value = CalculateProgressCount(indexDay, _rewardListUI.numChildren);
  89. }
  90. /// <summary>
  91. /// 滚动到最新日期
  92. /// </summary>
  93. private void ProgressAutoLocate()
  94. {
  95. _ui.m_panel.m_scrollPane.target.scrollPane.posX
  96. = (ActivityAfuGiftDataManager.Instance.GetIndexDay() - 1) * (_rewardListUI.GetChildAt(0).width + _rewardListUI.columnGap);
  97. }
  98. private float CalculateListWidth(int num, float itemWidth, float columnGap)
  99. {
  100. return num * itemWidth + (num - 1) * columnGap;
  101. }
  102. private double CalculateProgressCount(int indexDay, int sumDay)
  103. {
  104. int defaultLen = 18;
  105. if (indexDay == sumDay)
  106. {
  107. return 100;
  108. }
  109. if (indexDay == 1)
  110. {
  111. return defaultLen;
  112. }
  113. return defaultLen + (100 - defaultLen) / (sumDay - 1) * (indexDay - 1);
  114. }
  115. private void UpdateTime(object param)
  116. {
  117. long curTime = TimeHelper.ServerNow();
  118. long endTime = ActivityAfuGiftDataManager.Instance.GetEndTime();
  119. _ui.m_txtTime.text = TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime);
  120. }
  121. private void RenderListReward(int index, GObject item)
  122. {
  123. item.data = index;
  124. UI_reward.ProxyEnd();
  125. UI_reward rewardUI = UI_reward.Proxy(item);
  126. rewardUI.m_day.m_day.SetVar("day", (index + 1).ToString()).FlushVars();
  127. // 已经到达的日期
  128. int passDay = ActivityAfuGiftDataManager.Instance.GetIndexDay();
  129. int arrive = (index + 1) <= passDay ? 0 : 1;
  130. rewardUI.m_day.m_light.SetSelectedIndex(arrive);
  131. // 当日高亮
  132. rewardUI.m_c1.SetSelectedIndex((index + 1) == passDay ? 1 : 0);
  133. int itemNormalId = ActivityAfuGiftDataManager.Instance.RewardCfgs[index].bonusFreeArr[0][0];
  134. int itemVipId1 = ActivityAfuGiftDataManager.Instance.RewardCfgs[index].bonusPayArr[0][0];
  135. int itemVipId2 = ActivityAfuGiftDataManager.Instance.RewardCfgs[index].bonusPayArr[1][0];
  136. LoadItem(itemNormalId, rewardUI.m_reward_normal, ActivityAfuGiftDataManager.Instance.RewardCfgs[index].bonusFreeArr[0][1]);
  137. LoadItem(itemVipId1, rewardUI.m_reward_vip1, ActivityAfuGiftDataManager.Instance.RewardCfgs[index].bonusPayArr[0][1], true);
  138. LoadItem(itemVipId2, rewardUI.m_reward_vip2, ActivityAfuGiftDataManager.Instance.RewardCfgs[index].bonusPayArr[1][1], true, true);
  139. }
  140. private void LoadItem(int itemID, GObject obj, int num, bool isVip = false, bool release = false)
  141. {
  142. ItemCfg itemNormal = ItemCfgArray.Instance.GetCfg(itemID);
  143. UI_ComItem comItem = UI_ComItem.Proxy(obj);
  144. comItem.m_loaIcon.url = ResPathUtil.GetIconPath(itemNormal);
  145. comItem.m_txtCount.text = num.ToString();
  146. comItem.m_QualityType.selectedIndex = itemNormal.rarity - 1;
  147. comItem.target.onClick.Add(OnItemClick);
  148. int dayIndex = (int)obj.parent.data + 1;
  149. // 已经到达的日期
  150. int passDay = ActivityAfuGiftDataManager.Instance.GetIndexDay();
  151. bool arrive = dayIndex <= passDay;
  152. if (isVip)
  153. {
  154. if (ActivityAfuGiftDataManager.Instance.GetIsBuy())
  155. {
  156. comItem.m_Lock.SetSelectedIndex(arrive ? 0 : 2);
  157. }
  158. else
  159. {
  160. comItem.m_Lock.SetSelectedIndex(1);
  161. }
  162. }
  163. else
  164. {
  165. comItem.m_Lock.SetSelectedIndex(arrive ? 0 : 2);
  166. }
  167. bool canGet = false;
  168. int getState;
  169. if (arrive)
  170. {
  171. // Vip专属
  172. if (isVip)
  173. {
  174. getState = ActivityAfuGiftDataManager.Instance.GetSuperRewardStateByDay(dayIndex - 1);
  175. }
  176. else
  177. {
  178. getState = ActivityAfuGiftDataManager.Instance.GetNormalRewardStateByDay(dayIndex - 1);
  179. }
  180. switch (getState)
  181. {
  182. case ConstBonusStatus.CAN_NOT_GET:
  183. comItem.m_grpGot.visible = false;
  184. obj.touchable = true;
  185. // 隐藏红点
  186. RedDotController.Instance.SetComRedDot(obj.asCom, false);
  187. break;
  188. case ConstBonusStatus.CAN_GET:
  189. canGet = true;
  190. comItem.m_grpGot.visible = false;
  191. obj.touchable = true;
  192. // 显示红点
  193. RedDotController.Instance.SetComRedDot(obj.asCom, true, "", -33, 27);
  194. break;
  195. case ConstBonusStatus.GOT:
  196. comItem.m_grpGot.visible = true;
  197. obj.touchable = false;
  198. // 隐藏红点
  199. RedDotController.Instance.SetComRedDot(obj.asCom, false);
  200. break;
  201. }
  202. }
  203. obj.data = new GetState
  204. {
  205. rewardID = itemID,
  206. isVip = isVip,
  207. canGet = canGet
  208. };
  209. UI_ComItem.ProxyEnd();
  210. }
  211. private void OnItemClick(EventContext eventContext)
  212. {
  213. GObject obj = (GObject)eventContext.sender;
  214. GetState getState = (GetState)(obj.data);
  215. if (getState.canGet)
  216. {
  217. GetReward(getState, (int)obj.parent.data + 1);
  218. }
  219. else
  220. {
  221. GoodsItemTipsController.ShowItemTips(getState.rewardID);
  222. }
  223. }
  224. private async Task GetReward(GetState getState, int indexDay)
  225. {
  226. ActivityAfuGiftDataManager.Instance.ClearGetReward();
  227. await ActivityAfuGiftProxy.ReqGetReward(getState.isVip, indexDay);
  228. // 奖励弹窗
  229. BonusController.TryShowBonusList(ActivityAfuGiftDataManager.Instance.GetRewardList);
  230. }
  231. private async Task GetAllReward()
  232. {
  233. int passDay = ActivityAfuGiftDataManager.Instance.GetIndexDay();
  234. ActivityAfuGiftDataManager.Instance.ClearGetReward();
  235. for (int i = passDay - 1; i >= 0; i--)
  236. {
  237. if (ActivityAfuGiftDataManager.Instance.GetNormalRewardStateByDay(i) == ConstBonusStatus.CAN_GET)
  238. {
  239. await ActivityAfuGiftProxy.ReqGetReward(false, (i + 1));
  240. }
  241. if (ActivityAfuGiftDataManager.Instance.GetSuperRewardStateByDay(i) == ConstBonusStatus.CAN_GET)
  242. {
  243. await ActivityAfuGiftProxy.ReqGetReward(true, (i + 1));
  244. }
  245. }
  246. // 奖励弹窗
  247. BonusController.TryShowBonusList(ActivityAfuGiftDataManager.Instance.GetRewardList);
  248. }
  249. /// <summary>
  250. /// 领取所有奖励按钮
  251. /// </summary>
  252. private void OnClickBtnGet()
  253. {
  254. if (!ActivityAfuGiftDataManager.Instance.GetIsBuy())
  255. {
  256. // 跳转充值画面
  257. ReqShopBuy(990005).Coroutine();
  258. return;
  259. }
  260. GetAllReward();
  261. }
  262. /// <summary>
  263. /// 充值,领取东西后调用
  264. /// </summary>
  265. private void UpdateState()
  266. {
  267. // 更新底部按钮文本
  268. _ui.m_c1.SetSelectedIndex(ActivityAfuGiftDataManager.Instance.GetIsBuy() ? 1 : 0);
  269. // 更新锁 红点状态
  270. _rewardListUI.numItems = ActivityAfuGiftDataManager.Instance.RewardCfgs.Count;
  271. UpdateButtonState();
  272. }
  273. /// <summary>
  274. /// 更新一键领取按钮状态
  275. /// </summary>
  276. public void UpdateButtonState()
  277. {
  278. if (ActivityAfuGiftDataManager.Instance.GetIsBuy())
  279. {
  280. // 0-普通 1-变灰
  281. _ui.m_btnGetState.SetSelectedIndex(ActivityAfuGiftDataManager.Instance.HaveCanGetReward() ? 0 : 1);
  282. }
  283. // 没有充值,保持常亮
  284. else
  285. {
  286. _ui.m_btnGetState.SetSelectedIndex(0);
  287. }
  288. }
  289. }
  290. }