StudioBaseView.cs 4.5 KB

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