using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
public enum ItemCellformat
|
{
|
Format_120x120,
|
Format_100x100,
|
Format_84x84,
|
Format_80x80,
|
Format_70x70,
|
Format_64x64,
|
None,
|
}
|
|
public class CommonItemBaisc : MonoBehaviour
|
{
|
[SerializeField] ItemCellformat m_Format;
|
public ItemCellformat format { get { return m_Format; } set { m_Format = value; } }
|
|
Image m_BgIcon;
|
private Image bgIcon
|
{
|
get
|
{
|
if (m_BgIcon == null)
|
{
|
m_BgIcon = this.transform.GetComponent<Image>("Container_ItemCell/Img_BackGround");
|
}
|
return m_BgIcon;
|
}
|
}
|
|
Image m_ItemIcon;
|
private Image itemIcon
|
{
|
get
|
{
|
if (m_ItemIcon == null)
|
{
|
m_ItemIcon = this.transform.GetComponent<Image>("Container_ItemCell/Img_Icon");
|
}
|
return m_ItemIcon;
|
}
|
}
|
|
|
Image m_StateIcon;
|
public Image stateIcon
|
{
|
get
|
{
|
if (m_StateIcon == null)
|
{
|
m_StateIcon = this.transform.GetComponent<Image>("Container_ItemCell/Img_State");
|
}
|
return m_StateIcon;
|
}
|
}
|
|
Text m_CountText;
|
public Text countText
|
{
|
get
|
{
|
if (m_CountText == null)
|
{
|
m_CountText = this.transform.GetComponent<Text>("Container_ItemCell/Txt_Count");
|
}
|
return m_CountText;
|
}
|
}
|
|
Image m_CountryIcon;
|
public Image countryIcon
|
{
|
get
|
{
|
if (m_CountryIcon == null)
|
{
|
m_CountryIcon = this.transform.GetComponent<Image>("Container_ItemCell/Img_Country");
|
}
|
return m_CountryIcon;
|
}
|
}
|
|
Image m_PieceIcon;
|
public Image pieceIcon
|
{
|
get
|
{
|
if (m_PieceIcon == null)
|
{
|
m_PieceIcon = this.transform.GetComponent<Image>("Container_ItemCell/Img_Piece");
|
}
|
return m_PieceIcon;
|
}
|
}
|
|
Transform m_TimeForm;
|
public Transform timeForm
|
{
|
get
|
{
|
if (m_TimeForm == null)
|
{
|
m_TimeForm = this.transform.Find("Container_ItemCell/Bg_Time");
|
}
|
return m_TimeForm;
|
}
|
}
|
|
Text m_TimeText;
|
public Text timeText
|
{
|
get
|
{
|
if (m_TimeText == null)
|
{
|
m_TimeText = this.transform.GetComponent<Text>("Container_ItemCell/Bg_Time/Txt_Time");
|
}
|
return m_TimeText;
|
}
|
}
|
|
|
Button m_Button;
|
public Button button
|
{
|
get
|
{
|
if (m_Button == null)
|
{
|
m_Button = this.GetComponent<Button>("Container_ItemCell");
|
}
|
return m_Button;
|
}
|
}
|
|
|
//物品基础特效(物品表)
|
UIEffectPlayer m_ItemBaseEffect;
|
UIEffectPlayer itemBaseEffect
|
{
|
get
|
{
|
if (m_ItemBaseEffect == null)
|
{
|
m_ItemBaseEffect = transform.GetComponentInChildren<UIEffectPlayer>();
|
}
|
return m_ItemBaseEffect;
|
}
|
}
|
|
|
GameObject cellContainer;
|
protected void LoadPrefab()
|
{
|
if (cellContainer != null)
|
return;
|
//clone 会造成二次创建
|
var tmp = transform.Find("Container_ItemCell");
|
if (tmp != null)
|
{
|
cellContainer = tmp.gameObject;
|
return;
|
}
|
if (cellContainer == null)
|
{
|
cellContainer = UIUtility.CreateWidget("ItemCell_120", "Container_ItemCell");
|
|
if (cellContainer != null)
|
{
|
cellContainer.transform.SetParentEx(this.transform, Vector3.zero, Quaternion.identity, Vector3.one * GetScale(format));
|
cellContainer.transform.SetAsFirstSibling();
|
}
|
}
|
}
|
|
public int itemId { get; private set; }
|
PackManager packModel { get { return PackManager.Instance; } }
|
|
void OnEnable()
|
{
|
LoadPrefab();
|
}
|
|
/// <summary>
|
/// 初始化数据 bool值用来判断是否需要展示评分高低或者职业限制
|
/// </summary>
|
/// <param name="model"></param>
|
/// <param name="isCompare"></param>
|
public virtual void Init(ItemModel model, bool isCompare = false)
|
{
|
itemId = model.itemId;
|
InitUI(model.guid, model.itemId, model.count, model.isAuction, model.packType, isCompare, model.useDataDict);
|
}
|
|
/// <summary>
|
/// 初始化数据(预览)
|
/// </summary>
|
/// <param name="model"></param>
|
public virtual void Init(ItemCellModel model)
|
{
|
itemId = model.itemId;
|
InitUI(model.guid, model.itemId, model.count, false, model.packType, model.isCompare, model.useDataDic);
|
}
|
|
private void InitUI(string guid, int itemId, long count, bool isAuction, PackType type, bool isCompare, Dictionary<int, List<int>> useDataDic)
|
{
|
var config = ItemConfig.Get(itemId);
|
if (config == null) return;
|
|
itemIcon.SetActive(true);
|
bgIcon.SetActive(true);
|
itemIcon.SetOrgSprite(config.IconKey);
|
bgIcon.SetItemBackGround(ItemLogicUtility.Instance.GetItemQuality(itemId, useDataDic));
|
if (packModel.gameCashShow.Contains(itemId))
|
{
|
//代金券
|
countText.SetActive(true);
|
countText.text = count > 1000000 ? UIHelper.ReplaceLargeNum(count / 100.0f) : (count / 100.0f).ToString("0.#");
|
}
|
else if (!string.IsNullOrEmpty(guid))
|
{
|
if (GeneralDefine.itemMoneyCountDict.ContainsKey(itemId))
|
{
|
//展示货币数量的物品
|
count = UIHelper.GetMoneyCnt(GeneralDefine.itemMoneyCountDict[itemId]);
|
}
|
countText.SetActive(count > 0);
|
if (count > 0)
|
{
|
countText.text = UIHelper.ReplaceLargeNum(count);
|
}
|
}
|
else
|
{
|
countText.SetActive(count > 0);
|
if (count > 0)
|
{
|
countText.text = UIHelper.ReplaceLargeNum(count);
|
}
|
}
|
|
|
DisPlayEffect(config);
|
|
// var compareReslut = isCompare ? Compare(type, itemId, score, guid) : 0;
|
// switch (compareReslut)
|
// {
|
// case -1:
|
// stateIcon.SetActive(true);
|
// stateIcon.SetSprite("EquipDownIcon");
|
// break;
|
// case 0:
|
// stateIcon.SetActive(false);
|
// break;
|
// case 1:
|
// stateIcon.SetActive(true);
|
// stateIcon.SetSprite("EquipUpIcon");
|
// break;
|
// case 99:
|
// stateIcon.SetActive(true);
|
// stateIcon.SetSprite("EquipForbidIcon");
|
// break;
|
// }
|
|
//待策划确定
|
if (config.Type == (int)ItemType.Hero)
|
{
|
var heroConfig = HeroConfig.Get(itemId);
|
countryIcon.SetActive(true);
|
countryIcon.SetSprite(HeroUIManager.Instance.GetCountryIconName(heroConfig.Country));
|
|
}
|
else
|
{
|
countryIcon.SetActive(false);
|
}
|
// pieceIcon.SetActive();
|
}
|
|
// / <summary>
|
// / 0 相等 99 禁止比较 1 高评分 -1 低评分
|
// / </summary>
|
// / <param name="itemId"></param>
|
// / <param name="score"></param>
|
// / <param name="isCompare"></param>
|
// / <param name="compareSocre"></param>
|
// / <returns></returns>
|
int Compare(PackType type, int itemId, int score, string guid)
|
{
|
if (type == PackType.Equip || type == PackType.DogzEquip)
|
{
|
return 0;
|
}
|
|
//此处可能是武将卡
|
// if (!ItemLogicUtility.Instance.IsJobCompatibleItem(itemId))
|
// {
|
// return 99;
|
// }
|
|
var config = ItemConfig.Get(itemId);
|
if (config == null || config.EquipPlace == 0)
|
{
|
return 0;
|
}
|
|
var item = packModel.GetItemByGuid(guid);
|
|
if (item != null && ItemLogicUtility.Instance.IsOverdue(guid))
|
{
|
return 99;
|
}
|
|
// if (ItemLogicUtility.Instance.IsRealmEquip(itemId))
|
// {
|
// return EquipModel.Instance.CompareToCurrent(guid);
|
// }
|
// else
|
{
|
return 0;
|
}
|
}
|
|
void DisPlayEffect(ItemConfig config)
|
{
|
if (config.BaseEffectID == 0)
|
{
|
if (itemBaseEffect != null)
|
{
|
itemBaseEffect.SetActive(false);
|
}
|
}
|
else
|
{
|
itemBaseEffect.SetActive(true);
|
itemBaseEffect.effectId = config.BaseEffectID;
|
itemBaseEffect.Play();
|
}
|
}
|
|
float GetScale(ItemCellformat format)
|
{
|
switch (format)
|
{
|
case ItemCellformat.Format_120x120:
|
return 1f;
|
case ItemCellformat.Format_100x100:
|
return 0.83f;
|
case ItemCellformat.Format_84x84:
|
return 0.7f;
|
case ItemCellformat.Format_80x80:
|
return 0.66f;
|
case ItemCellformat.Format_70x70:
|
return 0.58f;
|
case ItemCellformat.Format_64x64:
|
return 0.53f;
|
default:
|
return 1f;
|
}
|
}
|
|
}
|
|
public class ItemCellModel
|
{
|
public string guid { get; private set; }
|
public int itemId { get; private set; }
|
public long count { get; private set; }
|
public int score { get; private set; }
|
public bool isCompare { get; private set; }
|
public ItemConfig itemConfig { get { return ItemConfig.Get(itemId); } }
|
public PackType packType { get; private set; }
|
public Dictionary<int, List<int>> useDataDic { get; private set; }
|
|
|
public ItemCellModel(int itemId, bool isPreview = false, long count = 0, string guid = "", PackType type = PackType.Deleted, bool isCompare = false, Dictionary<int, List<int>> useDataDic = null)
|
{
|
this.itemId = AdjustItemId(itemId);
|
this.guid = guid;
|
this.count = count;
|
this.isCompare = isCompare;
|
this.useDataDic = useDataDic;
|
this.packType = type;
|
|
//this.score = ItemLogicUtility.Instance.GetEquipScore(itemId, useDataDic, isPreview);
|
}
|
|
public ItemCellModel(int itemId)
|
{
|
this.itemId = AdjustItemId(itemId);
|
this.guid = "";
|
this.count = 0;
|
this.isCompare = false;
|
this.useDataDic = null;
|
this.packType = PackType.Deleted;
|
this.score = 0;
|
}
|
|
public ItemCellModel(int itemId, bool isPreview, long count)
|
{
|
this.itemId = AdjustItemId(itemId);
|
this.guid = "";
|
this.count = count;
|
this.isCompare = false;
|
this.useDataDic = null;
|
this.packType = PackType.Deleted;
|
|
//this.score = ItemLogicUtility.Instance.GetEquipScore(itemId, null, isPreview);
|
}
|
|
int AdjustItemId(int itemId)
|
{
|
var config = ItemConfig.Get(itemId);
|
if (config != null && config.Effect1 == 220)
|
{
|
return config.EffectValueA1;
|
}
|
else
|
{
|
return itemId;
|
}
|
}
|
|
}
|
|