LeagueGiftView.cs 9.3 KB

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