PearlRebateTipsView.cs 7.7 KB

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