PearlRebateTipsView.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. using FairyGUI;
  2. using UI.ActivityMain;
  3. using UI.CommonGame;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using cfg.GfgCfg;
  7. using ET;
  8. using static GFGGame.ShopSProxy;
  9. namespace GFGGame
  10. {
  11. public class PearRebateTipsView : BaseWindow
  12. {
  13. private UI_PearlRebateTipsUI _ui;
  14. private EffectUI _effectUI1;
  15. private EffectUI _effectUI2;
  16. private int indexNum = 0;
  17. public override void Dispose()
  18. {
  19. EffectUIPool.Recycle(_effectUI1);
  20. _effectUI1 = null;
  21. EffectUIPool.Recycle(_effectUI2);
  22. _effectUI2 = null;
  23. if (_ui != null)
  24. {
  25. _ui.Dispose();
  26. _ui = null;
  27. }
  28. base.Dispose();
  29. }
  30. protected override void OnInit()
  31. {
  32. base.OnInit();
  33. packageName = UI_PearlRebateTipsUI.PACKAGE_NAME;
  34. _ui = UI_PearlRebateTipsUI.Create();
  35. this.viewCom = _ui.target;
  36. this.modal = true;
  37. this.viewCom.Center();
  38. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  39. _ui.m_buyBtn.target.onClick.Add(OnClickGetReward);
  40. _ui.m_backBtn.onClick.Add(OnClickChange);
  41. _ui.m_one.target.onClick.Add(UpdateIndex1);
  42. _ui.m_two.target.onClick.Add(UpdateIndex2);
  43. _ui.m_three.target.onClick.Add(UpdateIndex3);
  44. _ui.m_notTips.onClick.Add(OnClickTips);
  45. EffectUIPool.CreateEffectUI(_ui.m_effectBtn, "ui_Activity", "",
  46. onComplete: (effect) =>
  47. {
  48. if (effect != null)
  49. {
  50. _effectUI1 = effect;
  51. }
  52. });
  53. EffectUIPool.CreateEffectUI(_ui.m_effectBG, "ui_Activity", "",
  54. onComplete: (effect) =>
  55. {
  56. if (effect != null)
  57. {
  58. _effectUI2 = effect;
  59. }
  60. });
  61. }
  62. protected override void AddEventListener()
  63. {
  64. base.AddEventListener();
  65. EventAgent.AddEventListener(ConstMessage.SHOP_BUY, UpdateView);
  66. }
  67. protected override void RemoveEventListener()
  68. {
  69. base.RemoveEventListener();
  70. EventAgent.RemoveEventListener(ConstMessage.SHOP_BUY, UpdateView);
  71. }
  72. protected override void OnShown()
  73. {
  74. base.OnShown();
  75. UpdateIndex1();
  76. Timers.inst.Add(1, 0, UpdateTime);
  77. }
  78. protected async override void OnHide()
  79. {
  80. if (_ui.m_TipImg.visible)
  81. {
  82. await ActivitySProxy.SetTipsStatus(6000, 1, 1);
  83. }
  84. else
  85. {
  86. await ActivitySProxy.SetTipsStatus(6000, 0, 1);
  87. }
  88. Timers.inst.Remove(UpdateTime);
  89. base.OnHide();
  90. }
  91. private void UpdateListItem(int giftId)
  92. {
  93. ItemCfg item = CommonDataManager.Tables.TblItemCfg.GetOrDefault(giftId);
  94. int index = item.Items.Count;
  95. _ui.m_c1.selectedIndex = index;
  96. switch (index)
  97. {
  98. case 1:
  99. int id = item.Items[0].ItemId;
  100. int count = item.Items[0].Count;
  101. ItemData itemDate = ItemUtil.createItemData(id, count);
  102. ItemView itemView = new ItemView(_ui.m_item1);
  103. itemView.SetData(itemDate);
  104. break;
  105. case 2:
  106. int id0 = item.Items[0].ItemId;
  107. int count0 = item.Items[0].Count;
  108. ItemData itemDate0 = ItemUtil.createItemData(id0, count0);
  109. ItemView itemView0 = new ItemView(_ui.m_item0);
  110. itemView0.SetData(itemDate0);
  111. id0 = item.Items[1].ItemId;
  112. count0 = item.Items[1].Count;
  113. itemDate0 = ItemUtil.createItemData(id0, count0);
  114. itemView0 = new ItemView(_ui.m_item1);
  115. itemView0.SetData(itemDate0);
  116. break;
  117. case 3:
  118. for (int i = 0; i < item.Items.Count; i++)
  119. {
  120. int id3 = item.Items[i].ItemId;
  121. int count3 = item.Items[i].Count;
  122. ItemData itemDate3 = ItemUtil.createItemData(id3, count3);
  123. ItemView itemView3 =
  124. new ItemView(_ui.target.GetChild(string.Format("item{0}", i)) as GComponent);
  125. itemView3.SetData(itemDate3);
  126. }
  127. break;
  128. default:
  129. break;
  130. }
  131. }
  132. private void UpdateView()
  133. {
  134. int discount;
  135. ActivityOpenCfg activityCfg = CommonDataManager.Tables.TblActivityOpenCfg.GetOrDefault(6000);
  136. ShopCfg shopCfg = CommonDataManager.Tables.TblShopCfg.GetOrDefault(activityCfg.Params1[indexNum]);
  137. ItemCfg item = CommonDataManager.Tables.TblItemCfg.GetOrDefault(shopCfg.ItemId);
  138. if (shopCfg.Price == 0) discount = 0;
  139. discount = (int)(((double)shopCfg.OriginalPrice / (double)shopCfg.ConfigPrice) * 100);
  140. int buyNum = ShopDataManager.Instance.GetGoodsBuyNumById(shopCfg.Id);
  141. if (shopCfg.MaxBuyNum == 0 || buyNum < shopCfg.MaxBuyNum)
  142. {
  143. _ui.m_buyBtn.target.visible = true;
  144. _ui.m_gotbtn.target.visible = false;
  145. _ui.m_buyBtn.m_Number.text = string.Format("{0}元", shopCfg.ConfigPrice.ToString());
  146. }
  147. else
  148. {
  149. _ui.m_buyBtn.target.visible = false;
  150. _ui.m_gotbtn.target.visible = true;
  151. }
  152. UpdateListItem(item.Id);
  153. }
  154. private void UpdateIndex1()
  155. {
  156. indexNum = 0;
  157. _ui.m_one.m_c1.selectedIndex = 1;
  158. _ui.m_two.m_c1.selectedIndex = 0;
  159. _ui.m_three.m_c1.selectedIndex = 0;
  160. UpdateView();
  161. }
  162. private void UpdateIndex2()
  163. {
  164. indexNum = 1;
  165. _ui.m_one.m_c1.selectedIndex = 0;
  166. _ui.m_two.m_c1.selectedIndex = 1;
  167. _ui.m_three.m_c1.selectedIndex = 0;
  168. UpdateView();
  169. }
  170. private void UpdateIndex3()
  171. {
  172. indexNum = 2;
  173. _ui.m_one.m_c1.selectedIndex = 0;
  174. _ui.m_two.m_c1.selectedIndex = 0;
  175. _ui.m_three.m_c1.selectedIndex = 1;
  176. UpdateView();
  177. }
  178. private void OnClickGetReward()
  179. {
  180. var activityInfo = ActivityGlobalDataManager.Instance.GetActivityInfo(6000);
  181. if (activityInfo != null)
  182. {
  183. var cfg = CommonDataManager.Tables.TblActivityOpenCfg.GetOrDefault(6000);
  184. if (cfg.Params1 != null && cfg.Params1.Count > 0)
  185. {
  186. int id = cfg.Params1[indexNum];
  187. ReqShopBuy(id).Coroutine();
  188. }
  189. }
  190. return;
  191. }
  192. private void OnClickTips()
  193. {
  194. if (_ui.m_TipImg.visible == false)
  195. {
  196. _ui.m_TipImg.visible = true;
  197. }
  198. else
  199. {
  200. _ui.m_TipImg.visible = false;
  201. }
  202. }
  203. private void OnClickChange()
  204. {
  205. this.Hide();
  206. }
  207. private void UpdateTime(object param)
  208. {
  209. var activityInfo = ActivityGlobalDataManager.Instance.GetActivityInfo(6000);
  210. long endTime = 0;
  211. if (activityInfo != null)
  212. {
  213. endTime = activityInfo.EndTime;
  214. }
  215. var leftTime = endTime - TimeHelper.ServerNow();
  216. if (leftTime <= 0)
  217. {
  218. _ui.m_timeText.text = "";
  219. _ui.m_buyBtn.target.visible = false;
  220. Timers.inst.Remove(UpdateTime);
  221. return;
  222. }
  223. _ui.m_timeText.text = TimeUtil.FormattingTimeTo_DDHHmm((int)leftTime);
  224. }
  225. }
  226. }