WeeklyGiftTipsView.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using FairyGUI;
  2. using UI.ActivityMain;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using ET;
  6. using static GFGGame.ShopSProxy;
  7. using UI.CommonGame;
  8. namespace GFGGame
  9. {
  10. class WeeklyGiftTipsView : BaseWindow
  11. {
  12. private UI_WeeklyGiftTipsUI _ui;
  13. private int giftShopId = 0;
  14. public override void Dispose()
  15. {
  16. if (_ui != null)
  17. {
  18. _ui.Dispose();
  19. _ui = null;
  20. }
  21. base.Dispose();
  22. }
  23. protected override void OnInit()
  24. {
  25. base.OnInit();
  26. packageName = UI_WeeklyGiftTipsUI.PACKAGE_NAME;
  27. _ui = UI_WeeklyGiftTipsUI.Create();
  28. this.viewCom = _ui.target;
  29. modal = true;
  30. this.viewCom.Center();
  31. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  32. _ui.m_rewardList.itemRenderer = ListItemRender;
  33. _ui.m_rewardList.onClickItem.Add(OnListSelectorItemClick);
  34. _ui.m_backBtn.onClick.Add(OnClickChange);
  35. _ui.m_buyBtn.target.onClick.Add(OnClickBuy);
  36. }
  37. protected override void OnShown()
  38. {
  39. base.OnShown();
  40. ActivityOpenCfg activityCfg = ActivityOpenCfgArray.Instance.GetCfg(ActivityDataManager.Instance.GetCurOpenActiveByType(101));
  41. giftShopId = activityCfg.paramsArr[0];
  42. if (giftShopId != 0)
  43. {
  44. var shopCfg = ShopCfgArray.Instance.GetCfg(giftShopId);
  45. ItemCfg item = ItemCfgArray.Instance.GetCfg(shopCfg.itemId);
  46. _ui.m_rewardList.numItems = item.itemsArr.Length;
  47. }
  48. else
  49. {
  50. _ui.m_rewardList.numItems = 0;
  51. }
  52. UpdateBtn();
  53. }
  54. protected override void OnHide()
  55. {
  56. base.OnHide();
  57. }
  58. protected override void AddEventListener()
  59. {
  60. base.AddEventListener();
  61. EventAgent.AddEventListener(ConstMessage.SHOP_BUY, UpdateBtn);
  62. }
  63. protected override void RemoveEventListener()
  64. {
  65. base.RemoveEventListener();
  66. EventAgent.RemoveEventListener(ConstMessage.SHOP_BUY, UpdateBtn);
  67. }
  68. private void OnClickChange()
  69. {
  70. this.Hide();
  71. }
  72. private void ListItemRender(int index, GObject obj)
  73. {
  74. UI_ComItem uiItemChild = UI_ComItem.Proxy(obj);
  75. var shopCfg = ShopCfgArray.Instance.GetCfg(giftShopId);
  76. var itemCfg = ItemCfgArray.Instance.GetCfg(shopCfg.itemId);
  77. int[][] result;
  78. result = itemCfg.itemsArr;
  79. var itemArr = result[index];
  80. var itemCfgChild = ItemCfgArray.Instance.GetCfg(itemArr[0]);
  81. uiItemChild.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfgChild);
  82. uiItemChild.m_txtCount.text = itemArr[1].ToString();
  83. uiItemChild.target.data = itemCfgChild;
  84. uiItemChild.m_QualityType.selectedIndex = itemCfgChild.rarity - 1;
  85. UI_ComItem.ProxyEnd();
  86. }
  87. //弹出物品详细描述框
  88. private void OnListSelectorItemClick(EventContext context)
  89. {
  90. GComponent item = context.data as GComponent;
  91. ItemCfg itemCfg = item.data as ItemCfg;
  92. GoodsItemTipsController.ShowItemTips(itemCfg.id);
  93. }
  94. private async void OnClickBuy()
  95. {
  96. if(giftShopId == 0)
  97. {
  98. return;
  99. }
  100. await ReqShopBuy(giftShopId);
  101. }
  102. private void UpdateBtn()
  103. {
  104. ShopCfg shopCfg = ShopCfgArray.Instance.GetCfg(giftShopId);
  105. var remainBuyNum = shopCfg.maxBuyNum - ShopDataManager.Instance.GetGoodsBuyNumById(shopCfg.id);
  106. if (remainBuyNum == 0)
  107. {
  108. //已售完
  109. _ui.m_buyBtn.target.visible = false;
  110. }
  111. else
  112. {
  113. //未售完
  114. _ui.m_buyBtn.target.visible = true;
  115. }
  116. _ui.m_buyBtn.m_descText.text = string.Format("{0}元购买", shopCfg.configPrice);
  117. _ui.m_descText.text = string.Format("限购次数:{0}/{1}", ShopDataManager.Instance.GetGoodsBuyNumById(shopCfg.id) ,shopCfg.maxBuyNum);
  118. }
  119. }
  120. }