using UnityEngine;
|
using UnityEngine.UI;
|
|
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;
|
|
PlayerPackModel _playerPack;
|
protected PlayerPackModel playerPack
|
{
|
get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PlayerPackModel>()); }
|
}
|
|
ItemTipsModel tipsModel { get { return ModelCenter.Instance.GetModel<ItemTipsModel>(); } }
|
|
/// <summary>
|
/// 初始化数据 bool值用来判断是否需要展示评分高低或者职业限制
|
/// </summary>
|
/// <param name="model"></param>
|
/// <param name="isCompare"></param>
|
public virtual void Init(ItemModel model,bool isCompare = false,int compareScore = 0)
|
{
|
itemConfig = ItemConfig.Get(model.itemId);
|
InitUI(model.guid,model.itemId,(ulong)model.count,model.equipScore,model.isBind,model.packType,isCompare,model.useDataDict,compareScore);
|
}
|
|
/// <summary>
|
/// 初始化数据(预览)
|
/// </summary>
|
/// <param name="model"></param>
|
public virtual void Init(ItemCellModel model, int compareScore = 0)
|
{
|
itemConfig = model.itemConfig;
|
InitUI(model.guid,model.itemId, model.count, model.score, model.isBind,model.packType,model.isCompare,model.useDataDic,compareScore);
|
}
|
|
private void InitUI(string guid,int itemId,ulong count,int score,int isBind,PackType type,bool isCompare, Dictionary<int, List<int>> useDataDic, int compareScore = 0)
|
{
|
if (itemConfig == null) return;
|
|
itemIcon.gameObject.SetActive(true);
|
bgIcon.gameObject.SetActive(true);
|
itemIcon.SetSprite(itemConfig.IconKey);
|
bgIcon.SetItemBackGround(ItemLogicUtility.Instance.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);
|
}
|
|
int compareReslut = CheckIsCompare(type,itemId,score,isCompare,compareScore,guid);
|
switch(compareReslut)
|
{
|
case 0:
|
stateIcon.gameObject.SetActive(false);
|
break;
|
case 1:
|
stateIcon.gameObject.SetActive(true);
|
stateIcon.SetSprite("EquipForbidIcon");
|
break;
|
case 2:
|
stateIcon.gameObject.SetActive(true);
|
stateIcon.SetSprite("EquipUpIcon");
|
break;
|
case 3:
|
stateIcon.gameObject.SetActive(true);
|
stateIcon.SetSprite("EquipDownIcon");
|
break;
|
}
|
}
|
|
/// <summary>
|
/// 0 不比较 1 禁止比较 2 高评分 3 低评分
|
/// </summary>
|
/// <param name="itemId"></param>
|
/// <param name="score"></param>
|
/// <param name="isCompare"></param>
|
/// <param name="compareSocre"></param>
|
/// <returns></returns>
|
public int CheckIsCompare(PackType type,int itemId, int score, bool isCompare,int compareSocre,string guid = "")
|
{
|
ItemConfig config = ItemConfig.Get(itemId);
|
int playerJob = PlayerDatas.Instance.baseData.Job;
|
if (config == null || (!isCompare && compareSocre == 0) || config.EquipPlace == 0
|
|| (score == compareSocre && compareSocre != 0) || (compareSocre <= 0 && (type == PackType.Equip || type == PackType.DogzEquip
|
|| type == PackType.JadeDynastyEquip))) return 0;
|
|
ItemModel model = playerPack.GetItemByGuid(guid);
|
if (model != null && ItemLogicUtility.Instance.IsOverdue(guid, itemId, model.useDataDict)) return 1;
|
if (playerJob != Math.Floor((double)config.JobLimit / 100) && config.JobLimit != 0) return 1;
|
|
if (isCompare)
|
{
|
switch(type)
|
{
|
case PackType.DogzItem:
|
compareSocre = GetCompareSocre(PackType.DogzEquip, config.EquipPlace);
|
break;
|
case PackType.JadeDynastyItem:
|
compareSocre = GetCompareSocre(PackType.JadeDynastyEquip, config.EquipPlace);
|
break;
|
default:
|
compareSocre = GetCompareSocre(PackType.Equip, config.EquipPlace);
|
break;
|
}
|
}
|
|
if (score == compareSocre)
|
{
|
return 0;
|
}
|
else
|
{
|
return score > compareSocre ? 2 : 3;
|
}
|
|
}
|
|
public int GetCompareSocre(PackType type,int equipPlace)
|
{
|
ItemModel fairy01 = null;
|
ItemModel fairy02 = null;
|
switch (type)
|
{
|
case PackType.Equip:
|
switch ((RoleEquipType)equipPlace)
|
{
|
case RoleEquipType.FairyCan:
|
fairy01 = playerPack.GetItemByIndex(type,(int)RoleEquipType.FairyCan);
|
fairy02 = playerPack.GetItemByIndex(type, (int)RoleEquipType.FairyCan2);
|
if(fairy01 == null || fairy02 == null)
|
{
|
return 0;
|
}
|
else
|
{
|
return fairy01.equipScore >= fairy02.equipScore ? fairy02.equipScore : fairy01.equipScore;
|
}
|
default:
|
ItemModel model = playerPack.GetItemByIndex(type,equipPlace);
|
return model == null ? 0 : model.equipScore;
|
}
|
case PackType.DogzEquip:
|
var dogzModel = ModelCenter.Instance.GetModel<DogzModel>();
|
ItemModel putOnModel = null;
|
dogzModel.TryGetDogzEquip(dogzModel.presentSelectDogz, equipPlace, out putOnModel);
|
return putOnModel == null ? 0 : putOnModel.equipScore;
|
case PackType.JadeDynastyEquip:
|
|
switch ((RoleEquipType)equipPlace)
|
{
|
case RoleEquipType.JadeDynasty_Glove1:
|
fairy01 = playerPack.GetItemByIndex(type, (int)RoleEquipType.JadeDynasty_Glove1);
|
fairy02 = playerPack.GetItemByIndex(type, (int)RoleEquipType.JadeDynasty_Glove2);
|
if (fairy01 == null || fairy02 == null)
|
{
|
return 0;
|
}
|
else
|
{
|
return fairy01.equipScore >= fairy02.equipScore ? fairy02.equipScore : fairy01.equipScore;
|
}
|
case RoleEquipType.JadeDynasty_Ring1:
|
fairy01 = playerPack.GetItemByIndex(type, (int)RoleEquipType.JadeDynasty_Ring1);
|
fairy02 = playerPack.GetItemByIndex(type, (int)RoleEquipType.JadeDynasty_Ring2);
|
if (fairy01 == null || fairy02 == null)
|
{
|
return 0;
|
}
|
else
|
{
|
return fairy01.equipScore >= fairy02.equipScore ? fairy02.equipScore : fairy01.equipScore;
|
}
|
default:
|
ItemModel model = playerPack.GetItemByIndex(type, equipPlace);
|
return model == null ? 0 : model.equipScore;
|
}
|
}
|
return 0;
|
}
|
}
|
|
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; }
|
|
public ItemCellModel(int itemId,bool isPreview = false,ulong count = 0,int isBind = 0,string guid = "",PackType type = PackType.Deleted,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 = ItemConfig.Get(itemId);
|
this.isCompare = isCompare;
|
this.useDataDic = useDataDic;
|
this.packType = type;
|
if(CheckIsCustomItem())
|
{
|
this.itemId = itemConfig.EffectValueA1;
|
this.itemConfig = ItemConfig.Get(this.itemId);
|
}
|
this.score = ItemLogicUtility.Instance.GetEquipScore(type,itemId,useDataDic,isPreview);
|
}
|
|
public bool CheckIsCustomItem()
|
{
|
if (itemConfig == null) return false;
|
|
if (itemConfig.Effect1 == 220)
|
{
|
return true;
|
}
|
return false;
|
}
|
}
|
}
|
|