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

102 lines
3.7 KiB
C#

using asap.core;
using cfg;
using game;
using GameCore;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class EnergyShopSlot : MonoBehaviour
{
//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;
Button
btn_showItem;
// public GameObject tag_first;
// public TMP_Text text_first_num;
ResourceStore _shopToken;
int Number;
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/bg").GetComponent<Image>();
text_num = transform.Find("position/text_num").GetComponent<TMP_Text>();
txt_value = transform.Find("position/text_cost").GetComponent<TMP_Text>();
btn_showItem = transform.Find("position/reward").GetComponent<Button>();
// 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>();
btn_buy1.onClick.AddListener(OnBuy);
btn_showItem.onClick.AddListener(OnShowItemInfo);
}
public void SetData(cfg.ResourceStore data)
{
Init();
_shopToken = data;
Number = GContext.container.Resolve<PlayerItemData>().IntInflation(data.Number, null);
text_num.text = Number.ToString();
if (data.Value == 0)
txt_value.gameObject.SetActive(false);
else
txt_value.text = LocalizationMgr.GetFormatTextValue("UI_FishingShopPanel_29", data.Value);
text_price.text = data.Price.ToString();
}
void OnBuy()
{
var cost = _shopToken.Price;
Number = GContext.container.Resolve<PlayerItemData>().IntInflation(_shopToken.Number, null);
var itemData = new ItemData { id = _shopToken.ItemID, origin = (_shopToken.Number), count = Number };
itemData.curCount = (ulong)GContext.container.Resolve<PlayerItemData>().GetItemCount(_shopToken.ItemID);
if (cost == 0)
{
GContext.container.Resolve<PlayerItemData>().AddItem(itemData, null);
GContext.Publish(new ShowData(itemData));
GContext.Publish(new ShowData());
}
else
{
var curDiamond = GContext.container.Resolve<PlayerData>().diamond;
//Not Free
if (curDiamond >= cost)
{
GContext.container.Resolve<PlayerData>().AddDiamond(-cost);
GContext.container.Resolve<PlayerItemData>().AddItem(itemData, null);
GContext.Publish(new ShowData(new List<ItemData> { itemData }, RewardType.NormalOne));
GContext.Publish(new ShowData());
#if AGG
using (var e = GEvent.GameEvent("resource_shop"))
{
e.AddContent("cost_diamond_count", cost)
.AddContent("change_type", 1)
.AddContent("change_num", _shopToken.Number)
.AddContent("item_id", _shopToken.ItemID);
}
#endif
}
else
{
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_59"));
_ = UIManager.Instance.ShowUI(UITypes.LackOfResourceConfirmPopupPanel);
}
}
}
void OnShowItemInfo()
{
GContext.container.Resolve<PlayerItemData>().ShowItemTips(1001, btn_showItem.transform);
}
}