StudioBaseView.cs 4.4 KB

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