123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- using System;
- using Core.Language;
- using Core.Utility;
- using Excel2Json;
- using Fort23.UTool;
- using GameLogic.Bag;
- namespace Fort23.Mono
- {
- /// <summary>
- /// 商店购买确认弹框
- /// </summary>
- [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<bool, int> _callback;
- private bool _buyMark = false;
- private void Init()
- {
- }
- public async void CustomInit(AccountFileInfo.ShopItem shopItem, Action<bool, int> callback)
- {
- _buyMark = false;
- UIManager.Instance.DormancyAllGComponent<WidgetItem>(_poolName);
- _shopItem = shopItem;
- ShopConfig shopConfig = ConfigComponent.Instance.Get<ShopConfig>(shopItem.id);
- _shopItemConfig = ConfigComponent.Instance.Get<ShopItemConfig>(shopConfig.shopItemID);
- _callback = callback;
- WidgetItem itemWidget = await UIManager.Instance.CreateGComponent<WidgetItem>(null, ItemRoot, poolName: _poolName);
- itemWidget.InitWidget(new ItemInfo(_shopItemConfig.itemId[0], _shopItemConfig.itemCount[0]));
- Text_name.text = LanguageManager.Instance.Text(shopConfig.shopName);
- Text_desc.text = LanguageManager.Instance.Text(itemWidget.itemInfo.config.itemName);
- UseSlider.value = 1;
- UseSlider.minValue = 1;
- Text_BuyCount.text = "1";
- Refresh();
- UpdateShowData(1);
- }
- private void Refresh()
- {
- //无限制 最多购买十个
- if (_shopItemConfig.buyCount == -1)
- {
- LimitObj.SetActive(false);
- Text_LimitCount.text = "无";
- 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;
- 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<ItemConfig>(_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);
- }
- private async void Function()
- {
- _buyMark = true;
- UIManager.Instance.HideUIUIPanel(this);
- }
- private void Reduce()
- {
- currentSelectCount--;
- if (currentSelectCount < 1)
- {
- currentSelectCount = 1;
- }
- UseSlider.value = currentSelectCount;
- }
- private void Add()
- {
- currentSelectCount++;
- if (currentSelectCount > maxCount)
- {
- currentSelectCount = maxCount;
- }
- UseSlider.value = currentSelectCount;
- }
- 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<WidgetItem>(_poolName);
- _callback?.Invoke(_buyMark, currentSelectCount);
- }
- }
- }
|