using UnityEngine;
|
using UnityEngine.UI;
|
using TableConfig;
|
using Snxxz.UI;
|
using System.Collections.Generic;
|
using System;
|
using System.Linq;
|
|
namespace Snxxz.UI
|
{
|
public class CommonItemBaisc : MonoBehaviour
|
{
|
Image _bgIcon;
|
public Image bgIcon
|
{
|
get
|
{
|
if (_bgIcon == null)
|
{
|
var _trans = transform.Find("EquipBG");
|
_bgIcon = _trans != null ? _trans.GetComponent<Image>() : null;
|
}
|
return _bgIcon;
|
}
|
}
|
|
Image _itemIcon;
|
public Image itemIcon
|
{
|
get
|
{
|
if (_itemIcon == null)
|
{
|
var _trans = transform.Find("ItemIcon");
|
_itemIcon = _trans != null ? _trans.GetComponent<Image>() : null;
|
}
|
return _itemIcon;
|
}
|
}
|
|
Image _bindIcon;
|
public Image bindIcon
|
{
|
get
|
{
|
if (_bindIcon == null)
|
{
|
var _trans = transform.Find("BindBG");
|
_bindIcon = _trans != null ? _trans.GetComponent<Image>() : null;
|
}
|
return _bindIcon;
|
}
|
}
|
|
Image _stateIcon;
|
public Image stateIcon
|
{
|
get
|
{
|
if (_stateIcon == null)
|
{
|
var _trans = transform.Find("stateIcon");
|
_stateIcon = _trans != null ? _trans.GetComponent<Image>() : null;
|
}
|
return _stateIcon;
|
}
|
}
|
|
Text _countText;
|
public Text countText
|
{
|
get
|
{
|
if (_countText == null)
|
{
|
var _trans = transform.Find("CountText");
|
_countText = _trans != null ? _trans.GetComponent<Text>() : null;
|
}
|
return _countText;
|
}
|
}
|
|
GameObject _starlist;
|
public GameObject starlist
|
{
|
get
|
{
|
if (_starlist == null)
|
{
|
var _trans = transform.Find("StarList");
|
_starlist = _trans != null ? _trans.gameObject : null;
|
}
|
return _starlist;
|
}
|
}
|
|
Button _cellBtn;
|
public Button cellBtn
|
{
|
get
|
{
|
if (_cellBtn == null)
|
_cellBtn = this.GetComponent<Button>();
|
return _cellBtn;
|
}
|
}
|
|
public ItemConfig itemConfig;
|
|
PackModelInterface _modelInterface;
|
protected PackModelInterface modelInterface
|
{
|
get { return _modelInterface ?? (_modelInterface = ModelCenter.Instance.GetModel<PackModelInterface>()); }
|
}
|
|
PlayerPackModel _playerPack;
|
protected PlayerPackModel playerPack
|
{
|
get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PlayerPackModel>()); }
|
}
|
|
/// <summary>
|
/// 初始化数据 bool值用来判断是否需要展示评分高低或者职业限制
|
/// </summary>
|
/// <param name="model"></param>
|
/// <param name="isCompare"></param>
|
public virtual void Init(ItemModel model,bool isCompare = false)
|
{
|
itemConfig = Config.Instance.Get<ItemConfig>(model.itemInfo.ItemID);
|
InitUI(model.itemInfo.ItemGUID,model.itemInfo.ItemID,(ulong)model.itemInfo.ItemCount,model.equipScore,model.itemInfo.IsBind,model.packType,isCompare,model.useDataDict);
|
}
|
|
/// <summary>
|
/// 初始化数据(预览)
|
/// </summary>
|
/// <param name="model"></param>
|
public virtual void Init(ItemCellModel model)
|
{
|
itemConfig = model.itemConfig;
|
InitUI(model.guid,model.itemId, model.count, model.score, model.isBind,model.packType,model.isCompare,model.useDataDic);
|
}
|
|
private void InitUI(string guid,int itemId,ulong count,int score,int isBind,PackType type,bool isCompare, Dictionary<int, List<int>> useDataDic)
|
{
|
if (itemConfig == null) return;
|
|
itemIcon.gameObject.SetActive(true);
|
bgIcon.gameObject.SetActive(true);
|
itemIcon.SetSprite(itemConfig.IconKey);
|
bgIcon.SetItemBackGround(modelInterface.GetItemQuality(itemId, useDataDic));
|
|
int i = 0;
|
for(i = 0; i < starlist.transform.childCount; i++)
|
{
|
Image starIcon = starlist.transform.GetChild(i).GetComponent<Image>();
|
starIcon.SetSprite("Stars_a");
|
if (i >= itemConfig.StarLevel)
|
{
|
starIcon.gameObject.SetActive(false);
|
}
|
else
|
{
|
starIcon.gameObject.SetActive(true);
|
}
|
}
|
|
if(isBind == 0)
|
{
|
bindIcon.gameObject.SetActive(false);
|
}
|
else
|
{
|
bindIcon.gameObject.SetActive(true);
|
}
|
|
countText.text = UIHelper.ReplaceLargeNum((double)count);
|
if(count > 1)
|
{
|
countText.gameObject.SetActive(true);
|
}
|
else
|
{
|
countText.gameObject.SetActive(false);
|
}
|
|
if(!isCompare || type == PackType.rptEquip)
|
{
|
stateIcon.gameObject.SetActive(false);
|
}
|
else
|
{
|
stateIcon.gameObject.SetActive(true);
|
if(type != PackType.rptDogzItem)
|
{
|
bool isOverdue = modelInterface.IsOverdue(guid, itemId, useDataDic);
|
if (!isOverdue)
|
{
|
ItemModel putOnModel = playerPack.GetItemModelByIndex(PackType.rptEquip, itemConfig.EquipPlace);
|
if (itemConfig.EquipPlace == (int)RoleEquipType.retFairyCan)
|
{
|
ItemModel fairyModel2 = playerPack.GetItemModelByIndex(PackType.rptEquip, (int)RoleEquipType.retFairyCan2);
|
if (fairyModel2 != null)
|
{
|
if (putOnModel != null)
|
{
|
if (fairyModel2.equipScore < putOnModel.equipScore)
|
{
|
putOnModel = fairyModel2;
|
}
|
}
|
}
|
else
|
{
|
putOnModel = fairyModel2;
|
}
|
}
|
int equipScore1 = 0;
|
if (putOnModel != null)
|
{
|
equipScore1 = putOnModel.equipScore;
|
}
|
|
int playerJob = PlayerDatas.Instance.baseData.Job;
|
|
if (playerJob == Math.Floor((double)itemConfig.JobLimit / 100) || itemConfig.JobLimit == 0)
|
{
|
if (equipScore1 > score)
|
{
|
stateIcon.SetSprite("EquipDownIcon");
|
}
|
else if (equipScore1 < score)
|
{
|
stateIcon.SetSprite("EquipUpIcon");
|
}
|
else
|
{
|
stateIcon.gameObject.SetActive(false);
|
}
|
}
|
else
|
{
|
stateIcon.SetSprite("EquipForbidIcon");
|
}
|
}
|
else
|
{
|
stateIcon.SetSprite("EquipForbidIcon");
|
}
|
}
|
else
|
{
|
var dogzModel = ModelCenter.Instance.GetModel<DogzModel>();
|
ItemModel putOnModel = null;
|
dogzModel.TryGetDogzEquip(dogzModel.presentSelectDogz, itemConfig.EquipPlace,out putOnModel);
|
if(putOnModel != null)
|
{
|
if(putOnModel.equipScore > score)
|
{
|
stateIcon.SetSprite("EquipDownIcon");
|
}
|
else if(putOnModel.equipScore < score)
|
{
|
stateIcon.SetSprite("EquipUpIcon");
|
}
|
else
|
{
|
stateIcon.gameObject.SetActive(false);
|
}
|
}
|
else
|
{
|
if(score > 0)
|
{
|
stateIcon.SetSprite("EquipUpIcon");
|
}
|
else
|
{
|
stateIcon.gameObject.SetActive(false);
|
}
|
}
|
}
|
|
}
|
}
|
}
|
|
public class ItemCellModel
|
{
|
public string guid { get; private set; }
|
public int itemId { get; private set; }
|
public ulong count { get; private set; }
|
public int isBind { get; private set; }
|
public int score { get; private set; }
|
public bool isCompare { get; private set; }
|
public ItemConfig itemConfig { get; private set;}
|
public PackType packType { get; private set; }
|
public Dictionary<int, List<int>> useDataDic { get; private set; }
|
|
public Dictionary<int, int> specAttrDic { get; private set; }
|
|
PackModelInterface _modelInterface;
|
PackModelInterface modelInterface
|
{
|
get { return _modelInterface ?? (_modelInterface = ModelCenter.Instance.GetModel<PackModelInterface>()); }
|
}
|
|
public ItemCellModel(int itemId,bool isPreview = false,ulong count = 0,int isBind = 0,string guid = "",PackType type = PackType.rptDeleted,bool isCompare = false, Dictionary<int, List<int>> useDataDic = null)
|
{
|
specAttrDic = new Dictionary<int, int>();
|
this.guid = guid;
|
this.itemId = itemId;
|
this.count = count;
|
this.isBind = isBind;
|
this.itemConfig = Config.Instance.Get<ItemConfig>(itemId);
|
this.isCompare = isCompare;
|
this.useDataDic = useDataDic;
|
this.packType = type;
|
if(CheckIsCustomItem())
|
{
|
this.itemId = itemConfig.EffectValueA1;
|
this.itemConfig = Config.Instance.Get<ItemConfig>(this.itemId);
|
}
|
this.score = modelInterface.SetEquipScore(type,itemId,useDataDic,isPreview);
|
}
|
|
public bool CheckIsCustomItem()
|
{
|
if (itemConfig == null) return false;
|
|
if (itemConfig.Effect1 == 220)
|
{
|
return true;
|
}
|
return false;
|
}
|
}
|
}
|