Files
MinFt/Client/Assets/Scripts/UI/Shop/DiamondShopSlot.cs
Liubing\LB 3d8d4d18f3 first commit
先修复一下,错误的场景

删除不必要的钓场资产

修复into场景

update:更新meta文件,修复报错

update:修复资源

修复第一章节建造

修复建造第三章

update:删除多余内容

update:更新README.md

update:还原图标

update:更新README

update:更新配置
2026-04-28 02:17:22 +08:00

160 lines
6.2 KiB
C#

using asap.core;
using cfg;
using GameCore;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class DiamondShopSlot : MonoBehaviour
{
//public Button btn_buy;
public Button btn_buy1;
public Image bg;
// public Image icon;
public TMP_Text text_num;
public GameObject tag_first;
public TMP_Text text_first_num;
public TMP_Text txt_cost;
//价钱
public TMP_Text text_price;
Button btn_showItem;
ShopToken shopToken;
IAPItemList iAPItemList;
/// <summary>
/// Used to be just for BlackFriday Coupon, now it is used as a general coupon data.
/// </summary>
private BlackFridayCouponData _couponData;
bool _isFirstPurchase = false;
private GameObject _blackFridayGo;
private TMP_Text _textDiscount, _textDiamondCount, _textDiamondCountOld;
private IEventAggregator _eventAggregator;
private Image _bgDiscountTag;
private void Init()
{
btn_buy1 = transform.Find("position/btn_purchase/btn_green").GetComponent<Button>();
// icon = transform.Find("position/icon").GetComponent<Image>();
btn_showItem = transform.Find("position/reward").GetComponent<Button>();
bg = transform.Find("position/bg").GetComponent<Image>();
text_num = transform.Find("position/text_num").GetComponent<TMP_Text>();
txt_cost = transform.Find("position/text_cost").GetComponent<TMP_Text>();
tag_first = transform.Find("position/tag_first").gameObject;
text_first_num = transform.Find("position/tag_first/text_num").GetComponent<TMP_Text>();
text_price = transform.Find("position/btn_purchase/btn_green/Ani_Container/p_text").GetComponent<TMP_Text>();
btn_buy1.onClick.AddListener(OnBuy);
btn_showItem.onClick.AddListener(OnShowItemInfo);
_couponData = GContext.container.Resolve<PlayerShopData>().CouponData;
_blackFridayGo = transform.Find("position/friday").gameObject;
_textDiscount = transform.Find("position/friday/text_cost").GetComponent<TMP_Text>();
_textDiamondCount = transform.Find("position/friday/text_num1").GetComponent<TMP_Text>();
_textDiamondCountOld = transform.Find("position/friday/text_num2").GetComponent<TMP_Text>();
_bgDiscountTag = transform.Find("position/friday/bg").GetComponent<Image>();
}
public void SetData(cfg.ShopToken shopToken)
{
Init();
this.shopToken = shopToken;
iAPItemList = GContext.container.Resolve<Tables>().TbIAPItemList.GetOrDefault(shopToken.IAPID);
RefreshUI();
txt_cost.text = LocalizationMgr.GetFormatTextValue("UI_FishingShopPanel_29", shopToken.ValueMore * 100);
txt_cost.gameObject.SetActive(shopToken.ValueMore > 0);
text_first_num.text = "+" + shopToken.FirstPurchaseGift;
SKUDetailDataEvent sKUDetailDataEvent = new SKUDetailDataEvent(iAPItemList);
GContext.Publish(sKUDetailDataEvent);
//Change!!!
text_price.text = sKUDetailDataEvent.price;
}
public void RefreshUI()
{
int number = shopToken.Number;
if (_couponData is { IsActive: true })
{
_textDiscount.text = LocalizationMgr.GetFormatTextValue("UI_FishingShopPanel_29", _couponData.Multiplier);
if (ColorUtility.TryParseHtmlString(
GContext.container.Resolve<Tables>().TbEventCoupon[_couponData.RedirectId].FontColorPercent,
out var c))
_textDiscount.color = c;
_textDiamondCountOld.text = LocalizationMgr.GetFormatTextValue("UI_FishingShopPanel_23", number);
number += shopToken.Number * _couponData.Multiplier / 100;
_textDiamondCount.text = number.ToString();
GContext.container.Resolve<IUIService>().SetImageSprite(_bgDiscountTag,
GContext.container.Resolve<Tables>().TbEventCoupon[_couponData.RedirectId].LabelShop2);
}
text_num.text = number.ToString();
PlayerShopData playerShopData = GContext.container.Resolve<PlayerShopData>();
_isFirstPurchase = playerShopData.GiftBuyCount(shopToken.IAPID) == 0
&& playerShopData.GiftBuyCount(shopToken.ID) == 0
&& shopToken.FirstPurchaseGift > 0;
tag_first.SetActive(_isFirstPurchase);
}
async void OnBuy()
{
int number = shopToken.Number;
if (_isFirstPurchase)
{
number += shopToken.FirstPurchaseGift;
}
if (_couponData.IsActive)
number += (int)(shopToken.Number * _couponData.Multiplier / 100f);
double curCount = GContext.container.Resolve<PlayerItemData>().GetItemCount(shopToken.TokenID);
List<ItemData> itemData = new List<ItemData> {
new ItemData {
count = number,
id = shopToken.TokenID,
curCount = (ulong)curCount } };
btn_buy1.enabled = false;
ShopBuyTypeData shopBuyTypeData = new ShopBuyTypeData();
shopBuyTypeData.type = ShopBuyType.ShopToken;
shopBuyTypeData.ID = shopToken.ID;
bool Result = await GContext.container.Resolve<PlayerShopData>().OnBuy(shopToken.TokenID, shopBuyTypeData, iAPItemList, itemData, game.RewardType.NormalOne);
if (Result)
{
}
OnBuySuccess();
_eventAggregator.Publish(new BlackFridayCouponBanner.EventTerminateBlackFriday());
btn_buy1.enabled = true;
}
void OnBuySuccess()
{
RefreshUI();
}
void OnShowItemInfo()
{
GContext.container.Resolve<PlayerItemData>().ShowItemTips(1005, btn_showItem.transform);
}
private void OnDestroy()
{
btn_buy1.onClick.RemoveAllListeners();
btn_showItem.onClick.RemoveAllListeners();
}
public void SetUpBlackFriday(bool isOpen, IEventAggregator ea)
{
_eventAggregator = ea;
if (isOpen)
{
text_num.gameObject.SetActive(false);
txt_cost.gameObject.SetActive(false);
_blackFridayGo.SetActive(true);
}
else
{
text_num.gameObject.SetActive(true);
txt_cost.gameObject.SetActive(shopToken.ValueMore > 0);
_blackFridayGo.SetActive(false);
}
RefreshUI();
}
}