PearlRebateTipsView.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_effectBtn, "ui_Activity", "");
  46. _effectUI2 = EffectUIPool.CreateEffectUI(_ui.m_effectBG, "ui_Activity", "");
  47. }
  48. protected override void AddEventListener()
  49. {
  50. base.AddEventListener();
  51. EventAgent.AddEventListener(ConstMessage.SHOP_BUY, UpdateView);
  52. }
  53. protected override void RemoveEventListener()
  54. {
  55. base.RemoveEventListener();
  56. EventAgent.RemoveEventListener(ConstMessage.SHOP_BUY, UpdateView);
  57. }
  58. protected override void OnShown()
  59. {
  60. base.OnShown();
  61. UpdateIndex1();
  62. Timers.inst.Add(1, 0, UpdateTime);
  63. }
  64. protected async override void OnHide()
  65. {
  66. if (_ui.m_TipImg.visible)
  67. {
  68. await ActivitySProxy.SetTipsStatus(6000, 1, 1);
  69. }
  70. else
  71. {
  72. await ActivitySProxy.SetTipsStatus(6000, 0, 1);
  73. }
  74. Timers.inst.Remove(UpdateTime);
  75. base.OnHide();
  76. }
  77. private void UpdateListItem(int giftId)
  78. {
  79. ItemCfg item = CommonDataManager.Tables.TblItemCfg.GetOrDefault(giftId);
  80. int index = item.Items.Count;
  81. _ui.m_c1.selectedIndex = index;
  82. switch (index)
  83. {
  84. case 1:
  85. int id = item.Items[0].ItemId;
  86. int count = item.Items[0].Count;
  87. ItemData itemDate = ItemUtil.createItemData(id, count);
  88. ItemView itemView = new ItemView(_ui.m_item1);
  89. itemView.SetData(itemDate);
  90. break;
  91. case 2:
  92. int id0 = item.Items[0].ItemId;
  93. int count0 = item.Items[0].Count;
  94. ItemData itemDate0 = ItemUtil.createItemData(id0, count0);
  95. ItemView itemView0 = new ItemView(_ui.m_item0);
  96. itemView0.SetData(itemDate0);
  97. id0 = item.Items[1].ItemId;
  98. count0 = item.Items[1].Count;
  99. itemDate0 = ItemUtil.createItemData(id0, count0);
  100. itemView0 = new ItemView(_ui.m_item1);
  101. itemView0.SetData(itemDate0);
  102. break;
  103. case 3:
  104. for (int i = 0; i < item.Items.Count; i++)
  105. {
  106. int id3 = item.Items[i].ItemId;
  107. int count3 = item.Items[i].Count;
  108. ItemData itemDate3 = ItemUtil.createItemData(id3, count3);
  109. ItemView itemView3 =
  110. new ItemView(_ui.target.GetChild(string.Format("item{0}", i)) as GComponent);
  111. itemView3.SetData(itemDate3);
  112. }
  113. break;
  114. default:
  115. break;
  116. }
  117. }
  118. private void UpdateView()
  119. {
  120. int discount;
  121. ActivityOpenCfg activityCfg = CommonDataManager.Tables.TblActivityOpenCfg.GetOrDefault(6000);
  122. ShopCfg shopCfg = CommonDataManager.Tables.TblShopCfg.GetOrDefault(activityCfg.Params1[indexNum]);
  123. ItemCfg item = CommonDataManager.Tables.TblItemCfg.GetOrDefault(shopCfg.ItemId);
  124. if (shopCfg.Price == 0) discount = 0;
  125. discount = (int)(((double)shopCfg.OriginalPrice / (double)shopCfg.ConfigPrice) * 100);
  126. int buyNum = ShopDataManager.Instance.GetGoodsBuyNumById(shopCfg.Id);
  127. if (shopCfg.MaxBuyNum == 0 || buyNum < shopCfg.MaxBuyNum)
  128. {
  129. _ui.m_buyBtn.target.visible = true;
  130. _ui.m_gotbtn.target.visible = false;
  131. _ui.m_buyBtn.m_Number.text = string.Format("{0}元", shopCfg.ConfigPrice.ToString());
  132. }
  133. else
  134. {
  135. _ui.m_buyBtn.target.visible = false;
  136. _ui.m_gotbtn.target.visible = true;
  137. }
  138. UpdateListItem(item.Id);
  139. }
  140. private void UpdateIndex1()
  141. {
  142. indexNum = 0;
  143. _ui.m_one.m_c1.selectedIndex = 1;
  144. _ui.m_two.m_c1.selectedIndex = 0;
  145. _ui.m_three.m_c1.selectedIndex = 0;
  146. UpdateView();
  147. }
  148. private void UpdateIndex2()
  149. {
  150. indexNum = 1;
  151. _ui.m_one.m_c1.selectedIndex = 0;
  152. _ui.m_two.m_c1.selectedIndex = 1;
  153. _ui.m_three.m_c1.selectedIndex = 0;
  154. UpdateView();
  155. }
  156. private void UpdateIndex3()
  157. {
  158. indexNum = 2;
  159. _ui.m_one.m_c1.selectedIndex = 0;
  160. _ui.m_two.m_c1.selectedIndex = 0;
  161. _ui.m_three.m_c1.selectedIndex = 1;
  162. UpdateView();
  163. }
  164. private void OnClickGetReward()
  165. {
  166. var activityInfo = ActivityGlobalDataManager.Instance.GetActivityInfo(6000);
  167. if (activityInfo != null)
  168. {
  169. var cfg = CommonDataManager.Tables.TblActivityOpenCfg.GetOrDefault(6000);
  170. if (cfg.Params1 != null && cfg.Params1.Count > 0)
  171. {
  172. int id = cfg.Params1[indexNum];
  173. ReqShopBuy(id).Coroutine();
  174. }
  175. }
  176. return;
  177. }
  178. private void OnClickTips()
  179. {
  180. if (_ui.m_TipImg.visible == false)
  181. {
  182. _ui.m_TipImg.visible = true;
  183. }
  184. else
  185. {
  186. _ui.m_TipImg.visible = false;
  187. }
  188. }
  189. private void OnClickChange()
  190. {
  191. this.Hide();
  192. }
  193. private void UpdateTime(object param)
  194. {
  195. var activityInfo = ActivityGlobalDataManager.Instance.GetActivityInfo(6000);
  196. long endTime = 0;
  197. if (activityInfo != null)
  198. {
  199. endTime = activityInfo.EndTime;
  200. }
  201. var leftTime = endTime - TimeHelper.ServerNow();
  202. if (leftTime <= 0)
  203. {
  204. _ui.m_timeText.text = "";
  205. _ui.m_buyBtn.target.visible = false;
  206. Timers.inst.Remove(UpdateTime);
  207. return;
  208. }
  209. _ui.m_timeText.text = TimeUtil.FormattingTimeTo_DDHHmm((int)leftTime);
  210. }
  211. }
  212. }