StudioBaseView.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. long curTime = TimeHelper.ServerNow();
  81. long endTime = GameGlobal.myNumericComponent.GetAsInt(NumericType.DailyResetSecs);
  82. _ui.m_txtTime.text = string.Format("{0}后刷新", TimeUtil.FormattingTime(curTime, endTime * 1000));
  83. }
  84. private void ListItemRender(int index, GObject obj)
  85. {
  86. UI_ListItem item = UI_ListItem.Proxy(obj);
  87. StudioDataManager.Instance.IsCanFight(storyLevelCfgs, index, out bool canFight, out string content);
  88. ItemData itemData = StoryBonusDataCache.GetBonusData(storyLevelCfgs[index].id).bonusBase[0];
  89. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  90. item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  91. item.m_star.selectedIndex = InstanceZonesDataManager.GetStarCountHistory(storyLevelCfgs[index].id);
  92. item.m_imgLock.visible = canFight ? false : true;
  93. item.m_txtTitle.text = canFight ? storyLevelCfgs[index].name : content;
  94. if (canFight) curIndex = index;
  95. if (item.m_loaIcon.data == null)
  96. {
  97. item.m_loaIcon.onClick.Add(OnLoaItemClick);
  98. }
  99. item.m_loaIcon.data = index;
  100. if (item.m_loaBg.data == null)
  101. {
  102. item.m_loaBg.onClick.Add(OnCliclListItem);
  103. }
  104. item.m_loaBg.data = index;
  105. UI_ListItem.ProxyEnd();
  106. }
  107. private void OnCliclListItem(EventContext context)
  108. {
  109. GObject obj = context.sender as GObject;
  110. int index = (int)obj.data;
  111. StoryLevelCfg storyLevelCfg = storyLevelCfgs[index];
  112. StudioDataManager.Instance.IsCanFight(storyLevelCfgs, index, out bool canFight, out string content);
  113. if (!canFight)
  114. {
  115. PromptController.Instance.ShowFloatTextPrompt(content);
  116. return;
  117. }
  118. StudioDataManager.Instance.PROPERTY_SELECT_INDEX = _ui.m_listProperty.selectedIndex;
  119. StudioDataManager.Instance.TYPE_SELECT_INDEX = _ui.m_c1.selectedIndex;
  120. InstanceZonesController.ShowLevelView(storyLevelCfg.id, StudioDataManager.Instance.OnFinishStudioStoryLevel);
  121. }
  122. private void OnLoaItemClick(EventContext context)
  123. {
  124. GObject obj = context.sender as GObject;
  125. int index = (int)obj.data;
  126. ItemData itemData = StoryBonusDataCache.GetBonusData(storyLevelCfgs[index].id).bonusBase[0];
  127. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  128. GoodsItemTipsController.ShowItemTips(itemCfg.id);
  129. }
  130. private void OnCliclBtnBuy()
  131. {
  132. ViewManager.Show<StudioBuyNumView>(this.studioCfg.id);
  133. }
  134. }
  135. }