StudioBaseView.cs 4.6 KB

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