using System;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
using System.Collections.Generic;
|
using System.Text;
|
using System.Collections;
|
|
namespace Snxxz.UI
|
{
|
public class MakeDrugCell : MonoBehaviour
|
{
|
[SerializeField] Image icon;
|
[SerializeField] Button iconBtn;
|
[SerializeField] Image iconBGIcon;
|
[SerializeField] Text itemCntText;
|
[SerializeField] Slider numSlider;
|
[SerializeField] Text useCntText;
|
[SerializeField] Text attrDesText;
|
[SerializeField] Text nameText;
|
[SerializeField] Button useBtn;
|
[SerializeField] Image useBtnBG;
|
[SerializeField] Text useBtnText;
|
[SerializeField] GameObject reachMaxUse;
|
|
Dictionary<int, int> attrDict = new Dictionary<int, int>();
|
StringBuilder attrSB = new StringBuilder();
|
PackModel _playerPack;
|
PackModel playerPack {
|
get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PackModel>()); }
|
}
|
BlastFurnaceModel furnaceModel { get { return ModelCenter.Instance.GetModel<BlastFurnaceModel>(); } }
|
|
ItemTipsModel _itemTipsModel;
|
ItemTipsModel itemTipsModel { get { return _itemTipsModel ?? (_itemTipsModel = ModelCenter.Instance.GetModel<ItemTipsModel>()); } }
|
int itemId = 0;
|
|
Color32 brightColor = new Color32(64, 28, 6, 255);
|
Color32 greyColor = new Color32(247, 247, 247, 255);
|
AttrFruitConfig fruitConfig;
|
|
private void OnEnable()
|
{
|
attrDesText.gameObject.SetActive(false);
|
iconBtn.AddListener(ClickIconBtn);
|
playerPack.refreshItemSumUseCountEvent += RefreshItemUsce;
|
playerPack.refreshItemCountEvent += RefreshItemCnt;
|
StartCoroutine(SetAttrDesUI());
|
}
|
|
private void OnDisable()
|
{
|
playerPack.refreshItemSumUseCountEvent -= RefreshItemUsce;
|
playerPack.refreshItemCountEvent -= RefreshItemCnt;
|
iconBtn.RemoveAllListeners();
|
useBtn.RemoveAllListeners();
|
}
|
|
IEnumerator SetAttrDesUI()
|
{
|
yield return null;
|
attrDesText.gameObject.SetActive(true);
|
}
|
|
public void InitModel(int id)
|
{
|
attrDict.Clear();
|
this.itemId = id;
|
ItemConfig itemConfig = ItemConfig.Get(itemId);
|
if (itemConfig == null) return;
|
|
fruitConfig = AttrFruitConfig.Get(itemId);
|
icon.SetSprite(itemConfig.IconKey);
|
iconBGIcon.SetItemBackGround(itemConfig.ItemColor);
|
nameText.text = itemConfig.ItemName;
|
nameText.color = UIHelper.GetUIColor(itemConfig.ItemColor, true);
|
numSlider.minValue = 0;
|
numSlider.maxValue = fruitConfig.MaxUseCnt;
|
if (itemConfig.Effect1 != 0)
|
{
|
attrDict.Add(itemConfig.Effect1, itemConfig.EffectValueA1);
|
}
|
|
if (itemConfig.Effect2 != 0)
|
{
|
attrDict.Add(itemConfig.Effect2, itemConfig.EffectValueA2);
|
}
|
|
if (itemConfig.Effect3 != 0)
|
{
|
attrDict.Add(itemConfig.Effect3, itemConfig.EffectValueA3);
|
}
|
if (itemConfig.Effect4 != 0)
|
{
|
attrDict.Add(itemConfig.Effect4, itemConfig.EffectValueA4);
|
}
|
if (itemConfig.Effect5 != 0)
|
{
|
attrDict.Add(itemConfig.Effect5, itemConfig.EffectValueA5);
|
}
|
RefreshUI();
|
}
|
|
private void RefreshUI()
|
{
|
int haveCnt = playerPack.GetItemCountByID(PackType.Item, itemId);
|
itemCntText.text = StringUtility.Contact(haveCnt, "/", 1);
|
int useNum = playerPack.GetItemTotalUsedTimes(itemId);
|
numSlider.value = useNum;
|
useCntText.text = StringUtility.Contact(useNum, "/", numSlider.maxValue);
|
attrSB.Length = 0;
|
foreach (var id in attrDict.Keys)
|
{
|
PlayerPropertyConfig attrConfig = PlayerPropertyConfig.Get(id);
|
if (attrConfig != null)
|
{
|
int value = attrDict[id] * useNum;
|
string valueStr = StringUtility.Contact("+", UIHelper.AppendColor(TextColType.Green, PlayerPropertyConfig.GetValueDescription(id, value), true));
|
string attrStr = StringUtility.Contact(attrConfig.Name, valueStr);
|
if (attrSB.Length != 0)
|
{
|
attrSB.Append(" " + attrStr);
|
}
|
else
|
{
|
attrSB.Append(attrStr);
|
}
|
|
}
|
else
|
{
|
DebugEx.Log("属性表中不存在此属性:" + id + "丹药Id" + this.itemId);
|
}
|
|
}
|
attrDesText.text = attrSB.ToString();
|
useBtn.RemoveAllListeners();
|
if (useNum < fruitConfig.MaxUseCnt)
|
{
|
reachMaxUse.SetActive(false);
|
useBtnText.text = Language.Get("KnapS103");
|
useBtn.AddListener(ClickMakeUseBtn);
|
useBtn.gameObject.SetActive(true);
|
if (haveCnt > 0)
|
{
|
useBtnBG.material = MaterialUtility.GetUIDefaultGraphicMaterial();
|
useBtnText.color = brightColor;
|
}
|
else
|
{
|
useBtnBG.material = MaterialUtility.GetInstantiatedSpriteGrayMaterial();
|
useBtnText.color = greyColor;
|
}
|
}
|
else
|
{
|
useBtn.gameObject.SetActive(false);
|
reachMaxUse.SetActive(true);
|
}
|
|
|
}
|
|
private void RefreshItemUsce(int id)
|
{
|
if (id != itemId) return;
|
|
RefreshUI();
|
}
|
private void RefreshItemCnt(PackType type, int index, int id)
|
{
|
if (type != PackType.Item || id != itemId) return;
|
RefreshUI();
|
}
|
|
private void ClickMakeUseBtn()
|
{
|
SinglePack singlePack = playerPack.GetSinglePack(PackType.Item);
|
if (singlePack == null) return;
|
|
var list = singlePack.GetItemsById(itemId);
|
if (list.Count > 0)
|
{
|
if (ItemOperateUtility.Instance.CheckItemUselimit(itemId))
|
{
|
ItemOperateUtility.Instance.UseItem(list[0].guid);
|
}
|
}
|
}
|
|
private void ClickRecycle()
|
{
|
furnaceModel.RecycleDrug(itemId, fruitConfig.RecycleExp);
|
}
|
|
private void ClickIconBtn()
|
{
|
ItemAttrData attrData = new ItemAttrData(itemId);
|
itemTipsModel.SetItemTipsModel(attrData);
|
}
|
}
|
}
|