备份CatanBuilding瘦身独立工程
This commit is contained in:
106
Assets/Scripts/UI/Shop/EnergyShopSlot.cs
Normal file
106
Assets/Scripts/UI/Shop/EnergyShopSlot.cs
Normal file
@@ -0,0 +1,106 @@
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using game;
|
||||
using GameCore;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using tysdk;
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
text_num.text = data.Number.ToString();
|
||||
if (data.Value == 0)
|
||||
txt_value.gameObject.SetActive(false);
|
||||
else
|
||||
txt_value.text = LocalizationMgr.GetFormatTextValue("UI_FishingShopPanel_2", data.Value);
|
||||
|
||||
text_price.text = data.Price.ToString();
|
||||
|
||||
}
|
||||
void OnBuy()
|
||||
{
|
||||
var cost = _shopToken.Price;
|
||||
if (cost == 0)
|
||||
{
|
||||
//Free
|
||||
var itemData = new ItemData { id = _shopToken.ItemID, count = (_shopToken.Number) };
|
||||
// var itemData = new ItemData { id = _shopToken.ItemID, count = (_shopToken.AddNumber+_shopToken.Number)};
|
||||
itemData.curCount = (ulong)GContext.container.Resolve<PlayerItemData>().GetItemCount(_shopToken.ItemID);
|
||||
GContext.container.Resolve<PlayerItemData>().AddItem(itemData);
|
||||
GContext.Publish(new ShowData(itemData));
|
||||
GContext.Publish(new ShowData());
|
||||
}
|
||||
else
|
||||
{
|
||||
var curDiamond = GContext.container.Resolve<PlayerData>().diamond;
|
||||
//Not Free
|
||||
if (curDiamond >= cost)
|
||||
{
|
||||
// var itemData = new ItemData { id = _shopToken.ItemID, count = ( _shopToken.AddNumber + _shopToken.Number ) };
|
||||
var itemData = new ItemData { id = _shopToken.ItemID, count = (_shopToken.Number) };
|
||||
itemData.curCount = (ulong)GContext.container.Resolve<PlayerItemData>().GetItemCount(_shopToken.ItemID);
|
||||
GContext.container.Resolve<PlayerData>().AddDiamond(-cost);
|
||||
GContext.container.Resolve<PlayerItemData>().AddItem(itemData);
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user