641 lines
21 KiB
C#
641 lines
21 KiB
C#
//**********************************************//
|
|
//作者:#AUTHOR#
|
|
//日期:#DATE#
|
|
//简述:#DESCRIPTION#
|
|
//*********************************************//
|
|
using UnityEngine;
|
|
|
|
using Thousandto.Code.Logic;
|
|
using Thousandto.Code.Center;
|
|
using Thousandto.Code.Global;
|
|
using Thousandto.Cfg.Data;
|
|
using Thousandto.Plugins.Common;
|
|
|
|
namespace Thousandto.GameUI.Form
|
|
{
|
|
/// <summary>
|
|
/// 类UIItem说明
|
|
/// </summary>
|
|
public class UIItem : UIIcon
|
|
{
|
|
#region //私有变量
|
|
public delegate void UIItemDelegate(UIItem item);
|
|
private UISprite _qualtySprite; //背景
|
|
private UISprite _iconBind; //是否绑定
|
|
private UILabel _numLabel; //数量
|
|
private UILabel _strenLv; //装备等级
|
|
private UISprite _effect; //装备特效
|
|
private ItemBase _showItem; //要显示的物品
|
|
private UIGrid _diamondGrid;//装备钻石
|
|
private UILabel _starNumLabel; //超过五星的用数字表示
|
|
private UISpriteAnimation _effectAni; // 帧动画
|
|
private UISpriteAnimation _effectAni2; // 帧动画2
|
|
private Transform _unUseEquipSprite; //装备不可穿戴图片
|
|
|
|
private Transform _upEquipSprite; // 更优装备
|
|
private Transform _xijiaBg;
|
|
|
|
private ItemTipsLocation _location;
|
|
|
|
private bool _isBindBagNum = false;
|
|
private string _bindBagNumFormatString = string.Empty;
|
|
private string _enoughColor = "[00ff00]";
|
|
private string _notEnoughColor = "[ff0000]";
|
|
private bool _isRegisterBagMsg = false;
|
|
private long _showNum = 0;
|
|
|
|
//private DeclarePeopleSoul _peopleSoulCfg = null;
|
|
#endregion
|
|
|
|
#region //属性
|
|
public bool isShowTips
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
|
|
public bool isShowGet
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
public bool IsBindBagNum
|
|
{
|
|
get
|
|
{
|
|
return _isBindBagNum;
|
|
}
|
|
}
|
|
public string BindBagNumFormatString
|
|
{
|
|
get
|
|
{
|
|
return _bindBagNumFormatString;
|
|
}
|
|
set
|
|
{
|
|
_bindBagNumFormatString = value;
|
|
}
|
|
}
|
|
public string EnoughColor
|
|
{
|
|
get
|
|
{
|
|
return _enoughColor;
|
|
}
|
|
set
|
|
{
|
|
_enoughColor = value;
|
|
}
|
|
}
|
|
public string NotEnoughColor
|
|
{
|
|
get
|
|
{
|
|
return _notEnoughColor;
|
|
}
|
|
set
|
|
{
|
|
_notEnoughColor = value;
|
|
}
|
|
}
|
|
|
|
public ItemBase ShowItem
|
|
{
|
|
get { return _showItem; }
|
|
}
|
|
public UIItemDelegate SingleClick
|
|
{ get; set; }
|
|
#endregion
|
|
|
|
#region//继承父类
|
|
protected override void OnInitialization()
|
|
{
|
|
base.OnInitialization();
|
|
var quaTrans = transform.Find("Quality");
|
|
if(quaTrans != null)
|
|
{
|
|
_qualtySprite = quaTrans.GetComponent<UISprite>();
|
|
}
|
|
Transform bindTran = transform.Find("Bind");
|
|
if (null != bindTran)
|
|
{
|
|
_iconBind = bindTran.GetComponent<UISprite>();
|
|
}
|
|
Transform numTran = transform.Find("Num");
|
|
if (null != numTran)
|
|
{
|
|
_numLabel = numTran.GetComponent<UILabel>();
|
|
}
|
|
numTran = transform.Find("Level");
|
|
if (null != numTran)
|
|
{
|
|
_strenLv = numTran.GetComponent<UILabel>();
|
|
}
|
|
|
|
numTran = transform.Find("Effect");
|
|
if(null != numTran)
|
|
{
|
|
_effect = numTran.GetComponent<UISprite>();
|
|
}
|
|
|
|
numTran = transform.Find("Effect1");
|
|
if (null != numTran)
|
|
{
|
|
_effectAni = numTran.RequireComponent<UISpriteAnimation>();
|
|
_effectAni.namePrefix = "item_";
|
|
_effectAni.framesPerSecond = 10;
|
|
_effectAni.PrefixSnap = false;
|
|
}
|
|
numTran = transform.Find("Effect2");
|
|
if (null != numTran)
|
|
{
|
|
_effectAni2 = numTran.RequireComponent<UISpriteAnimation>();
|
|
_effectAni2.namePrefix = "item1_";
|
|
_effectAni2.framesPerSecond = 10;
|
|
_effectAni2.PrefixSnap = false;
|
|
}
|
|
numTran = TransformInst.Find("StarNum");
|
|
if (numTran != null)
|
|
{
|
|
_starNumLabel = numTran.GetComponent<UILabel>();
|
|
}
|
|
_upEquipSprite = TransformInst.Find("up");
|
|
_unUseEquipSprite = TransformInst.Find("UnUseSprite");
|
|
_xijiaBg = TransformInst.Find("XJbg");
|
|
|
|
numTran = transform.Find("Grid");
|
|
if (null != numTran)
|
|
{
|
|
_diamondGrid = numTran.GetComponent<UIGrid>();
|
|
}
|
|
_location = ItemTipsLocation.Defult;
|
|
UIButton button = TransformInst.RequireComponent<UIButton>();
|
|
button.onClick.Clear();
|
|
button.onClick.Add(new EventDelegate(OnBtnItemClick));
|
|
isShowTips = true;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region//公共接口
|
|
/// <summary>
|
|
/// 通过物品或装备实例数据生成
|
|
/// </summary>
|
|
/// <param name="cfgId"></param>
|
|
public void InitializationWithIdAndNum(ItemBase itemInfo, long num, bool mastShowNum = false, bool isShowGetBtn = true, ItemTipsLocation location = ItemTipsLocation.Defult)
|
|
{
|
|
InitializationWithCheck();
|
|
if (_numLabel != null)
|
|
{
|
|
_numLabel.gameObject.SetActive(true);
|
|
}
|
|
if(_strenLv)
|
|
{
|
|
_strenLv.gameObject.SetActive(false);
|
|
}
|
|
if (_upEquipSprite != null)
|
|
{
|
|
_upEquipSprite.gameObject.SetActive(false);
|
|
}
|
|
if (_unUseEquipSprite != null)
|
|
_unUseEquipSprite.gameObject.SetActive(false);
|
|
if (_xijiaBg != null)
|
|
_xijiaBg.gameObject.SetActive(false);
|
|
|
|
_showItem = itemInfo;
|
|
isShowGet = isShowGetBtn;
|
|
_location = location;
|
|
if (null != _showItem && _showItem.IsValid())
|
|
{
|
|
int iconId = itemInfo.Icon;
|
|
string qualtyName = ItemBase.GetQualitySpriteName(_showItem.Quality);
|
|
OnSetDiamondSpr(_showItem.StarNum);
|
|
OnSetEffect(_showItem.Effect);
|
|
if (_showItem.Type == ItemType.Equip || _showItem.Type == ItemType.HolyEquip)
|
|
{
|
|
var equipItem = _showItem as Equipment;
|
|
|
|
if (_showItem.CheackOcc((int)GameCenter.GameSceneSystem.GetLocalPlayer().Occ) && _upEquipSprite != null)
|
|
{
|
|
_upEquipSprite.gameObject.SetActive(_showItem.CheckBetterThanDress());
|
|
}
|
|
|
|
if (_unUseEquipSprite != null)
|
|
{
|
|
_unUseEquipSprite.gameObject.SetActive(!_showItem.CheackOcc((int)GameCenter.GameSceneSystem.GetLocalPlayer().Occ));
|
|
}
|
|
|
|
if (_strenLv)
|
|
{
|
|
_strenLv.gameObject.SetActive(true);
|
|
_strenLv.text = DeclareMessageString.Format(DeclareMessageString.LEVEL_FOR_JIE, _showItem.Grade);
|
|
}
|
|
}
|
|
else if(_showItem.Type == ItemType.ImmortalEquip)
|
|
{
|
|
if (_xijiaBg != null)
|
|
_xijiaBg.gameObject.SetActive(true);
|
|
var equipItem = _showItem as ImmortalEquip;
|
|
|
|
if (equipItem.CheackOcc((int)GameCenter.GameSceneSystem.GetLocalPlayer().Occ) && _upEquipSprite != null)
|
|
{
|
|
_upEquipSprite.gameObject.SetActive(equipItem.CheckBetterThanDress());
|
|
}
|
|
|
|
if (_unUseEquipSprite != null)
|
|
{
|
|
_unUseEquipSprite.gameObject.SetActive(!equipItem.CheackOcc((int)GameCenter.GameSceneSystem.GetLocalPlayer().Occ));
|
|
}
|
|
|
|
if (_strenLv)
|
|
{
|
|
_strenLv.gameObject.SetActive(true);
|
|
_strenLv.text = "";
|
|
}
|
|
}
|
|
|
|
UpdateIcon(iconId);
|
|
if(_numLabel != null)
|
|
{
|
|
if (num > 1 || mastShowNum)
|
|
{
|
|
_numLabel.text = OnGetNumStr(num);
|
|
}
|
|
else
|
|
{
|
|
_numLabel.text = "";
|
|
}
|
|
}
|
|
if(_iconBind != null)
|
|
{
|
|
_iconBind.gameObject.SetActive(_showItem.IsBind);
|
|
}
|
|
if (_qualtySprite != null)
|
|
{
|
|
_qualtySprite.spriteName = qualtyName;
|
|
}
|
|
_showNum = num;
|
|
}
|
|
else
|
|
{
|
|
UpdateIcon(-1);
|
|
if(_iconBind != null)
|
|
{
|
|
_iconBind.gameObject.SetActive(false);
|
|
}
|
|
if (_qualtySprite != null)
|
|
{
|
|
_qualtySprite.gameObject.SetActive(false);
|
|
}
|
|
if(_numLabel != null)
|
|
{
|
|
_numLabel.text = "";
|
|
}
|
|
}
|
|
if (_numLabel != null)
|
|
{
|
|
_numLabel.color = Color.white;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 通过物品配置ID初始化item
|
|
/// </summary>
|
|
/// <param name="cfgId"></param>
|
|
public void InitializationWithIdAndNum(int itemID, long num, bool isBind = false, bool isShowGetBtn = true)
|
|
{
|
|
InitializationWithCheck();
|
|
|
|
if (_strenLv)
|
|
{
|
|
_strenLv.gameObject.SetActive(false);
|
|
}
|
|
if (_upEquipSprite != null)
|
|
{
|
|
_upEquipSprite.gameObject.SetActive(false);
|
|
}
|
|
if (_unUseEquipSprite != null)
|
|
_unUseEquipSprite.gameObject.SetActive(false);
|
|
|
|
if (_xijiaBg != null)
|
|
_xijiaBg.gameObject.SetActive(false);
|
|
|
|
_location = ItemTipsLocation.Defult;
|
|
isShowGet = isShowGetBtn;
|
|
_showItem = ItemContianerSystem.GetItemCfgWithID<ItemBase>(itemID);
|
|
if (null != _showItem && _showItem.Type != ItemType.UnDefine)
|
|
{
|
|
_showItem.IsBind = isBind;
|
|
int iconId = _showItem.Icon;
|
|
string qualtyName = ItemBase.GetQualitySpriteName(_showItem.Quality);
|
|
OnSetEffect(_showItem.Effect);
|
|
OnSetDiamondSpr(_showItem.StarNum);
|
|
if (_showItem.Type == ItemType.Equip || _showItem.Type == ItemType.HolyEquip)
|
|
{
|
|
if (_showItem.CheackOcc((int)GameCenter.GameSceneSystem.GetLocalPlayer().Occ) && _upEquipSprite != null)
|
|
{
|
|
_upEquipSprite.gameObject.SetActive(_showItem.CheckBetterThanDress());
|
|
}
|
|
if (_strenLv)
|
|
{
|
|
_strenLv.gameObject.SetActive(true);
|
|
_strenLv.text = DeclareMessageString.Format(DeclareMessageString.LEVEL_FOR_JIE, _showItem.Grade);
|
|
}
|
|
}
|
|
else if (_showItem.Type == ItemType.ImmortalEquip)
|
|
{
|
|
if (_xijiaBg != null)
|
|
_xijiaBg.gameObject.SetActive(true);
|
|
var equipItem = _showItem as ImmortalEquip;
|
|
|
|
if (equipItem.CheackOcc((int)GameCenter.GameSceneSystem.GetLocalPlayer().Occ) && _upEquipSprite != null)
|
|
{
|
|
_upEquipSprite.gameObject.SetActive(equipItem.CheckBetterThanDress());
|
|
}
|
|
|
|
if (_unUseEquipSprite != null)
|
|
{
|
|
_unUseEquipSprite.gameObject.SetActive(!equipItem.CheackOcc((int)GameCenter.GameSceneSystem.GetLocalPlayer().Occ));
|
|
}
|
|
|
|
if (_strenLv)
|
|
{
|
|
_strenLv.gameObject.SetActive(true);
|
|
_strenLv.text = "";
|
|
}
|
|
}
|
|
UpdateIcon(iconId);
|
|
if(_numLabel != null)
|
|
{
|
|
if (num <= 1)
|
|
{
|
|
_numLabel.text = string.Empty;
|
|
}
|
|
else
|
|
{
|
|
_numLabel.text = OnGetNumStr(num);
|
|
}
|
|
}
|
|
if(_iconBind != null)
|
|
{
|
|
_iconBind.gameObject.SetActive(isBind);
|
|
}
|
|
if (_qualtySprite != null)
|
|
{
|
|
_qualtySprite.spriteName = qualtyName;
|
|
}
|
|
_showNum = num;
|
|
}
|
|
else
|
|
{
|
|
UpdateIcon(-1);
|
|
if(_iconBind != null)
|
|
{
|
|
_iconBind.gameObject.SetActive(false);
|
|
}
|
|
if (_qualtySprite != null)
|
|
{
|
|
_qualtySprite.gameObject.SetActive(false);
|
|
}
|
|
if(_numLabel != null)
|
|
{
|
|
_numLabel.text = "";
|
|
}
|
|
}
|
|
}
|
|
|
|
//绑定背包中的数量
|
|
public void BindBagNum(string formatString = "{0}/{1}")
|
|
{
|
|
_isBindBagNum = true;
|
|
_bindBagNumFormatString = formatString;
|
|
RegisterMsg();
|
|
UpdateBagNum();
|
|
}
|
|
//取消绑定背包中的数量
|
|
public void CanelBindBagNum()
|
|
{
|
|
_isBindBagNum = false;
|
|
UnRegisterMsg();
|
|
}
|
|
|
|
public void OnSetNum(string sTx)
|
|
{
|
|
if(_numLabel != null)
|
|
{
|
|
_numLabel.gameObject.SetActive(true);
|
|
_numLabel.text = sTx;
|
|
}
|
|
}
|
|
public void OnSetNumColor(Color col)
|
|
{
|
|
if (_numLabel != null)
|
|
{
|
|
_numLabel.color = col;
|
|
}
|
|
}
|
|
|
|
public void OnSetShowEffect(int effic)
|
|
{
|
|
OnSetEffect(effic);
|
|
if ( _xijiaBg != null)
|
|
{
|
|
_xijiaBg.gameObject.SetActive(effic == 3);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region //按钮事件
|
|
public void OnBtnItemClick()
|
|
{
|
|
if (isShowTips)
|
|
{
|
|
if(_showItem != null)
|
|
{
|
|
GameCenter.LuaSystem.Adaptor.ShowItemTips(_showItem, gameObject, _location, isShowGet);
|
|
}
|
|
//else if(_peopleSoulCfg != null)
|
|
//{
|
|
//GameCenter.PeopleSoulSystem.ShowTips(GameCenter.PeopleSoulSystem.CreateItemByCfg(_peopleSoulCfg), false);
|
|
//}
|
|
}
|
|
if (SingleClick != null)
|
|
SingleClick(this);
|
|
}
|
|
#endregion
|
|
|
|
#region//私有函数
|
|
private new void OnEnable()
|
|
{
|
|
if(_isBindBagNum)
|
|
{
|
|
RegisterMsg();
|
|
}
|
|
base.OnEnable();
|
|
|
|
}
|
|
private new void OnDisable()
|
|
{
|
|
if (_isBindBagNum)
|
|
{
|
|
UnRegisterMsg();
|
|
}
|
|
base.OnDisable();
|
|
}
|
|
private void OnDestroy()
|
|
{
|
|
if (_isBindBagNum)
|
|
{
|
|
UnRegisterMsg();
|
|
}
|
|
}
|
|
|
|
private void UpdateBagNum()
|
|
{
|
|
if (_showItem == null)
|
|
return;
|
|
if (!_isBindBagNum)
|
|
return;
|
|
|
|
var haveNum = GameCenter.ItemContianerSystem.GetItemCountFromCfgId(_showItem.CfgID);
|
|
var formatString = string.Empty;
|
|
if(haveNum >= _showNum)
|
|
{
|
|
formatString = string.Format("{0}{1}[-]", _enoughColor, _bindBagNumFormatString);
|
|
}
|
|
else
|
|
{
|
|
formatString = string.Format("{0}{1}[-]", _notEnoughColor, _bindBagNumFormatString);
|
|
}
|
|
OnSetNum(string.Format(formatString, OnGetNumStr(haveNum), OnGetNumStr(_showNum)));
|
|
}
|
|
|
|
private void OnBagItemChanged(object obj,object sender=null)
|
|
{
|
|
if (_showItem == null)
|
|
return;
|
|
if (!_isBindBagNum)
|
|
return;
|
|
var itemBase = obj as ItemBase;
|
|
if(itemBase != null && itemBase.CfgID == _showItem.CfgID)
|
|
{
|
|
UpdateBagNum();
|
|
}
|
|
}
|
|
private void RegisterMsg()
|
|
{
|
|
if (_isRegisterBagMsg)
|
|
return;
|
|
_isRegisterBagMsg = true;
|
|
GameCenter.RegFixEventHandle(LogicEventDefine.EVENT_BACKFORM_ITEM_UPDATE, OnBagItemChanged);
|
|
}
|
|
private void UnRegisterMsg()
|
|
{
|
|
if (!_isRegisterBagMsg)
|
|
return;
|
|
_isRegisterBagMsg = false;
|
|
GameCenter.UnRegFixEventHandle(LogicEventDefine.EVENT_BACKFORM_ITEM_UPDATE, OnBagItemChanged);
|
|
}
|
|
|
|
private void OnSetEffect(int effectID)
|
|
{
|
|
if (_effect != null)
|
|
_effect.gameObject.SetActive(false);
|
|
if (_effectAni != null)
|
|
_effectAni.gameObject.SetActive(false);
|
|
if (_effectAni2 != null)
|
|
_effectAni2.gameObject.SetActive(false);
|
|
if ((effectID == 1 || effectID == 3) && _effect != null)
|
|
{
|
|
_effect.gameObject.SetActive(true);
|
|
}
|
|
if ((effectID == 2 || effectID > 3) && _effectAni != null)
|
|
{
|
|
_effectAni.gameObject.SetActive(true);
|
|
if (effectID == 2)
|
|
_effectAni.namePrefix = "item_";
|
|
else if (effectID == 4)
|
|
_effectAni.namePrefix = "item3_";
|
|
else if (effectID == 5)
|
|
_effectAni.namePrefix = "item4_";
|
|
else if (effectID == 6)
|
|
_effectAni.namePrefix = "item5_";
|
|
else if (effectID == 7)
|
|
_effectAni.namePrefix = "item6_";
|
|
}
|
|
if (effectID == 3 && _effectAni2 != null)
|
|
{
|
|
_effectAni2.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
|
|
//com_decbg_star_p
|
|
//com_decbg_zuanshi
|
|
private void OnSetDiamondSpr(int diaNum)
|
|
{
|
|
if (_diamondGrid == null)
|
|
return;
|
|
_diamondGrid.gameObject.SetActive(diaNum <= 5);
|
|
if(_starNumLabel != null)
|
|
_starNumLabel.gameObject.SetActive(diaNum > 5);
|
|
if (diaNum <= 5)
|
|
{
|
|
int oldIndex = 0;
|
|
int oldCount = _diamondGrid.transform.childCount;
|
|
|
|
if (oldCount == 0)
|
|
return;
|
|
|
|
for (int i = 0; i < oldCount; i++)
|
|
{
|
|
_diamondGrid.transform.GetChild(i).gameObject.SetActive(false);
|
|
}
|
|
if (diaNum > 0)
|
|
{
|
|
GameObject childGo = null;
|
|
|
|
if (oldIndex < oldCount)
|
|
childGo = _diamondGrid.transform.GetChild(oldIndex).gameObject;
|
|
|
|
oldIndex++;
|
|
|
|
childGo.SetActive(true);
|
|
|
|
for (; oldIndex < diaNum; oldIndex++)
|
|
{
|
|
if (oldIndex >= oldCount)
|
|
{
|
|
var insGo = NGUITools.AddChild(_diamondGrid.gameObject, childGo);
|
|
insGo.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
var child = _diamondGrid.transform.GetChild(oldIndex);
|
|
child.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
_diamondGrid.repositionNow = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(_starNumLabel != null)
|
|
{
|
|
_starNumLabel.text = diaNum.ToString();
|
|
}
|
|
}
|
|
}
|
|
|
|
private string OnGetNumStr(long num)
|
|
{
|
|
return CommonUtils.CovertToBigUnit(num, 4);
|
|
}
|
|
#endregion
|
|
}
|
|
}
|