StudioBaseView.cs 6.2 KB

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