StudioBaseView.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. using System.Collections.Generic;
  2. using ET;
  3. using FairyGUI;
  4. using UI.Studio;
  5. namespace GFGGame
  6. {
  7. public class StudioBaseView : BaseWindow
  8. {
  9. protected UI_StudioEctypeUI _ui;
  10. private ValueBarController _valueBarController;
  11. public GList list;
  12. private GTextField _txtTime;
  13. private GTextField _txtNum;
  14. private GButton _btnBuy;
  15. private int _time = 0;
  16. protected StudioCfg _studioCfg;
  17. protected List<StoryLevelCfg> storyLevelCfgs;
  18. protected int curIndex = 0;
  19. public override void Dispose()
  20. {
  21. if (_valueBarController != null)
  22. {
  23. _valueBarController.Dispose();
  24. _valueBarController = null;
  25. }
  26. if (_ui != null)
  27. {
  28. _ui.Dispose();
  29. _ui = null;
  30. }
  31. base.Dispose();
  32. }
  33. protected override void OnInit()
  34. {
  35. base.OnInit();
  36. packageName = UI_StudioEctypeUI.PACKAGE_NAME;
  37. _ui = UI_StudioEctypeUI.Create();
  38. this.viewCom = _ui.target;
  39. isfullScreen = true;
  40. isReturnView = 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.NOTICE_LIMIT_CHANGED, OnLimitChanged);
  51. }
  52. public void AddChildCom(GComponent com,bool isNeedRender = true)
  53. {
  54. _ui.target.AddChildAt(com, 1);
  55. list = com.GetChild("list").asList;
  56. _txtNum = com.GetChild("txtNum").asTextField;
  57. _txtTime = com.GetChild("txtTime").asTextField;
  58. _btnBuy = com.GetChild("btnBuy").asButton;
  59. if (isNeedRender)
  60. {
  61. list.itemRenderer = ListItemRender;
  62. }
  63. _btnBuy.onClick.Add(OnCliclBtnBuy);
  64. }
  65. protected override void OnShown()
  66. {
  67. base.OnShown();
  68. _valueBarController.OnShown();
  69. // _valueBarController.Controller(1);
  70. //_ui.m_loaBg.url = ResPathUtil.GetBgImgPath("gzs_bjbj");
  71. //add by zyq
  72. UpdateItem();
  73. UpdateView();
  74. Timers.inst.Add(1, 0, UpdateShowTime);
  75. }
  76. protected override void OnHide()
  77. {
  78. _ui.target.RemoveChildAt(1);
  79. base.OnHide();
  80. _valueBarController.OnHide();
  81. _studioCfg = null;
  82. storyLevelCfgs = null;
  83. Timers.inst.Remove(UpdateShowTime);
  84. Timers.inst.Remove(OnTimerUpdate);
  85. }
  86. protected override void RemoveEventListener()
  87. {
  88. base.RemoveEventListener();
  89. EventAgent.RemoveEventListener(ConstMessage.NOTICE_LIMIT_CHANGED, OnLimitChanged);
  90. }
  91. private void OnLimitChanged(EventContext context)
  92. {
  93. int limitId = (int)context.data;
  94. if (this._studioCfg.limit != limitId)
  95. {
  96. return;
  97. }
  98. UpdateView();
  99. }
  100. protected void UpdateView()
  101. {
  102. var limitData = RoleLimitDataManager.GetLimitData(this._studioCfg.limit);
  103. _txtNum.text = string.Format("剩余次数:{0}/{1}", limitData.TotalPlayMax - limitData.PlayTimes,
  104. limitData.MaxStorageCount);
  105. }
  106. private void UpdateView(int limitId)
  107. {
  108. }
  109. private void UpdateShowTime(object param)
  110. {
  111. long curTime = TimeHelper.ServerNow();
  112. long endTime = GameGlobal.myNumericComponent.GetAsInt(NumericType.DailyResetSecs);
  113. _txtTime.text = string.Format("{0}后刷新", TimeUtil.FormattingTime(curTime, endTime * 1000));
  114. }
  115. protected virtual void ListItemRender(int index, GObject obj)
  116. {
  117. UI_ListItem item = UI_ListItem.Proxy(obj);
  118. StudioDataManager.Instance.IsCanFight(storyLevelCfgs, index, out bool canFight, out string content);
  119. ItemData itemData = StoryBonusDataCache.GetBonusData(storyLevelCfgs[index].id).bonusBase[0];
  120. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  121. item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  122. item.m_star.selectedIndex = InstanceZonesDataManager.GetStarCountHistory(storyLevelCfgs[index].id);
  123. item.m_imgLock.visible = canFight ? false : true;
  124. if (item.m_imgLockBg != null)
  125. {
  126. item.m_imgLockBg.visible = canFight ? false : true;
  127. }
  128. item.m_txtTitle.text = canFight ? storyLevelCfgs[index].name : content;
  129. if (canFight) curIndex = index;
  130. if (item.m_loaIcon.data == null)
  131. {
  132. item.m_loaIcon.onClick.Add(OnLoaItemClick);
  133. }
  134. item.m_loaIcon.data = index;
  135. if (item.m_loaBg.data == null)
  136. {
  137. item.m_loaBg.onClick.Add(OnCliclListItem);
  138. }
  139. item.m_loaBg.data = index;
  140. UI_ListItem.ProxyEnd();
  141. }
  142. public void OnCliclListItem(EventContext context)
  143. {
  144. GObject obj = context.sender as GObject;
  145. int index = (int)obj.data;
  146. StoryLevelCfg storyLevelCfg = storyLevelCfgs[index];
  147. StudioDataManager.Instance.IsCanFight(storyLevelCfgs, index, out bool canFight, out string content);
  148. if (!canFight)
  149. {
  150. PromptController.Instance.ShowFloatTextPrompt(content);
  151. return;
  152. }
  153. // StudioDataManager.Instance.PROPERTY_SELECT_INDEX = _ui.m_listProperty.selectedIndex;
  154. // StudioDataManager.Instance.TYPE_SELECT_INDEX = _ui.m_c1.selectedIndex;
  155. InstanceZonesController.ShowLevelView(storyLevelCfg.id, StudioDataManager.Instance.OnFinishStudioStoryLevel);
  156. }
  157. public void OnLoaItemClick(EventContext context)
  158. {
  159. GObject obj = context.sender as GObject;
  160. int index = (int)obj.data;
  161. ItemData itemData = StoryBonusDataCache.GetBonusData(storyLevelCfgs[index].id).bonusBase[0];
  162. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  163. GoodsItemTipsController.ShowItemTips(itemCfg.id);
  164. }
  165. private void OnCliclBtnBuy()
  166. {
  167. ViewManager.Show<StudioBuyNumView>(this._studioCfg.limit);
  168. }
  169. private void UpdateItem()
  170. {
  171. for (int i = 0; i < list.numChildren; i++)
  172. {
  173. list.GetChildAt(i).visible = false;
  174. }
  175. _time = 0;
  176. Timers.inst.Add(0.07f, list.numChildren, OnTimerUpdate, 1);
  177. }
  178. private void OnTimerUpdate(object param)
  179. {
  180. list.GetChildAt(_time).visible = true;
  181. UI_ListItem listItem = UI_ListItem.Proxy(list.GetChildAt(_time++));
  182. //播放动效
  183. if (listItem.m_test != null)
  184. {
  185. listItem.m_test.Play();
  186. }
  187. UI_ListItem.ProxyEnd();
  188. }
  189. }
  190. }