TimeTracingSwitchView.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. using System;
  2. using System.Collections.Generic;
  3. using ET;
  4. using FairyGUI;
  5. using UI.CommonGame;
  6. using UI.TimeTracing;
  7. using UnityEngine;
  8. namespace GFGGame
  9. {
  10. public class TimeTracingSwitchView : BaseWindow
  11. {
  12. private UI_TimeTracingSwitchUI _ui;
  13. private List<int> suitIdList = new List<int>() { 201030, 201010, 202006, 0};
  14. private List<int> chapterIdList = new List<int>() { 61001,62002,62003 ,0};
  15. private List<string> NumStringList = new List<string>() {"", "一", "二", "三", "四", "五" };
  16. public override void Dispose()
  17. {
  18. base.Dispose();
  19. }
  20. protected override void OnInit()
  21. {
  22. base.OnInit();
  23. packageName = UI_TimeTracingSwitchUI.PACKAGE_NAME;
  24. _ui = UI_TimeTracingSwitchUI.Create();
  25. this.viewCom = _ui.target;
  26. isfullScreen = true;
  27. modal = true;
  28. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  29. _ui.m_List.itemRenderer = RenderListItem;
  30. _ui.m_List.scrollPane.onScroll.Add(DoSpecialEffect);//滚动时派发事件
  31. }
  32. protected override void OnShown()
  33. {
  34. base.OnShown();
  35. UpdateList();
  36. _ui.m_List.numItems = suitIdList.Count + 2;
  37. for(int i = 0;i< suitIdList.Count;i++)
  38. {
  39. if(TimeTracingDataManager.SuitID == suitIdList[i])
  40. {
  41. _ui.m_List.ScrollToView(i, true, true);
  42. break;
  43. }
  44. }
  45. DoSpecialEffect();
  46. }
  47. protected override void OnHide()
  48. {
  49. base.OnHide();
  50. }
  51. private void RenderListItem(int index, GObject obj)
  52. {
  53. UI_TimeTracingSwitchItem listItem = UI_TimeTracingSwitchItem.Proxy(obj);
  54. int isLock = 1;
  55. if (index == 0 || index == _ui.m_List.numItems - 1)
  56. {
  57. listItem.target.visible = false;
  58. UI_TimeTracingSwitchItem.ProxyEnd();
  59. return;
  60. }
  61. if (index != _ui.m_List.numItems - 2)
  62. {
  63. listItem.m_TimeTracingSwitchItm.m_periodsNumText.text = "第" + NumStringList[index] + "期";
  64. listItem.m_TimeTracingSwitchItm.m_periodsNameText.text = "";
  65. listItem.m_TimeTracingSwitchItm.m_suitIcon.icon = string.Format("ui://TimeTracing/select{0}",index);
  66. listItem.m_TimeTracingSwitchItm.m_waitText.visible = false;
  67. }
  68. else
  69. {
  70. listItem.m_TimeTracingSwitchItm.m_periodsNumText.visible = false;
  71. listItem.m_TimeTracingSwitchItm.m_periodsNameText.visible = false;
  72. listItem.m_TimeTracingSwitchItm.m_suitIcon.icon = "";
  73. listItem.m_TimeTracingSwitchItm.m_waitText.visible = true;
  74. }
  75. if (index > 1 && index < _ui.m_List.numItems - 2)
  76. {
  77. int count;
  78. int totalCount;
  79. DressUpMenuSuitDataManager.GetSuitProgressBySuitId(suitIdList[index - 2], out count, out totalCount);
  80. if (count >= totalCount)
  81. {
  82. isLock = 1;
  83. }
  84. else
  85. {
  86. isLock = 0;
  87. }
  88. }
  89. if (listItem.target.data == null)
  90. {
  91. listItem.target.onClick.Add(OnClickListChapterItem);
  92. }
  93. RedDotController.Instance.SetComRedDot(listItem.target, TimeTracingDataManager.Instance.GetChapterIDRewardStatus(chapterIdList[index - 1]), "", 0, 65);
  94. listItem.target.data = new List<int>() { index, suitIdList[index - 1], chapterIdList[index - 1], isLock };
  95. UI_TimeTracingSwitchItem.ProxyEnd();
  96. }
  97. private void OnClickListChapterItem(EventContext context)
  98. {
  99. GObject chapterItem = context.sender as GObject;
  100. List<int> chapterID = (List<int>)chapterItem.data;
  101. StoryChapterCfg chapterCfg = StoryChapterCfgArray.Instance.GetCfg(chapterID[1]);
  102. //这里变成-1,是因为调整了item,最左右两边现在有item但是是透明没数据的
  103. int index = chapterID[0];
  104. int firstChildIndex = _ui.m_List.GetFirstChildInView();
  105. if (firstChildIndex + 1 != index)
  106. {
  107. _ui.m_List.ScrollToView(index - 1, true, true);
  108. }
  109. else
  110. {
  111. if (chapterID[3] == 1)
  112. {
  113. if(chapterID[0] == _ui.m_List.numItems - 2 || chapterID[1] == 0)
  114. {
  115. return;
  116. }
  117. TimeTracingDataManager.SuitID = chapterID[1];
  118. TimeTracingDataManager._currentChapterId = chapterID[2];
  119. EventAgent.DispatchEvent(ConstMessage.TIMETRACINGUPDATE);
  120. this.Hide();
  121. }
  122. else
  123. {
  124. PromptController.Instance.ShowFloatTextPrompt("需集齐前置套装");
  125. return;
  126. }
  127. }
  128. }
  129. private void OnClickBtnBack()
  130. {
  131. ViewManager.GoBackFrom(typeof(TimeTracingSwitchView).FullName);
  132. }
  133. private void UpdateList()
  134. {
  135. chapterIdList.Clear();
  136. suitIdList.Clear();
  137. for (int i = 0;i<TimeTracingDataManager.Instance.IdList.Count;i++)
  138. {
  139. ActivityOpenCfg activityDate = ActivityOpenCfgArray.Instance.GetCfg(TimeTracingDataManager.Instance.IdList[i]);
  140. chapterIdList.Add(activityDate.params3Arr[0]);
  141. ActivityFightCfg storydate = ActivityFightCfgArray.Instance.GetCfg(chapterIdList[i]);
  142. if(storydate.activitySuitIdArr == null || storydate.activitySuitIdArr.Length == 0)
  143. {
  144. suitIdList.Add(0);
  145. }
  146. else
  147. {
  148. suitIdList.Add(storydate.activitySuitIdArr[0]);
  149. }
  150. }
  151. chapterIdList.Add(0);
  152. suitIdList.Add(0);
  153. }
  154. private void DoSpecialEffect(object parm = null)
  155. {
  156. //scrollPane.scrollingPosX这个实时变化,。scrollPane.posX这个使用ScrlootoVIew直接取终值
  157. float listCenter = _ui.m_List.scrollPane.scrollingPosX + _ui.m_List.viewWidth / 2;
  158. float listLeft = _ui.m_List.scrollPane.posX + _ui.m_List.viewWidth / 2; ;
  159. for (int i = 0; i < _ui.m_List.numChildren; i++)
  160. {
  161. GObject item = _ui.m_List.GetChildAt(i);
  162. float itemCenter = item.x + item.width / 2;//循环列表内元素的中心x值
  163. float itemWidth = item.width;//列表元素的宽度
  164. float distance = Mathf.Abs(listCenter - itemCenter);
  165. // if (distance < item.width)
  166. {
  167. float distanceRange = 1 + (1 - distance / itemWidth) * 0.2f;//使放大动画有渐进效果
  168. item.SetScale(distanceRange, distanceRange);//设置放大比例
  169. ////设置颜色变化
  170. //if (distance < item.width / 2)
  171. //{
  172. // UI_TimeTracingSwitchItem listItem = UI_TimeTracingSwitchItem.Proxy(_ui.m_List.GetChildAt(i));
  173. // listItem.m_content.m_compPic.m_pic.color = new Color(1.0f, 1.0f, 1.0f, 1.000f);
  174. //}
  175. //else
  176. //{
  177. // UI_TimeTracingSwitchItem listItem = UI_TimeTracingSwitchItem.Proxy(_ui.m_List.GetChildAt(i));
  178. // listItem.m_content.m_compPic.m_pic.color = new Color(0.4f, 0.4f, 0.4f, 1.000f);
  179. //}
  180. }
  181. //float distanceX = ((1 - (listCenter - itemCenter)) / itemWidth) * 0.05f;//使y轴移动有渐进效果
  182. //item.y = -_ui.m_List.height * distanceX;
  183. }
  184. }
  185. }
  186. }