519 lines
14 KiB
C#
519 lines
14 KiB
C#
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
using System;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using Games.ChatHistory;
|
|||
|
using GCGame.Table;
|
|||
|
using Games.GlobeDefine;
|
|||
|
using GCGame;
|
|||
|
using Module.Log;
|
|||
|
using Games.LogicObj;
|
|||
|
|
|||
|
public class ChatFrameLogic : MonoBehaviour
|
|||
|
{
|
|||
|
private static ChatFrameLogic m_Instance = null;
|
|||
|
public static ChatFrameLogic Instance()
|
|||
|
{
|
|||
|
return m_Instance;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
void Awake()
|
|||
|
{
|
|||
|
#if UNITY_IPHONE || UNITY_WP8 || UNITY_BLACKBERRY //|| UNITY_ANDROID
|
|||
|
TouchScreenKeyboard.hideInput = true;
|
|||
|
#endif
|
|||
|
LogModule.DebugLog("ChatFrameLogic awake");
|
|||
|
m_Instance = this;
|
|||
|
|
|||
|
LoadShowChannel();
|
|||
|
|
|||
|
InitRedDotTip();
|
|||
|
|
|||
|
//初始化博客
|
|||
|
Community.Instance.InitResUrl();
|
|||
|
try
|
|||
|
{
|
|||
|
ChatVoice.Instance().ChatVoiceInit();
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void OnEnable()
|
|||
|
{
|
|||
|
OperationShowOrHideExpandBtn();
|
|||
|
transform.SetAsFirstSibling(); //防止界面被挡,放到最底层
|
|||
|
}
|
|||
|
|
|||
|
void OnDisable()
|
|||
|
{
|
|||
|
#if UNITY_IPHONE || UNITY_WP8 || UNITY_BLACKBERRY //|| UNITY_ANDROID
|
|||
|
TouchScreenKeyboard.hideInput = false;
|
|||
|
#endif
|
|||
|
m_Instance = null;
|
|||
|
if(GameManager.gameManager!=null)
|
|||
|
PlayerPreferenceData.SetFriendChatHistory(GameManager.gameManager.PlayerDataPool.ChatHistory.FriendChatList);
|
|||
|
if(ChatVoice.Instance()!=null)
|
|||
|
ChatVoice.Instance().ChatVoiceLogout();
|
|||
|
}
|
|||
|
|
|||
|
public void PlayTween(bool nDirection)
|
|||
|
{
|
|||
|
|
|||
|
if (nDirection)
|
|||
|
{
|
|||
|
gameObject.SetActive(false);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
gameObject.SetActive(true);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public Animator _ShowAnimator;
|
|||
|
|
|||
|
public void ShowChatFrame()
|
|||
|
{
|
|||
|
_ShowAnimator.Play("Show");
|
|||
|
//gameObject.SetActive(true);
|
|||
|
}
|
|||
|
|
|||
|
public void HideChatFrame()
|
|||
|
{
|
|||
|
_ShowAnimator.Play("Hide");
|
|||
|
//gameObject.SetActive(false);
|
|||
|
}
|
|||
|
|
|||
|
public void BtnShowChatInfo()
|
|||
|
{
|
|||
|
UIManager.ShowUI(UIInfo.ChatInfoRoot);
|
|||
|
}
|
|||
|
|
|||
|
public void OnReceiveChat(GC_CHAT pak)
|
|||
|
{
|
|||
|
if (m_IsLockChat)
|
|||
|
return;
|
|||
|
|
|||
|
if (!gameObject.activeSelf)
|
|||
|
return;
|
|||
|
//// if (pak.Chattype == (int)GC_CHAT.CHATTYPE.CHAT_TYPE_LOUDSPEAKER)
|
|||
|
// {
|
|||
|
// //if (null != LoudSpeakerFrameLogic.Instance())
|
|||
|
// // LoudSpeakerFrameLogic.Instance().OnReceiveLoudSpeaker();
|
|||
|
// }
|
|||
|
//else
|
|||
|
{
|
|||
|
AddNewChatItem();
|
|||
|
}
|
|||
|
|
|||
|
UpdateRedDotTip();
|
|||
|
}
|
|||
|
|
|||
|
public void SetChatTips(bool show)
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private bool m_IsLockChat = false;
|
|||
|
public void OnLockClick(bool isOn)
|
|||
|
{
|
|||
|
m_IsLockChat = isOn;
|
|||
|
if(m_IsLockChat==false)
|
|||
|
{
|
|||
|
AddNewChatItem();
|
|||
|
UpdateRedDotTip();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void OnSettingClick()
|
|||
|
{
|
|||
|
UIManager.ShowUI(UIInfo.SystemAndAutoFight);
|
|||
|
}
|
|||
|
|
|||
|
public void OnPicturClick()
|
|||
|
{
|
|||
|
UIManager.ShowUI(UIInfo.CameraTest);
|
|||
|
}
|
|||
|
|
|||
|
public void OnSpaceClick()
|
|||
|
{
|
|||
|
CommunityLogic.ShowMyCommunityRoot();
|
|||
|
}
|
|||
|
|
|||
|
#region auto fight
|
|||
|
public GameObject m_BtnAutoStop;
|
|||
|
public GameObject m_BtnAutoBegin;
|
|||
|
// 直接调用自动战斗
|
|||
|
public void OnDoAutoFightClick()
|
|||
|
{
|
|||
|
//组队跟随,不响应技能
|
|||
|
if (GameManager.gameManager.PlayerDataPool.IsFollowTeam)
|
|||
|
{
|
|||
|
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{5128}"));
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
if (!PvpSceneCanAutoCombat())
|
|||
|
return;
|
|||
|
|
|||
|
var mainPalyer = Singleton<ObjManager>.Instance.MainPlayer;
|
|||
|
if (null == mainPalyer)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
if (AllowAutoFight())
|
|||
|
mainPalyer.EnterAutoCombat();
|
|||
|
else if (!mainPalyer.isAutoCombat)
|
|||
|
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{9006}"));
|
|||
|
}
|
|||
|
|
|||
|
bool PvpSceneCanAutoCombat()
|
|||
|
{
|
|||
|
if (GameManager.gameManager.RunningScene == GameManager.gameManager.PlayerDataPool.pvpIfo._PvpBattleSceneId
|
|||
|
&& GlobalData._EnterSceneStartTime != -1
|
|||
|
&& Time.time - GlobalData._EnterSceneStartTime <= 5.0f)
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
// 原逻辑所在,暂时不移动所在类型
|
|||
|
public static bool AllowAutoFight()
|
|||
|
{
|
|||
|
var result = true;
|
|||
|
var sceneInfo = TableManager.GetSceneClassByID(GameManager.gameManager.RunningScene, 0);
|
|||
|
if (sceneInfo != null && sceneInfo.IsAutoFight < 1)
|
|||
|
result = false;
|
|||
|
return result;
|
|||
|
}
|
|||
|
|
|||
|
public void OnDoAutoStopFightClick()
|
|||
|
{
|
|||
|
//组队跟随,不响应技能
|
|||
|
if (GameManager.gameManager.PlayerDataPool.IsFollowTeam)
|
|||
|
{
|
|||
|
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{5128}"));
|
|||
|
return;
|
|||
|
}
|
|||
|
var mainPalyer = Singleton<ObjManager>.Instance.MainPlayer;
|
|||
|
if (null == mainPalyer)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
mainPalyer.LeveAutoCombat();
|
|||
|
}
|
|||
|
|
|||
|
public void UpdateAutoFightBtnState()
|
|||
|
{
|
|||
|
Obj_MainPlayer mainPalyer = Singleton<ObjManager>.Instance.MainPlayer;
|
|||
|
if (null == mainPalyer)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
var autoCombat = mainPalyer.isAutoCombat;
|
|||
|
m_BtnAutoStop.SetActive(autoCombat);
|
|||
|
m_BtnAutoBegin.SetActive(!autoCombat);
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
public void OnFriendClick()
|
|||
|
{
|
|||
|
UIManager.ShowUI(UIInfo.FriendAndMail);
|
|||
|
}
|
|||
|
|
|||
|
#region chat voice
|
|||
|
|
|||
|
public RectTransform VoiceOPenBtnParent;
|
|||
|
public Transform VoiceOPenBtn;
|
|||
|
public GameObject[] VoiceBtns;
|
|||
|
public GameObject[] voiceBGs;
|
|||
|
public void OnVoiceClick(GameObject voiceBtn)
|
|||
|
{
|
|||
|
if (voiceBtn == null)
|
|||
|
return;
|
|||
|
//VoiceOPenBtnParent.anchoredPosition = new Vector3(-235, 107);
|
|||
|
// VoiceOPenBtn.localEulerAngles = new Vector3(0, 0, 0);
|
|||
|
//var showIndex = -1;
|
|||
|
//for (int i = 0; i < VoiceBtns.Length; i++)
|
|||
|
//{
|
|||
|
// VoiceBtns[i].SetActive(voiceBtn == VoiceBtns[i]);
|
|||
|
// if (voiceBtn == VoiceBtns[i])
|
|||
|
// showIndex = i;
|
|||
|
//}
|
|||
|
//voiceBtn.transform.SetAsFirstSibling();
|
|||
|
}
|
|||
|
|
|||
|
private bool isShow = false;
|
|||
|
public void OnVoiceListClick()
|
|||
|
{
|
|||
|
if (isShow)
|
|||
|
{
|
|||
|
//GameObject activeBtn = null;
|
|||
|
//int lowindex = 100;
|
|||
|
//for (int i = 0; i < VoiceBtns.Length; i++)
|
|||
|
//{
|
|||
|
// int index = VoiceBtns[i].transform.GetSiblingIndex();
|
|||
|
// if (index < lowindex)
|
|||
|
// {
|
|||
|
// activeBtn = VoiceBtns[i];
|
|||
|
// lowindex = index;
|
|||
|
// }
|
|||
|
// VoiceBtns[i].SetActive(false);
|
|||
|
//}
|
|||
|
//if (activeBtn != null)
|
|||
|
// activeBtn.SetActive(true);
|
|||
|
|
|||
|
for(int index = 1; index < voiceBGs.Length; index++)
|
|||
|
{
|
|||
|
voiceBGs[index].SetActive(false);
|
|||
|
}
|
|||
|
|
|||
|
// VoiceOPenBtnParent.anchoredPosition = new Vector3(-235, 107);
|
|||
|
VoiceOPenBtn.localEulerAngles = new Vector3(0, 0, 0);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//for (int i = 0; i < VoiceBtns.Length; i++)
|
|||
|
//{
|
|||
|
// VoiceBtns[i].SetActive(true);
|
|||
|
//}
|
|||
|
//VoiceOPenBtnParent.anchoredPosition = new Vector3(-235, 245);
|
|||
|
VoiceOPenBtn.localEulerAngles = new Vector3(180, 0, 0);
|
|||
|
|
|||
|
for (int index = 1; index < voiceBGs.Length; index++)
|
|||
|
{
|
|||
|
voiceBGs[index].SetActive(true);
|
|||
|
}
|
|||
|
}
|
|||
|
isShow = !isShow;
|
|||
|
}
|
|||
|
|
|||
|
public void OnChatPress(CG_CHAT.CHATTYPE chatType)
|
|||
|
{ }
|
|||
|
|
|||
|
public void OnChatRelease(CG_CHAT.CHATTYPE chatType)
|
|||
|
{ }
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region show chat
|
|||
|
|
|||
|
public RectTransform _ChatLogContent;
|
|||
|
public GameObject _ChatLogPrefab;
|
|||
|
|
|||
|
private float _LogContentPosY = 0;
|
|||
|
private List<ChatInfoLogItemInFrame> _ChatPrefabs = new List<ChatInfoLogItemInFrame>();
|
|||
|
private List<ChatHistoryItem> _ShowHistorys = new List<ChatHistoryItem>();
|
|||
|
private const int MAX_SHOW_HISTORY_COUNT = 5;
|
|||
|
|
|||
|
public void AddNewChatItem()
|
|||
|
{
|
|||
|
int HistoryCount = GameManager.gameManager.PlayerDataPool.ChatHistory.ChatHistoryList.Count;
|
|||
|
if (HistoryCount <= 0)
|
|||
|
return;
|
|||
|
ChatHistoryItem LastHistory = GameManager.gameManager.PlayerDataPool.ChatHistory.ChatHistoryList[HistoryCount - 1];
|
|||
|
if (LastHistory.EChannel == GC_CHAT.CHATTYPE.CHAT_TYPE_FRIEND ||
|
|||
|
//LastHistory.EChannel == GC_CHAT.CHATTYPE.CHAT_TYPE_BATTLE ||
|
|||
|
LastHistory.EChannel == GC_CHAT.CHATTYPE.CHAT_TYPE_TELL)
|
|||
|
return;
|
|||
|
if(_ChatChannels.Contains(LastHistory.EChannel))
|
|||
|
HandleChatHistory(LastHistory);
|
|||
|
}
|
|||
|
|
|||
|
void HandleChatHistory(ChatHistoryItem history)
|
|||
|
{
|
|||
|
ChatInfoLogItem chatLogInfo = null;
|
|||
|
|
|||
|
chatLogInfo = GetIdleChatLogItem();
|
|||
|
|
|||
|
chatLogInfo.SetChatLog(history);
|
|||
|
SetChatListBG();
|
|||
|
}
|
|||
|
|
|||
|
void SetChatListBG()
|
|||
|
{
|
|||
|
_LogContentPosY = 0;
|
|||
|
for (int i = _ChatPrefabs.Count - 1; i >= 0; --i)
|
|||
|
{
|
|||
|
_LogContentPosY += _ChatPrefabs[i].GetItemHeight();
|
|||
|
_ChatPrefabs[i].GetComponent<RectTransform>().anchoredPosition = new Vector2(0, _LogContentPosY);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
ChatInfoLogItemInFrame GetIdleChatLogItem()
|
|||
|
{
|
|||
|
ChatInfoLogItemInFrame idleChatItem = null;
|
|||
|
if (_ChatPrefabs.Count == MAX_SHOW_HISTORY_COUNT)
|
|||
|
{
|
|||
|
idleChatItem = _ChatPrefabs[0];
|
|||
|
_ChatPrefabs.RemoveAt(0);
|
|||
|
idleChatItem.gameObject.SetActive(true);
|
|||
|
_ChatPrefabs.Add(idleChatItem);
|
|||
|
return idleChatItem;
|
|||
|
}
|
|||
|
|
|||
|
var idleItemGO = GameObject.Instantiate(_ChatLogPrefab) as GameObject;
|
|||
|
idleChatItem = idleItemGO.GetComponent<ChatInfoLogItemInFrame>();
|
|||
|
|
|||
|
idleItemGO.transform.SetParent(_ChatLogContent);
|
|||
|
idleItemGO.transform.localScale = Vector3.one;
|
|||
|
idleItemGO.SetActive(true);
|
|||
|
_ChatPrefabs.Add(idleChatItem);
|
|||
|
return idleChatItem;
|
|||
|
}
|
|||
|
|
|||
|
void ClearHistory()
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region channel
|
|||
|
|
|||
|
public List<GC_CHAT.CHATTYPE> _ChatChannels = new List<GC_CHAT.CHATTYPE>();
|
|||
|
|
|||
|
public void SetShowChannel(List<int> channels)
|
|||
|
{
|
|||
|
_ChatChannels.Clear();
|
|||
|
foreach (var channel in channels)
|
|||
|
{
|
|||
|
_ChatChannels.Add((GC_CHAT.CHATTYPE)channel);
|
|||
|
}
|
|||
|
|
|||
|
PlayerPreferenceData.SetChatFrameChannels(_ChatChannels);
|
|||
|
|
|||
|
string channelStr = "";
|
|||
|
for (int i = 0; i < _ChatChannels.Count; ++i)
|
|||
|
{
|
|||
|
channelStr += _ChatChannels[i] + ",";
|
|||
|
}
|
|||
|
LogModule.DebugLog("Channel:" + channelStr);
|
|||
|
}
|
|||
|
|
|||
|
public void LoadShowChannel()
|
|||
|
{
|
|||
|
_ChatChannels = PlayerPreferenceData.GetChatFrameChannels();
|
|||
|
string channelStr = "";
|
|||
|
for (int i = 0; i < _ChatChannels.Count; ++i)
|
|||
|
{
|
|||
|
channelStr += _ChatChannels[i] + ",";
|
|||
|
}
|
|||
|
LogModule.DebugLog("Channel:" + channelStr);
|
|||
|
}
|
|||
|
|
|||
|
public void OpenChatChannel()
|
|||
|
{
|
|||
|
UIManager.ShowUI(UIInfo.ChatFrameChannel);
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region friend check
|
|||
|
|
|||
|
public GameObject _FriendRedDot;
|
|||
|
public Text allUnCheckedCountText;
|
|||
|
public GameObject _MailFullMark;
|
|||
|
|
|||
|
|
|||
|
public void UpdateRedDotTip()
|
|||
|
{
|
|||
|
//放在Return前面
|
|||
|
if (ExtraFunTipRoot.Instance())
|
|||
|
ExtraFunTipRoot.Instance().ShowMailIcon(MailData.IsHaveUpReadMail());
|
|||
|
|
|||
|
_MailFullMark.SetActive(MailData.GetAllMailCount() >= 100);
|
|||
|
|
|||
|
if (GameManager.gameManager.PlayerDataPool.ChatHistory.IsHaveUnCheckChat())
|
|||
|
{
|
|||
|
_FriendRedDot.SetActive(true);
|
|||
|
}else if (GameManager.gameManager.PlayerDataPool.NewApplyCheck
|
|||
|
&& GameManager.gameManager.PlayerDataPool.GetNewApplyListCount() > 0)
|
|||
|
{
|
|||
|
_FriendRedDot.SetActive(true);
|
|||
|
}else
|
|||
|
{
|
|||
|
_FriendRedDot.SetActive(false);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
var totalCount = GameManager.gameManager.PlayerDataPool.GetNewApplyListCount()
|
|||
|
+ GameManager.gameManager.PlayerDataPool.ChatHistory.GetAllUnCheckedChatCount();
|
|||
|
if (allUnCheckedCountText)
|
|||
|
allUnCheckedCountText.text = (totalCount >= 99 ? 99 : totalCount).ToString();
|
|||
|
}
|
|||
|
|
|||
|
private IEnumerator InitRedDotTip()
|
|||
|
{
|
|||
|
yield return new WaitForSeconds(5);
|
|||
|
|
|||
|
UpdateRedDotTip();
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region space check
|
|||
|
|
|||
|
public GameObject _SpaceTip;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Expand
|
|||
|
public RectTransform _BGRect;
|
|||
|
public Image _ExpandImage;
|
|||
|
public GameObject _ExpandBtnObj;
|
|||
|
public GameObject _ResumeExpandObj;
|
|||
|
private bool _IsExpand = false;
|
|||
|
|
|||
|
private void OperationShowOrHideExpandBtn()
|
|||
|
{
|
|||
|
_ExpandBtnObj.SetActive(!_IsExpand);
|
|||
|
_ResumeExpandObj.SetActive(_IsExpand);
|
|||
|
}
|
|||
|
public void OnExpandBtnClick()
|
|||
|
{
|
|||
|
if(_IsExpand)
|
|||
|
{
|
|||
|
ResumeExpandOperation();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
ExpandOperation();
|
|||
|
}
|
|||
|
_IsExpand = !_IsExpand;
|
|||
|
OperationShowOrHideExpandBtn();
|
|||
|
}
|
|||
|
|
|||
|
public void ExpandOperation()
|
|||
|
{
|
|||
|
var _ChangedValue = _BGRect.sizeDelta.y * 2;
|
|||
|
_BGRect.sizeDelta = new Vector2(_BGRect.sizeDelta.x, _BGRect.sizeDelta.y + _ChangedValue);
|
|||
|
ChangeExtraPos(_ChangedValue);
|
|||
|
//_ExpandImage.transform.localRotation = Quaternion.Euler(new Vector3(180, 0, 0));
|
|||
|
//_ExpandImage.transform.localPosition = new Vector3(_ExpandImage.transform.localPosition.x, _ExpandImage.transform.localPosition.y - _ExpandImage.rectTransform.sizeDelta.y, 0);
|
|||
|
}
|
|||
|
|
|||
|
public void ResumeExpandOperation()
|
|||
|
{
|
|||
|
var _ChangedValue = -_BGRect.sizeDelta.y / 3 * 2;
|
|||
|
_BGRect.sizeDelta = new Vector2(_BGRect.sizeDelta.x, _BGRect.sizeDelta.y + _ChangedValue);
|
|||
|
ChangeExtraPos(_ChangedValue);
|
|||
|
//_ExpandImage.transform.localRotation = Quaternion.Euler(new Vector3(0, 0, 0));
|
|||
|
//_ExpandImage.transform.localPosition = new Vector3(_ExpandImage.transform.localPosition.x, _ExpandImage.transform.localPosition.y + _ExpandImage.rectTransform.sizeDelta.y, 0);
|
|||
|
}
|
|||
|
|
|||
|
private void ChangeExtraPos(float _ChangeValue)
|
|||
|
{
|
|||
|
if(ExtraFunTipRoot.Instance())
|
|||
|
{
|
|||
|
ExtraFunTipRoot.Instance().OperationOffsetPos(_ChangeValue);
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|