StudioBaseView.cs 8.2 KB

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