先修复一下,错误的场景 删除不必要的钓场资产 修复into场景 update:更新meta文件,修复报错 update:修复资源 修复第一章节建造 修复建造第三章 update:删除多余内容 update:更新README.md update:还原图标 update:更新README update:更新配置
176 lines
6.0 KiB
C#
176 lines
6.0 KiB
C#
using asap.core;
|
|
using cfg;
|
|
using game;
|
|
using GameCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class ItemShopSlot : MonoBehaviour
|
|
{
|
|
#region Field&&Property
|
|
[SerializeField]
|
|
private Button btn_buy;
|
|
|
|
[SerializeField]
|
|
private RewardItemNew rewardItem;
|
|
|
|
[SerializeField]
|
|
private GameObject
|
|
go_soldOut;
|
|
|
|
[SerializeField]
|
|
private Transform
|
|
tran_tag;
|
|
|
|
[SerializeField]
|
|
TMP_Text
|
|
txt_itemName;
|
|
|
|
private PlayerShopData.ItemShopData _data;
|
|
#endregion
|
|
|
|
|
|
private void Start()
|
|
{
|
|
}
|
|
#region Function
|
|
public void SetData(PlayerShopData.ItemShopData data)
|
|
{
|
|
gameObject.SetActive(true);
|
|
_data = data;
|
|
if (_data.Record.ItemID == 1002)
|
|
{
|
|
_data.Count = (int)GContext.container.Resolve<PlayerItemData>().GetExtraCoinMag(_data.Count);
|
|
}
|
|
RefreshView();
|
|
}
|
|
|
|
public void RefreshView()
|
|
{
|
|
rewardItem.SetData(new ItemData
|
|
{
|
|
id = _data.Record.ItemID,
|
|
count = _data.Count,
|
|
});
|
|
rewardItem.transform.Find("text_num").GetComponent<TMP_Text>().text = "x" + ConvertTools.GetNumberString(_data.Count);
|
|
txt_itemName.text = LocalizationMgr.GetText(GContext.container.Resolve<Tables>().TbItem.DataMap[_data.Record.ItemID].Name_l10n_key);
|
|
|
|
for (int i = 0; i < tran_tag.childCount; i++)
|
|
{
|
|
tran_tag.GetChild(i).gameObject.SetActive(false);
|
|
}
|
|
// go_redPoint.SetActive(false);
|
|
btn_buy.transform.Find("Ani_Container/p_text").gameObject.SetActive(false);
|
|
if (_data.Record.hasBought == 0)
|
|
{
|
|
// GContext.container.Resolve<IUIService>().SetImageSprite(img_light, ( $"bg_shop_resource_item_{quality + 1}" ));
|
|
|
|
//Not Boudght
|
|
go_soldOut.SetActive(false);
|
|
btn_buy.transform.parent.gameObject.SetActive(true);
|
|
btn_buy.onClick.AddListener(OnBuy);
|
|
|
|
//Cost
|
|
var cost = _data.GetDiscountDiamondCost();
|
|
//Not Free
|
|
btn_buy.transform.Find("Ani_Container/p_text").gameObject.SetActive(true);
|
|
btn_buy.transform.Find("Ani_Container/p_text").GetComponent<TMP_Text>().text = ConvertTools.GetNumberString(cost);
|
|
|
|
|
|
//Discount
|
|
var discount = _data.Record.Discount;
|
|
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}");
|
|
|
|
var tag = tran_tag.GetChild(index);
|
|
tag.gameObject.SetActive(true);
|
|
tag.GetChild(0).GetComponent<TMP_Text>().text = ConvertTools.GetNumberString3(discount);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
//Has Bought
|
|
// img_light.enabled = false;
|
|
go_soldOut.SetActive(true);
|
|
btn_buy.transform.parent.gameObject.SetActive(false);
|
|
btn_buy.onClick.RemoveAllListeners();
|
|
|
|
// cg_rewardItem.alpha = 0.6f;
|
|
}
|
|
|
|
}
|
|
|
|
private void OnBuy()
|
|
{
|
|
if (_data.Record.hasBought == 0)
|
|
{
|
|
var cost = _data.GetDiscountDiamondCost();
|
|
if (cost == 0)
|
|
{
|
|
//Free
|
|
var itemData = new ItemData { id = _data.Record.ItemID, count = _data.Count };
|
|
itemData.curCount = (ulong)GContext.container.Resolve<PlayerItemData>().GetItemCount(_data.Record.ItemID);
|
|
GContext.container.Resolve<PlayerItemData>().AddItem(itemData, null);
|
|
GContext.container.Resolve<PlayerShopData>().SetItemShopSlotBought(_data.ItemShopID);
|
|
GContext.Publish(new ShowData(new List<ItemData> { itemData }, RewardType.NormalOne));
|
|
GContext.Publish(new ShowData());
|
|
RefreshView();
|
|
}
|
|
else
|
|
{
|
|
var curDiamond = GContext.container.Resolve<PlayerData>().diamond;
|
|
//Not Free
|
|
if (curDiamond >= cost)
|
|
{
|
|
var itemData = new ItemData { id = _data.Record.ItemID, count = _data.Count };
|
|
itemData.curCount = (ulong)GContext.container.Resolve<PlayerItemData>().GetItemCount(_data.Record.ItemID);
|
|
GContext.container.Resolve<PlayerData>().AddDiamond(-cost);
|
|
GContext.container.Resolve<PlayerShopData>().SetItemShopSlotBought(_data.ItemShopID);
|
|
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", 2)
|
|
.AddContent("change_num", _data.Count)
|
|
.AddContent("item_id", _data.Record.ItemID);
|
|
}
|
|
#endif
|
|
RefreshView();
|
|
}
|
|
else
|
|
{
|
|
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_59"));
|
|
_ = UIManager.Instance.ShowUI(UITypes.LackOfResourceConfirmPopupPanel);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|