StudioBaseView.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. using System;
  2. using System.Collections.Generic;
  3. using ET;
  4. using FairyGUI;
  5. using UI.Studio;
  6. namespace GFGGame
  7. {
  8. public class StudioBaseView : BaseWindow
  9. {
  10. protected UI_StudioEctypeUI _ui;
  11. private ValueBarController _valueBarController;
  12. protected StudioCfg studioCfg;
  13. protected List<StoryLevelCfg> storyLevelCfgs;
  14. protected StudioData studioData;
  15. protected int curIndex = 0;
  16. public override void Dispose()
  17. {
  18. if (_valueBarController != null)
  19. {
  20. _valueBarController.Dispose();
  21. _valueBarController = null;
  22. }
  23. _ui.m_loaBg.Dispose();
  24. // for (int i = 0; i < _ui.m_list.numItems; i++)
  25. // {
  26. // UI_ListItem listItem = UI_ListItem.Proxy(_ui.m_list);
  27. // listItem.m_loaIcon.Dispose();
  28. // UI_ListItem.ProxyEnd();
  29. // }
  30. if (_ui != null)
  31. {
  32. _ui.Dispose();
  33. _ui = null;
  34. }
  35. base.Dispose();
  36. }
  37. protected override void OnInit()
  38. {
  39. base.OnInit();
  40. packageName = UI_StudioEctypeUI.PACKAGE_NAME;
  41. _ui = UI_StudioEctypeUI.Create();
  42. this.viewCom = _ui.target;
  43. isfullScreen = true;
  44. _valueBarController = new ValueBarController(_ui.m_valueBar);
  45. _ui.m_list.itemRenderer = ListItemRender;
  46. _ui.m_list.onClickItem.Add(OnCliclListItem);
  47. _ui.m_list.SetVirtual();
  48. _ui.m_btnBuy.onClick.Add(OnCliclBtnBuy);
  49. }
  50. protected override void AddEventListener()
  51. {
  52. base.AddEventListener();
  53. EventAgent.AddEventListener(ConstMessage.BUY_STUDIO_PLAY_TIMES, UpdateView);
  54. EventAgent.AddEventListener(ConstMessage.NOTICE_STUDIO_PLAY_TIMES, UpdateView);
  55. }
  56. protected override void OnShown()
  57. {
  58. base.OnShown();
  59. _valueBarController.OnShown();
  60. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("gzs_bjbj");
  61. UpdateView();
  62. Timers.inst.Add(1, 0, UpdateShowTime);
  63. }
  64. protected override void OnHide()
  65. {
  66. base.OnHide();
  67. _valueBarController.OnHide();
  68. studioCfg = null;
  69. storyLevelCfgs = null;
  70. studioData = null;
  71. Timers.inst.Remove(UpdateShowTime);
  72. }
  73. protected override void RemoveEventListener()
  74. {
  75. base.RemoveEventListener();
  76. EventAgent.RemoveEventListener(ConstMessage.BUY_STUDIO_PLAY_TIMES, UpdateView);
  77. EventAgent.RemoveEventListener(ConstMessage.NOTICE_STUDIO_PLAY_TIMES, UpdateView);
  78. }
  79. protected void UpdateView()
  80. {
  81. studioData = StudioDataManager.Instance.GetStudioDataById(this.studioCfg.id);
  82. _ui.m_txtNum.text = string.Format("剩余次数:{0}/{1}", this.studioData.TotalPlayTimes - this.studioData.PlayTimes, studioCfg.num);
  83. }
  84. private void UpdateShowTime(object param)
  85. {
  86. _ui.m_txtTime.text = string.Format("{0}后刷新", TimeUtil.FormattingTime(TimeHelper.ServerNowSecs, GameGlobal.myNumericComponent.GetAsInt(NumericType.DailyResetSecs)));
  87. }
  88. private void ListItemRender(int index, GObject obj)
  89. {
  90. UI_ListItem item = UI_ListItem.Proxy(obj);
  91. StudioDataManager.Instance.IsCanFight(storyLevelCfgs, index, out bool canFight, out string content);
  92. ItemData itemData = StoryBonusDataCache.GetBonusData(storyLevelCfgs[index].id).bonusBase[0];
  93. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  94. item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  95. item.m_star.selectedIndex = InstanceZonesDataManager.GetStarCountHistory(storyLevelCfgs[index].id);
  96. item.m_imgLock.visible = canFight ? false : true;
  97. item.m_txtTitle.text = canFight ? storyLevelCfgs[index].name : content;
  98. if (canFight) curIndex = index;
  99. item.target.data = index;
  100. UI_ListItem.ProxyEnd();
  101. }
  102. private void OnCliclListItem(EventContext context)
  103. {
  104. UI_ListItem item = UI_ListItem.Proxy(context.data as GObject);
  105. int index = (int)item.target.data;
  106. StoryLevelCfg storyLevelCfg = storyLevelCfgs[index];
  107. StudioDataManager.Instance.IsCanFight(storyLevelCfgs, index, out bool canFight, out string content);
  108. if (!canFight)
  109. {
  110. PromptController.Instance.ShowFloatTextPrompt(content);
  111. return;
  112. }
  113. StudioDataManager.Instance.PROPERTY_SELECT_INDEX = _ui.m_listProperty.selectedIndex;
  114. StudioDataManager.Instance.TYPE_SELECT_INDEX = _ui.m_c1.selectedIndex;
  115. InstanceZonesController.ShowLevelView(storyLevelCfg.id, StudioDataManager.Instance.OnFinishStoryLevel);
  116. UI_ListItem.ProxyEnd();
  117. }
  118. private void OnCliclBtnBuy()
  119. {
  120. ViewManager.Show<StudioBuyNumView>(this.studioCfg.id);
  121. }
  122. }
  123. }