LeagueGiftView.cs 9.2 KB

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