StudioBaseView.cs 4.2 KB

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