Files
MinFt/Client/Assets/Scripts/UI/Shop/FishCardShopSlot.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

159 lines
5.7 KiB
C#

using asap.core;
using cfg;
using game;
using GameCore;
using System.Collections.Generic;
using System.Xml.Linq;
using TMPro;
using UniRx;
using UnityEngine;
using UnityEngine.UI;
public class FishCardShopSlot : MonoBehaviour
{
public struct SChangeFishCardMapEvent
{
public bool IsConfirm;
public MapData MapData;
}
//public Button btn_buy;
public Button btn_buy1;
public Image bg;
// public Image icon;
// public TMP_Text text_num;
// public TMP_Text txt_value;
public TMP_Text text_price;
public TMP_Text txt_itemName;
public TMP_Text txt_mapName;
public RewardItemNew _rewardItem;
public Transform tran_tag;
private int _itemID;
private int _mapID;
// public GameObject tag_first;
// public TMP_Text text_first_num;
private CompositeDisposable _disposables = new();
ResourceStore _shopToken;
private void Init()
{
btn_buy1 = transform.Find("position/btn_purchase/btn_green").GetComponent<Button>();
// icon = transform.Find("position/icon").GetComponent<Image>();
bg = transform.Find("position/reward/mask_map/img_map").GetComponent<Image>();
// text_num = transform.Find("position/price/text_num").GetComponent<TMP_Text>();
// txt_value = transform.Find("position/text_cost").GetComponent<TMP_Text>();
txt_itemName = transform.Find("position/reward/text_title").GetComponent<TMP_Text>();
_rewardItem = transform.Find("position/reward").GetComponent<RewardItemNew>();
txt_mapName = transform.Find("position/reward/text_map").GetComponent<TMP_Text>();
tran_tag = transform.Find("position/tag");
// tag_first = transform.Find("position/tag_first").gameObject;
// text_first_num = transform.Find("position/tag_first/text_best").GetComponent<TMP_Text>();
text_price = transform.Find("position/btn_purchase/btn_green/Ani_Container/p_text").GetComponent<TMP_Text>();
gameObject.SetActive(true);
}
private void Start()
{
btn_buy1.onClick.AddListener(OnBuy);
GContext.OnEvent<SChangeFishCardMapEvent>().Where(x => _mapID != x.MapData.ID && x.IsConfirm).Subscribe(x => OnChangeMapID(x)).AddTo(_disposables);
}
public void SetData(cfg.ResourceStore data, int curMapID)
{
Init();
_shopToken = data;
//Discount
var discount = data.Discount;
if (discount > 0 && discount < 1)
{
var tagJudgeList = GContext.container.Resolve<Tables>().TbStoreConfig.Get(1).PriceTag;
if (!Mathf.Approximately(discount, 1f))
{
var lastDiscount = 0f;
var index = 0;
foreach (var tagjudge in tagJudgeList)
{
if (discount * 10f > lastDiscount && discount * 10f <= tagjudge)
{
break;
}
index++;
lastDiscount = tagjudge;
}
if (tran_tag.childCount <= index)
Debug.LogError($"[ItemShopSlot::RefreshView] tagJudge {index} exceeds tagsCount {tran_tag.childCount}");
tran_tag.gameObject.SetActive(true);
var tag = tran_tag.GetChild(index);
tag.gameObject.SetActive(true);
tag.GetChild(0).GetComponent<TMP_Text>().text = ConvertTools.GetNumberString3(discount);
}
text_price.text = (data.Price * data.Discount).ToString("F0"); ;
}
else
{
text_price.text = data.Price.ToString("F0"); ;
}
var mapData = GContext.container.Resolve<Tables>().TbMapData.Get(curMapID);
OnChangeMapID(new SChangeFishCardMapEvent { MapData = mapData });
}
public void OnChangeMapID(SChangeFishCardMapEvent data)
{
var itemID = GContext.container.Resolve<PlayerItemData>().GetFishCardItemIdByItemIDAndMapId(_shopToken.ItemID, data.MapData.ID);
_rewardItem.SetData(new ItemData
{
count = _shopToken.Number,
id = itemID,
});
txt_mapName.text = LocalizationMgr.GetText(data.MapData.Name_l10n_key);
_itemID = itemID;
_mapID = data.MapData.ID;
var imgUrl = data.MapData.Bg;
GContext.container.Resolve<IUIService>().SetImageSprite(bg, imgUrl);
}
void OnBuy()
{
var discount = _shopToken.Discount == 0 ? 1 : _shopToken.Discount;
var cost = _shopToken.Price * discount;
var curDiamond = GContext.container.Resolve<PlayerData>().diamond;
//Not Free
if (curDiamond >= cost)
{
var itemData = new ItemData { id = _itemID, count = (_shopToken.Number) };
GContext.container.Resolve<PlayerData>().AddDiamond(-(int)cost);
GContext.Publish(new ShowData(new List<ItemData> { itemData }, RewardType.NormalOne));
GContext.container.Resolve<PlayerItemData>().AddItem(itemData, null);
GContext.Publish(new ShowData());
#if AGG
using (var e = GEvent.GameEvent("resource_shop"))
{
e.AddContent("cost_diamond_count", cost)
.AddContent("change_type", 3)
.AddContent("change_num", _shopToken.Number)
.AddContent("item_id", _itemID);
}
#endif
}
else
{
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_59"));
_ = UIManager.Instance.ShowUI(UITypes.LackOfResourceConfirmPopupPanel);
}
}
private void OnDestroy()
{
_disposables.Dispose();
btn_buy1.onClick.RemoveAllListeners();
}
}