ActivityDay7View.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. using System.Collections.Generic;
  2. using ET;
  3. using FairyGUI;
  4. using Game.HotUpdate.ServerProxy;
  5. using UI.ActivityDay7;
  6. using UI.CommonGame;
  7. using UI.Task;
  8. namespace GFGGame
  9. {
  10. public class ActivityDay7View : BaseWindow
  11. {
  12. private UI_ActivityDay7UI _ui;
  13. //7日活动配置
  14. private Activity7DaysCfg[] cfgDataArray;
  15. //7日活动积分配置
  16. private Activity7DaysCfg[] activity7DaysCfgs;
  17. //选中的天数index 天数=index+1
  18. private int onClickDayIndex;
  19. public override void Dispose()
  20. {
  21. if (_ui != null)
  22. {
  23. _ui.Dispose();
  24. _ui = null;
  25. }
  26. base.Dispose();
  27. }
  28. protected override void OnInit()
  29. {
  30. base.OnInit();
  31. packageName = UI_ActivityDay7UI.PACKAGE_NAME;
  32. _ui = UI_ActivityDay7UI.Create();
  33. viewCom = _ui.target;
  34. isfullScreen = true;
  35. bringToFontOnClick = false;
  36. _ui.m_btnBack.onClick.Add(OnBtnBackClick);
  37. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("lm_beijing2");
  38. _ui.m_DayList.itemRenderer = DayListRenderer;
  39. _ui.m_TaskList.itemRenderer = TaskListRenderer;
  40. }
  41. private void OnBtnBackClick()
  42. {
  43. ViewManager.GoBackFrom(typeof(ActivityDay7View).FullName);
  44. }
  45. protected override void OnShown()
  46. {
  47. base.OnShown();
  48. onClickDayIndex = ActivityDay7DataManager.Instance.GetActivityDay7Day() - 1;
  49. SetScoreList();
  50. SetScore();
  51. SetDayList();
  52. SetTasks();
  53. }
  54. private void SetScore()
  55. {
  56. var score = ActivityDay7DataManager.Instance.GetScore();
  57. _ui.m_Score.text = score.ToString();
  58. _ui.m_ExpProcess.value = score;
  59. }
  60. protected override void OnHide()
  61. {
  62. base.OnHide();
  63. }
  64. //DayListRenderer
  65. private void DayListRenderer(int index, GObject obj)
  66. {
  67. var item = UI_ButtonDay.Proxy(obj);
  68. if (item.target.data == null)
  69. {
  70. var cfg = cfgDataArray[index];
  71. item.m_text.text = $"第{cfg.id}天";
  72. item.target.data = index;
  73. item.target.onClick.Add(OnClickDay);
  74. }
  75. //设置按钮状态
  76. item.m_c1.selectedIndex = index == onClickDayIndex ? 0 : 1;
  77. UI_ButtonDay.ProxyEnd();
  78. }
  79. //选中天数
  80. private void OnClickDay(EventContext context)
  81. {
  82. if (!(context.sender is GObject typeItem)) return;
  83. onClickDayIndex = (int)typeItem.data;
  84. SetTasks();
  85. //设置其他按钮选中状态
  86. SetDayList();
  87. FreshGetStatus();
  88. }
  89. private void SetTasks()
  90. {
  91. var activity7DaysTaskCfg = Activity7DaysTaskCfgArray.Instance.GetCfg(onClickDayIndex + 1);
  92. var taskIdArr = activity7DaysTaskCfg.taskIdArr;
  93. //排序根据领取状态
  94. var taskCfgs = TaskDataManager.Instance.GetTaskCfgs(taskIdArr);
  95. _ui.m_TaskList.data = taskCfgs;
  96. _ui.m_TaskList.numItems = taskIdArr.Length;
  97. if (_ui.m_TaskList.numItems > 0)
  98. {
  99. _ui.m_TaskList.ScrollToView(0);
  100. }
  101. }
  102. //TaskListRenderer
  103. private void TaskListRenderer(int index, GObject obj)
  104. {
  105. var item = UI_TaskListItem.Proxy(obj);
  106. var tasks = (TaskCfg[])obj.parent.data;
  107. var taskCfg = tasks[index];
  108. item.m_c1.selectedIndex = TaskDataManager.Instance.GetTaskStateById(taskCfg.id);
  109. item.m_c2.selectedIndex = taskCfg.jumpId == "" ? 1 : 0;
  110. item.m_txtDesc.text = TaskDataManager.Instance.GetTaskDesc(taskCfg.id);
  111. item.m_txtCount.text =
  112. $"{TaskDataManager.Instance.GetTaskProgressById(taskCfg.id)}/{taskCfg.count}";
  113. if (item.m_GetRewardBt.data == null)
  114. {
  115. item.m_GetRewardBt.onClick.Add(OnBtnGetClick);
  116. }
  117. item.m_GetRewardBt.data = taskCfg.id;
  118. if (item.m_ComeBt.data == null)
  119. {
  120. item.m_ComeBt.onClick.Add(OnBtnGoClick);
  121. }
  122. item.m_ComeBt.data = taskCfg.jumpId;
  123. if (item.m_listTaskReward.data == null)
  124. {
  125. item.m_listTaskReward.itemRenderer = ListTaskRewardItemRender;
  126. }
  127. item.m_listTaskReward.data = taskCfg.rewardsArr;
  128. item.m_listTaskReward.numItems = taskCfg.rewardsArr.Length;
  129. UI_TaskListItem.ProxyEnd();
  130. }
  131. private static void ListTaskRewardItemRender(int index, GObject obj)
  132. {
  133. var rewards = (int[][])obj.parent.data;
  134. ItemUtil.CreateItemView(rewards[index], obj as GComponent);
  135. }
  136. private void OnBtnGoClick(EventContext context)
  137. {
  138. Hide();
  139. var btnGo = context.sender as GObject;
  140. if (btnGo == null) return;
  141. ViewManager.Show($"GFGGame.{btnGo.data}", null, new[] { typeof(ActivityDay7View).FullName, viewData },
  142. true);
  143. }
  144. private List<GComponent> components = new List<GComponent>();
  145. //设置积分列表
  146. private void SetScoreList()
  147. {
  148. //7日活动配置
  149. activity7DaysCfgs = Activity7DaysCfgArray.Instance.dataArray;
  150. var maxCfg = activity7DaysCfgs[activity7DaysCfgs.Length - 1];
  151. var maxCfgID = maxCfg.id;
  152. var maxScore = maxCfg.score;
  153. var pos = _ui.m_StartIndex.position;
  154. var endY = _ui.m_EndIndex.position.y;
  155. _ui.m_ExpProcess.max = maxScore;
  156. //循环设置UI
  157. foreach (var cfg in activity7DaysCfgs)
  158. {
  159. var cfgScore = cfg.score;
  160. var item = UI_ExpProcessItem.Create();
  161. var target = item.target;
  162. components.Add(target);
  163. _ui.target.AddChild(target);
  164. // 根据 maxScore cfgScore pos.y endY 设置target 位置 x,z不变,y根据比例设置
  165. var y = pos.y - (pos.y - endY) * cfgScore / maxScore;
  166. target.SetPosition(pos.x, y, pos.z);
  167. item.m_Score.text = cfgScore.ToString();
  168. var cfgBonusArr = cfg.bonusArr;
  169. var itemCfg = ItemCfgArray.Instance.GetCfg(cfgBonusArr[0][0]);
  170. item.m_loaIcon.url = string.IsNullOrEmpty(itemCfg.res) ? "" : ResPathUtil.GetIconPath(itemCfg);
  171. item.m_Num.text = cfgBonusArr[0][1].ToString();
  172. item.m_c1.selectedIndex = cfg.id == maxCfgID ? 1 : 0;
  173. item.target.data = cfg;
  174. item.target.onClick.Add(OnClickReward);
  175. UI_ExpProcess.ProxyEnd();
  176. }
  177. }
  178. //设置天数列表
  179. private void SetDayList()
  180. {
  181. //7日活动配置
  182. cfgDataArray = Activity7DaysCfgArray.Instance.dataArray;
  183. _ui.m_DayList.numItems = cfgDataArray.Length;
  184. }
  185. private void FreshGetStatus()
  186. {
  187. components.ForEach(com =>
  188. {
  189. var item = UI_ExpProcessItem.Create(com);
  190. var cfg = (Activity7DaysCfg)item.target.data;
  191. var cfgID = cfg.id;
  192. var state = ActivityDay7DataManager.Instance.GetActivityDay7RewardState(cfgID);
  193. item.m_c2.selectedIndex = state ? 1 : 0;
  194. });
  195. }
  196. private async void OnBtnGetClick(EventContext context)
  197. {
  198. if (!(context.sender is GObject btnGet)) return;
  199. var result = await TaskSProxy.GetTaskBonus((int)btnGet.data);
  200. if (!result) return;
  201. SetTasks();
  202. }
  203. private async void OnClickReward(EventContext context)
  204. {
  205. if (!(context.sender is GObject btnGet)) return;
  206. var activity7DaysCfg = (Activity7DaysCfg)btnGet.data;
  207. var id = activity7DaysCfg.id;
  208. var get = ActivityDay7DataManager.Instance.GetActivityDay7RewardState(id);
  209. if (get)
  210. {
  211. ViewManager.Show<RewardPreView>(new object[] { "已领取过了" });
  212. }
  213. else
  214. {
  215. var result = await ActivityDay7SProxy.ReqGetActivityDay7Reward(activity7DaysCfg);
  216. if (!result) return;
  217. FreshGetStatus();
  218. }
  219. }
  220. }
  221. }