376 lines
10 KiB
C#
376 lines
10 KiB
C#
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System.Collections;
|
|
using GCGame.Table;
|
|
using Games.Mission;
|
|
using Games.Events;
|
|
using Games.Item;
|
|
using Games.GlobeDefine;
|
|
using UnityEngine.EventSystems;
|
|
|
|
public class CommonItemBackPackItem : UIItemSelect, IPointerDownHandler, IPointerUpHandler
|
|
{
|
|
#region
|
|
|
|
public class BackPackItem
|
|
{
|
|
public GameItem GameItem;
|
|
public bool IsPosLock;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region
|
|
|
|
void Update()
|
|
{
|
|
HoldUpdate();
|
|
UpdateCDIcon();
|
|
}
|
|
|
|
#endregion
|
|
|
|
public GameObject _ImgLock;
|
|
public CommonItemTipsSlot _ItemSlot;
|
|
public Text _ItemCount;
|
|
public GameObject _CantSellGO;
|
|
public GameObject _CanSellToggle;
|
|
public GameObject _NormalSelectGO;
|
|
public GameObject _SellSelectGO;
|
|
|
|
public BackPackItem _ItemBackPack;
|
|
|
|
public Image _ItemCDIcon;
|
|
|
|
private bool _IsInSell = false;
|
|
private float itemTotalCdTime = 0.0f;
|
|
private float itemCdRemainTime = 0.0f;
|
|
|
|
public override void Show(Hashtable hash)
|
|
{
|
|
base.Show();
|
|
|
|
var itemInfo = (BackPackItem)hash["InitObj"];
|
|
InitItem(itemInfo);
|
|
}
|
|
|
|
public override void Refresh()
|
|
{
|
|
base.Refresh();
|
|
InitItem(_ItemBackPack);
|
|
}
|
|
|
|
public override void Selected()
|
|
{
|
|
bool isSelect = _SelectGO.activeSelf;
|
|
|
|
if(_IsInSell && !isSelect)
|
|
{
|
|
if(_ItemBackPack.GameItem.CanSell() == false)
|
|
{
|
|
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{8902}"));
|
|
return;
|
|
}
|
|
|
|
if (_ItemBackPack != null && BackPackLogic.Instance() != null && BackPackLogic.Instance().gameObject.activeInHierarchy)
|
|
BackPackLogic.Instance().AddAnalyGameItem(_ItemBackPack.GameItem);
|
|
}
|
|
base.Selected();
|
|
}
|
|
|
|
public override void UnSelected()
|
|
{
|
|
bool isSelect = _SelectGO.activeSelf;
|
|
base.UnSelected();
|
|
if (_IsInSell && isSelect)
|
|
{
|
|
if (_IsInSell)
|
|
{
|
|
if (_ItemBackPack != null && BackPackLogic.Instance() != null && BackPackLogic.Instance().gameObject.activeInHierarchy)
|
|
BackPackLogic.Instance().DelAnalyGameItem(_ItemBackPack.GameItem);
|
|
}
|
|
}
|
|
}
|
|
|
|
public override bool IsCanSelect()
|
|
{
|
|
if(_IsInSell)
|
|
{
|
|
return (_ItemBackPack.GameItem != null && _ItemBackPack.GameItem.IsValid() && _ItemBackPack.IsPosLock == false);
|
|
}
|
|
else
|
|
{
|
|
return ((_ItemBackPack.GameItem != null && _ItemBackPack.GameItem.IsValid()) || _ItemBackPack.IsPosLock == true);
|
|
}
|
|
}
|
|
|
|
void InitItem(BackPackItem itemParam)
|
|
{
|
|
_ItemBackPack = itemParam;
|
|
|
|
if (_ItemBackPack.GameItem != null && _ItemBackPack.GameItem.IsValid())
|
|
{
|
|
_ItemSlot.InitItem(_ItemBackPack.GameItem);
|
|
if (_ItemBackPack.GameItem.StackCount > 1)
|
|
{
|
|
_ItemCount.text = _ItemBackPack.GameItem.StackCount.ToString();
|
|
}
|
|
else
|
|
{
|
|
_ItemCount.text = "";
|
|
}
|
|
_ImgLock.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
_ItemSlot.InitItem(null);
|
|
|
|
_ItemCount.text = "";
|
|
|
|
if (_ItemBackPack.IsPosLock)
|
|
{
|
|
_ImgLock.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
_ImgLock.SetActive(false);
|
|
}
|
|
}
|
|
|
|
ShowSell(_IsInSell);
|
|
RefreshItemCD();
|
|
GetItemRemainCDTime();
|
|
UpdateEquipCombat();
|
|
}
|
|
|
|
public void ShowSell(bool isShow)
|
|
{
|
|
_IsInSell = isShow;
|
|
if (isShow && _ItemBackPack.GameItem != null && _ItemBackPack.GameItem.IsValid())
|
|
{
|
|
if (_ItemBackPack.GameItem.CanSell())
|
|
{
|
|
_CantSellGO.SetActive(false);
|
|
_CanSellToggle.SetActive(true);
|
|
_SelectGO = _SellSelectGO;
|
|
}
|
|
else
|
|
{
|
|
_CantSellGO.SetActive(true);
|
|
_CanSellToggle.SetActive(false);
|
|
_SelectGO = _SellSelectGO;
|
|
}
|
|
if (BackPackLogic.Instance() != null
|
|
&& BackPackLogic.Instance()._AnalyzeGame != null
|
|
&& BackPackLogic.Instance()._AnalyzeGame.IsInAnalyze(_ItemBackPack.GameItem))
|
|
_SelectGO.SetActive(true);
|
|
else
|
|
_SelectGO.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
_CantSellGO.SetActive(false);
|
|
_CanSellToggle.SetActive(false);
|
|
_SelectGO = _NormalSelectGO;
|
|
}
|
|
}
|
|
Tab_UsableItem usabItem = new Tab_UsableItem();
|
|
public void GetItemRemainCDTime()
|
|
{
|
|
|
|
if (_ItemBackPack.GameItem == null)
|
|
{
|
|
itemCdRemainTime = 0;
|
|
return;
|
|
}
|
|
|
|
if(itemCdRemainTime > 0) //处于CD中就不再判断
|
|
{
|
|
return;
|
|
}
|
|
|
|
itemCdRemainTime = 0.0f; //每次重置,重新计算
|
|
|
|
if (_ItemBackPack.GameItem != null && _ItemBackPack.GameItem.IsValid())
|
|
{
|
|
if (ItemCDInfoCtr.GetItemCDRemainTime(_ItemBackPack.GameItem.DataID) > 0)
|
|
{
|
|
if(!_ItemCDIcon.gameObject.activeInHierarchy)
|
|
_ItemCDIcon.gameObject.SetActive(true);
|
|
itemCdRemainTime = ItemCDInfoCtr.GetItemCDRemainTime(_ItemBackPack.GameItem.DataID);
|
|
|
|
usabItem = TableManager.GetUsableItemByID(_ItemBackPack.GameItem.DataID, 0);
|
|
|
|
if(usabItem == null)
|
|
{
|
|
itemCdRemainTime = 0;
|
|
return;
|
|
}
|
|
|
|
Tab_CoolDownTime coolDownTime = TableManager.GetCoolDownTimeByID(usabItem.CoolDownId, 0);
|
|
if(coolDownTime == null)
|
|
{
|
|
itemCdRemainTime = 0;
|
|
return;
|
|
}
|
|
itemTotalCdTime = coolDownTime.CDTime / 1000;
|
|
}
|
|
else
|
|
{
|
|
if (_ItemCDIcon.gameObject.activeInHierarchy)
|
|
_ItemCDIcon.gameObject.SetActive(false);
|
|
itemCdRemainTime = 0.0f;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void RefreshItemCD()
|
|
{
|
|
itemCdRemainTime = 0.0f;
|
|
GetItemRemainCDTime();
|
|
}
|
|
|
|
void UpdateCDIcon()
|
|
{
|
|
|
|
if (usabItem != null && GameManager.gameManager.m_RunningScene == 658 && usabItem.DrugType == 1)
|
|
{
|
|
_ItemCDIcon.gameObject.SetActive(false);
|
|
return; // 在紫禁之巅关闭CD
|
|
}
|
|
if (_ItemBackPack == null || _ItemBackPack.GameItem == null)
|
|
{
|
|
if (_ItemCDIcon != null && _ItemCDIcon.gameObject.activeInHierarchy)
|
|
{
|
|
_ItemCDIcon.gameObject.SetActive(false);
|
|
}
|
|
return;
|
|
}
|
|
if(_ItemBackPack.GameItem.DataID <= 0)
|
|
{
|
|
if (_ItemCDIcon.gameObject.activeInHierarchy)
|
|
{
|
|
_ItemCDIcon.gameObject.SetActive(false);
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (itemCdRemainTime > 0)
|
|
{
|
|
if (!_ItemCDIcon.gameObject.activeInHierarchy)
|
|
{
|
|
_ItemCDIcon.gameObject.SetActive(true);
|
|
}
|
|
itemCdRemainTime -= Time.deltaTime;
|
|
_ItemCDIcon.fillAmount = itemCdRemainTime / itemTotalCdTime;
|
|
}
|
|
else
|
|
{
|
|
if (itemCdRemainTime <= 0 && _ItemCDIcon.gameObject.activeInHierarchy)
|
|
{
|
|
_ItemCDIcon.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
#region hold btn
|
|
|
|
private bool _IsPointDown = false;
|
|
private const float _HoldTime = 1.0f;
|
|
private float _HoldStart = 0.0f;
|
|
|
|
public void OnPointerDown(PointerEventData eventData)
|
|
{
|
|
if (!_IsInSell)
|
|
return;
|
|
|
|
_IsPointDown = true;
|
|
_HoldStart = Time.time;
|
|
}
|
|
|
|
public void OnPointerUp(PointerEventData eventData)
|
|
{
|
|
_IsPointDown = false;
|
|
_HoldStart = 0;
|
|
}
|
|
|
|
public void HoldUpdate()
|
|
{
|
|
if (_IsPointDown)
|
|
{
|
|
if (_HoldStart > 0 && Time.time - _HoldStart >= _HoldTime)
|
|
{
|
|
ShowTooltips();
|
|
_HoldStart = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ShowTooltips()
|
|
{
|
|
if (_ItemBackPack.GameItem != null && _ItemBackPack.GameItem.IsValid())
|
|
{
|
|
if (_ItemBackPack.GameItem.IsEquipMent())
|
|
{
|
|
EquipTooltipsLogic.ShowEquipTooltip(_ItemBackPack.GameItem, ItemTooltipsLogic.ShowType.Info, transform.position);
|
|
|
|
}
|
|
else
|
|
{
|
|
ItemTooltipsLogic.ShowItemTooltip(_ItemBackPack.GameItem, ItemTooltipsLogic.ShowType.Info, transform.position);
|
|
|
|
}
|
|
}
|
|
}
|
|
private void OnDisable()
|
|
{
|
|
itemCdRemainTime = 0.0f;
|
|
}
|
|
#endregion
|
|
|
|
#region equip combat
|
|
|
|
public GameObject _EquipHeightCombat;
|
|
|
|
public void UpdateEquipCombat()
|
|
{
|
|
_EquipHeightCombat.gameObject.SetActive(false);
|
|
if (_ItemBackPack.GameItem == null)
|
|
return;
|
|
|
|
if (!_ItemBackPack.GameItem.IsValid())
|
|
return;
|
|
|
|
if (!_ItemBackPack.GameItem.IsEquipMent())
|
|
return;
|
|
|
|
int equipProfession = _ItemBackPack.GameItem.GetProfessionRequire();
|
|
if (equipProfession > 0)
|
|
{
|
|
int nPlayerProfession = GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Profession;
|
|
if (((equipProfession >> nPlayerProfession) & 1) == 0)
|
|
{
|
|
//Singleton<ObjManager>.GetInstance().MainPlayer.SendNoticMsg(false, "#{1256}");
|
|
//GUIData.AddNotifyData2Client(false, "#{1256}");
|
|
return;
|
|
}
|
|
}
|
|
|
|
int slot = _ItemBackPack.GameItem.GetEquipSlotIndex();
|
|
var usingEuip = GameManager.gameManager.PlayerDataPool.EquipPack.Items[slot];
|
|
bool isHeight = false;
|
|
if (!usingEuip.IsValid())
|
|
isHeight = true;
|
|
if(_ItemBackPack.GameItem.BaseCombat > usingEuip.BaseCombat)
|
|
isHeight = true;
|
|
|
|
if (isHeight)
|
|
{
|
|
_EquipHeightCombat.SetActive(true);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|