BlindBoxView.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. using FairyGUI;
  2. using UI.BlindBox;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using ET;
  6. using System.Threading.Tasks;
  7. using System.Linq;
  8. using System.Text.RegularExpressions;
  9. using cfg.GfgCfg;
  10. namespace GFGGame
  11. {
  12. public struct BlindBoxType
  13. {
  14. public int type;
  15. public bool check;
  16. }
  17. public class BlindBoxView : BaseWindow
  18. {
  19. private UI_BlindBoxUI _ui;
  20. //private EffectUI _effectUI1;
  21. private Dictionary<string, EffectUI> _effectUIDic = new Dictionary<string, EffectUI>();
  22. private ItemCfg itemcfg;
  23. private int listIndex = 0;
  24. BlindBoxCfg blindBoxCfg = CommonDataManager.Tables.TblBlindBoxCfg.GetOrDefault(2);
  25. public override void Dispose()
  26. {
  27. // EffectUIPool.Recycle(_effectUI1);
  28. // _effectUI1 = null;
  29. foreach (var v in _effectUIDic)
  30. {
  31. EffectUIPool.Recycle(v.Value);
  32. }
  33. _effectUIDic.Clear();
  34. if (_ui != null)
  35. {
  36. _ui.Dispose();
  37. _ui = null;
  38. }
  39. base.Dispose();
  40. }
  41. protected override void OnInit()
  42. {
  43. base.OnInit();
  44. packageName = UI_BlindBoxUI.PACKAGE_NAME;
  45. _ui = UI_BlindBoxUI.Create();
  46. this.viewCom = _ui.target;
  47. modal = true;
  48. this.viewCom.Center();
  49. //viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  50. _ui.m_backBtn.onClick.Add(this.Hide);
  51. _ui.m_buyBtn.target.onClick.Add(OnClickBuyAll);
  52. _ui.m_hiddenItem.onClick.Add(OnClickRewardBtn);
  53. _ui.m_rewardList.onClick.Add(OnClickRewardBtn);
  54. _ui.m_ruleBtn.onClick.Add(OnClickRuleBtn);
  55. _ui.m_rewardList.itemRenderer = RenderRewardList;
  56. List<DropOutCfg> dropOutCfgList =
  57. CommonDataManager.Tables.TblDropOutCfg.DataList.Where(a => a.Id == blindBoxCfg.OrdinaryDropDisplay)
  58. .ToList();
  59. List<DropOutCfg> hidDropOutCfgList =
  60. CommonDataManager.Tables.TblDropOutCfg.DataList.Where(a => a.Id == blindBoxCfg.HideDropDisplay)
  61. .ToList();
  62. ItemCfg hidItemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(hidDropOutCfgList[0].Item);
  63. _ui.m_rewardList.numItems = dropOutCfgList.Count;
  64. _ui.m_hiddenItem.url = ResPathUtil.GetIconPath(hidItemCfg);
  65. _ui.m_buyBtn.m_num.text = blindBoxCfg.CostIDNum[1].ToString();
  66. _ui.m_boxList.itemRenderer = RenderBoxList;
  67. //_effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_effect, "ui_Activity", "WSJ_UI_DX/WSJ_UI_DX");
  68. }
  69. protected override void OnShown()
  70. {
  71. base.OnShown();
  72. //_ui.m_bg.visible = false;
  73. _ui.m_t1.Play();
  74. clickBlankToClose = false;
  75. itemcfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(blindBoxCfg.CostID);
  76. if (itemcfg == null)
  77. {
  78. Log.Error(string.Format("没有{0}物品"));
  79. }
  80. _ui.m_buyBtn.m_newimg.url = "ui://eg2y0ldpuje19g0w";
  81. // _ui.m_buyBtn.m_img.width = 5;
  82. _ui.m_boxList.numItems = 6;
  83. _ui.m_rewardList.numItems = 6;
  84. UpdateTime(null);
  85. Timers.inst.Add(1, 0, UpdateTime);
  86. Timers.inst.Add(0.75f, 1, TimeUpdateShow);
  87. }
  88. protected override void OnHide()
  89. {
  90. base.OnHide();
  91. ActivityDataManager.Instance.BlindBoxType = 0;
  92. Timers.inst.Remove(UpdateTime);
  93. Timers.inst.Remove(TimeUpdateShow);
  94. }
  95. protected override void AddEventListener()
  96. {
  97. base.AddEventListener();
  98. EventAgent.AddEventListener(ConstMessage.BlindBox_BuyOne, ReqBuyOne);
  99. EventAgent.AddEventListener(ConstMessage.BlindBox_BuyAll, ReqBuyAll);
  100. }
  101. protected override void RemoveEventListener()
  102. {
  103. base.RemoveEventListener();
  104. EventAgent.RemoveEventListener(ConstMessage.BlindBox_BuyOne, ReqBuyOne);
  105. EventAgent.RemoveEventListener(ConstMessage.BlindBox_BuyAll, ReqBuyAll);
  106. }
  107. private void OnClickRewardBtn()
  108. {
  109. ViewManager.Show<BlindBoxRewardView>(new object[] { 30000066, 30000078 });
  110. }
  111. private void OnClickRuleBtn()
  112. {
  113. ViewManager.Show<BlindBoxRuleView>(300037);
  114. }
  115. private void RenderRewardList(int index, GObject obj)
  116. {
  117. UI_rewardItem uiItemChild = UI_rewardItem.Proxy(obj);
  118. List<DropOutCfg> dropOutCfgList =
  119. CommonDataManager.Tables.TblDropOutCfg.DataList.Where(a => a.Id == blindBoxCfg.OrdinaryDropDisplay)
  120. .ToList();
  121. ItemCfg itemCfgChild = CommonDataManager.Tables.TblItemCfg.GetOrDefault(dropOutCfgList[index].Item);
  122. uiItemChild.target.data = itemCfgChild;
  123. uiItemChild.m_reward.url = ResPathUtil.GetIconPath(itemCfgChild);
  124. UI_rewardItem.ProxyEnd();
  125. }
  126. private void RenderBoxList(int index, GObject obj)
  127. {
  128. UI_boxItem item = UI_boxItem.Proxy(obj);
  129. item.target.onClick.Add(OnClickBuyOne);
  130. if (!_effectUIDic.ContainsKey("WSJ_Box" + index.ToString()))
  131. {
  132. EffectUIPool.CreateEffectUI(item.m_effect, "ui_Activity", "WSJ_Box/WSJ_Box",
  133. onComplete: (effect) =>
  134. {
  135. if (effect != null)
  136. {
  137. _effectUIDic.Add("WSJ_Box" + index.ToString(), effect);
  138. }
  139. });
  140. }
  141. if (!_effectUIDic.ContainsKey("WSJ_OpenBox" + index.ToString()))
  142. {
  143. EffectUIPool.CreateEffectUI(item.m_effectOpen, "ui_Activity", "WSJ_OpenBox/WSJ_OpenBox",
  144. onComplete: (effect) =>
  145. {
  146. if (effect != null)
  147. {
  148. _effectUIDic.Add("WSJ_OpenBox" + index.ToString(), effect);
  149. }
  150. });
  151. item.m_effectOpen.visible = false;
  152. }
  153. UI_boxItem.ProxyEnd();
  154. }
  155. private void OnClickBuyAll()
  156. {
  157. ActivityDataManager.Instance.BlindBoxType = 6;
  158. int costNum = blindBoxCfg.CostIDNum[1];
  159. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(itemcfg.Id);
  160. if (ActivityDataManager.Instance.typeAll.check == false)
  161. {
  162. string desc = string.Format("确认是否消耗{0}{1}打开{2}个盲盒?", costNum, itemCfg.Name, _ui.m_boxList.numItems);
  163. ViewManager.Show<BlindBoxBuyTIpView>(desc);
  164. }
  165. else
  166. {
  167. ReqBuyAll();
  168. }
  169. }
  170. private async void ReqBuyAll()
  171. {
  172. bool result;
  173. result = await LuckyBoxSProxy.ReqGetBlindBox(2, 6);
  174. if (result)
  175. {
  176. UpdateAllBoxAni();
  177. }
  178. }
  179. private async void ReqBuyOne()
  180. {
  181. bool result;
  182. result = await LuckyBoxSProxy.ReqGetBlindBox(2, 1);
  183. if (result)
  184. {
  185. UI_boxItem listItem = UI_boxItem.Proxy(_ui.m_boxList.GetChildAt(listIndex));
  186. _ui.m_backBtn.touchable = false;
  187. _ui.m_buyBtn.target.touchable = false;
  188. _ui.m_boxList.touchable = false;
  189. clickBlankToClose = false;
  190. listItem.m_t0.Play(() =>
  191. {
  192. BonusController.TryShowBonusList(
  193. ItemUtil.CreateItemDataList(LuckyBoxDataManager.Instance.BlindBoxReward));
  194. _ui.m_backBtn.touchable = true;
  195. _ui.m_buyBtn.target.touchable = true;
  196. _ui.m_boxList.touchable = true;
  197. clickBlankToClose = true;
  198. });
  199. UI_boxItem.ProxyEnd();
  200. }
  201. }
  202. private void OnClickBuyOne(EventContext context)
  203. {
  204. GObject sender = context.sender as GObject;
  205. GObject obj = sender.parent;
  206. listIndex = _ui.m_boxList.GetChildIndex(sender);
  207. ActivityDataManager.Instance.BlindBoxType = 1;
  208. int costNum = blindBoxCfg.CostIDNum[0];
  209. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(itemcfg.Id);
  210. if (ActivityDataManager.Instance.typeOne.check == false)
  211. {
  212. string desc = string.Format("确认是否消耗{0}{1}打开一个盲盒?", costNum, itemCfg.Name);
  213. ViewManager.Show<BlindBoxBuyTIpView>(desc);
  214. }
  215. else
  216. {
  217. ReqBuyOne();
  218. }
  219. }
  220. private async void UpdateAllBoxAni()
  221. {
  222. _ui.m_backBtn.touchable = false;
  223. _ui.m_buyBtn.target.touchable = false;
  224. _ui.m_boxList.touchable = false;
  225. clickBlankToClose = false;
  226. for (int i = 0; i < _ui.m_boxList.numItems; i++)
  227. {
  228. UI_boxItem item = UI_boxItem.Proxy(_ui.m_boxList.GetChildAt(i));
  229. item.m_effect.visible = false;
  230. item.m_effectOpen.visible = true;
  231. await Task.Delay(200);
  232. UI_boxItem.ProxyEnd();
  233. }
  234. BonusController.TryShowBonusList(ItemUtil.CreateItemDataList(LuckyBoxDataManager.Instance.BlindBoxReward));
  235. for (int i = 0; i < _ui.m_boxList.numItems; i++)
  236. {
  237. UI_boxItem item = UI_boxItem.Proxy(_ui.m_boxList.GetChildAt(i));
  238. item.m_effect.visible = true;
  239. item.m_effectOpen.visible = false;
  240. UI_boxItem.ProxyEnd();
  241. }
  242. _ui.m_backBtn.touchable = true;
  243. _ui.m_buyBtn.target.touchable = true;
  244. _ui.m_boxList.touchable = true;
  245. clickBlankToClose = true;
  246. }
  247. private void TimeUpdateShow(object param)
  248. {
  249. clickBlankToClose = true;
  250. }
  251. private void UpdateTime(object param)
  252. {
  253. long curTime = TimeHelper.ServerNow();
  254. var activityInfo = ActivityGlobalDataManager.Instance.GetActivityInfo(10302);
  255. if (activityInfo != null)
  256. {
  257. long endTime = activityInfo.EndTime;
  258. _ui.m_txtTime.text = TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime);
  259. }
  260. }
  261. }
  262. }