//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Monday, April 09, 2018
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace Snxxz.UI {
|
|
public class ChatWin : Window
|
{
|
[SerializeField] Button m_CloseBtn;
|
[SerializeField] Text m_ChatTip;
|
[SerializeField] ChatSendComponent m_ChatSend;
|
[SerializeField] ScrollerController m_ChannelControl;
|
[SerializeField] ChatContentBehaviour m_ChatContent;
|
[SerializeField] ChatRecently m_ChatRecently;
|
[SerializeField] Button m_ChannelBtn;
|
[SerializeField] Text m_ChannelInfo;
|
|
ChatCenter m_ChatCenter;
|
ChatCenter chatCenter
|
{
|
get
|
{
|
return m_ChatCenter ?? (m_ChatCenter = ModelCenter.Instance.GetModel<ChatCenter>());
|
}
|
}
|
|
#region Built-in
|
protected override void BindController()
|
{
|
}
|
|
protected override void AddListeners()
|
{
|
m_CloseBtn.onClick.AddListener(OnClose);
|
m_ChannelBtn.onClick.AddListener(OnChannelBtn);
|
}
|
|
protected override void OnPreOpen()
|
{
|
if (!IsSatisfyShowChannel(ChatCtrl.Inst.presentChatType))
|
{
|
ChatCtrl.Inst.presentChatType = ChatInfoType.System;
|
}
|
|
m_ChatSend.parent = this;
|
ChatCtrl.Inst.lockUpdate = false;
|
ChatCtrl.Inst.OnPteChatChangeEvent += OnPteChatChangeEvent;
|
ChatCtrl.Inst.OpenPteChatEvent += OpenPteChatEvent;
|
DisplayChannel();
|
OnChatTypeChange();
|
chatCenter.UpdateChatContentPos();
|
}
|
|
protected override void OnAfterOpen()
|
{
|
AchievementRandomWord();
|
if (ChatCtrl.Inst.openFromDaily)
|
{
|
AssitRandomChat();
|
ChatCtrl.Inst.needCheckAssitChat = true;
|
}
|
else if (ChatCtrl.Inst.openFromGem)
|
{
|
GemFlauntChat();
|
}
|
else if (ChatCtrl.Inst.openFromFairyTask)
|
{
|
TaskRandomChat();
|
}
|
ChatCtrl.Inst.openFromDaily = false;
|
ChatCtrl.Inst.openFromGem = false;
|
ChatCtrl.Inst.openFromFairyTask = false;
|
}
|
|
protected override void OnPreClose()
|
{
|
ChatCtrl.Inst.OnPteChatChangeEvent -= OnPteChatChangeEvent;
|
ChatCtrl.Inst.OpenPteChatEvent -= OpenPteChatEvent;
|
ChatCtrl.Inst.openFromDaily = false;
|
ChatCtrl.Inst.openFromGem = false;
|
ChatCtrl.Inst.needCheckAssitChat = false;
|
ChatCtrl.Inst.openFromFairyTask = false;
|
chatCenter.ChangeChatValue(string.Empty, false, true);
|
}
|
|
protected override void OnAfterClose()
|
{
|
}
|
#endregion
|
|
private void OpenPteChatEvent()
|
{
|
OnChannelSelect(ChatInfoType.Friend);
|
}
|
|
private void DisplayChannel()
|
{
|
m_ChannelControl.Refresh();
|
for (int i = 0; i < chatCenter.chatChannels.Count; i++)
|
{
|
if (IsSatisfyShowChannel(chatCenter.chatChannels[i]))
|
{
|
m_ChannelControl.AddCell(ScrollerDataType.Normal, (int)chatCenter.chatChannels[i], OnChannelSelect);
|
}
|
}
|
m_ChannelControl.Restart();
|
}
|
|
private bool IsSatisfyShowChannel(ChatInfoType channel)
|
{
|
if (CrossServerUtility.IsCrossServer())
|
{
|
if (channel == ChatInfoType.Team || channel == ChatInfoType.Invite)
|
{
|
return false;
|
}
|
}
|
return true;
|
}
|
|
private void OnPteChatChangeEvent()
|
{
|
if (ChatCtrl.Inst.presentChatType == ChatInfoType.Friend)
|
{
|
OnChatTypeChange();
|
}
|
}
|
|
private void OnChatTypeChange()
|
{
|
m_ChannelBtn.gameObject.SetActive(false);
|
m_ChannelInfo.gameObject.SetActive(false);
|
m_ChatSend.placeholder.text= Language.Get("L1111");
|
m_CloseBtn.gameObject.SetActive(ChatCtrl.Inst.presentChatType != ChatInfoType.Friend);
|
switch (ChatCtrl.Inst.presentChatType)
|
{
|
case ChatInfoType.Trumpet:
|
m_ChatRecently.gameObject.SetActive(false);
|
m_ChatTip.gameObject.SetActive(false);
|
m_ChatSend.gameObject.SetActive(true);
|
m_ChatSend.placeholder.text = Language.Get("L1012");
|
break;
|
case ChatInfoType.Invite:
|
case ChatInfoType.System:
|
m_ChatRecently.gameObject.SetActive(false);
|
m_ChatTip.text = Language.Get("L1109");
|
m_ChatTip.gameObject.SetActive(true);
|
m_ChatSend.gameObject.SetActive(false);
|
break;
|
case ChatInfoType.World:
|
case ChatInfoType.Area:
|
case ChatInfoType.CrossServer:
|
m_ChatRecently.gameObject.SetActive(false);
|
m_ChatTip.gameObject.SetActive(false);
|
m_ChatSend.gameObject.SetActive(true);
|
break;
|
case ChatInfoType.Team:
|
m_ChatRecently.gameObject.SetActive(false);
|
var _team = ModelCenter.Instance.GetModel<TeamModel>().myTeam;
|
m_ChatSend.gameObject.SetActive(_team.teamId > 0);
|
m_ChatTip.gameObject.SetActive(_team.teamId <= 0);
|
m_ChatTip.text = Language.Get("L1110");
|
break;
|
case ChatInfoType.Fairy:
|
m_ChatRecently.gameObject.SetActive(false);
|
m_ChannelBtn.gameObject.SetActive(!PlayerDatas.Instance.fairyData.HasFairy);
|
m_ChannelInfo.gameObject.SetActive(!PlayerDatas.Instance.fairyData.HasFairy);
|
m_ChatTip.gameObject.SetActive(!PlayerDatas.Instance.fairyData.HasFairy);
|
m_ChatSend.gameObject.SetActive(PlayerDatas.Instance.fairyData.HasFairy);
|
if (!PlayerDatas.Instance.fairyData.HasFairy)
|
{
|
m_ChatTip.text = Language.Get("L1011");
|
}
|
break;
|
case ChatInfoType.Friend:
|
m_ChatSend.gameObject.SetActive(true);
|
m_ChatTip.gameObject.SetActive(false);
|
if (!m_ChatRecently.gameObject.activeSelf)
|
{
|
m_ChatRecently.gameObject.SetActive(true);
|
}
|
break;
|
}
|
m_ChatContent.chatType = ChatCtrl.Inst.presentChatType;
|
ChatCtrl.Inst.ViewChat(ChatCtrl.Inst.presentChatType);
|
}
|
|
private void OnChannelSelect(CellView _cell)
|
{
|
if ((ChatInfoType)_cell.index == ChatInfoType.CrossServer)
|
{
|
if (!FuncOpen.Instance.IsFuncOpen(162))
|
{
|
SysNotifyMgr.Instance.ShowTip("CrossServerHint");
|
return;
|
}
|
}
|
OnChannelSelect((ChatInfoType)_cell.index);
|
}
|
|
private void OnChannelSelect(ChatInfoType _type)
|
{
|
ChatCtrl.Inst.presentChatType = _type;
|
m_ChannelControl.m_Scorller.RefreshActiveCellViews();
|
if (_type == ChatInfoType.Friend)
|
{
|
ChatCtrl.Inst.lockUpdate = true;
|
}
|
else
|
{
|
ChatCtrl.Inst.lockUpdate = false;
|
}
|
OnChatTypeChange();
|
chatCenter.UpdateChatContentPos();
|
}
|
|
private void OnChannelBtn()
|
{
|
switch (ChatCtrl.Inst.presentChatType)
|
{
|
case ChatInfoType.Fairy:
|
{
|
int limit = FuncOpenLVConfig.Get((int)FuncOpenEnum.Fairy).LimitLV;
|
if (PlayerDatas.Instance.baseData.LV < limit)
|
{
|
ServerTipDetails.DisplayNormalTip(Language.Get("L1136", limit));
|
return;
|
}
|
CloseImmediately();
|
WindowJumpMgr.Instance.WindowJumpTo(JumpUIType.UnionFunc3);
|
}
|
break;
|
}
|
}
|
|
private void AchievementRandomWord()
|
{
|
if (AchievementGoto.achievementType != AchievementGoto.RandomFairyChat
|
&& AchievementGoto.achievementType != AchievementGoto.RandomWorldChat)
|
{
|
return;
|
}
|
AchievementGoto.achievementType = 0;
|
if (AchievementGoto.achievementType == AchievementGoto.RandomFairyChat && !PlayerDatas.Instance.fairyData.HasFairy)
|
{
|
return;
|
}
|
if (ChatCtrl.Inst.achievementRandoms.ContainsKey(ChatCtrl.Inst.presentChatType))
|
{
|
var _list = ChatCtrl.Inst.achievementRandoms[ChatCtrl.Inst.presentChatType];
|
int _index = UnityEngine.Random.Range(0, _list.Count);
|
chatCenter.ChangeChatValue(Language.Get(_list[_index]), false, true);
|
}
|
var _effect = AchievementGuideEffectPool.Require(1);
|
_effect.transform.SetParentEx(m_ChatSend.sendBtn.transform, Vector3.zero, Vector3.zero, Vector3.one);
|
}
|
|
private void AssitRandomChat()
|
{
|
chatCenter.ChangeChatValue(ChatCtrl.Inst.GetAssitRandomChat(ChatCtrl.Inst.presentChatType), false, true);
|
}
|
|
private void TaskRandomChat()
|
{
|
chatCenter.ChangeChatValue(ChatCtrl.Inst.GetTaskRandomChat(ChatCtrl.Inst.presentChatType), false, true);
|
}
|
|
private void GemFlauntChat()
|
{
|
chatCenter.ChangeChatValue(ChatCtrl.Inst.GetGemFlauntChat(), false, true);
|
var _effect = AchievementGuideEffectPool.Require(1);
|
_effect.transform.SetParentEx(m_ChatSend.sendBtn.transform, Vector3.zero, Vector3.zero, Vector3.one);
|
}
|
|
private void OnClose()
|
{
|
Close();
|
}
|
}
|
|
}
|
|
|
|
|