ShopBuyItemPanel.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. using System;
  2. using Core.Language;
  3. using Core.Utility;
  4. using Excel2Json;
  5. using Fort23.Core;
  6. using Fort23.UTool;
  7. using GameLogic.Bag;
  8. namespace Fort23.Mono
  9. {
  10. /// <summary>
  11. /// 商店购买确认弹框
  12. /// </summary>
  13. [UIBinding(prefab = "ShopBuyItemPanel")]
  14. public partial class ShopBuyItemPanel : UIPanel
  15. {
  16. private string _poolName = "ShopBuyItemPanelItemWidget";
  17. private string _ShopPackBuyItemPanelPoolName = "ShopPackBuyItemPanelPoolName";
  18. public int currentSelectCount;
  19. public int maxCount;
  20. private AccountFileInfo.ShopItem _shopItem;
  21. private ShopItemConfig _shopItemConfig;
  22. private Action<bool, int> _callback;
  23. private bool _buyMark = false;
  24. private void Init()
  25. {
  26. }
  27. public override CTask GetFocus()
  28. {
  29. if (PlayerGuideManager.Instance.GuideIsCanDo(7, 5))
  30. {
  31. PlayerGuideManager.Instance.NextGuide();
  32. }
  33. return base.GetFocus();
  34. }
  35. public async void CustomInit(AccountFileInfo.ShopItem shopItem, Action<bool, int> callback)
  36. {
  37. _buyMark = false;
  38. UIManager.Instance.DormancyAllGComponent<WidgetItem>(_poolName);
  39. _shopItem = shopItem;
  40. _shopItemConfig = ConfigComponent.Instance.Get<ShopItemConfig>(shopItem.id);
  41. _callback = callback;
  42. WidgetItem itemWidget =
  43. await UIManager.Instance.CreateGComponent<WidgetItem>(null, ItemRoot, poolName: _poolName);
  44. itemWidget.InitWidget(new ItemInfo(_shopItemConfig.itemId[0], _shopItemConfig.itemCount[0]));
  45. ItemConfig itemConfig = ConfigComponent.Instance.Get<ItemConfig>(_shopItemConfig.itemId[0]);
  46. Text_name.text = LanguageManager.Instance.Text(itemConfig.itemName);
  47. Text_desc.text = LanguageManager.Instance.Text(itemWidget.itemInfo.config.itemDesc);
  48. Text_ItemCount.text =
  49. "当前持有:" + PlayerManager.Instance.BagController.GetItemCount(_shopItemConfig.itemId[0]);
  50. // UseSlider.value = 1;
  51. // UseSlider.minValue = 1;
  52. Text_BuyCount.text = "1";
  53. Refresh();
  54. UpdateShowData(1);
  55. ChangeBtnState();
  56. }
  57. private void Refresh()
  58. {
  59. //无限制 最多购买十个
  60. if (_shopItemConfig.buyCount == -1)
  61. {
  62. LimitObj.SetActive(false);
  63. Text_LimitCount.text = "无";
  64. if (_shopItemConfig.price != 0)
  65. {
  66. int total = (int)(PlayerManager.Instance.BagController.GetItemCount(_shopItemConfig.costItemId) /
  67. _shopItemConfig.price);
  68. maxCount = total >= 10 ? 10 : total;
  69. }
  70. if (maxCount <= 1)
  71. {
  72. maxCount = 1;
  73. }
  74. SliderObj.SetActive(maxCount > 1);
  75. // UseSlider.maxValue = maxCount;
  76. // UseSlider.value = 1;
  77. }
  78. else
  79. {
  80. LimitObj.SetActive(true);
  81. Text_LimitCount.text = $"{_shopItem.buyCount}/{_shopItemConfig.buyCount}";
  82. maxCount = _shopItemConfig.buyCount - _shopItem.buyCount;
  83. if (_shopItemConfig.price != 0)
  84. {
  85. int temp = (int)(PlayerManager.Instance.BagController.GetItemCount(_shopItemConfig.costItemId) /
  86. _shopItemConfig.price);
  87. if (temp < maxCount)
  88. {
  89. maxCount = temp;
  90. }
  91. }
  92. if (maxCount <= 1)
  93. {
  94. maxCount = 1;
  95. }
  96. SliderObj.SetActive(maxCount > 1);
  97. // UseSlider.maxValue = maxCount;
  98. // UseSlider.value = 1;
  99. }
  100. if (_shopItemConfig.costItemId == GlobalParam.RMB_1031)
  101. {
  102. Text_Price.text = "¥" + _shopItemConfig.price.ToString();
  103. ImageCurrency.gameObject.SetActive(false);
  104. }
  105. else if (_shopItemConfig.costItemId == 0)
  106. {
  107. ImageCurrency.gameObject.SetActive(false);
  108. Text_Price.text = "免费";
  109. }
  110. else
  111. {
  112. Text_Price.text = _shopItemConfig.price.ToString();
  113. ImageCurrency.gameObject.SetActive(true);
  114. }
  115. ImageCurrency.icon_name = ConfigComponent.Instance.Get<ItemConfig>(_shopItemConfig.costItemId).icon;
  116. }
  117. protected override void AddEvent()
  118. {
  119. }
  120. protected override void DelEvent()
  121. {
  122. }
  123. public override void AddButtonEvent()
  124. {
  125. // Btn_Close.onClick.AddListener((() => { UIManager.Instance.HideUIUIPanel(this); }));
  126. Btn_Close1.onClick.AddListener((() => { UIManager.Instance.HideUIUIPanel(this); }));
  127. // UseSlider.onValueChanged.AddListener(OnValueChanged);
  128. Btn_Add.onClick.AddListener(Add);
  129. Btn_Reduce.onClick.AddListener(Reduce);
  130. Btn_Function.onClick.AddListener(Function);
  131. Btn_Min.onClick.AddListener(ReduceMin);
  132. Btn_Max.onClick.AddListener(AddMax);
  133. }
  134. private async void Function()
  135. {
  136. _buyMark = true;
  137. UIManager.Instance.HideUIUIPanel(this);
  138. if (PlayerGuideManager.Instance.GuideIsCanDo(7, 6))
  139. {
  140. PlayerGuideManager.Instance.NextGuide();
  141. }
  142. }
  143. private void Reduce()
  144. {
  145. currentSelectCount--;
  146. if (currentSelectCount < 1)
  147. {
  148. currentSelectCount = 1;
  149. }
  150. ChangeBtnState();
  151. OnValueChanged(currentSelectCount);
  152. // UseSlider.value = currentSelectCount;
  153. }
  154. private void Add()
  155. {
  156. currentSelectCount++;
  157. if (currentSelectCount > maxCount)
  158. {
  159. currentSelectCount = maxCount;
  160. }
  161. ChangeBtnState();
  162. OnValueChanged(currentSelectCount);
  163. // UseSlider.value = currentSelectCount;
  164. }
  165. private void ReduceMin()
  166. {
  167. currentSelectCount = 1;
  168. ChangeBtnState();
  169. OnValueChanged(currentSelectCount);
  170. }
  171. private void AddMax()
  172. {
  173. currentSelectCount = maxCount;
  174. ChangeBtnState();
  175. OnValueChanged(currentSelectCount);
  176. }
  177. private void ChangeBtnState()
  178. {
  179. if (currentSelectCount == 1)
  180. {
  181. Btn_Min.transform.Gray();
  182. Btn_Reduce.transform.Gray();
  183. }
  184. else
  185. {
  186. Btn_Min.transform.RecoverColor();
  187. Btn_Reduce.transform.RecoverColor();
  188. }
  189. if (currentSelectCount == maxCount)
  190. {
  191. Btn_Max.transform.Gray();
  192. Btn_Add.transform.Gray();
  193. }
  194. else
  195. {
  196. Btn_Max.transform.RecoverColor();
  197. Btn_Add.transform.RecoverColor();
  198. }
  199. }
  200. private void OnValueChanged(float arg0)
  201. {
  202. UpdateShowData(arg0);
  203. }
  204. private void UpdateShowData(float arg0)
  205. {
  206. int count = (int)arg0;
  207. currentSelectCount = count;
  208. Text_BuyCount.text = count.ToString();
  209. if (_shopItemConfig.costItemId == GlobalParam.RMB_1031)
  210. {
  211. Text_Price.text = $"¥{(count * _shopItemConfig.price).ToString()}";
  212. ImageCurrency.gameObject.SetActive(false);
  213. }
  214. else if (_shopItemConfig.costItemId == 0)
  215. {
  216. Text_Price.text = "免费";
  217. }
  218. else
  219. {
  220. Text_Price.text = $"{(count * _shopItemConfig.price).ToString()}";
  221. ImageCurrency.gameObject.SetActive(true);
  222. }
  223. // Text_Price.text = $"{(count * _shopItemConfig.price).ToString()}";
  224. }
  225. public async override CTask Close()
  226. {
  227. await base.Close();
  228. UIManager.Instance.DormancyAllGComponent<WidgetItem>(_poolName);
  229. _callback?.Invoke(_buyMark, currentSelectCount);
  230. }
  231. }
  232. }