247 lines
7.8 KiB
C#
247 lines
7.8 KiB
C#
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
using UnityEngine.EventSystems;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using GCGame.Table;
|
|||
|
using Games.Events;
|
|||
|
|
|||
|
public class ShowItemSameUseTip : MonoBehaviour {
|
|||
|
|
|||
|
public GameObject ItemObj;
|
|||
|
public GameObject _ExpItemPanel;
|
|||
|
|
|||
|
private static ShowItemSameUseTip m_Instance;
|
|||
|
public static ShowItemSameUseTip Instance()
|
|||
|
{
|
|||
|
return m_Instance;
|
|||
|
}
|
|||
|
|
|||
|
public void Awake()
|
|||
|
{
|
|||
|
m_Instance = this;
|
|||
|
|
|||
|
Hashtable calbackMoveparam = new Hashtable();
|
|||
|
calbackMoveparam["name"] = "Fresh";
|
|||
|
MessageEventCallBack fun = Fresh;
|
|||
|
calbackMoveparam.Add("callFun", fun);
|
|||
|
Games.Events.EventDispatcher.Instance.AddMessageEvent(Games.Events.EventId.FRESHSAMEUSETIP, calbackMoveparam);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
public void OnDestory()
|
|||
|
{
|
|||
|
m_Instance = null;
|
|||
|
Games.Events.EventDispatcher.Instance.RemoveMessage(Games.Events.EventId.FRESHSAMEUSETIP, "Fresh");
|
|||
|
}
|
|||
|
|
|||
|
public static void ShowToolTips(int classId, int subclassId,Vector3 showPos)
|
|||
|
{
|
|||
|
Hashtable hash = new Hashtable();
|
|||
|
hash.Add("ClassId", classId);
|
|||
|
hash.Add("SubClassId", subclassId);
|
|||
|
hash.Add("ShowPos", showPos);
|
|||
|
|
|||
|
UIManager.ShowUI(UIInfo.ShowItemSameUseTip, ShowItemSameUseTip.OnShowItemTip, hash);
|
|||
|
}
|
|||
|
|
|||
|
private static void OnShowItemTip(bool bSuccess, object param)
|
|||
|
{
|
|||
|
if (!bSuccess)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
Hashtable hash = param as Hashtable;
|
|||
|
if (hash == null)
|
|||
|
return;
|
|||
|
|
|||
|
ShowItemSameUseTip.Instance().AddItemToList((int)hash["ClassId"], (int)hash["SubClassId"], (Vector3)hash["ShowPos"]);
|
|||
|
}
|
|||
|
|
|||
|
public void AddItemToList(int classType,int subClassType,Vector3 pos)
|
|||
|
{
|
|||
|
_ExpItemPanel.SetActive(subClassType == 1);
|
|||
|
transform.position = pos;
|
|||
|
foreach(var ItemObj in m_ItemObjs)
|
|||
|
{
|
|||
|
if(ItemObj.Value!=null)
|
|||
|
{
|
|||
|
ItemObj.Value.transform.SetParent(null);
|
|||
|
ItemObj.Value.SetActive(false);
|
|||
|
GameObject.Destroy(ItemObj.Value);
|
|||
|
}
|
|||
|
}
|
|||
|
m_ItemObjs.Clear();
|
|||
|
var sameUses = TableManager.GetItemSameUse().Values;
|
|||
|
foreach(var item in sameUses)
|
|||
|
{
|
|||
|
if(item.ClassID == classType && item.SubClassID == subClassType)
|
|||
|
{
|
|||
|
CloneNewItem(item);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private Dictionary<int, GameObject> m_ItemObjs = new Dictionary<int, GameObject>();
|
|||
|
|
|||
|
public void Fresh(Hashtable addparam, Hashtable sendparam)
|
|||
|
{
|
|||
|
foreach(var ItemObj in m_ItemObjs)
|
|||
|
{
|
|||
|
if (ItemObj.Value == null)
|
|||
|
continue;
|
|||
|
int hasCount = GameManager.gameManager.PlayerDataPool.BackPack.GetItemCountByDataId(ItemObj.Key);
|
|||
|
Transform num = ItemObj.Value.transform.Find("num");
|
|||
|
Transform enough = ItemObj.Value.transform.Find("enough");
|
|||
|
if (enough != null)
|
|||
|
{
|
|||
|
enough.gameObject.SetActive(hasCount <= 0);
|
|||
|
}
|
|||
|
if (num != null)
|
|||
|
{
|
|||
|
Text numText = num.gameObject.GetComponent<Text>();
|
|||
|
if (numText != null)
|
|||
|
{
|
|||
|
numText.text = hasCount.ToString();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
public void CloneNewItem(Tab_ItemSameUse item)
|
|||
|
{
|
|||
|
if (item == null)
|
|||
|
return;
|
|||
|
Tab_CommonItem commonItem = TableManager.GetCommonItemByID(item.Id, 0);
|
|||
|
if (commonItem == null)
|
|||
|
return;
|
|||
|
GameObject petObj = UnityEngine.Object.Instantiate(ItemObj) as GameObject;
|
|||
|
if (petObj == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
petObj.transform.parent = ItemObj.transform.parent;
|
|||
|
petObj.transform.localEulerAngles = ItemObj.transform.localEulerAngles;
|
|||
|
petObj.transform.localScale = ItemObj.transform.localScale;
|
|||
|
petObj.SetActive(true);
|
|||
|
Transform name = petObj.transform.Find("Name");
|
|||
|
if(name!=null)
|
|||
|
{
|
|||
|
Text nameText = name.gameObject.GetComponent<Text>();
|
|||
|
if(nameText!=null)
|
|||
|
{
|
|||
|
nameText.text = item.Name;
|
|||
|
}
|
|||
|
}
|
|||
|
Transform Desc = petObj.transform.Find("Info");
|
|||
|
if (Desc != null)
|
|||
|
{
|
|||
|
Text DescText = Desc.gameObject.GetComponent<Text>();
|
|||
|
if (DescText != null)
|
|||
|
{
|
|||
|
DescText.text = item.Tips;
|
|||
|
}
|
|||
|
}
|
|||
|
Transform Quility = petObj.transform.Find("Quility");
|
|||
|
if (Quility != null)
|
|||
|
{
|
|||
|
Image QuilityImgae = Quility.gameObject.GetComponent<Image>();
|
|||
|
if (QuilityImgae != null)
|
|||
|
{
|
|||
|
LoadAssetBundle.Instance.SetImageSprite(QuilityImgae, GCGame.Utils.GetItemQualityFrame(commonItem));
|
|||
|
}
|
|||
|
}
|
|||
|
Transform head = petObj.transform.Find("headIcon");
|
|||
|
if (head != null)
|
|||
|
{
|
|||
|
Image headImgae = head.gameObject.GetComponent<Image>();
|
|||
|
if (headImgae != null)
|
|||
|
{
|
|||
|
LoadAssetBundle.Instance.SetImageSprite(headImgae, item.Icon);
|
|||
|
}
|
|||
|
}
|
|||
|
int hasCount = GameManager.gameManager.PlayerDataPool.BackPack.GetItemCountByDataId(item.Id);
|
|||
|
Transform num = petObj.transform.Find("num");
|
|||
|
Transform enough = petObj.transform.Find("enough");
|
|||
|
if(enough!=null)
|
|||
|
{
|
|||
|
enough.gameObject.SetActive(hasCount <= 0);
|
|||
|
}
|
|||
|
if (num != null)
|
|||
|
{
|
|||
|
Text numText = num.gameObject.GetComponent<Text>();
|
|||
|
if (numText != null)
|
|||
|
{
|
|||
|
numText.text = hasCount.ToString();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
Transform back = petObj.transform.Find("back");
|
|||
|
if(back!=null)
|
|||
|
{
|
|||
|
Hashtable table = new Hashtable();
|
|||
|
table["itemId"] = item.Id;
|
|||
|
//EventTriggerListener.Get(back.gameObject, table).onClick = ClickEvent;
|
|||
|
EventTriggerListener.Get(back.gameObject, table).onPress = OnPressEvent;
|
|||
|
}
|
|||
|
m_ItemObjs[item.Id] = petObj;
|
|||
|
}
|
|||
|
|
|||
|
public void ClickEvent(GameObject go, BaseEventData eventData, Hashtable table)
|
|||
|
{
|
|||
|
if(table!=null && table.ContainsKey("itemId"))
|
|||
|
{
|
|||
|
UseItem((int)table["itemId"]);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private float lastUpTime = 0.0f;
|
|||
|
public void OnPressEvent(GameObject go, BaseEventData eventData, Hashtable table)
|
|||
|
{
|
|||
|
if (Time.time - lastUpTime < 0.2f)
|
|||
|
return;
|
|||
|
if (table != null && table.ContainsKey("itemId"))
|
|||
|
{
|
|||
|
UseItem((int)table["itemId"]);
|
|||
|
lastUpTime = Time.time;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void UseItem(int itemId)
|
|||
|
{
|
|||
|
int hasCount = GameManager.gameManager.PlayerDataPool.BackPack.GetItemCountByDataId(itemId);
|
|||
|
if (hasCount <= 0)
|
|||
|
{
|
|||
|
ItemTooltipsLogic.ShowItemTooltip(itemId, ItemTooltipsLogic.ShowType.GetPath, transform.position);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Games.Item.GameItem gameItem = GameManager.gameManager.PlayerDataPool.BackPack.GetItemByDataID(itemId);
|
|||
|
if (gameItem != null)
|
|||
|
{
|
|||
|
if (gameItem.GetClass() == (int)Games.Item.ItemClass.FELLOW)
|
|||
|
{
|
|||
|
if (null != Singleton<ObjManager>.Instance.MainPlayer &&
|
|||
|
Singleton<ObjManager>.Instance.MainPlayer.CheckUseItem(gameItem))
|
|||
|
{
|
|||
|
Singleton<ObjManager>.Instance.MainPlayer.UseItem(gameItem);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void Close()
|
|||
|
{
|
|||
|
UIManager.CloseUI(UIInfo.ShowItemSameUseTip);
|
|||
|
}
|
|||
|
|
|||
|
public void OnOperationBtn(int operationIndex)
|
|||
|
{
|
|||
|
CG_REQ_TOPFELLOW req = (CG_REQ_TOPFELLOW)PacketDistributed.CreatePacket(MessageID.PACKET_CG_REQ_TOPFELLOW);
|
|||
|
req.Operation = operationIndex;
|
|||
|
req.SendPacket();
|
|||
|
}
|
|||
|
}
|