367 lines
9.6 KiB
C#
367 lines
9.6 KiB
C#
// Author: whc
|
|
// Desc:
|
|
|
|
using CaoCao;
|
|
using CaoCao.Event;
|
|
using Game;
|
|
using Game.HotFix;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class TipsUI : UIBase
|
|
{
|
|
public static TipsUI Instance;
|
|
|
|
public Transform m_NodeHintTf;
|
|
public Transform m_NodeLeftHintTf;
|
|
public Transform m_NodeWaitTf;
|
|
public Transform m_NodeDialogTf;
|
|
public Transform m_NodeChoiceTf;
|
|
public Transform m_NodeNRATF;
|
|
|
|
|
|
|
|
private UnitPool<TipHintUnit> m_HintPool;
|
|
public UnitPool<TipHintUnit> vHintPool {
|
|
get {
|
|
if (m_HintPool == null)
|
|
m_HintPool = new UnitPool<TipHintUnit>(null,m_NodeHintTf);
|
|
return m_HintPool;
|
|
}
|
|
}
|
|
private UnitPool<TipLeftHintUnit> m_LeftHintPool;
|
|
public UnitPool<TipLeftHintUnit> vLeftHintPool
|
|
{
|
|
get
|
|
{
|
|
if (m_LeftHintPool == null)
|
|
m_LeftHintPool = new UnitPool<TipLeftHintUnit>(null, m_NodeLeftHintTf);
|
|
return m_LeftHintPool;
|
|
}
|
|
}
|
|
|
|
private UnitPool<TipDialogUnit> m_DialogPool;
|
|
public UnitPool<TipDialogUnit> vDailogPool {
|
|
get {
|
|
if (m_DialogPool == null)
|
|
m_DialogPool = new UnitPool<TipDialogUnit>(null, m_NodeDialogTf);
|
|
return m_DialogPool;
|
|
}
|
|
}
|
|
|
|
private UnitPool<TipChoiceUnit> m_ChoicePool;
|
|
public UnitPool<TipChoiceUnit> vChoicePool {
|
|
get {
|
|
if (m_ChoicePool == null)
|
|
m_ChoicePool = new UnitPool<TipChoiceUnit>(null, m_NodeChoiceTf);
|
|
return m_ChoicePool;
|
|
}
|
|
}
|
|
|
|
private UnitPool<TipWaitUnit> m_WaitPool;
|
|
public UnitPool<TipWaitUnit> vWaitPool {
|
|
get {
|
|
if (m_WaitPool == null)
|
|
m_WaitPool = new UnitPool<TipWaitUnit>(null, m_NodeWaitTf);
|
|
return m_WaitPool;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private UnitPool<TipNotRemindAgainUnit> m_NotRemindAgainPool;
|
|
public UnitPool<TipNotRemindAgainUnit> vNotRemindAgainPool
|
|
{
|
|
get
|
|
{
|
|
if (m_NotRemindAgainPool == null)
|
|
m_NotRemindAgainPool = new UnitPool<TipNotRemindAgainUnit>(null, m_NodeNRATF);
|
|
return m_NotRemindAgainPool;
|
|
}
|
|
}
|
|
|
|
#region TipHintUnit 专属
|
|
|
|
/// <summary>
|
|
/// 显示队列
|
|
/// </summary>
|
|
private Queue<TipData> mHintTipsQue;
|
|
/// <summary>
|
|
/// 左侧显示队列
|
|
/// </summary>
|
|
private Queue<TipData> mLeftHintTipsQue;
|
|
/// <summary>
|
|
/// 最大等待条数
|
|
/// </summary>
|
|
const int mMaxWaitNum = 4;
|
|
/// <summary>
|
|
/// 最大显示条数
|
|
/// </summary>
|
|
const int mMaxShowNum = 4;
|
|
/// <summary>
|
|
/// 当前显示条数
|
|
/// </summary>
|
|
private int mNowShowNum = 0;
|
|
/// <summary>
|
|
/// 当前显示条数
|
|
/// </summary>
|
|
private int mNowLeftShowNum = 0;
|
|
|
|
public void ReduceShowNum(bool isLeft)
|
|
{
|
|
if (isLeft)
|
|
{
|
|
--mNowLeftShowNum;
|
|
}
|
|
else
|
|
{
|
|
--mNowShowNum;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
public override void Awake()
|
|
{
|
|
base.Awake();
|
|
Instance = this;
|
|
m_NodeHintTf = transform.Find("NodeHint");
|
|
m_NodeLeftHintTf = transform.Find("NodeLeftHint");
|
|
m_NodeWaitTf = transform.Find("NodeWait");
|
|
m_NodeDialogTf = transform.Find("NodeDialog");
|
|
m_NodeChoiceTf = transform.Find("NodeChoice");
|
|
m_NodeNRATF = transform.Find("NodeNRA");
|
|
|
|
mHintTipsQue = new Queue<TipData>();
|
|
mLeftHintTipsQue = new Queue<TipData>();
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
Inform<TipData>.Listen(eInformId.TipDialog, ShowDialog);
|
|
Inform<TipData>.Listen(eInformId.TipHint, ShowHint);
|
|
Inform<TipData>.Listen(eInformId.TipLeftHint, ShowLeftHint);
|
|
Inform<TipData>.Listen(eInformId.TipChoice, ShowChoice);
|
|
Inform<TipData>.Listen(eInformId.TipWait, ShowWait);
|
|
Inform<TipData>.Listen(eInformId.TipActivityStart, ShowActivityStart);
|
|
Inform<TipData, NotRemindAgainType>.Listen(eInformId.TipNotRemindAgain, ShowNotRemindAgain);
|
|
|
|
//AppEntry.Event.Subscribe(Listen.EventId, RefreshPanel);
|
|
Inform<bool>.Listen(eInformId.ReduceTipHintEventArgs, RefreshPanel2);
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
Inform<TipData>.Cancel(eInformId.TipDialog, ShowDialog);
|
|
Inform<TipData>.Cancel(eInformId.TipHint, ShowHint);
|
|
Inform<TipData>.Cancel(eInformId.TipLeftHint, ShowLeftHint);
|
|
Inform<TipData>.Cancel(eInformId.TipChoice, ShowChoice);
|
|
Inform<TipData>.Cancel(eInformId.TipWait, ShowWait);
|
|
Inform<TipData>.Cancel(eInformId.TipActivityStart, ShowActivityStart);
|
|
Inform<TipData, NotRemindAgainType>.Cancel(eInformId.TipNotRemindAgain, ShowNotRemindAgain);
|
|
|
|
//AppEntry.Event.Unsubscribe(ReduceTipHintEventArgs.EventId, RefreshPanel);
|
|
Inform<bool>.Cancel(eInformId.ReduceTipHintEventArgs, RefreshPanel2);
|
|
}
|
|
|
|
//bool isShowOutGame = false;
|
|
//bool isCheckWhenBack = false;
|
|
//void OnApplicationFocus(bool _focus)
|
|
//{
|
|
// //Debug.Log("OnApplicationFocus _focus:"+ _focus.ToString());
|
|
// if(_focus)
|
|
// {
|
|
// if (!isCheckWhenBack)
|
|
// return;
|
|
// isCheckWhenBack = false;
|
|
// isShowOutGame = true;
|
|
|
|
// if (!Game.Instance.GetNet().IsLoop())
|
|
// return;
|
|
|
|
// if (!Game.Instance.GetNet().IsConnected())
|
|
// {
|
|
// Game.Instance.GetNet().ShowReconnectTips();
|
|
// //Tips.Instance.SafeShowChoice("失去网络链接, 是否重连?", ReConnect, ExitWork);
|
|
// }
|
|
|
|
// }
|
|
// else
|
|
// {
|
|
// isCheckWhenBack = true;
|
|
// if (!isShowOutGame)
|
|
// return;
|
|
|
|
// Debug.Log("请不要离开太久, 否则会中断服务器链接.");
|
|
// //Tips.Instance.ShowHint("请不要离开太久, 否则会中断服务器链接.");
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
public void GameExit()
|
|
{
|
|
Application.Quit();
|
|
}
|
|
|
|
|
|
int m_lastFrame = 0;
|
|
private void Update()
|
|
{
|
|
if (m_lastFrame < 8)
|
|
{
|
|
m_lastFrame++;
|
|
return;
|
|
}
|
|
m_lastFrame = 0;
|
|
|
|
if (mHintTipsQue.Count > 0 && mNowShowNum < mMaxShowNum)
|
|
{
|
|
TipHintUnit vUnit = vHintPool.GetAnyHide();
|
|
vUnit.Refresh(mHintTipsQue.Dequeue());
|
|
++mNowShowNum;
|
|
}
|
|
|
|
if (mLeftHintTipsQue.Count > 0 && mNowLeftShowNum < mMaxShowNum)
|
|
{
|
|
TipLeftHintUnit vUnit = vLeftHintPool.GetAnyHide();
|
|
vUnit.Refresh(mLeftHintTipsQue.Dequeue());
|
|
++mNowLeftShowNum;
|
|
}
|
|
|
|
|
|
|
|
if (Tips.Instance.SafeTipQue.Count <= 0)
|
|
return;
|
|
|
|
SwitchTipDataShow(Tips.Instance.SafeTipQue.Dequeue());
|
|
}
|
|
|
|
public void SwitchTipDataShow(TipData _Data)
|
|
{
|
|
switch (_Data.m_type)
|
|
{
|
|
case eTipType.Hint:
|
|
ShowHint(_Data);
|
|
break;
|
|
case eTipType.LeftHint:
|
|
ShowLeftHint(_Data);
|
|
break;
|
|
case eTipType.Dialog:
|
|
ShowDialog(_Data);
|
|
break;
|
|
case eTipType.Choice:
|
|
ShowChoice(_Data);
|
|
break;
|
|
case eTipType.Wait:
|
|
ShowWait(_Data);
|
|
break;
|
|
case eTipType.ActivityStart:
|
|
ShowActivityStart(_Data);
|
|
break;
|
|
default:
|
|
Debug.LogError("not switch (_Data.m_type). type:" + _Data.m_type.ToString());
|
|
break;
|
|
}
|
|
}
|
|
|
|
public void ShowDialog(TipData _Data)
|
|
{
|
|
TipDialogUnit vUnit = vDailogPool.GetAnyHide();
|
|
vUnit.Refresh(_Data);
|
|
|
|
Setlen();
|
|
}
|
|
|
|
public void ShowHint(TipData _Data)
|
|
{
|
|
if(mHintTipsQue.Count < mMaxWaitNum)
|
|
{
|
|
mHintTipsQue.Enqueue(_Data);
|
|
}
|
|
|
|
Setlen();
|
|
}
|
|
|
|
|
|
public void ShowLeftHint(TipData _Data)
|
|
{
|
|
//TipHintUnit vUnit = vHintPool.GetAnyHide();
|
|
//vUnit.Refresh(_Data);
|
|
|
|
if (mLeftHintTipsQue.Count < mMaxWaitNum)
|
|
{
|
|
mLeftHintTipsQue.Enqueue(_Data);
|
|
}
|
|
|
|
Setlen();
|
|
}
|
|
|
|
public void ShowChoice(TipData _Data)
|
|
{
|
|
TipChoiceUnit vUnit = vChoicePool.GetAnyHide();
|
|
vUnit.Refresh(_Data);
|
|
|
|
Setlen();
|
|
}
|
|
|
|
public void ShowNotRemindAgain(TipData _Data, NotRemindAgainType pType)
|
|
{
|
|
TipNotRemindAgainUnit vUnit = vNotRemindAgainPool.GetAnyHide();
|
|
vUnit.Refresh(_Data, pType);
|
|
|
|
Setlen();
|
|
}
|
|
|
|
public void ShowWait(TipData _Data)
|
|
{
|
|
TipWaitUnit vUnit = vWaitPool.GetObj(0);//.GetAnyHide();
|
|
vUnit.Refresh(_Data);
|
|
|
|
Setlen();
|
|
}
|
|
|
|
public void ShowActivityStart(TipData _Data)
|
|
{
|
|
//TipActivityStartUnit vUnit = vActivityStartPool.GetAnyHide();
|
|
//vUnit.Refresh(_Data);
|
|
|
|
Setlen();
|
|
}
|
|
|
|
//private void RefreshPanel(object sender, LogicEventArgs e)
|
|
//{
|
|
// ReduceTipHintEventArgs roleListEvent = (ReduceTipHintEventArgs)e;
|
|
// if (roleListEvent == null)
|
|
// throw new GameException("ShowHint 显示更新失败");
|
|
|
|
// ReduceShowNum(roleListEvent.isLeft);
|
|
//}
|
|
|
|
private void RefreshPanel2(bool pValue)
|
|
{
|
|
ReduceShowNum(pValue);
|
|
}
|
|
|
|
|
|
public void Clean()
|
|
{
|
|
mHintTipsQue.Clear();
|
|
mLeftHintTipsQue.Clear();
|
|
mNowShowNum = 0;
|
|
mNowLeftShowNum = 0;
|
|
vChoicePool.Destory();
|
|
vDailogPool.Destory();
|
|
vHintPool.Destory();
|
|
vLeftHintPool.Destory();
|
|
vNotRemindAgainPool.Destory();
|
|
vWaitPool.Destory();
|
|
}
|
|
|
|
void Setlen()
|
|
{
|
|
transform.SetAsLastSibling();
|
|
}
|
|
}
|