shaoxiadiablo/Assets/AGame/Scripts/UI/Common/EquipmentWidget.cs
2025-05-18 01:04:31 +08:00

272 lines
6.6 KiB
C#

// ***********************************************************************
// Assembly : Game
// Author : Kimch
// Created : 2020-09-07
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
// <copyright file= "EquipmentWidget" company="Kimch"></copyright>
// <summary></summary>
// ***********************************************************************
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace G.UI
{
public class EquipmentWidget : KUIWidget
{
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
[KUIFlag]
KUIImage _imgQuality;
[KUIFlag]
Image _imgIcon;
[KUIFlag]
GameObject _goNew;
[KUIFlag]
GameObject _goPropLevel;
[KUIFlag]
TextMeshProUGUI _tmpPropLevel;
[KUIFlag]
TextMeshProUGUI _tmpName;
[KUIFlag]
GameObject _imgNormal;
[KUIFlag]
GameObject _imgOver;
[KUIFlag]
GameObject _goBetter;
[KUIFlag]
KUIImage _imgElement;
[KUIFlag]
RawImage _rawEffect;
[KUIFlag]
GameObject _goLocked;
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
private void Awake()
{
SetViewData();
GetComponent<Button>().onClick.AddListener(this.OnClick);
}
public void SetDefaultIcon(int index)
{
_imgIcon.GetComponent<KUIImage>().SetDefaultSprite(index);
if (_imgQuality)
_imgQuality.gameObject.SetActive(false);
}
public void SetDefaultIcon(string[] iconInfo)
{
IconProxy.Instance.SetSprite(_imgIcon, iconInfo);
if (_imgQuality)
_imgQuality.gameObject.SetActive(false);
}
public void SetSprite(string[] iconInfo, int quality)
{
IconProxy.Instance.SetSprite(_imgIcon, iconInfo);
//_imgIcon.sprite = AssetProxy.Instance.GetSprite(iconInfo);
if (_imgQuality)
{
_imgQuality.gameObject.SetActive(quality > 0);
_imgQuality.ShowSprite(quality);
}
if (quality >= 4)
{
_rawEffect.gameObject.SetActive(true);
_rawEffect.texture = EffectRoot.Instance.GetTexture();
//if (quality == 3)
//{
// _rawEffect.uvRect = new Rect(0f, 0.5f, 0.5f, 0.5f);
//}
//else
if (quality == 4)
{
_rawEffect.uvRect = new Rect(0.5f, 0.5f, 0.5f, 0.5f);
}
else if (quality == 5)
{
_rawEffect.uvRect = new Rect(0f, 0f, 0.5f, 0.5f);
}
else if (quality == 6)
{
_rawEffect.uvRect = new Rect(0.5f, 0f, 0.5f, 0.5f);
}
//if (_tfEffectRoot && _tfEffectRoot.childCount == 3)
//{
// _tfEffectRoot.gameObject.SetActive(true);
// for (int i = 0; i < 3; i++)
// {
// _tfEffectRoot.GetChild(i).gameObject.SetActive(i == (quality - 3));
// }
//}
}
else
{
_rawEffect.gameObject.SetActive(false);
//if (_tfEffectRoot)
// _tfEffectRoot.gameObject.SetActive(false);
}
}
public void SetName(string name, int quality)
{
if (_tmpName)
{
_tmpName.text = name;
_tmpName.color = Item.GetQualityColor(quality);
}
}
public void SetParticleMask(bool mask)
{
//var psrList = F.ListPool<ParticleSystemRenderer>.Get();
//GetComponentsInChildren(true, psrList);
//foreach (var psr in psrList)
//{
// psr.maskInteraction = mask ? SpriteMaskInteraction.VisibleInsideMask : SpriteMaskInteraction.None;
//}
//F.ListPool<ParticleSystemRenderer>.Release(psrList);
}
private void SetPropLevel(int level)
{
_goPropLevel.SetActive(true);
_tmpPropLevel.text = $"Lv.{level}";
//int result = (level / 10) + ((level % 10) != 0 ? 1 : 0);
//_tmpPropLevel.text = GlobalUtils.NumberToChinese(result) + "阶";
}
private void SetLockStatus(bool status)
{
if (_goLocked)
_goLocked.SetActive(status);
}
private void SetElement(int element)
{
if (element > 0)
{
_imgElement.gameObject.SetActive(true);
_imgElement.ShowSprite(element - 1);
}
else
{
_imgElement.gameObject.SetActive(false);
}
}
private void SetOver(bool over)
{
_imgNormal.SetActive(!over);
_imgOver.SetActive(over);
}
public override void Refresh()
{
if (this.data is EntityItemEquipment equipment)
{
var propItem = equipment.propItem;
this.SetSprite(propItem.icon, propItem.quality);
this.SetName(propItem.name, propItem.quality);
this.SetPropLevel(propItem.level);
var slot = PlayerProxy.Instance.GetEquipmentSlot(equipment);
if (slot != null)
{
_goBetter.SetActive(false);
_goNew.SetActive(false);
SetOver(false);
SetLockStatus(false);
//_tmpLevel.gameObject.SetActive(true);
//if (slot.grade > 0)
// _tmpLevel.text = $"+{slot.grade}";
//else
// _tmpLevel.text = "";
}
else
{
bool isOver = false;// propItem.level > PlayerProxy.Instance.grade;
SetOver(isOver);
var isBetter = PlayerProxy.Instance.IsBetterEquipment(equipment);
_goBetter.SetActive(isBetter);
_goNew.SetActive(equipment.isNew);
SetLockStatus(equipment.isLock);
//_tmpLevel.gameObject.SetActive(false);
}
SetElement(equipment.isWeapon && equipment.elementIndex > 0 ? equipment.elementIndex : 0);
}
else if (this.data is ItemEquipment equipmentItem)
{
var propItem = ItemProxy.Instance.GetStaticItem<ItemProp>(equipmentItem.id);
this.SetSprite(propItem.icon, propItem.quality);
this.SetPropLevel(propItem.level);
//_tmpLevel.gameObject.SetActive(false);
_goNew.SetActive(false);
_goBetter.SetActive(false);
SetElement(0);
SetOver(false);
SetLockStatus(false);
}
else if (this.data is ItemProp propItem)
{
this.SetSprite(propItem.icon, propItem.quality);
if (propItem.isMoney)
{
_goPropLevel.SetActive(false);
}
else
{
this.SetPropLevel(propItem.level);
}
//_tmpLevel.gameObject.SetActive(false);
_goNew.SetActive(false);
_goBetter.SetActive(false);
SetElement(0);
SetOver(false);
SetLockStatus(false);
}
else
{
this.SetSprite(null, 0);
//_tmpLevel.gameObject.SetActive(false);
_goPropLevel.SetActive(false);
SetElement(0);
SetOver(false);
SetLockStatus(false);
_goNew.SetActive(false);
_goBetter.SetActive(false);
_rawEffect.gameObject.SetActive(false);
//_tfEffectRoot.gameObject.SetActive(false);
}
}
private void OnClick()
{
if (this.data is EntityItemEquipment || this.data is ItemEquipment)
{
KUIWindow.OpenWindow<EquipmentDetailBox>(this.data);
EquipmentDetailBox.OnEquipmentLockChanged = OnLockChanged;
}
}
private void OnLockChanged(bool locked)
{
if (_goLocked)
_goLocked.SetActive(locked);
}
}
}