StudioBaseView.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. _valueBarController = new ValueBarController(_ui.m_valueBar);
  41. // _ui.m_list.itemRenderer = ListItemRender;
  42. // // _ui.m_list.onClickItem.Add(OnCliclListItem);
  43. // _ui.m_list.SetVirtual();
  44. // _ui.m_btnBuy.onClick.Add(OnCliclBtnBuy);
  45. }
  46. protected override void AddEventListener()
  47. {
  48. base.AddEventListener();
  49. EventAgent.AddEventListener(ConstMessage.NOTICE_LIMIT_CHANGED, OnLimitChanged);
  50. }
  51. public void AddChildCom(GComponent com,bool isNeedRender = true)
  52. {
  53. _ui.target.AddChildAt(com, 1);
  54. list = com.GetChild("list").asList;
  55. _txtNum = com.GetChild("txtNum").asTextField;
  56. _txtTime = com.GetChild("txtTime").asTextField;
  57. _btnBuy = com.GetChild("btnBuy").asButton;
  58. if (isNeedRender)
  59. {
  60. list.itemRenderer = ListItemRender;
  61. }
  62. _btnBuy.onClick.Add(OnCliclBtnBuy);
  63. }
  64. protected override void OnShown()
  65. {
  66. base.OnShown();
  67. _valueBarController.OnShown();
  68. // _valueBarController.Controller(1);
  69. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("gzs_bjbj");
  70. //add by zyq
  71. UpdateItem();
  72. UpdateView();
  73. Timers.inst.Add(1, 0, UpdateShowTime);
  74. }
  75. protected override void OnHide()
  76. {
  77. _ui.target.RemoveChildAt(1);
  78. base.OnHide();
  79. _valueBarController.OnHide();
  80. _studioCfg = null;
  81. storyLevelCfgs = null;
  82. Timers.inst.Remove(UpdateShowTime);
  83. Timers.inst.Remove(OnTimerUpdate);
  84. }
  85. protected override void RemoveEventListener()
  86. {
  87. base.RemoveEventListener();
  88. EventAgent.RemoveEventListener(ConstMessage.NOTICE_LIMIT_CHANGED, OnLimitChanged);
  89. }
  90. private void OnLimitChanged(EventContext context)
  91. {
  92. int limitId = (int)context.data;
  93. if (this._studioCfg.limit != limitId)
  94. {
  95. return;
  96. }
  97. UpdateView();
  98. }
  99. protected void UpdateView()
  100. {
  101. var limitData = RoleLimitDataManager.GetLimitData(this._studioCfg.limit);
  102. _txtNum.text = string.Format("剩余次数:{0}/{1}", limitData.TotalPlayMax - limitData.PlayTimes,
  103. limitData.MaxStorageCount);
  104. }
  105. private void UpdateView(int limitId)
  106. {
  107. }
  108. private void UpdateShowTime(object param)
  109. {
  110. long curTime = TimeHelper.ServerNow();
  111. long endTime = GameGlobal.myNumericComponent.GetAsInt(NumericType.DailyResetSecs);
  112. _txtTime.text = string.Format("{0}后刷新", TimeUtil.FormattingTime(curTime, endTime * 1000));
  113. }
  114. protected virtual void ListItemRender(int index, GObject obj)
  115. {
  116. UI_ListItem item = UI_ListItem.Proxy(obj);
  117. StudioDataManager.Instance.IsCanFight(storyLevelCfgs, index, out bool canFight, out string content);
  118. ItemData itemData = StoryBonusDataCache.GetBonusData(storyLevelCfgs[index].id).bonusBase[0];
  119. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  120. item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  121. item.m_star.selectedIndex = InstanceZonesDataManager.GetStarCountHistory(storyLevelCfgs[index].id);
  122. item.m_imgLock.visible = canFight ? false : true;
  123. item.m_txtTitle.text = canFight ? storyLevelCfgs[index].name : content;
  124. if (canFight) curIndex = index;
  125. if (item.m_loaIcon.data == null)
  126. {
  127. item.m_loaIcon.onClick.Add(OnLoaItemClick);
  128. }
  129. item.m_loaIcon.data = index;
  130. if (item.m_loaBg.data == null)
  131. {
  132. item.m_loaBg.onClick.Add(OnCliclListItem);
  133. }
  134. item.m_loaBg.data = index;
  135. UI_ListItem.ProxyEnd();
  136. }
  137. public void OnCliclListItem(EventContext context)
  138. {
  139. GObject obj = context.sender as GObject;
  140. int index = (int)obj.data;
  141. StoryLevelCfg storyLevelCfg = storyLevelCfgs[index];
  142. StudioDataManager.Instance.IsCanFight(storyLevelCfgs, index, out bool canFight, out string content);
  143. if (!canFight)
  144. {
  145. PromptController.Instance.ShowFloatTextPrompt(content);
  146. return;
  147. }
  148. // StudioDataManager.Instance.PROPERTY_SELECT_INDEX = _ui.m_listProperty.selectedIndex;
  149. // StudioDataManager.Instance.TYPE_SELECT_INDEX = _ui.m_c1.selectedIndex;
  150. InstanceZonesController.ShowLevelView(storyLevelCfg.id, StudioDataManager.Instance.OnFinishStudioStoryLevel);
  151. }
  152. public void OnLoaItemClick(EventContext context)
  153. {
  154. GObject obj = context.sender as GObject;
  155. int index = (int)obj.data;
  156. ItemData itemData = StoryBonusDataCache.GetBonusData(storyLevelCfgs[index].id).bonusBase[0];
  157. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  158. GoodsItemTipsController.ShowItemTips(itemCfg.id);
  159. }
  160. private void OnCliclBtnBuy()
  161. {
  162. ViewManager.Show<StudioBuyNumView>(this._studioCfg.limit);
  163. }
  164. private void UpdateItem()
  165. {
  166. for (int i = 0; i < list.numChildren; i++)
  167. {
  168. list.GetChildAt(i).visible = false;
  169. }
  170. _time = 0;
  171. Timers.inst.Add(0.07f, list.numChildren, OnTimerUpdate, 1);
  172. }
  173. private void OnTimerUpdate(object param)
  174. {
  175. list.GetChildAt(_time).visible = true;
  176. UI_ListItem listItem = UI_ListItem.Proxy(list.GetChildAt(_time++));
  177. //播放动效
  178. if (listItem.m_test != null)
  179. {
  180. listItem.m_test.Play();
  181. }
  182. UI_ListItem.ProxyEnd();
  183. }
  184. }
  185. }