Files
JJBB/Assets/Project/Script/GUI/WorldBoss/SceneItemUse.cs
2024-08-23 15:49:34 +08:00

113 lines
3.4 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using GCGame.Table;
using Games.Mission;
using Module.Log;
//世界BOSS和BOSS之家的副本也用这个UI显示
public class SceneItemUse : MonoBehaviour {
private int ItemID1 = -1;
private int ItemID2 = -1;
public UIImgText UIImgText1;
public UIImgText UIImgText2;
private void Awake()
{
Games.Events.EventDispatcher.Instance.Add(Games.Events.EventId.FRESHSAMEUSETIP, AfterUseItem);
UIImgText1._TextAnchor = TextAnchor.MiddleCenter;
UIImgText2._TextAnchor = TextAnchor.MiddleCenter;
}
private void OnDestroy()
{
Games.Events.EventDispatcher.Instance.Remove(Games.Events.EventId.FRESHSAMEUSETIP, AfterUseItem);
}
void AfterUseItem(object obj)
{
OnEnable();
}
private void OnEnable()
{
ItemID1 = SystemParam.GetSystemParam_INT(60);
ItemID2 = SystemParam.GetSystemParam_INT(61);
Tab_ItemGetPath tab_ItemGetPath = TableManager.GetItemGetPathByID(ItemID1, 0);
UIImgText1.transform.parent.gameObject.SetActive(tab_ItemGetPath != null);
tab_ItemGetPath = TableManager.GetItemGetPathByID(ItemID2, 0);
UIImgText2.transform.parent.gameObject.SetActive(tab_ItemGetPath != null);
int Count = GameManager.gameManager.PlayerDataPool.BackPack.GetItemCountByDataId(ItemID1);
if (Count > 0)
{
UIImgText1.text = "X" + Count.ToString();
}
else
{
UIImgText1.text = "D0";
}
Count = GameManager.gameManager.PlayerDataPool.BackPack.GetItemCountByDataId(ItemID2);
if (Count > 0)
{
UIImgText2.text = "X" + Count.ToString();
}
else
{
UIImgText2.text = "D0";
}
}
public void Click_Item1()
{
UsItem(ItemID1);
}
public void Click_Item2()
{
UsItem(ItemID2);
}
public void UsItem(int ItemID)
{
Games.Item.GameItem gameItem = GameManager.gameManager.PlayerDataPool.BackPack.GetItemByDataID(ItemID);
if (gameItem == null)
{
Tab_CommonItem tab_CommonItem = TableManager.GetCommonItemByID(ItemID, 0);
if (tab_CommonItem == null)
return;
int itemID = ItemID;
MessageBoxLogic.OpenOKCancelBox(StrDictionary.GetClientDictionaryString("#{4961}", tab_CommonItem.Name), "", delegate()
{
Tab_ItemGetPath tab_ItemGetPath = TableManager.GetItemGetPathByID(itemID, 0);
if (tab_ItemGetPath == null)
return;
for (int i = 0; i < tab_ItemGetPath.getItemPathCount(); i++)
{
string pathInfo = tab_ItemGetPath.GetItemPathbyIndex(i);
if (string.IsNullOrEmpty(pathInfo) || pathInfo == "-1")
continue;
ItemGetPathPopRoot.GetPathData getPathData = new ItemGetPathPopRoot.GetPathData();
getPathData.pathType = i;
getPathData.info = pathInfo.Trim('"');
getPathData.itemID = itemID;
ItemGetPathPopRoot.GoGetPath(getPathData);
return;
}
});
}
else
{
ItemTooltipsLogic.ItemUse(gameItem);
}
}
}