using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace vnxbqy.UI
|
{
|
public class AlchemyUseDrugCell : CellView
|
{
|
[SerializeField] ItemCell m_Item;
|
[SerializeField] Slider m_Slider;
|
[SerializeField] Text m_UseCount;
|
[SerializeField] PropertyBehaviour[] m_Propertys;
|
[SerializeField] Button m_Func;
|
[SerializeField] Text m_FuncLabel;
|
|
static Dictionary<int, int> propertys = new Dictionary<int, int>();
|
|
AlchemyModel model { get { return ModelCenter.Instance.GetModel<AlchemyModel>(); } }
|
|
PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
|
public void Display(int itemId, int displayIndex)
|
{
|
this.gameObject.name = "AlchemyUseDrugCell_" + displayIndex;
|
|
var count = packModel.GetItemCountByID(PackType.Item, itemId);
|
var itemModel = new ItemCellModel(itemId, true, (ulong)count);
|
m_Item.Init(itemModel);
|
m_Item.button.SetListener(() =>
|
{
|
ItemTipUtility.Show(itemId);
|
});
|
|
m_Item.countText.SetActive(count > 0);
|
m_Item.countText.text = count.ToString();
|
|
var eatTimes = 0;
|
|
AlchemyDrugUseLimit drugUseLimit;
|
if (model.TryGetAlchemyUseLimit(itemId, out drugUseLimit))
|
{
|
var useLimit = drugUseLimit.GetUseLimit();
|
m_UseCount.text = StringUtility.Contact(drugUseLimit.eatTimes, "/", useLimit);
|
m_Slider.value = Mathf.Clamp01((float)drugUseLimit.eatTimes / useLimit);
|
eatTimes = drugUseLimit.eatTimes;
|
}
|
|
GetProperty(itemId, ref propertys);
|
|
var index = 0;
|
foreach (var key in propertys.Keys)
|
{
|
if (index < m_Propertys.Length)
|
{
|
m_Propertys[index].SetActive(true);
|
m_Propertys[index].DisplayUpper(key, propertys[key] * eatTimes);
|
index++;
|
}
|
}
|
for (int i = index; i < m_Propertys.Length; i++)
|
{
|
m_Propertys[i].SetActive(false);
|
}
|
|
var state = model.GetAlchemyDrugState(itemId);
|
m_Func.SetInteractable(m_FuncLabel, state == 0 || state == 1);
|
|
if (state == 1)
|
{
|
m_Func.image.SetSprite("TY_AN_31");
|
}
|
else
|
{
|
m_Func.image.SetSprite("TY_AN_32");
|
}
|
|
switch (state)
|
{
|
case 0:
|
case 2:
|
m_FuncLabel.text = Language.Get("AlchemyDrugState_1");
|
break;
|
case 1:
|
case 3:
|
m_FuncLabel.text = Language.Get("AlchemyDrugState_2");
|
break;
|
}
|
|
m_Func.SetListener(() =>
|
{
|
OnFunc(itemId);
|
});
|
}
|
|
private void OnFunc(int itemId)
|
{
|
var state = model.GetAlchemyDrugState(itemId);
|
switch (state)
|
{
|
case 0:
|
var itemCount = packModel.GetItemCountByID(PackType.Item, itemId);
|
var list = packModel.GetItemsById(PackType.Item, itemId);
|
if (list != null && list.Count > 0)
|
{
|
int maxValue = itemCount;
|
AlchemyDrugUseLimit drugUseLimit;
|
if (model.TryGetAlchemyUseLimit(itemId, out drugUseLimit))
|
{
|
maxValue = Mathf.Min(itemCount, drugUseLimit.GetUseLimit() - drugUseLimit.eatTimes);
|
}
|
|
//if (maxValue > 1)
|
//{
|
// AlchemyDrugBatchUseWin.itemId = itemId;
|
// WindowCenter.Instance.Open<AlchemyDrugBatchUseWin>();
|
//}
|
//else
|
if (ItemOperateUtility.Instance.CheckItemUselimit(itemId))
|
{
|
var config = ItemConfig.Get(itemId);
|
if (config != null && config.Effect1 == 200)
|
{
|
ModelCenter.Instance.GetModel<ReikiRootModel>().reikiPointPromoteSymbol = true;
|
}
|
ItemOperateUtility.Instance.UseItem(list[0].guid, maxValue);
|
}
|
}
|
break;
|
case 1:
|
AlchemyDrugLimitWin.drugId = itemId;
|
WindowCenter.Instance.Open<AlchemyDrugLimitWin>();
|
break;
|
}
|
}
|
|
static void GetProperty(int itemId, ref Dictionary<int, int> dict)
|
{
|
dict.Clear();
|
var itemConfig = ItemConfig.Get(itemId);
|
if (itemConfig == null)
|
{
|
return;
|
}
|
if (itemConfig.Effect1 != 0)
|
{
|
dict.Add(itemConfig.Effect1, itemConfig.EffectValueA1);
|
}
|
if (itemConfig.Effect2 != 0)
|
{
|
dict.Add(itemConfig.Effect2, itemConfig.EffectValueA2);
|
}
|
if (itemConfig.Effect3 != 0)
|
{
|
dict.Add(itemConfig.Effect3, itemConfig.EffectValueA3);
|
}
|
if (itemConfig.Effect4 != 0)
|
{
|
dict.Add(itemConfig.Effect4, itemConfig.EffectValueA4);
|
}
|
if (itemConfig.Effect5 != 0)
|
{
|
dict.Add(itemConfig.Effect5, itemConfig.EffectValueA5);
|
}
|
}
|
}
|
}
|
|