StudioBaseView.cs 6.3 KB

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