LeagueGiftView.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. using System.Collections.Generic;
  2. using System.Text.RegularExpressions;
  3. using ET;
  4. using FairyGUI;
  5. using UI.League;
  6. using UnityEngine;
  7. namespace GFGGame
  8. {
  9. //联盟礼包
  10. public class LeagueGiftView : BaseWindow
  11. {
  12. private UI_LeagueGiftUI _ui;
  13. private List<LeagueGiftGetData> _getDatas;
  14. private List<LeagueGiftBuyData> _buyDatas;
  15. public override void Dispose()
  16. {
  17. if (_ui != null)
  18. {
  19. _ui.Dispose();
  20. _ui = null;
  21. }
  22. base.Dispose();
  23. }
  24. protected override void OnInit()
  25. {
  26. base.OnInit();
  27. packageName = UI_LeagueGiftUI.PACKAGE_NAME;
  28. _ui = UI_LeagueGiftUI.Create();
  29. this.viewCom = _ui.target;
  30. this.viewCom.Center();
  31. this.modal = true;
  32. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  33. _ui.m_btnBack.onClick.Add(OnBtnBackClick);
  34. _ui.m_btnGet.onClick.Add(OnBtnGetClick);
  35. _ui.m_btnRule.onClick.Add(RuleController.ShowRuleView);
  36. _ui.m_btnRule.data = 300003;
  37. _ui.m_listBuy.itemRenderer = RenderListBuyItem;
  38. _ui.m_listBuy.itemProvider = GetListBuyItemResource;
  39. _ui.m_listGet.itemRenderer = RenderListGetItem;
  40. _ui.m_listGet.itemProvider = GetListGetItemResource;
  41. }
  42. protected override void AddEventListener()
  43. {
  44. base.AddEventListener();
  45. EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateBuyList);
  46. EventAgent.AddEventListener(ConstMessage.LEAGUE_NUMBERIC_CHANGE, UpdateView);
  47. }
  48. protected override void OnShown()
  49. {
  50. base.OnShown();
  51. UpdateView();
  52. }
  53. protected override void OnHide()
  54. {
  55. base.OnHide();
  56. if (_ui.m_listBuy.numItems > 0) _ui.m_listBuy.ScrollToView(0);
  57. if (_ui.m_listGet.numItems > 0) _ui.m_listGet.ScrollToView(0);
  58. }
  59. protected override void RemoveEventListener()
  60. {
  61. base.RemoveEventListener();
  62. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateBuyList);
  63. EventAgent.RemoveEventListener(ConstMessage.LEAGUE_NUMBERIC_CHANGE, UpdateView);
  64. }
  65. private void OnBtnBackClick()
  66. {
  67. ViewManager.GoBackFrom(typeof(LeagueGiftView).FullName);
  68. }
  69. private void OnBtnCreatClick()
  70. {
  71. }
  72. private void UpdateView()
  73. {
  74. UpdateGetList();
  75. UpdateBuyList();
  76. }
  77. private void UpdateGetList()
  78. {
  79. _getDatas = LeagueDataManager.Instance.GetGiftGetDatas();
  80. _ui.m_listGet.numItems = _getDatas.Count;
  81. _ui.m_grpTips.visible = _getDatas.Count == 0;
  82. }
  83. private void UpdateBuyList()
  84. {
  85. _buyDatas = LeagueDataManager.Instance.GetGiftBuyDatas();
  86. _ui.m_listBuy.numItems = _buyDatas.Count;
  87. }
  88. private void RenderListGetItem(int index, GObject obj)
  89. {
  90. UI_ListGiftGetItemTop item = UI_ListGiftGetItemTop.Proxy(obj);
  91. if (item.m_listGift.data == null)
  92. {
  93. item.m_listGift.itemRenderer = RenderListRewardItem;
  94. }
  95. item.m_listGift.data = _getDatas[index].GiftCfg.bonusArr;
  96. item.m_listGift.numItems = _getDatas[index].GiftCfg.bonusArr.Length;
  97. UI_ListGiftGetItemTop.ProxyEnd();
  98. }
  99. private void RenderListBuyItem(int index, GObject obj)
  100. {
  101. UI_ListGiftBuyItemTop item = UI_ListGiftBuyItemTop.Proxy(obj);
  102. LeagueGiftBuyData buyData = _buyDatas[index];
  103. string strCount = buyData.GiftCfg.limitType == 1 ? "今日剩余:{0}/{1}" : "本周剩余:{0}/{1}";
  104. item.m_txtCount.text = string.Format(strCount, buyData.GiftCfg.limit - buyData.BuyCount, buyData.GiftCfg.limit);
  105. int day = TimeUtil.FormattingTime11(TimeHelper.ServerNow(), buyData.EndTime);
  106. // item.m_txtTime.text = buyData.EndTime == 0 ? "" : string.Format("(剩余{0}天)", day);
  107. item.m_txtTime.SetVar("value", buyData.EndTime == 0 ? "" : day.ToString());
  108. ItemUtil.UpdateItemNeedNum(item.m_comCost, buyData.GiftCfg.consumeArr[0]);
  109. if (item.m_listGift.data == null)
  110. {
  111. item.m_listGift.itemRenderer = RenderListRewardItem;
  112. }
  113. item.m_listGift.data = _buyDatas[index].GiftCfg.bonusArr;
  114. item.m_listGift.numItems = _buyDatas[index].GiftCfg.bonusArr.Length;
  115. if (item.m_btnBuy.data == null)
  116. {
  117. item.m_btnBuy.onClick.Add(OnBtnBuyClick);
  118. }
  119. item.m_btnBuy.data = buyData;
  120. UI_ListGiftBuyItemTop.ProxyEnd();
  121. }
  122. private void RenderListRewardItem(int index, GObject obj)
  123. {
  124. int[][] reward = (int[][])obj.parent.data;
  125. ItemData itemData = ItemUtil.createItemData(reward[index]);
  126. if (obj.data == null)
  127. {
  128. obj.data = new ItemView(obj as GComponent);
  129. }
  130. (obj.data as ItemView).SetData(itemData);
  131. (obj.data as ItemView).SetComItemScale = 0.6f;
  132. (obj.data as ItemView).SetTxtCountPos(185, 155);
  133. }
  134. private string GetListGetItemResource(int index)
  135. {
  136. if (index < _ui.m_listBuy.columnCount)
  137. {
  138. return "ui://League/ListGiftGetItemTop";
  139. }
  140. else if (index >= _ui.m_listBuy.numItems - _ui.m_listBuy.columnCount - 1)
  141. {
  142. return "ui://League/ListGiftGetItemBottom";
  143. }
  144. else
  145. {
  146. return "ui://League/ListGiftGetItemCenter";
  147. }
  148. }
  149. private string GetListBuyItemResource(int index)
  150. {
  151. if (index < _ui.m_listBuy.columnCount)
  152. {
  153. return "ui://League/ListGiftBuyItemTop";
  154. }
  155. else if (index >= _ui.m_listBuy.numItems - _ui.m_listBuy.columnCount - 1)
  156. {
  157. return "ui://League/ListGiftBuyItemBottom";
  158. }
  159. else
  160. {
  161. return "ui://League/ListGiftBuyItemCenter";
  162. }
  163. }
  164. private void OnBtnBuyClick(EventContext context)
  165. {
  166. GObject obj = context.sender as GObject;
  167. LeagueGiftBuyData buyData = obj.data as LeagueGiftBuyData;
  168. int myPos = LeagueDataManager.Instance.GetMyPos();
  169. bool isLeader = myPos == LeaguePos.Owner || myPos == LeaguePos.SubOwner;
  170. if (!isLeader)
  171. {
  172. PromptController.Instance.ShowFloatTextPrompt("权限不足");
  173. return;
  174. }
  175. if (LeagueDataManager.Instance.HallLevel < buyData.GiftCfg.level)
  176. {
  177. PromptController.Instance.ShowFloatTextPrompt("宴客厅等级不足");
  178. return;
  179. }
  180. int needNum = buyData.GiftCfg.consumeArr[0][1];
  181. int hasNum = (int)ItemDataManager.GetItemNum(buyData.GiftCfg.consumeArr[0][0]);
  182. if (hasNum < needNum)
  183. {
  184. PromptController.Instance.ShowFloatTextPrompt("消耗不足");
  185. return;
  186. }
  187. if (buyData.BuyCount == buyData.GiftCfg.limit)
  188. {
  189. PromptController.Instance.ShowFloatTextPrompt("购买次数不足");
  190. return;
  191. }
  192. LeagueSproxy.ReqBuyLeagueWelfare(buyData.GiftCfg.type).Coroutine();
  193. }
  194. private void OnBtnGetClick()
  195. {
  196. // bool result = await LeagueSproxy.ReqGetLeagueWelfare();
  197. // if (result)
  198. // {
  199. // UpdateGetList();
  200. // }
  201. LeagueSproxy.ReqGetLeagueWelfare().Coroutine();
  202. }
  203. }
  204. }