StudioActivityView.cs 8.9 KB

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