StudioActivityView.cs 9.2 KB

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