using System.Collections;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
|
namespace vnxbqy.UI
|
{
|
|
public class LingShiChange : Window
|
{
|
// 1. 界面 2. 物品获得调整背包 3. 物品使用改兑换 4. 灵石名称和描述 5. 红点
|
[SerializeField] Text Money;
|
[SerializeField] Text ItemName;
|
[SerializeField] Button sureBtn;
|
[SerializeField] Button closeBtn;
|
[SerializeField] Text m_Count;
|
[SerializeField] Button m_Add;
|
[SerializeField] Button m_Sub;
|
[SerializeField] Button m_Max;
|
[SerializeField] ItemCell m_Itemcell;
|
[SerializeField] Text HaveCount;
|
[SerializeField] Text baseMoneyText;
|
PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
Coroutine m_Coroutine = null;
|
|
bool isPointAdd = false;
|
bool isPointSub = false;
|
int point = 0;
|
|
int m_itemId = 150;
|
int m_haveCnt = 0;
|
static WaitForSeconds waitSpeedSlow = new WaitForSeconds(0.2f);
|
|
private void ShowMoney()
|
{
|
var Item = ItemConfig.Get(m_itemId);
|
m_Count.text = point.ToString();
|
Money.text = (int.Parse(m_Count.text) * Item.EffectValueA1).ToString();
|
}
|
|
private void ShowItem()
|
{
|
var Item = ItemConfig.Get(m_itemId);
|
ItemCellModel cellModel = new ItemCellModel(m_itemId, true, 1);
|
m_Itemcell.Init(cellModel);
|
ItemName.text = Item.ItemName;
|
baseMoneyText.text = Item.EffectValueA1.ToString();
|
}
|
|
private void UseItem()
|
{
|
var itemModels = packModel.GetItemsById(PackType.Item, m_itemId);
|
if (itemModels != null && itemModels.Count > 0 && point > 0)
|
{
|
ItemOperateUtility.Instance.UseItem(itemModels[0].guid, point);
|
}
|
CloseClick();
|
}
|
|
private void ShowItemCount()
|
{
|
m_haveCnt = packModel.GetItemCountByID(PackType.Item, m_itemId);
|
|
HaveCount.text = Language.Get("HasCount") + UIHelper.AppendColor(m_haveCnt == 0 ? TextColType.Red : TextColType.Green, m_haveCnt.ToString(), true);
|
//SetColorful
|
m_Add.SetInteractable(null, m_haveCnt > 0);
|
m_Sub.SetInteractable(null, m_haveCnt > 0);
|
m_Max.SetInteractable(null, m_haveCnt > 0);
|
}
|
|
#region Built-in
|
protected override void BindController()
|
{
|
|
}
|
protected override void AddListeners()
|
{
|
sureBtn.AddListener(UseItem);
|
closeBtn.AddListener(CloseClick);
|
}
|
protected override void OnPreOpen()
|
{
|
packModel.refreshItemCountEvent += OnItemCountRefresh;
|
UIEventTrigger.Get(m_Sub.gameObject).OnDown = OnSubDown;
|
UIEventTrigger.Get(m_Sub.gameObject).OnUp = OnSubUp;
|
UIEventTrigger.Get(m_Add.gameObject).OnDown = OnAddDown;
|
UIEventTrigger.Get(m_Add.gameObject).OnUp = OnAddUp;
|
m_Max.AddListener(OnMax);
|
point = packModel.GetItemCountByID(PackType.Item, m_itemId);
|
ShowItem();
|
ShowItemCount();
|
ShowMoney();
|
}
|
protected override void OnAfterOpen()
|
{
|
|
}
|
|
protected override void OnPreClose()
|
{
|
point = 0;
|
packModel.refreshItemCountEvent -= OnItemCountRefresh;
|
}
|
|
protected override void OnAfterClose()
|
{
|
|
}
|
#endregion
|
|
private void OnItemCountRefresh(PackType type, int index, int itemId)
|
{
|
|
if (type == PackType.Item && itemId == m_itemId)
|
{
|
ShowItemCount();
|
}
|
}
|
|
public void Dispose()
|
{
|
|
if (m_Coroutine != null)
|
{
|
StopCoroutine(m_Coroutine);
|
}
|
isPointAdd = false;
|
isPointSub = false;
|
}
|
|
|
|
private void OnAddDown(GameObject go)
|
{
|
|
isPointAdd = true;
|
if (m_Coroutine != null)
|
{
|
StopCoroutine(m_Coroutine);
|
}
|
m_Coroutine = StartCoroutine(Co_PointRefresh(true));
|
}
|
|
private void OnAddUp(GameObject go)
|
{
|
isPointAdd = false;
|
if (m_Coroutine != null)
|
{
|
StopCoroutine(m_Coroutine);
|
}
|
}
|
|
private void OnSubDown(GameObject go)
|
{
|
if (m_Coroutine != null)
|
{
|
StopCoroutine(m_Coroutine);
|
}
|
isPointSub = true;
|
m_Coroutine = StartCoroutine(Co_PointRefresh(false));
|
}
|
|
private void OnSubUp(GameObject go)
|
{
|
isPointSub = false;
|
if (m_Coroutine != null)
|
{
|
StopCoroutine(m_Coroutine);
|
}
|
}
|
|
private void OnMax()
|
{
|
point = m_haveCnt;
|
ShowMoney();
|
}
|
|
IEnumerator Co_PointRefresh(bool pointUp)
|
{
|
while (pointUp ? isPointAdd : isPointSub)
|
{
|
if (pointUp && m_haveCnt > 0 && point < m_haveCnt)
|
{
|
|
point += 1;
|
}
|
else if (!pointUp && point > 0)
|
{
|
point -= 1;
|
}
|
ShowMoney();
|
yield return waitSpeedSlow;
|
}
|
}
|
}
|
}
|