StudioBaseView.cs 3.5 KB

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