StudioBaseView.cs 4.1 KB

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