ShopBuyItemPanel.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. using System;
  2. using Core.Language;
  3. using Core.Utility;
  4. using Excel2Json;
  5. using Fort23.UTool;
  6. using GameLogic.Bag;
  7. namespace Fort23.Mono
  8. {
  9. /// <summary>
  10. /// 商店购买确认弹框
  11. /// </summary>
  12. [UIBinding(prefab = "ShopBuyItemPanel")]
  13. public partial class ShopBuyItemPanel : UIPanel
  14. {
  15. private string _poolName = "ShopBuyItemPanelItemWidget";
  16. private string _ShopPackBuyItemPanelPoolName = "ShopPackBuyItemPanelPoolName";
  17. public int currentSelectCount;
  18. public int maxCount;
  19. private AccountFileInfo.ShopItem _shopItem;
  20. private ShopItemConfig _shopItemConfig;
  21. private Action<bool, int> _callback;
  22. private bool _buyMark = false;
  23. private void Init()
  24. {
  25. }
  26. public async void CustomInit(AccountFileInfo.ShopItem shopItem, Action<bool, int> callback)
  27. {
  28. _buyMark = false;
  29. UIManager.Instance.DormancyAllGComponent<WidgetItem>(_poolName);
  30. _shopItem = shopItem;
  31. _shopItemConfig = ConfigComponent.Instance.Get<ShopItemConfig>(shopItem.id);
  32. _callback = callback;
  33. WidgetItem itemWidget = await UIManager.Instance.CreateGComponent<WidgetItem>(null, ItemRoot, poolName: _poolName);
  34. itemWidget.InitWidget(new ItemInfo(_shopItemConfig.itemId[0], _shopItemConfig.itemCount[0]));
  35. Text_name.text = LanguageManager.Instance.Text(_shopItemConfig.shopName);
  36. Text_desc.text = LanguageManager.Instance.Text(itemWidget.itemInfo.config.itemName);
  37. UseSlider.value = 1;
  38. UseSlider.minValue = 1;
  39. Text_BuyCount.text = "1";
  40. Refresh();
  41. UpdateShowData(1);
  42. }
  43. private void Refresh()
  44. {
  45. //无限制 最多购买十个
  46. if (_shopItemConfig.buyCount == -1)
  47. {
  48. LimitObj.SetActive(false);
  49. Text_LimitCount.text = "无";
  50. if (_shopItemConfig.price != 0)
  51. {
  52. int total = (int)(PlayerManager.Instance.BagController.GetItemCount(_shopItemConfig.costItemId) / _shopItemConfig.price);
  53. maxCount = total >= 10 ? 10 : total;
  54. }
  55. if (maxCount <= 1)
  56. {
  57. maxCount = 1;
  58. }
  59. SliderObj.SetActive(maxCount > 1);
  60. UseSlider.maxValue = maxCount;
  61. UseSlider.value = 1;
  62. }
  63. else
  64. {
  65. LimitObj.SetActive(true);
  66. Text_LimitCount.text = $"{_shopItemConfig.buyCount - _shopItem.buyCount}/{_shopItemConfig.buyCount}";
  67. maxCount = _shopItemConfig.buyCount - _shopItem.buyCount;
  68. if (_shopItemConfig.price != 0)
  69. {
  70. int temp = (int)(PlayerManager.Instance.BagController.GetItemCount(_shopItemConfig.costItemId) / _shopItemConfig.price);
  71. if (temp < maxCount)
  72. {
  73. maxCount = temp;
  74. }
  75. }
  76. if (maxCount <= 1)
  77. {
  78. maxCount = 1;
  79. }
  80. SliderObj.SetActive(maxCount > 1);
  81. UseSlider.maxValue = maxCount;
  82. UseSlider.value = 1;
  83. }
  84. Text_Price.text = _shopItemConfig.price.ToString();
  85. if (_shopItemConfig.costItemId == GlobalParam.RMB_1031)
  86. {
  87. ImageCurrency.gameObject.SetActive(false);
  88. }
  89. else
  90. {
  91. ImageCurrency.gameObject.SetActive(true);
  92. }
  93. ImageCurrency.icon_name = ConfigComponent.Instance.Get<ItemConfig>(_shopItemConfig.costItemId).icon;
  94. }
  95. protected override void AddEvent()
  96. {
  97. }
  98. protected override void DelEvent()
  99. {
  100. }
  101. public override void AddButtonEvent()
  102. {
  103. Btn_Close.onClick.AddListener((() => { UIManager.Instance.HideUIUIPanel(this); }));
  104. Btn_Close1.onClick.AddListener((() => { UIManager.Instance.HideUIUIPanel(this); }));
  105. UseSlider.onValueChanged.AddListener(OnValueChanged);
  106. Btn_Add.onClick.AddListener(Add);
  107. Btn_Reduce.onClick.AddListener(Reduce);
  108. Btn_Function.onClick.AddListener(Function);
  109. }
  110. private async void Function()
  111. {
  112. _buyMark = true;
  113. UIManager.Instance.HideUIUIPanel(this);
  114. }
  115. private void Reduce()
  116. {
  117. currentSelectCount--;
  118. if (currentSelectCount < 1)
  119. {
  120. currentSelectCount = 1;
  121. }
  122. UseSlider.value = currentSelectCount;
  123. }
  124. private void Add()
  125. {
  126. currentSelectCount++;
  127. if (currentSelectCount > maxCount)
  128. {
  129. currentSelectCount = maxCount;
  130. }
  131. UseSlider.value = currentSelectCount;
  132. }
  133. private void OnValueChanged(float arg0)
  134. {
  135. UpdateShowData(arg0);
  136. }
  137. private void UpdateShowData(float arg0)
  138. {
  139. int count = (int)arg0;
  140. currentSelectCount = count;
  141. Text_BuyCount.text = count.ToString();
  142. Text_Price.text = $"{(count * _shopItemConfig.price).ToString()}";
  143. }
  144. public override void Close()
  145. {
  146. base.Close();
  147. UIManager.Instance.DormancyAllGComponent<WidgetItem>(_poolName);
  148. _callback?.Invoke(_buyMark, currentSelectCount);
  149. }
  150. }
  151. }