PearlRebateTipsView.cs 7.1 KB

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