StudioBaseView.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. 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_StudioEctypeUI.PACKAGE_NAME;
  34. _ui = UI_StudioEctypeUI.Create();
  35. this.viewCom = _ui.target;
  36. isfullScreen = true;
  37. _valueBarController = new ValueBarController(_ui.m_valueBar);
  38. _ui.m_list.itemRenderer = ListItemRender;
  39. _ui.m_list.onClickItem.Add(OnCliclListItem);
  40. _ui.m_list.SetVirtual();
  41. _ui.m_btnBuy.onClick.Add(OnCliclBtnBuy);
  42. }
  43. protected override void AddEventListener()
  44. {
  45. base.AddEventListener();
  46. EventAgent.AddEventListener(ConstMessage.BUY_STUDIO_PLAY_TIMES, UpdateView);
  47. EventAgent.AddEventListener(ConstMessage.NOTICE_STUDIO_PLAY_TIMES, UpdateView);
  48. }
  49. protected override void OnShown()
  50. {
  51. base.OnShown();
  52. _valueBarController.OnShown();
  53. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("gzs_bjbj");
  54. UpdateView();
  55. Timers.inst.Add(1, 0, UpdateShowTime);
  56. }
  57. protected override void OnHide()
  58. {
  59. base.OnHide();
  60. _valueBarController.OnHide();
  61. studioCfg = null;
  62. storyLevelCfgs = null;
  63. studioData = null;
  64. Timers.inst.Remove(UpdateShowTime);
  65. }
  66. protected override void RemoveEventListener()
  67. {
  68. base.RemoveEventListener();
  69. EventAgent.RemoveEventListener(ConstMessage.BUY_STUDIO_PLAY_TIMES, UpdateView);
  70. EventAgent.RemoveEventListener(ConstMessage.NOTICE_STUDIO_PLAY_TIMES, UpdateView);
  71. }
  72. protected void UpdateView()
  73. {
  74. studioData = StudioDataManager.Instance.GetStudioDataById(this.studioCfg.id);
  75. _ui.m_txtNum.text = string.Format("剩余次数:{0}/{1}", this.studioData.TotalPlayTimes - this.studioData.PlayTimes, studioCfg.num);
  76. }
  77. private void UpdateShowTime(object param)
  78. {
  79. _ui.m_txtTime.text = string.Format("{0}后刷新", TimeUtil.FormattingTime(TimeHelper.ServerNowSecs, GameGlobal.myNumericComponent.GetAsInt(NumericType.DailyResetSecs)));
  80. }
  81. private void ListItemRender(int index, GObject obj)
  82. {
  83. UI_ListItem item = UI_ListItem.Proxy(obj);
  84. StudioDataManager.Instance.IsCanFight(storyLevelCfgs, index, out bool canFight, out string content);
  85. ItemData itemData = StoryBonusDataCache.GetBonusData(storyLevelCfgs[index].id).bonusBase[0];
  86. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  87. item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  88. item.m_star.selectedIndex = InstanceZonesDataManager.GetStarCountHistory(storyLevelCfgs[index].id);
  89. item.m_imgLock.visible = canFight ? false : true;
  90. item.m_txtTitle.text = canFight ? storyLevelCfgs[index].name : content;
  91. if (canFight) curIndex = index;
  92. item.target.data = index;
  93. UI_ListItem.ProxyEnd();
  94. }
  95. private void OnCliclListItem(EventContext context)
  96. {
  97. UI_ListItem item = UI_ListItem.Proxy(context.data as GObject);
  98. int index = (int)item.target.data;
  99. StoryLevelCfg storyLevelCfg = storyLevelCfgs[index];
  100. StudioDataManager.Instance.IsCanFight(storyLevelCfgs, index, out bool canFight, out string content);
  101. if (!canFight)
  102. {
  103. PromptController.Instance.ShowFloatTextPrompt(content);
  104. return;
  105. }
  106. StudioDataManager.Instance.PROPERTY_SELECT_INDEX = _ui.m_listProperty.selectedIndex;
  107. StudioDataManager.Instance.TYPE_SELECT_INDEX = _ui.m_c1.selectedIndex;
  108. InstanceZonesController.ShowLevelView(storyLevelCfg.id, StudioDataManager.Instance.OnFinishStoryLevel);
  109. UI_ListItem.ProxyEnd();
  110. }
  111. private void OnCliclBtnBuy()
  112. {
  113. ViewManager.Show<StudioBuyNumView>(this.studioCfg.id);
  114. }
  115. }
  116. }