StudioActivityView.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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_Bg.url = ResPathUtil.GetBgImgPath("bg_fhl");
  40. _ui.m_btnChageLine.url = ResPathUtil.GetCommonGameResPath("zsx_fl");
  41. _ui.m_list.itemRenderer = RenderListItem;
  42. _ui.m_btnBack.onClick.Add(OnBtnBackClick);
  43. _ui.m_btnReward.onClick.Add(OnBtnRewardClick);
  44. }
  45. protected override void AddEventListener()
  46. {
  47. base.AddEventListener();
  48. EventAgent.AddEventListener(ConstMessage.STORY_LEVEL_CHANGE, UpdateView);
  49. EventAgent.AddEventListener(ConstMessage.FILLING_CHANGE_CHAPTER, UpdateView);
  50. EventAgent.AddEventListener(ConstMessage.NOTICE_LIMIT_CHANGED, OnLimitChanged);
  51. EventAgent.AddEventListener(ConstMessage.RED_CHANGE, UpdateRedDot);
  52. }
  53. protected override void RemoveEventListener()
  54. {
  55. base.RemoveEventListener();
  56. EventAgent.RemoveEventListener(ConstMessage.STORY_LEVEL_CHANGE, UpdateView);
  57. EventAgent.RemoveEventListener(ConstMessage.FILLING_CHANGE_CHAPTER, UpdateView);
  58. EventAgent.RemoveEventListener(ConstMessage.NOTICE_LIMIT_CHANGED, OnLimitChanged);
  59. EventAgent.RemoveEventListener(ConstMessage.RED_CHANGE, UpdateRedDot);
  60. //EventAgent.RemoveEventListener(ConstMessage.STUDIO_FILING_UPDATE, UpdateView);
  61. }
  62. protected override void OnShown()
  63. {
  64. base.OnShown();
  65. _valueBarController.OnShown();
  66. _valueBarController.UpdateList(new List<int>() { 3000015, ConstItemID.GOLD, ConstItemID.DIAMOND_RED });
  67. StudioDataManager.Instance.filingChapterId = StudioDataManager.Instance.GetLuckyBoxActivityID();
  68. UpdateView();
  69. UpdateItem();
  70. }
  71. protected override void OnHide()
  72. {
  73. base.OnHide();
  74. _valueBarController.OnHide();
  75. }
  76. private void UpdateRedDot()
  77. {
  78. RedDotController.Instance.SetComRedDot(_ui.m_btnReward, StudioDataManager.Instance.GetStudioFilingRewardRed());
  79. }
  80. private void RenderListItem(int index, GObject obj)
  81. {
  82. UI_ListLevelItem item = UI_ListLevelItem.Proxy(obj);
  83. item.m_txtName.text = _storyLevelCfgs[index].name;
  84. bool isFight = string.IsNullOrEmpty(_storyLevelCfgs[index].storyStartID);
  85. string resBg = isFight ? "cyjd_di_1" : "cyjd_di_2";
  86. if (isFight)
  87. {
  88. item.m_loaIcon.visible = false;
  89. item.m_loaItem.visible = true;
  90. StoryFightCfg storyFightCfg = StoryFightCfgArray.Instance.GetCfg(_storyLevelCfgs[index].fightID);
  91. int itemId = DropOutCfgArray.Instance.GetCfgsByid(storyFightCfg.bonusRandomArr[0])[0].item;
  92. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId);
  93. item.m_loaItem.url = ResPathUtil.GetIconPath(itemCfg);
  94. if (item.m_loaItem.data == null)
  95. {
  96. item.m_loaItem.onClick.Add(OnLoaItemClick);
  97. }
  98. item.m_loaItem.data = index;
  99. }
  100. else
  101. {
  102. item.m_loaItem.visible = false;
  103. item.m_loaIcon.visible = true;
  104. item.m_loaIcon.url = string.Format("ui://Studio/{0}", _studioCfg.res);
  105. }
  106. item.m_grpLock.visible = index > 0 && !InstanceZonesDataManager.CheckLevelPass(_storyLevelCfgs[index - 1].id);
  107. item.m_comFlower.m_c1.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. RoleLimitData limitData = RoleLimitDataManager.GetLimitData(this._studioCfg.limit);
  145. var limitCfg = LimitCfgArray.Instance.GetCfg(this._studioCfg.limit);
  146. _ui.m_loaBg.url = ResPathUtil.GetStudioFilingPicPath(_studioCfg.res); //ResPathUtil.GetBgImgPath(_studioCfg.res);
  147. _ui.m_txtNum.text = string.Format("剩余次数:{0}/{1}", limitData.TotalPlayMax - limitData.PlayTimes, limitData.MaxStorageCount);
  148. _ui.m_activityTipText.SetVar("name", _studioCfg.name).FlushVars();
  149. _ui.m_activityTitle.text = _studioCfg.name;
  150. _storyLevelCfgs = StoryLevelCfgArray.Instance.GetCfgsBytypeAndsubTypeAndchapterId(_studioCfg.type, _studioCfg.subType, StudioDataManager.Instance.filingChapterId);
  151. _ui.m_list.numItems = _storyLevelCfgs.Count;
  152. UpdateRedDot();
  153. }
  154. private void UpdateItem()
  155. {
  156. for (int i = 0; i < _ui.m_list.numChildren; i++)
  157. {
  158. _ui.m_list.GetChildAt(i).visible = false;
  159. }
  160. _itemIndex = 0;
  161. Timers.inst.Add(0.05f, _ui.m_list.numChildren, AddItemUpdate, 1);
  162. }
  163. private void AddItemUpdate(object param)
  164. {
  165. _ui.m_list.GetChildAt(_itemIndex).visible = true;
  166. UI_ListLevelItem item = UI_ListLevelItem.Proxy(_ui.m_list.GetChildAt(_itemIndex));
  167. item.m_Left.Play();
  168. _itemIndex++;
  169. UI_ListLevelItem.ProxyEnd();
  170. }
  171. protected void OnBtnBackClick()
  172. {
  173. var activityId = ActivityDataManager.Instance.GetCurOpenActiveByType(ConstLimitTimeActivityType.ActLimitLuckyBox);
  174. if (activityId <= 0)
  175. {
  176. ViewManager.DeleteViewStackCountDown("MainUIView");
  177. PromptController.Instance.ShowFloatTextPrompt("活动已结束");
  178. }
  179. Hide();
  180. }
  181. private void OnBtnRewardClick()
  182. {
  183. ViewManager.Show<StudioFilingRewardView>();
  184. }
  185. private void OnLimitChanged(EventContext context)
  186. {
  187. int limitId = (int)context.data;
  188. if (this._studioCfg.limit != limitId)
  189. {
  190. return;
  191. }
  192. UpdateView();
  193. }
  194. }
  195. }