Files
JJBB/Assets/Project/Script/GUI/StroyCopy/DailyCopyUseItem.cs

214 lines
6.5 KiB
C#
Raw Normal View History

2024-08-23 15:49:34 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using GCGame.Table;
using Module.Log;
using GCGame;
using Games.Events;
public class DailyCopyUseItem : UIItemBase {
public Image icon;
public Image quality;
public Text num;
public Text itemName;
public Text itemDesc;
public Button useBtn;
private int itemID = -1;
private int itemNum = 0;
public override void Init()
{
useBtn.onClick.RemoveAllListeners();
useBtn.onClick.AddListener(OnUseBtnClick);
//title.text = StrDictionary.GetClientDictionaryString("#{}");
//tip.text = StrDictionary.GetClientDictionaryString("#{}");
//title.text = "标题未配置";
//tip.text = "描述未配置";
}
public override void Show(Hashtable hash)
{
itemID = (int)hash["InitObj"];
//itemNum = ObjManager.GetInstance
itemNum = GameManager.gameManager.PlayerDataPool.BackPack.GetItemCountByDataId(itemID);
ShowInfo(itemID);
base.Show(hash);
}
#region
private void OnEnable()
{
EventDispatcher.Instance.Remove(Games.Events.EventId.FRESHSAMEUSETIP, OnItemUpdate);
EventDispatcher.Instance.Add(Games.Events.EventId.FRESHSAMEUSETIP, OnItemUpdate);
}
private void OnDisable()
{
EventDispatcher.Instance.Remove(Games.Events.EventId.FRESHSAMEUSETIP, OnItemUpdate);
}
#endregion
private void OnItemUpdate(object args)
{
itemNum = GameManager.gameManager.PlayerDataPool.BackPack.GetItemCountByDataId(itemID);
SetItemNum(itemNum);
}
public void ShowInfo(int id)
{
Tab_CommonItem commonItem = TableManager.GetCommonItemByID(itemID, 0);
if (commonItem != null)
{
SetItemNum(itemNum);
itemName.text = Utils.GetItemNameColor(itemID);
itemDesc.text = commonItem.Tips.Replace("#r", "\n");
LoadAssetBundle.Instance.SetImageSprite(icon, commonItem.Icon);
LoadAssetBundle.Instance.SetImageSprite(quality, GCGame.Utils.GetItemQualityFrame(commonItem));
if (commonItem.QualityEffect > 0)
{
CommonItemContainerItem.ShowQualityEffect(true, commonItem.QualityEffect, icon.transform);
}
else
{
CommonItemContainerItem.ShowQualityEffect(false, commonItem.QualityEffect, icon.transform);
}
}
else
{
LogModule.ErrorLog("Can't Show Item, commonitem is null");
}
}
public void OnUseBtnClick()
{
if (itemNum > 0)
{
//var useitem = (CG_USE_ITEM)PacketDistributed.CreatePacket(MessageID.PACKET_CG_USE_ITEM);
//ulong itemGuid = GameManager.gameManager.PlayerDataPool.BackPack.GetItemGuidByDataID(itemID);
//useitem.SetItemguid(itemGuid);
//useitem.SendPacket();
Games.Item.GameItem gameItem = GameManager.gameManager.PlayerDataPool.BackPack.GetItemByDataID(itemID);
ItemTooltipsLogic.UseGameProp(gameItem);
}
else
{
Tab_ItemGetPath tab = TableManager.GetItemGetPathByID(itemID, 0);
if (tab != null)
{
ItemGetPathPopRoot.Show(itemID, transform.position);
//string path_0 = tab.GetItemPathbyIndex(0).Trim(' ', '\'', '"');
//string path_1 = tab.GetItemPathbyIndex(1).Trim(' ', '\'', '"');
//string path_2 = tab.GetItemPathbyIndex(2).Trim(' ', '\'', '"');
//int t = -1;
//string jumpInfo = "";
//if (path_0 != "-1")
//{
// t = 0;
// jumpInfo = path_0;
//}
//else if (path_1 != "-1")
//{
// t = 1;
// jumpInfo = path_1;
//}
//else if (path_2 != "-1")
//{
// t = 2;
// jumpInfo = path_2;
//}
//ItemGetPathPopRoot.GetPathData getPathInfo = GetItemGetPath(t, jumpInfo);
//if (getPathInfo != null)
//{
// ItemGetPathPopRoot.GoGetPath(getPathInfo);
//}
//else
//{
// LogModule.ErrorLog("Can get get path info");
//}
}
else
{
//GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{}"));
GUIData.AddNotifyData("未配置");
}
}
}
public ItemGetPathPopRoot.GetPathData GetItemGetPath(int t, string param)
{
switch(t)
{
case 0:
{
// 以上为只会有一种情况的路径
ItemGetPathPopRoot.GetPathData pathInfo = new ItemGetPathPopRoot.GetPathData();
pathInfo.pathType = 0;
pathInfo.info = param;
pathInfo.itemID = itemID;
return pathInfo;
}
case 1:
case 2:
{
// 多种情况的路径
string[] infos = param.Split('|');
ItemGetPathPopRoot.GetPathData pathInfo = new ItemGetPathPopRoot.GetPathData();
for (int j = 0; j < infos.Length; ++j)
{
pathInfo.pathType = t;
pathInfo.info = param;
pathInfo.itemID = itemID;
}
return pathInfo;
}
}
return null;
}
private void SetItemNum(int count)
{
string s = Utils.ConvertLargeNumToString(itemNum);
if (count > 0)
{
num.text = s;
L_getBtn.SetActive(false);
}
else
{
num.text = StrDictionary.GetClientDictionaryString("#{51916}", s);
L_getBtn.SetActive(true);
}
}
public override void OnItemClick()
{
ItemTooltipsLogic.ShowItemTooltip(itemID, ItemTooltipsLogic.ShowType.GetPath, this.transform.position);
base.OnItemClick();
}
#region "去获取"
public GameObject L_getBtn;
public void L_OnItemGetBtn()
{
ItemTooltipsLogic.ShowItemTooltip(itemID, ItemTooltipsLogic.ShowType.GetPath, this.transform.position);
}
#endregion
}