468 lines
16 KiB
C#
468 lines
16 KiB
C#
//**********************************************//
|
|
//作者:#何健#
|
|
//日期:#2016.11.14#
|
|
//简述:#装备成长选取装备时,格子数据填充#
|
|
//*********************************************//
|
|
using Thousandto.Cfg.Data;
|
|
using Thousandto.Code.Center;
|
|
using Thousandto.Code.Global;
|
|
using Thousandto.Code.Logic;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using UnityEngine;
|
|
|
|
namespace Thousandto.GameUI.Form
|
|
{
|
|
public class UISelectEquipItem : UIIconBase
|
|
{
|
|
#region //编辑器变量
|
|
private bool _isInit = false;
|
|
public delegate void ItemDelegate(GameObject obj);
|
|
private UIIconBase _iconSprite; // 物品图标
|
|
private UISprite _bindSprite; // 绑定图标
|
|
private UISprite _qualtySprite; // 品质
|
|
private UILabel _levelLabel; // 装备阶数
|
|
private ItemBase _showGoods; // 显示的物品信息
|
|
private Transform _effectSprite; // 装备效果
|
|
private UISprite _effectAni; // 帧动画
|
|
private UISprite _selectSprite; // 选中图标
|
|
private Transform _equipTrans; // 已装备标识
|
|
private Transform _equipAdd; // 添加装备图标
|
|
private UILabel _itemNum; // 物品数量
|
|
private Transform _redTrans; // 红点
|
|
private Transform _unUseTrans; // 不可使用
|
|
private Transform _upEquipSprite; // 更优装备
|
|
private UIGrid _diamondGrid;
|
|
private Transform _lockTrans;
|
|
private UILabel _elseNum; // 额外增加一个数字显示
|
|
|
|
private int index;
|
|
private float _timeCount; //更新时间计数
|
|
private string[] effNameArr;
|
|
#endregion
|
|
|
|
#region //属性
|
|
|
|
//单机回调
|
|
public ItemDelegate SingleClick
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
|
|
public ItemBase ItemInfo
|
|
{
|
|
get
|
|
{
|
|
return _showGoods;
|
|
}
|
|
set
|
|
{
|
|
_showGoods = value;
|
|
}
|
|
}
|
|
public int GetExtData
|
|
{ get; set; }
|
|
|
|
public int Num
|
|
{ get; set; }
|
|
#endregion
|
|
|
|
#region//继承MonoBehaviour
|
|
private void Awake()
|
|
{
|
|
_iconSprite = TransformInst.Find("Back/icon").RequireComponent<UIIconBase>();
|
|
_bindSprite = TransformInst.Find("Back/Bind").GetComponent<UISprite>();
|
|
_qualtySprite = TransformInst.Find("Back/Qualty").GetComponent<UISprite>();
|
|
_selectSprite = TransformInst.Find("Back/GraySelect").GetComponent<UISprite>();
|
|
_levelLabel = TransformInst.Find("Back/Level").GetComponent<UILabel>();
|
|
_effectSprite = TransformInst.Find("Back/Effect");
|
|
_equipTrans = TransformInst.Find("Back/Sprite");
|
|
_equipAdd = TransformInst.Find("Back/Add");
|
|
_redTrans = TransformInst.Find("Back/Red");
|
|
_unUseTrans = TransformInst.Find("Back/UnUseSprite");
|
|
_lockTrans = TransformInst.Find("Back/Lock");
|
|
_upEquipSprite = TransformInst.Find("Back/up");
|
|
Transform transs = TransformInst.Find("Back/Grid");
|
|
if (transs != null)
|
|
_diamondGrid = transs.GetComponent<UIGrid>();
|
|
_isInit = true;
|
|
|
|
Transform numTran = transform.Find("Back/Effect1");
|
|
if (null != numTran)
|
|
{
|
|
_effectAni = numTran.GetComponent<UISprite>();
|
|
}
|
|
|
|
numTran = transform.Find("Back/Num");
|
|
if (null != numTran)
|
|
{
|
|
_itemNum = numTran.GetComponent<UILabel>();
|
|
}
|
|
|
|
numTran = transform.Find("Back/ElseNum");
|
|
if (null != numTran)
|
|
{
|
|
_elseNum = numTran.GetComponent<UILabel>();
|
|
}
|
|
effNameArr = new string[7];
|
|
for (int i = 0; i < 7; i++)
|
|
{
|
|
effNameArr[i] = string.Format("item_{0}", i);
|
|
}
|
|
|
|
UIButton button = transform.Find("Back").GetComponent<UIButton>();
|
|
if(button == null)
|
|
{
|
|
button = transform.GetComponent<UIButton>();
|
|
}
|
|
button.onClick.Clear();
|
|
button.onClick.Add(new EventDelegate(OnOwnClick));
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
_timeCount += Time.deltaTime;
|
|
if (_timeCount > 0.1f)
|
|
{
|
|
if (_effectAni != null && _effectAni.gameObject.activeSelf)
|
|
{
|
|
_effectAni.spriteName = effNameArr[index];
|
|
index--;
|
|
if (index < 0)
|
|
index = 6;
|
|
|
|
}
|
|
_timeCount = 0f;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region//公共接口
|
|
/// <summary>
|
|
/// 点击事件
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public void OnOwnClick()
|
|
{
|
|
//Debug.Log("click");
|
|
if (null != SingleClick)
|
|
{
|
|
SingleClick(gameObject);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新物品
|
|
/// </summary>
|
|
/// <param name="good"></param>
|
|
public void UpdateItem(ItemBase good, bool isShowRed = false, int extData = 0)
|
|
{
|
|
if (_isInit == false)
|
|
{
|
|
Awake();
|
|
}
|
|
|
|
bool isIconSpriteActive = false;
|
|
bool isBindSpriteActive = false;
|
|
bool isShowStren = false;
|
|
bool isDressEquip = false;
|
|
bool isAdd = false;
|
|
bool isNum = false;
|
|
bool isShowRedPoint = false;
|
|
bool isUnuse = false;
|
|
|
|
GetExtData = extData;
|
|
ItemInfo = good;
|
|
Num = 0;
|
|
if (_upEquipSprite != null)
|
|
_upEquipSprite.gameObject.SetActive(false);
|
|
if (_elseNum != null)
|
|
_elseNum.text = "";
|
|
if (null == good)
|
|
{
|
|
isAdd = true;
|
|
isIconSpriteActive = false;
|
|
isBindSpriteActive = false;
|
|
isShowStren = false;
|
|
string qualityName = "";
|
|
_qualtySprite.spriteName = qualityName;
|
|
_qualtySprite.gameObject.SetActive(true);
|
|
isShowRedPoint = false;
|
|
OnSetDiamondSpr(0);
|
|
OnSetEffect(0);
|
|
}
|
|
else
|
|
{
|
|
isIconSpriteActive = true;
|
|
if (good.IsBind)
|
|
{
|
|
isBindSpriteActive = true;
|
|
}
|
|
Num = (int)good.Count;
|
|
if (null != ItemInfo)
|
|
{
|
|
isUnuse = !ItemInfo.CheckCanEquip();
|
|
|
|
var qulityValue = 0;
|
|
if (ItemInfo.Type == ItemType.Equip)
|
|
{
|
|
var equipItem = ItemInfo as Equipment;
|
|
_iconSprite.UpdateIcon( equipItem.ItemInfo.Icon);
|
|
qulityValue = equipItem.ItemInfo.Quality;
|
|
|
|
OnSetEffect(equipItem.ItemInfo.Effect);
|
|
OnSetDiamondSpr(equipItem.ItemInfo.DiamondNumber);
|
|
|
|
Equipment dressEquip = GameCenter.EquipmentSystem.GetPlayerDressEquip(equipItem.ItemInfo.Part);
|
|
var backEquip = GameCenter.EquipmentSystem.GetPlayerDressBackEquip(equipItem.ItemInfo.Part);
|
|
if ((dressEquip != null && dressEquip.DBID == equipItem.DBID) || (backEquip != null && backEquip.DBID == equipItem.DBID))
|
|
{
|
|
isDressEquip = true;
|
|
}
|
|
|
|
if (equipItem.CheackOcc(GameCenter.GameSceneSystem.GetLocalPlayer().Occ) && _upEquipSprite != null)
|
|
{
|
|
uint itemFight = equipItem.Power;
|
|
uint itemFightBody = 0;
|
|
if (dressEquip != null)
|
|
{
|
|
itemFightBody = dressEquip.Power;
|
|
if (itemFight > itemFightBody && equipItem.ItemInfo.Gender == dressEquip.ItemInfo.Gender)
|
|
{
|
|
_upEquipSprite.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_upEquipSprite.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
isShowStren = true;
|
|
_levelLabel.text = DeclareMessageString.Format(DeclareMessageString.LEVEL_FOR_JIE, equipItem.ItemInfo.Grade);
|
|
}
|
|
else if (ItemInfo.Type == ItemType.HolyEquip)
|
|
{
|
|
var equipItem = ItemInfo as HolyEquip;
|
|
_iconSprite.UpdateIcon(equipItem.ItemInfo.Icon);
|
|
qulityValue = equipItem.ItemInfo.Quality;
|
|
|
|
OnSetEffect(equipItem.ItemInfo.Effect);
|
|
OnSetDiamondSpr(equipItem.ItemInfo.DiamondNumber);
|
|
|
|
var dressEquip = GameCenter.LuaSystem.Adaptor.GetDressHolyEquip(equipItem.Part);
|
|
if (dressEquip != null && dressEquip.DBID == equipItem.DBID)
|
|
{
|
|
isDressEquip = true;
|
|
}
|
|
|
|
if (equipItem.CheackOcc(GameCenter.GameSceneSystem.GetLocalPlayer().Occ) && _upEquipSprite != null)
|
|
{
|
|
uint itemFight = equipItem.Power;
|
|
uint itemFightBody = 0;
|
|
if (dressEquip != null)
|
|
{
|
|
itemFightBody = dressEquip.Power;
|
|
if (itemFight > itemFightBody && equipItem.ItemInfo.Gender == dressEquip.ItemInfo.Gender)
|
|
{
|
|
_upEquipSprite.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_upEquipSprite.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
isShowStren = true;
|
|
_levelLabel.text = DeclareMessageString.Format(DeclareMessageString.LEVEL_FOR_JIE, equipItem.ItemInfo.Grade);
|
|
}
|
|
else
|
|
{
|
|
var equipItem = ItemInfo as ItemModel;
|
|
_iconSprite.UpdateIcon(equipItem.ItemInfo.Icon);
|
|
qulityValue = equipItem.ItemInfo.Color;
|
|
long count = equipItem.Count;
|
|
if (count > 1 && _itemNum != null)
|
|
{
|
|
isNum = true;
|
|
_itemNum.text = count.ToString();
|
|
}
|
|
OnSetEffect(equipItem.ItemInfo.Effect);
|
|
OnSetDiamondSpr(0);
|
|
}
|
|
string qualityName = ItemBase.GetQualitySpriteName(qulityValue);
|
|
_qualtySprite.spriteName = qualityName;
|
|
_qualtySprite.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
|
|
_iconSprite.gameObject.SetActive(isIconSpriteActive);
|
|
_bindSprite.gameObject.SetActive(isBindSpriteActive);
|
|
_levelLabel.gameObject.SetActive(isShowStren);
|
|
if(_equipTrans != null)
|
|
{
|
|
_equipTrans.gameObject.SetActive(isDressEquip);
|
|
}
|
|
if(_equipAdd != null)
|
|
{
|
|
_equipAdd.gameObject.SetActive(isAdd);
|
|
}
|
|
if(_itemNum != null)
|
|
{
|
|
_itemNum.gameObject.SetActive(isNum);
|
|
}
|
|
if(_redTrans != null)
|
|
{
|
|
_redTrans.gameObject.SetActive(isShowRedPoint);
|
|
}
|
|
if(_unUseTrans != null)
|
|
{
|
|
_unUseTrans.gameObject.SetActive(isUnuse);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 选中道具
|
|
/// </summary>
|
|
/// <param name="isShowTips"></param>
|
|
public void SelectItem(bool isShowTips = true)
|
|
{
|
|
if (_selectSprite == null)
|
|
{
|
|
_selectSprite = transform.Find("Back/GraySelect").GetComponent<UISprite>();
|
|
}
|
|
_selectSprite.gameObject.SetActive(isShowTips);
|
|
}
|
|
|
|
public void SetUseTrans(bool isShow)
|
|
{
|
|
if (_unUseTrans != null)
|
|
{
|
|
_unUseTrans.gameObject.SetActive(isShow);
|
|
}
|
|
}
|
|
|
|
public void SetCountLabel(int count, bool isShowNum = false)
|
|
{
|
|
bool isNum = false;
|
|
if(count > 0 || isShowNum == true)
|
|
{
|
|
isNum = true;
|
|
}
|
|
if (_itemNum != null)
|
|
{
|
|
_itemNum.gameObject.SetActive(isNum);
|
|
_itemNum.text = count.ToString();
|
|
}
|
|
Num = count;
|
|
}
|
|
public void SetCountLabel(int ownCount, int needCount)
|
|
{
|
|
if(_itemNum != null)
|
|
{
|
|
_itemNum.gameObject.SetActive(true);
|
|
_itemNum.text = string.Format("{0}/{1}", ownCount, needCount);
|
|
if (ownCount < needCount)
|
|
_itemNum.color = Color.red;
|
|
else
|
|
_itemNum.color = Color.green;
|
|
}
|
|
Num = ownCount;
|
|
}
|
|
|
|
public void OnSetElseNum(int count, bool isShow = false)
|
|
{
|
|
bool isNum = false;
|
|
if (count > 0 || isShow == true)
|
|
{
|
|
isNum = true;
|
|
}
|
|
else
|
|
{
|
|
_elseNum.gameObject.SetActive(false);
|
|
}
|
|
if (_elseNum != null)
|
|
{
|
|
_elseNum.gameObject.SetActive(isNum);
|
|
_elseNum.GetComponent<UILabel>().text = string.Format("+{0}", count);
|
|
}
|
|
}
|
|
|
|
public bool IsSelect()
|
|
{
|
|
if (_selectSprite != null)
|
|
return _selectSprite.gameObject.activeSelf;
|
|
return false;
|
|
}
|
|
|
|
public void OnLock(bool isLock)
|
|
{
|
|
if(_lockTrans != null)
|
|
{
|
|
_lockTrans.gameObject.SetActive(isLock);
|
|
}
|
|
}
|
|
|
|
public void OnSetRedPoint(bool isShow)
|
|
{
|
|
if(_redTrans != null)
|
|
{
|
|
_redTrans.gameObject.SetActive(isShow);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 私有接口
|
|
/// <summary>
|
|
/// 设置特效图片,图片特效及帧动画
|
|
/// </summary>
|
|
/// <param name="effectID"></param>
|
|
private void OnSetEffect(int effectID)
|
|
{
|
|
if (_effectSprite != null)
|
|
_effectSprite.gameObject.SetActive(false);
|
|
if (_effectAni != null)
|
|
_effectAni.gameObject.SetActive(false);
|
|
if (effectID == 1 && _effectSprite != null)
|
|
{
|
|
_effectSprite.gameObject.SetActive(true);
|
|
}
|
|
else if (effectID == 2 && _effectAni != null)
|
|
{
|
|
_effectAni.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置钻石图片
|
|
/// </summary>
|
|
/// <param name="diaNum"></param>
|
|
private void OnSetDiamondSpr(int diaNum)
|
|
{
|
|
if (_diamondGrid == null)
|
|
return;
|
|
for (int i = 0; i < _diamondGrid.transform.childCount; i++)
|
|
{
|
|
_diamondGrid.transform.GetChild(i).gameObject.SetActive(false);
|
|
}
|
|
if (diaNum > 0)
|
|
{
|
|
for (int i = 0; i < diaNum; i++)
|
|
{
|
|
if (_diamondGrid.transform.childCount <= i)
|
|
{
|
|
var obj = NGUITools.AddChild(_diamondGrid.gameObject, _diamondGrid.transform.GetChild(0).gameObject);
|
|
obj.SetActive(true);
|
|
}
|
|
else
|
|
_diamondGrid.transform.GetChild(i).gameObject.SetActive(true);
|
|
}
|
|
_diamondGrid.repositionNow = true;
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|