StudioBaseView.cs 3.9 KB

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