180 lines
5.5 KiB
C#
180 lines
5.5 KiB
C#
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using Games.GlobeDefine;
|
|||
|
using GCGame.Table;
|
|||
|
using GCGame;
|
|||
|
using Games.Item;
|
|||
|
|
|||
|
public class GiftWordsRoot : MonoBehaviour
|
|||
|
{
|
|||
|
private Dictionary<int, int> m_dialogs = new Dictionary<int, int>()
|
|||
|
{
|
|||
|
{1,5129 },
|
|||
|
{2,5130 },
|
|||
|
{3,5131 },
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
public GameObject cloneBnt;
|
|||
|
public InputField inputDialog;
|
|||
|
|
|||
|
int m_selectIndex = 1;
|
|||
|
GameItem m_gameItem;
|
|||
|
|
|||
|
|
|||
|
void Awake()
|
|||
|
{
|
|||
|
Hashtable add = new Hashtable();
|
|||
|
add["name"] = "UseItemDialog";
|
|||
|
Games.Events.MessageEventCallBack call = OnOpen;
|
|||
|
add["callFun"] = call;
|
|||
|
Games.Events.EventDispatcher.Instance.AddMessageEvent(Games.Events.EventId.OpenUseItemWithDialogWnd, add);
|
|||
|
|
|||
|
Hashtable add1 = new Hashtable();
|
|||
|
add1["name"] = "SendChatTo";
|
|||
|
Games.Events.MessageEventCallBack call1 = SendChatTo;
|
|||
|
add1["callFun"] = call1;
|
|||
|
Games.Events.EventDispatcher.Instance.AddMessageEvent(Games.Events.EventId.SendMailInfoChatLink, add1);
|
|||
|
}
|
|||
|
|
|||
|
public void OnOpen(Hashtable addparam, Hashtable sendparam)
|
|||
|
{
|
|||
|
if (sendparam == null)
|
|||
|
return;
|
|||
|
if (sendparam.ContainsKey("item") == false)
|
|||
|
return;
|
|||
|
GameItem item = (GameItem)sendparam["item"];
|
|||
|
if(item==null)
|
|||
|
{
|
|||
|
UIManager.CloseUI(UIInfo.GiftWordsRoot);
|
|||
|
return;
|
|||
|
}
|
|||
|
m_gameItem = item;
|
|||
|
int i = 0;
|
|||
|
int firstkey = 0;
|
|||
|
foreach (var dialog in m_dialogs)
|
|||
|
{
|
|||
|
if (i == 0)
|
|||
|
firstkey = dialog.Key;
|
|||
|
i++;
|
|||
|
ClonedialogBtn(dialog.Key);
|
|||
|
}
|
|||
|
SelectDialog(firstkey);
|
|||
|
}
|
|||
|
|
|||
|
void OnDestroy()
|
|||
|
{
|
|||
|
Games.Events.EventDispatcher.Instance.RemoveMessage(Games.Events.EventId.OpenUseItemWithDialogWnd, "UseItemDialog");
|
|||
|
Games.Events.EventDispatcher.Instance.RemoveMessage(Games.Events.EventId.SendMailInfoChatLink, "SendChatTo");
|
|||
|
}
|
|||
|
|
|||
|
void ClonedialogBtn(int index)
|
|||
|
{
|
|||
|
if (cloneBnt == null)
|
|||
|
return;
|
|||
|
GameObject btnObj = Object.Instantiate(cloneBnt) as GameObject;
|
|||
|
if (btnObj == null)
|
|||
|
return;
|
|||
|
btnObj.SetActive(true);
|
|||
|
btnObj.transform.parent = cloneBnt.transform.parent;
|
|||
|
btnObj.transform.localPosition = Vector3.zero;
|
|||
|
btnObj.transform.localScale = cloneBnt.transform.localScale;
|
|||
|
|
|||
|
Text ms = btnObj.GetComponentInChildren<Text>();
|
|||
|
if(ms!=null)
|
|||
|
{
|
|||
|
Tab_StrDictionary pGoodNameDictionary = TableManager.GetStrDictionaryByID(m_dialogs[index], 0);
|
|||
|
if (pGoodNameDictionary != null)
|
|||
|
{
|
|||
|
ms.text = pGoodNameDictionary.StrDictionary;
|
|||
|
}
|
|||
|
}
|
|||
|
Button btn = btnObj.GetComponentInChildren<Button>();
|
|||
|
if(btn != null)
|
|||
|
{
|
|||
|
btn.onClick.AddListener(delegate ()
|
|||
|
{
|
|||
|
SelectDialog(index);
|
|||
|
});
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void SelectDialog(int index)
|
|||
|
{
|
|||
|
if (m_dialogs.ContainsKey(index) == false)
|
|||
|
return;
|
|||
|
Tab_StrDictionary pGoodNameDictionary = TableManager.GetStrDictionaryByID(m_dialogs[index], 0);
|
|||
|
if (pGoodNameDictionary != null)
|
|||
|
{
|
|||
|
inputDialog.text = pGoodNameDictionary.StrDictionary;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void AddFriend_Click()
|
|||
|
{
|
|||
|
if (m_gameItem == null)
|
|||
|
return;
|
|||
|
Singleton<ObjManager>.GetInstance().MainPlayer.ReqAddFriend(m_gameItem.SignDataID);
|
|||
|
}
|
|||
|
|
|||
|
public void Close_Click()
|
|||
|
{
|
|||
|
UIManager.CloseUI(UIInfo.GiftWordsRoot);
|
|||
|
}
|
|||
|
|
|||
|
public void Send_Click()
|
|||
|
{
|
|||
|
if (m_gameItem == null)
|
|||
|
return;
|
|||
|
if(GameManager.gameManager.PlayerDataPool.FriendList.IsExist(m_gameItem.SignDataID)==false)
|
|||
|
{
|
|||
|
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{5215}"));
|
|||
|
return;
|
|||
|
}
|
|||
|
if (false == m_gameItem.IsMountItem())
|
|||
|
{
|
|||
|
CG_USE_ITEM useitem = (CG_USE_ITEM)PacketDistributed.CreatePacket(MessageID.PACKET_CG_USE_ITEM);
|
|||
|
useitem.SetItemguid(m_gameItem.Guid);
|
|||
|
useitem.SendPacket();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void SendChatTo(Hashtable addparam, Hashtable sendparam)
|
|||
|
{
|
|||
|
if (string.IsNullOrEmpty(inputDialog.text))
|
|||
|
{
|
|||
|
UIManager.CloseUI(UIInfo.GiftWordsRoot);
|
|||
|
return;
|
|||
|
}
|
|||
|
if (sendparam == null)
|
|||
|
{
|
|||
|
UIManager.CloseUI(UIInfo.GiftWordsRoot);
|
|||
|
return;
|
|||
|
}
|
|||
|
if (sendparam.ContainsKey("data") == false)
|
|||
|
return;
|
|||
|
GC_MAIL_INFO_CHAT_LINK packet = (GC_MAIL_INFO_CHAT_LINK)sendparam["data"];
|
|||
|
if (packet == null)
|
|||
|
{
|
|||
|
UIManager.CloseUI(UIInfo.GiftWordsRoot);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
CG_CHAT sendChat = (CG_CHAT)PacketDistributed.CreatePacket(MessageID.PACKET_CG_CHAT);
|
|||
|
sendChat.Chattype = (int)CG_CHAT.CHATTYPE.CHAT_TYPE_FRIEND;
|
|||
|
|
|||
|
sendChat.Chatinfo = string.Format("{0}[#5,{1},{2},{3},{4}]", inputDialog.text, packet.MailGuid, packet.ItemId, packet.ItemNum, packet.PassTime);
|
|||
|
|
|||
|
sendChat.Receiverguid = m_gameItem.SignDataID;
|
|||
|
Relation relation = GameManager.gameManager.PlayerDataPool.FriendList.RelationDataList[m_gameItem.SignDataID];
|
|||
|
if (relation != null)
|
|||
|
{
|
|||
|
sendChat.Receivername = relation.Name;
|
|||
|
}
|
|||
|
sendChat.Linktype = (int)ChatLinkBase.ChatLinkType.TeamAward;
|
|||
|
sendChat.SendPacket();
|
|||
|
UIManager.CloseUI(UIInfo.GiftWordsRoot);
|
|||
|
}
|
|||
|
}
|