StudioBaseView.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. if (_valueBarController != null)
  19. {
  20. _valueBarController.Dispose();
  21. _valueBarController = null;
  22. }
  23. if (_ui != null)
  24. {
  25. _ui.Dispose();
  26. _ui = null;
  27. }
  28. base.Dispose();
  29. }
  30. protected override void OnInit()
  31. {
  32. base.OnInit();
  33. packageName = UI_StudioEctypeUI.PACKAGE_NAME;
  34. _ui = UI_StudioEctypeUI.Create();
  35. this.viewCom = _ui.target;
  36. isfullScreen = true;
  37. _valueBarController = new ValueBarController(_ui.m_valueBar);
  38. _ui.m_list.itemRenderer = ListItemRender;
  39. // _ui.m_list.onClickItem.Add(OnCliclListItem);
  40. _ui.m_list.SetVirtual();
  41. _ui.m_btnBuy.onClick.Add(OnCliclBtnBuy);
  42. }
  43. protected override void AddEventListener()
  44. {
  45. base.AddEventListener();
  46. EventAgent.AddEventListener(ConstMessage.BUY_STUDIO_PLAY_TIMES, UpdateView);
  47. EventAgent.AddEventListener(ConstMessage.NOTICE_STUDIO_PLAY_TIMES, UpdateView);
  48. }
  49. protected override void OnShown()
  50. {
  51. base.OnShown();
  52. _valueBarController.OnShown();
  53. // _valueBarController.Controller(1);
  54. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("gzs_bjbj");
  55. UpdateView();
  56. Timers.inst.Add(1, 0, UpdateShowTime);
  57. }
  58. protected override void OnHide()
  59. {
  60. base.OnHide();
  61. _valueBarController.OnHide();
  62. studioCfg = null;
  63. storyLevelCfgs = null;
  64. studioData = null;
  65. Timers.inst.Remove(UpdateShowTime);
  66. }
  67. protected override void RemoveEventListener()
  68. {
  69. base.RemoveEventListener();
  70. EventAgent.RemoveEventListener(ConstMessage.BUY_STUDIO_PLAY_TIMES, UpdateView);
  71. EventAgent.RemoveEventListener(ConstMessage.NOTICE_STUDIO_PLAY_TIMES, UpdateView);
  72. }
  73. protected void UpdateView()
  74. {
  75. studioData = StudioDataManager.Instance.GetStudioDataById(this.studioCfg.id);
  76. _ui.m_txtNum.text = string.Format("剩余次数:{0}/{1}", this.studioData.TotalPlayTimes - this.studioData.PlayTimes, studioCfg.num);
  77. }
  78. private void UpdateShowTime(object param)
  79. {
  80. _ui.m_txtTime.text = string.Format("{0}后刷新", TimeUtil.FormattingTime(TimeHelper.ServerNowSecs, GameGlobal.myNumericComponent.GetAsInt(NumericType.DailyResetSecs)));
  81. }
  82. private void ListItemRender(int index, GObject obj)
  83. {
  84. UI_ListItem item = UI_ListItem.Proxy(obj);
  85. StudioDataManager.Instance.IsCanFight(storyLevelCfgs, index, out bool canFight, out string content);
  86. ItemData itemData = StoryBonusDataCache.GetBonusData(storyLevelCfgs[index].id).bonusBase[0];
  87. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  88. item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  89. item.m_star.selectedIndex = InstanceZonesDataManager.GetStarCountHistory(storyLevelCfgs[index].id);
  90. item.m_imgLock.visible = canFight ? false : true;
  91. item.m_txtTitle.text = canFight ? storyLevelCfgs[index].name : content;
  92. if (canFight) curIndex = index;
  93. if (item.m_loaIcon.data == null)
  94. {
  95. item.m_loaIcon.onClick.Add(OnLoaItemClick);
  96. }
  97. item.m_loaIcon.data = index;
  98. if (item.m_loaBg.data == null)
  99. {
  100. item.m_loaBg.onClick.Add(OnCliclListItem);
  101. }
  102. item.m_loaBg.data = index;
  103. UI_ListItem.ProxyEnd();
  104. }
  105. private void OnCliclListItem(EventContext context)
  106. {
  107. GObject obj = context.sender as GObject;
  108. int index = (int)obj.data;
  109. StoryLevelCfg storyLevelCfg = storyLevelCfgs[index];
  110. StudioDataManager.Instance.IsCanFight(storyLevelCfgs, index, out bool canFight, out string content);
  111. if (!canFight)
  112. {
  113. PromptController.Instance.ShowFloatTextPrompt(content);
  114. return;
  115. }
  116. StudioDataManager.Instance.PROPERTY_SELECT_INDEX = _ui.m_listProperty.selectedIndex;
  117. StudioDataManager.Instance.TYPE_SELECT_INDEX = _ui.m_c1.selectedIndex;
  118. InstanceZonesController.ShowLevelView(storyLevelCfg.id, StudioDataManager.Instance.OnFinishStudioStoryLevel);
  119. }
  120. private void OnLoaItemClick(EventContext context)
  121. {
  122. GObject obj = context.sender as GObject;
  123. int index = (int)obj.data;
  124. ItemData itemData = StoryBonusDataCache.GetBonusData(storyLevelCfgs[index].id).bonusBase[0];
  125. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  126. GoodsItemTipsController.ShowItemTips(itemCfg.id);
  127. }
  128. private void OnCliclBtnBuy()
  129. {
  130. ViewManager.Show<StudioBuyNumView>(this.studioCfg.id);
  131. }
  132. }
  133. }