NewLimitChargeView.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. using UI.Store;
  2. using UI.CommonGame;
  3. using FairyGUI;
  4. using System.Collections.Generic;
  5. using ET;
  6. using System;
  7. using Hutool;
  8. using UI.DailyWelfare;
  9. namespace GFGGame
  10. {
  11. public class NewLimitChargeView : BaseWindow
  12. {
  13. private UI_NewLimitChargeUI _ui;
  14. private List<ShopCfg> _shopCfgs;
  15. private List<DressUpObjUI> _dressUpObjUIs = new List<DressUpObjUI>();
  16. private int _curSelectIndex = 0;
  17. private int _activityId = 0;
  18. private ActivityInfo _activityInfo;
  19. private List<ActivityRechargeCfg> _rechargeCfgs;
  20. private int previousIndex = 0;
  21. private bool isGoChargeView = false;
  22. public override void Dispose()
  23. {
  24. for (int i = 0; i < _dressUpObjUIs.Count; i++)
  25. {
  26. if (_dressUpObjUIs[i] != null)
  27. {
  28. _dressUpObjUIs[i].Dispose();
  29. _dressUpObjUIs[i] = null;
  30. }
  31. }
  32. if (_ui != null)
  33. {
  34. _ui.Dispose();
  35. }
  36. _ui = null;
  37. base.Dispose();
  38. }
  39. protected override void OnInit()
  40. {
  41. base.OnInit();
  42. packageName = UI_LimitChargeUI.PACKAGE_NAME;
  43. _ui = UI_NewLimitChargeUI.Create();
  44. this.viewCom = _ui.target;
  45. isfullScreen = true;
  46. isReturnView = true;
  47. this.clickBlankToClose = false;
  48. this.bringToFontOnClick = false;
  49. _ui.m_btnLeft.onClick.Add(OnBtnLeftClick);
  50. _ui.m_btnRight.onClick.Add(OnBtnRightClick);
  51. _ui.m_btnBack.onClick.Add(OnBtnBackClick);
  52. _ui.m_btnCharge.onClick.Add(OnBtnChargeClick);
  53. }
  54. protected override void AddEventListener()
  55. {
  56. base.AddEventListener();
  57. EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, RefreshList);
  58. EventAgent.AddEventListener(ConstMessage.NEWLIMITCHARGE_GET, OnBtnRightClick);
  59. //EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateRedDot);
  60. }
  61. protected override void OnShown()
  62. {
  63. base.OnShown();
  64. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("bg_fhl");
  65. _activityId = (int)(this.viewData as object[])[0];
  66. _rechargeCfgs = ActivityRechargeCfgArray.Instance.GetCfgsByactivityId(_activityId);
  67. _activityInfo = ActivityGlobalDataManager.Instance.GetActivityInfo(_activityId);
  68. //UpdateRedDot();
  69. RefreshList();
  70. string name = SuitCfgArray.Instance.GetCfg(_rechargeCfgs[0].suitId).name;
  71. _ui.m_packageName.text = name;
  72. if (!isGoChargeView)
  73. {
  74. for (int i = 0; i < _rechargeCfgs.Count; i++)
  75. {
  76. if (_activityInfo.CountValue >= _rechargeCfgs[i].value)
  77. {
  78. if (_activityInfo.GetRewards.IndexOf(_rechargeCfgs[i].id) < 0)
  79. {
  80. _curSelectIndex = i;
  81. break;
  82. }
  83. }
  84. }
  85. }
  86. isGoChargeView = false;
  87. _ui.m_btnLeft.visible = _curSelectIndex == 0 ? false : true;
  88. _ui.m_btnRight.visible = _curSelectIndex < _rechargeCfgs.Count - 1 ? true : false;
  89. _ui.m_packageName.text = SuitCfgArray.Instance.GetCfg(_rechargeCfgs[_curSelectIndex].suitId).name;
  90. ItemRenderer(_curSelectIndex);
  91. Timers.inst.Add(1, 0, UpdateTime);
  92. }
  93. protected override void OnHide()
  94. {
  95. base.OnHide();
  96. Timers.inst.Remove(UpdateTime);
  97. }
  98. protected override void RemoveEventListener()
  99. {
  100. base.RemoveEventListener();
  101. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, RefreshList);
  102. EventAgent.RemoveEventListener(ConstMessage.NEWLIMITCHARGE_GET, OnBtnRightClick);
  103. //EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateRedDot);
  104. }
  105. private void RefreshList()
  106. {
  107. ItemRenderer(_curSelectIndex);
  108. }
  109. private void ItemRenderer(int index)
  110. {
  111. ActivityRechargeCfg lastVipCfg = _rechargeCfgs[index];
  112. ActivityRechargeCfg vipCfg = _rechargeCfgs[index];
  113. UI_ListShowItem item = _ui.m_showItem;
  114. string name = SuitCfgArray.Instance.GetCfg(vipCfg.suitId).name;
  115. item.m_txtName0.text = name;
  116. if (vipCfg.res != "")
  117. {
  118. item.m_cardIcon.visible = true;
  119. item.m_cardBg.visible = true;
  120. item.m_cardIcon.url = "ui://DailyWelfare/" + vipCfg.res;
  121. }
  122. else
  123. {
  124. item.m_cardIcon.visible = false;
  125. item.m_cardBg.visible = false;
  126. }
  127. if (item.m_listGiftBag.data == null)
  128. {
  129. item.m_listGiftBag.itemRenderer = ListRewardItemRender;
  130. item.m_listGiftBag.onClickItem.Add(OnListItemClick);
  131. }
  132. item.m_listGiftBag.data = lastVipCfg.bonusArr;
  133. item.m_listGiftBag.numItems = lastVipCfg.bonusArr.Length;
  134. if (_rechargeCfgs[index].suitId != previousIndex)
  135. {
  136. int rolesScale = 80;
  137. if (_rechargeCfgs[index].suitId == 200055 || _rechargeCfgs[index].suitId == 201027)
  138. {
  139. //这里由于这两个套装模型太小,特殊处理放大
  140. rolesScale = 120;
  141. }
  142. if (item.m_holder.data == null)
  143. {
  144. DressUpObjUI dressUpObjUI = new DressUpObjUI("SceneSuitFoster");
  145. item.m_holder.data = dressUpObjUI;
  146. _dressUpObjUIs.Add(dressUpObjUI);
  147. }
  148. DressUpObjUI _dressUpObjUI = item.m_holder.data as DressUpObjUI;
  149. _dressUpObjUI.ResetSceneObj(rolesScale, false, true, null, false);
  150. _dressUpObjUI.dressUpObj.PutOnSuitCfg(vipCfg.suitId, true, new int[] { ConstDressUpItemType.BEI_JING }, false, false);
  151. _dressUpObjUI.UpdateWrapper(item.m_holder);
  152. }
  153. previousIndex = _rechargeCfgs[index].suitId;
  154. if (item.m_btnShow.data == null)
  155. {
  156. item.m_btnShow.onClick.Add(OnBtnShowClick);
  157. }
  158. item.m_btnShow.data = vipCfg.suitId;
  159. if (item.m_btnGetGiftBag.data == null)
  160. {
  161. item.m_btnGetGiftBag.onClick.Add(OnBtnGetGiftBagClick);
  162. }
  163. item.m_btnGetGiftBag.data = vipCfg.id;
  164. bool isGet = MathUtil.isBitSet(GameGlobal.myNumericComponent.GetAsInt(NumericType.VipGetStatus), vipCfg.id);
  165. long limitChargeExp = _activityInfo.CountValue;
  166. //item.m_btnGetGiftBag.grayed = limitChargeExp < _rechargeCfgs[index].value;
  167. item.m_txtGiftBag.text = string.Format("活动期间累计获得{0}会员积分({1}/{2})", _rechargeCfgs[index].value, limitChargeExp, _rechargeCfgs[index].value);
  168. if (limitChargeExp >= _rechargeCfgs[index].value)
  169. {
  170. if(_activityInfo.GetRewards.IndexOf(_rechargeCfgs[index].id) >= 0)
  171. {
  172. item.m_btnGetGiftBag.grayed = true;
  173. item.m_btnGetGiftBag.title = "已领取";
  174. }
  175. else
  176. {
  177. item.m_btnGetGiftBag.grayed = false;
  178. item.m_btnGetGiftBag.title = "领取";
  179. }
  180. }
  181. else
  182. {
  183. item.m_btnGetGiftBag.grayed = true;
  184. item.m_btnGetGiftBag.title = "领取";
  185. }
  186. }
  187. private void ListRewardItemRender(int index, GObject obj)
  188. {
  189. int[][] rewards = (int[][])obj.parent.data;
  190. UI_ComItem item = UI_ComItem.Proxy(obj);
  191. ItemData itemData = ItemUtil.createItemData(rewards[index]);
  192. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  193. item.m_txtCount.text = itemData.num.ToString();
  194. item.target.data = itemCfg;
  195. item.m_QualityType.selectedIndex = itemData.rarity - 1;
  196. item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  197. UI_ComItem.ProxyEnd();
  198. }
  199. private void OnBtnShowClick(EventContext context)
  200. {
  201. GObject obj = context.sender as GObject;
  202. int suitId = (int)obj.data;
  203. int _suitTypeId = 0;
  204. for (int i = 0; i < SuitGuideMenuCfgArray.Instance.dataArray.Length; i++)
  205. {
  206. string[] suitIds = SuitGuideMenuCfgArray.Instance.dataArray[i].suitIds.Split(';');
  207. if (Array.IndexOf(suitIds, suitId.ToString()) >= 0)
  208. {
  209. _suitTypeId = SuitGuideMenuCfgArray.Instance.dataArray[i].id;
  210. break;
  211. }
  212. }
  213. ViewManager.Show<SuitShowView>(new object[] { _suitTypeId, suitId, new List<int>() { suitId }, false });
  214. }
  215. private void OnBtnGetGiftBagClick(EventContext context)
  216. {
  217. GObject obj = context.sender as GObject;
  218. int id = (int)obj.data;
  219. ActivityGlobalSProxy.ReqGetActivityBonus(_activityId, id).Coroutine();
  220. }
  221. private void OnBtnLeftClick()
  222. {
  223. if (_curSelectIndex == 0) return;
  224. _curSelectIndex = _curSelectIndex - 1;
  225. string name = SuitCfgArray.Instance.GetCfg(_rechargeCfgs[_curSelectIndex].suitId).name;
  226. _ui.m_packageName.text = name;
  227. UpdateSuitView();
  228. //UpdateRedDot();
  229. }
  230. private void OnBtnRightClick()
  231. {
  232. if (_curSelectIndex == _rechargeCfgs.Count - 1) return;
  233. _curSelectIndex = _curSelectIndex + 1;
  234. string name = SuitCfgArray.Instance.GetCfg(_rechargeCfgs[_curSelectIndex].suitId).name;
  235. _ui.m_packageName.text = name;
  236. UpdateSuitView();
  237. //UpdateRedDot();
  238. }
  239. private void OnBtnChargeClick()
  240. {
  241. ViewManager.Show<StoreView>(new object[] { ConstStoreTabId.STORE_CHARGE, ConstStoreSubId.STORE_CHARGE });
  242. isGoChargeView = true;
  243. }
  244. private void UpdateSuitView()
  245. {
  246. _ui.m_btnLeft.visible = _curSelectIndex == 0 ? false : true;
  247. _ui.m_btnRight.visible = _curSelectIndex < _rechargeCfgs.Count - 1 ? true : false;
  248. ItemRenderer(_curSelectIndex);
  249. }
  250. private void UpdateTime(object param)
  251. {
  252. long curTime = TimeHelper.ServerNow();
  253. long endTime = _activityInfo.EndTime;
  254. _ui.m_txtTime.text = TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime);
  255. }
  256. private void OnListItemClick(EventContext context)
  257. {
  258. GComponent comItem = (context.data as GComponent);
  259. ItemCfg itemCfg = comItem.data as ItemCfg;
  260. GoodsItemTipsController.ShowItemTips(itemCfg.id);
  261. }
  262. private void OnBtnBackClick()
  263. {
  264. ViewManager.GoBackFrom(typeof(NewLimitChargeView).FullName);
  265. }
  266. }
  267. }