using System; using Core.Language; using Core.Utility; using Excel2Json; using Fort23.UTool; using GameLogic.Bag; namespace Fort23.Mono { /// /// 商店购买确认弹框 /// [UIBinding(prefab = "ShopBuyItemPanel")] public partial class ShopBuyItemPanel : UIPanel { private string _poolName = "ShopBuyItemPanelItemWidget"; private string _ShopPackBuyItemPanelPoolName = "ShopPackBuyItemPanelPoolName"; public int currentSelectCount; public int maxCount; private AccountFileInfo.ShopItem _shopItem; private ShopItemConfig _shopItemConfig; private Action _callback; private bool _buyMark = false; private void Init() { } public async void CustomInit(AccountFileInfo.ShopItem shopItem, Action callback) { _buyMark = false; UIManager.Instance.DormancyAllGComponent(_poolName); _shopItem = shopItem; _shopItemConfig = ConfigComponent.Instance.Get(shopItem.id); _callback = callback; WidgetItem itemWidget = await UIManager.Instance.CreateGComponent(null, ItemRoot, poolName: _poolName); itemWidget.InitWidget(new ItemInfo(_shopItemConfig.itemId[0], _shopItemConfig.itemCount[0])); Text_name.text = LanguageManager.Instance.Text(_shopItemConfig.shopName); Text_desc.text = LanguageManager.Instance.Text(itemWidget.itemInfo.config.itemName); Text_ItemCount.text = "当前持有:" + PlayerManager.Instance.BagController.GetItemCount(_shopItemConfig.itemId[0]); // UseSlider.value = 1; // UseSlider.minValue = 1; Text_BuyCount.text = "1"; Refresh(); UpdateShowData(1); ChangeBtnState(); } private void Refresh() { //无限制 最多购买十个 if (_shopItemConfig.buyCount == -1) { LimitObj.SetActive(false); Text_LimitCount.text = "无"; if (_shopItemConfig.price != 0) { int total = (int)(PlayerManager.Instance.BagController.GetItemCount(_shopItemConfig.costItemId) / _shopItemConfig.price); maxCount = total >= 10 ? 10 : total; } if (maxCount <= 1) { maxCount = 1; } SliderObj.SetActive(maxCount > 1); // UseSlider.maxValue = maxCount; // UseSlider.value = 1; } else { LimitObj.SetActive(true); Text_LimitCount.text = $"{_shopItemConfig.buyCount - _shopItem.buyCount}/{_shopItemConfig.buyCount}"; maxCount = _shopItemConfig.buyCount - _shopItem.buyCount; if (_shopItemConfig.price != 0) { int temp = (int)(PlayerManager.Instance.BagController.GetItemCount(_shopItemConfig.costItemId) / _shopItemConfig.price); if (temp < maxCount) { maxCount = temp; } } if (maxCount <= 1) { maxCount = 1; } SliderObj.SetActive(maxCount > 1); // UseSlider.maxValue = maxCount; // UseSlider.value = 1; } Text_Price.text = _shopItemConfig.price.ToString(); if (_shopItemConfig.costItemId == GlobalParam.RMB_1031) { ImageCurrency.gameObject.SetActive(false); } else { ImageCurrency.gameObject.SetActive(true); } ImageCurrency.icon_name = ConfigComponent.Instance.Get(_shopItemConfig.costItemId).icon; } protected override void AddEvent() { } protected override void DelEvent() { } public override void AddButtonEvent() { // Btn_Close.onClick.AddListener((() => { UIManager.Instance.HideUIUIPanel(this); })); Btn_Close1.onClick.AddListener((() => { UIManager.Instance.HideUIUIPanel(this); })); // UseSlider.onValueChanged.AddListener(OnValueChanged); Btn_Add.onClick.AddListener(Add); Btn_Reduce.onClick.AddListener(Reduce); Btn_Function.onClick.AddListener(Function); Btn_Min.onClick.AddListener(ReduceMin); Btn_Max.onClick.AddListener(AddMax); } private async void Function() { _buyMark = true; UIManager.Instance.HideUIUIPanel(this); } private void Reduce() { currentSelectCount--; if (currentSelectCount < 1) { currentSelectCount = 1; } ChangeBtnState(); OnValueChanged(currentSelectCount); // UseSlider.value = currentSelectCount; } private void Add() { currentSelectCount++; if (currentSelectCount > maxCount) { currentSelectCount = maxCount; } ChangeBtnState(); OnValueChanged(currentSelectCount); // UseSlider.value = currentSelectCount; } private void ReduceMin() { currentSelectCount = 1; ChangeBtnState(); OnValueChanged(currentSelectCount); } private void AddMax() { currentSelectCount = maxCount; ChangeBtnState(); OnValueChanged(currentSelectCount); } private void ChangeBtnState() { if (currentSelectCount == 1) { Btn_Min.transform.Gray(); Btn_Reduce.transform.Gray(); } else { Btn_Min.transform.RecoverColor(); Btn_Reduce.transform.RecoverColor(); } if (currentSelectCount == maxCount) { Btn_Max.transform.Gray(); Btn_Add.transform.Gray(); } else { Btn_Max.transform.RecoverColor(); Btn_Add.transform.RecoverColor(); } } private void OnValueChanged(float arg0) { UpdateShowData(arg0); } private void UpdateShowData(float arg0) { int count = (int)arg0; currentSelectCount = count; Text_BuyCount.text = count.ToString(); Text_Price.text = $"{(count * _shopItemConfig.price).ToString()}"; } public override void Close() { base.Close(); UIManager.Instance.DormancyAllGComponent(_poolName); _callback?.Invoke(_buyMark, currentSelectCount); } } }