StudioActivityView.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. using System.Collections.Generic;
  2. using ET;
  3. using FairyGUI;
  4. using UI.CommonGame;
  5. using UI.Studio;
  6. using UnityEngine;
  7. namespace GFGGame
  8. {
  9. public class StudioActivityView : BaseWindow
  10. {
  11. private UI_StudioActivityUI _ui;
  12. private ValueBarController _valueBarController;
  13. private StudioCfg _studioCfg;
  14. private List<StoryLevelCfg> _storyLevelCfgs;
  15. private int _itemIndex = 0;
  16. public override void Dispose()
  17. {
  18. if (_valueBarController != null)
  19. {
  20. _valueBarController.Dispose();
  21. _valueBarController = null;
  22. }
  23. if (_ui != null)
  24. {
  25. _ui.Dispose();
  26. _ui = null;
  27. }
  28. base.Dispose();
  29. }
  30. protected override void OnInit()
  31. {
  32. base.OnInit();
  33. packageName = UI_StudioActivityUI.PACKAGE_NAME;
  34. _ui = UI_StudioActivityUI.Create();
  35. this.viewCom = _ui.target;
  36. isfullScreen = true;
  37. isReturnView = true;
  38. _valueBarController = new ValueBarController(_ui.m_comValueBar);
  39. _ui.m_btnChageLine.url = ResPathUtil.GetCommonGameResPath("zsx_fl");
  40. _ui.m_list.itemRenderer = RenderListItem;
  41. _ui.m_btnBack.onClick.Add(OnBtnBackClick);
  42. _ui.m_btnReward.onClick.Add(OnBtnRewardClick);
  43. }
  44. protected override void AddEventListener()
  45. {
  46. base.AddEventListener();
  47. EventAgent.AddEventListener(ConstMessage.STORY_LEVEL_CHANGE, UpdateView);
  48. EventAgent.AddEventListener(ConstMessage.FILLING_CHANGE_CHAPTER, UpdateView);
  49. EventAgent.AddEventListener(ConstMessage.NOTICE_LIMIT_CHANGED, OnLimitChanged);
  50. EventAgent.AddEventListener(ConstMessage.RED_CHANGE, UpdateRedDot);
  51. }
  52. protected override void RemoveEventListener()
  53. {
  54. base.RemoveEventListener();
  55. EventAgent.RemoveEventListener(ConstMessage.STORY_LEVEL_CHANGE, UpdateView);
  56. EventAgent.RemoveEventListener(ConstMessage.FILLING_CHANGE_CHAPTER, UpdateView);
  57. EventAgent.RemoveEventListener(ConstMessage.NOTICE_LIMIT_CHANGED, OnLimitChanged);
  58. EventAgent.RemoveEventListener(ConstMessage.RED_CHANGE, UpdateRedDot);
  59. //EventAgent.RemoveEventListener(ConstMessage.STUDIO_FILING_UPDATE, UpdateView);
  60. }
  61. protected override void OnShown()
  62. {
  63. base.OnShown();
  64. StudioDataManager.Instance.filingChapterId = StudioDataManager.Instance.GetLuckyBoxActivityID();
  65. UpdateView();
  66. UpdateItem();
  67. _valueBarController.OnShown();
  68. }
  69. protected override void OnHide()
  70. {
  71. base.OnHide();
  72. _valueBarController.OnHide();
  73. }
  74. private void UpdateRedDot()
  75. {
  76. RedDotController.Instance.SetComRedDot(_ui.m_btnReward, StudioDataManager.Instance.GetStudioFilingRewardRed());
  77. }
  78. private void RenderListItem(int index, GObject obj)
  79. {
  80. UI_ListLevelItem item = UI_ListLevelItem.Proxy(obj);
  81. item.m_txtName.text = _storyLevelCfgs[index].name;
  82. bool isFight = string.IsNullOrEmpty(_storyLevelCfgs[index].storyStartID);
  83. string resBg = isFight ? "cyjd_di_1" : "cyjd_di_2";
  84. if (isFight)
  85. {
  86. item.m_loaIcon.visible = false;
  87. item.m_loaItem.visible = true;
  88. StoryFightCfg storyFightCfg = StoryFightCfgArray.Instance.GetCfg(_storyLevelCfgs[index].fightID);
  89. int itemId = DropOutCfgArray.Instance.GetCfgsByid(storyFightCfg.bonusRandomArr[0])[0].item;
  90. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId);
  91. item.m_loaItem.url = ResPathUtil.GetIconPath(itemCfg);
  92. if (item.m_loaItem.data == null)
  93. {
  94. item.m_loaItem.onClick.Add(OnLoaItemClick);
  95. }
  96. item.m_loaItem.data = index;
  97. }
  98. else
  99. {
  100. item.m_loaItem.visible = false;
  101. item.m_loaIcon.visible = true;
  102. item.m_flow.visible = false;
  103. item.m_loaIcon.url = ResPathUtil.GetActivityPath(_studioCfg.res,"png");
  104. }
  105. item.m_grpLock.visible = index > 0 && !InstanceZonesDataManager.CheckLevelPass(_storyLevelCfgs[index - 1].id);
  106. item.m_comFlower.target.visible = false;//.m_c1.selectedIndex = InstanceZonesDataManager.GetStarCountHistory(_storyLevelCfgs[index].id);
  107. item.m_c2.selectedIndex = InstanceZonesDataManager.GetStarCountHistory(_storyLevelCfgs[index].id);
  108. if (item.m_loaBg.data == null)
  109. {
  110. item.m_loaBg.onClick.Add(OnListItemClick);
  111. }
  112. item.m_loaBg.data = index;
  113. UI_ListLevelItem.ProxyEnd();
  114. }
  115. private void OnLoaItemClick(EventContext context)
  116. {
  117. GObject obj = context.sender as GObject;
  118. int index = (int)obj.data;
  119. StoryFightCfg storyFightCfg = StoryFightCfgArray.Instance.GetCfg(_storyLevelCfgs[index].fightID);
  120. int itemId = DropOutCfgArray.Instance.GetCfgsByid(storyFightCfg.bonusRandomArr[0])[0].item;
  121. GoodsItemTipsController.ShowItemTips(itemId);
  122. }
  123. private void OnListItemClick(EventContext context)
  124. {
  125. GObject obj = context.sender as GObject;
  126. int index = (int)obj.data;
  127. StoryLevelCfg storyLevelCfg = _storyLevelCfgs[index];
  128. if (index > 0 && !InstanceZonesDataManager.CheckLevelPass(_storyLevelCfgs[index - 1].id))
  129. {
  130. PromptController.Instance.ShowFloatTextPrompt("需通关前置关卡");
  131. return;
  132. }
  133. MainStoryDataManager.currentLevelCfgId = storyLevelCfg.id;
  134. InstanceZonesController.ShowLevelView(storyLevelCfg.id, OnFinishFilingStoryLevel);
  135. }
  136. private void OnFinishFilingStoryLevel(int levelCfgId, bool firstPass, bool success)
  137. {
  138. //StudioDataManager.Instance.SetLuckyBoxActivityID(MainStoryDataManager.currentChapterCfgId);
  139. ViewManager.Show<StudioActivityView>();
  140. }
  141. private void UpdateView()
  142. {
  143. _studioCfg = StudioCfgArray.Instance.GetCfg(StudioDataManager.Instance.filingChapterId);
  144. _valueBarController.UpdateList(new List<int>(_studioCfg.ItemIDArrArr));
  145. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath(_studioCfg.LeveRes);
  146. RoleLimitData limitData = RoleLimitDataManager.GetLimitData(this._studioCfg.limit);
  147. var limitCfg = LimitCfgArray.Instance.GetCfg(this._studioCfg.limit);
  148. _ui.m_loaRole.url = ResPathUtil.GetStudioFilingPicPath(_studioCfg.res); //ResPathUtil.GetBgImgPath(_studioCfg.res);
  149. _ui.m_txtNum.text = string.Format("剩余次数:{0}/{1}", limitData.TotalPlayMax - limitData.PlayTimes, limitData.MaxStorageCount);
  150. _ui.m_activityTipText.SetVar("name", _studioCfg.name).FlushVars();
  151. _ui.m_activityTitle.text = _studioCfg.name;
  152. _storyLevelCfgs = StoryLevelCfgArray.Instance.GetCfgsBytypeAndsubTypeAndchapterId(_studioCfg.type, _studioCfg.subType, StudioDataManager.Instance.filingChapterId);
  153. _ui.m_list.numItems = _storyLevelCfgs.Count;
  154. UpdateRedDot();
  155. }
  156. private void UpdateItem()
  157. {
  158. for (int i = 0; i < _ui.m_list.numChildren; i++)
  159. {
  160. _ui.m_list.GetChildAt(i).visible = false;
  161. }
  162. _itemIndex = 0;
  163. Timers.inst.Add(0.05f, _ui.m_list.numChildren, AddItemUpdate, 1);
  164. }
  165. private void AddItemUpdate(object param)
  166. {
  167. _ui.m_list.GetChildAt(_itemIndex).visible = true;
  168. UI_ListLevelItem item = UI_ListLevelItem.Proxy(_ui.m_list.GetChildAt(_itemIndex));
  169. item.m_Left.Play();
  170. _itemIndex++;
  171. UI_ListLevelItem.ProxyEnd();
  172. }
  173. protected void OnBtnBackClick()
  174. {
  175. var activityId = ActivityDataManager.Instance.GetCurOpenActiveByType(ConstLimitTimeActivityType.ActLimitLuckyBox);
  176. if (activityId <= 0)
  177. {
  178. ViewManager.DeleteViewStackCountDown("MainUIView");
  179. PromptController.Instance.ShowFloatTextPrompt("活动已结束");
  180. }
  181. Hide();
  182. }
  183. private void OnBtnRewardClick()
  184. {
  185. ViewManager.Show<StudioFilingRewardView>();
  186. }
  187. private void OnLimitChanged(EventContext context)
  188. {
  189. int limitId = (int)context.data;
  190. if (this._studioCfg.limit != limitId)
  191. {
  192. return;
  193. }
  194. UpdateView();
  195. }
  196. }
  197. }