328 lines
8.3 KiB
C#
328 lines
8.3 KiB
C#
// Author: whc
|
|
// Desc: 各种提示
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using CaoCao.Runtime;
|
|
|
|
public enum eTipType
|
|
{
|
|
None,
|
|
Dialog, // 弹窗
|
|
Hint, // 飘字
|
|
LeftHint, // 飘字
|
|
Choice, // 选择框
|
|
Wait, // 等待框
|
|
ActivityStart, // 活动开启倒计时
|
|
}
|
|
|
|
public enum NotRemindAgainType
|
|
{
|
|
/// <summary>
|
|
/// 默认
|
|
/// </summary>
|
|
None,
|
|
|
|
/// <summary>
|
|
/// 1
|
|
/// </summary>
|
|
Type1,
|
|
|
|
/// <summary>
|
|
/// 2
|
|
/// </summary>
|
|
Type2,
|
|
}
|
|
|
|
public class Tips : GameComponent
|
|
{
|
|
//public static readonly Tips Instance= new Tips();
|
|
public static Tips Instance = null;
|
|
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
Instance = this;
|
|
}
|
|
|
|
private Queue<TipData> m_SafeTipQue; // 用于线程安全的提示队列
|
|
public Queue<TipData> SafeTipQue {
|
|
get {
|
|
if (m_SafeTipQue == null)
|
|
m_SafeTipQue = new Queue<TipData>();
|
|
|
|
return m_SafeTipQue;
|
|
}
|
|
}
|
|
|
|
// 提示框
|
|
public void ShowDialog(string _text, string _title = "提示")
|
|
{
|
|
DialogData vData = new DialogData(_text, _title);
|
|
Inform<TipData>.Dispatch(eInformId.TipDialog, vData);
|
|
}
|
|
|
|
long lastTimeShowHint = 0;
|
|
string lastHintText = string.Empty;
|
|
|
|
// 提示文字
|
|
public void ShowHint(string _text, eHintType _type = eHintType.Warn)
|
|
{
|
|
long nowTicks = DateTime.Now.Ticks;
|
|
if (nowTicks - lastTimeShowHint < 3)
|
|
{
|
|
if(!string.IsNullOrEmpty(lastHintText))
|
|
{
|
|
if(lastHintText.CompareTo(_text) == 0)
|
|
{// 3秒内 同样的提示, 过滤掉
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
lastTimeShowHint = nowTicks;
|
|
//lastHintText = _text;
|
|
|
|
|
|
HintData vData = new HintData(_text, _type);
|
|
|
|
eInformId etype;
|
|
//if (HotfixEntry.IsPC)
|
|
// etype = eInformId.TipLeftHint;
|
|
//else
|
|
etype = eInformId.TipHint;
|
|
|
|
Inform<TipData>.Dispatch(etype, vData);
|
|
|
|
//if (_type == eHintType.Error)
|
|
// Debug.LogError("ShowHint. _text:" + _text);
|
|
|
|
}
|
|
|
|
public void ShowLeftHint(string _text, eHintType _type = eHintType.Warn)
|
|
{
|
|
long nowTicks = DateTime.Now.Ticks;
|
|
if (nowTicks - lastTimeShowHint < 3)
|
|
{
|
|
if (!string.IsNullOrEmpty(lastHintText))
|
|
{
|
|
if (lastHintText.CompareTo(_text) == 0)
|
|
{// 3秒内 同样的提示, 过滤掉
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
lastTimeShowHint = nowTicks;
|
|
//lastHintText = _text;
|
|
|
|
|
|
HintData vData = new HintData(_text, _type);
|
|
|
|
eInformId etype;
|
|
etype = eInformId.TipLeftHint;
|
|
|
|
Inform<TipData>.Dispatch(etype, vData);
|
|
|
|
//if (_type == eHintType.Error)
|
|
// Debug.LogError("ShowHint. _text:" + _text);
|
|
|
|
}
|
|
|
|
|
|
//// 提示文字
|
|
//public void ShowLeftHint(string _text, eHintType _type = eHintType.Info)
|
|
//{
|
|
// //需求神特么又要改回去
|
|
// ShowHint(_text, _type);
|
|
// return;
|
|
|
|
// //HintData vData = new HintData(_text, _type);
|
|
// //Inform<TipData>.Dispatch(eInformId.TipLeftHint, vData);
|
|
|
|
// //if (_type == eHintType.Error)
|
|
// // Debug.LogError("ShowHint. _text:" + _text);
|
|
|
|
//}
|
|
|
|
public void ShowHint(string _text, int _type)
|
|
{
|
|
ShowHint(_text, (eHintType)_type);
|
|
}
|
|
|
|
// 提示选择框
|
|
public void ShowChoice(string _text, Action _Call, Action _NoCall = null, string _title = "提示")
|
|
{
|
|
ChoiceData vData = new ChoiceData(_text, _Call, _NoCall, _title);
|
|
Inform<TipData>.Dispatch(eInformId.TipChoice, vData);
|
|
}
|
|
|
|
// 活动开启倒计时
|
|
//public void ShowActivityStart(ActivityBookCfg _cfg, string _title = "活动名称", string _text = "开启倒计时:{0}")
|
|
//{
|
|
// TipActivityData vData = new TipActivityData(_cfg, _title, _text);
|
|
// Inform<TipData>.Dispatch(eInformId.TipActivityStart, vData);
|
|
//}
|
|
|
|
//不再提示框
|
|
public void ShowNotRemindAgain(string _text, NotRemindAgainType pType, Action _Call, Action _NoCall = null, string _title = "提示")
|
|
{
|
|
ChoiceData vData = new ChoiceData(_text, _Call, _NoCall, _title);
|
|
Inform<TipData, NotRemindAgainType>.Dispatch(eInformId.TipNotRemindAgain, vData, pType);
|
|
}
|
|
|
|
// 提示等待
|
|
public void ShowWait(string _text, float _waitTimeMax = 15f)
|
|
{
|
|
WaitData vData = new WaitData(_text, _waitTimeMax);
|
|
Inform<TipData>.Dispatch(eInformId.TipWait, vData);
|
|
}
|
|
|
|
// 主线程安全 提示框
|
|
public void SafeShowDialog(string _text, string _title = "提示")
|
|
{
|
|
DialogData vData = new DialogData(_text, _title);
|
|
SafeTipQue.Enqueue(vData);
|
|
}
|
|
|
|
// 主线程安全 提示文字
|
|
public void SafeShowHint(string _text, eHintType _type = eHintType.Info)
|
|
{
|
|
long nowTicks = DateTime.Now.Ticks;
|
|
if (nowTicks - lastTimeShowHint < 3)
|
|
{
|
|
if (!string.IsNullOrEmpty(lastHintText))
|
|
{
|
|
if (lastHintText.CompareTo(_text) == 0)
|
|
{// 3秒内 同样的提示, 过滤掉
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
lastTimeShowHint = nowTicks;
|
|
|
|
HintData vData = new HintData(_text, _type);
|
|
SafeTipQue.Enqueue(vData);
|
|
|
|
}
|
|
public void SafeShowHint(string _text, int _type)
|
|
{
|
|
SafeShowHint(_text, (eHintType)_type);
|
|
}
|
|
|
|
// 主线程安全 提示选择框
|
|
public void SafeShowChoice(string _text, Action _Call, Action _NoCall = null, string _title = "提示")
|
|
{
|
|
ChoiceData vData = new ChoiceData(_text, _Call, _NoCall, _title);
|
|
SafeTipQue.Enqueue(vData);
|
|
}
|
|
|
|
// 主线程安全 提示等待
|
|
public void SafeShowWait(string _text, float _waitTimeMax = 15f)
|
|
{
|
|
WaitData vData = new WaitData(_text, _waitTimeMax);
|
|
SafeTipQue.Enqueue(vData);
|
|
}
|
|
|
|
public void HideChoice()
|
|
{
|
|
Inform.Dispatch(eInformId.TipChoiceClose); // 关闭选择框
|
|
}
|
|
|
|
// 关闭等待界面
|
|
public void HideWait()
|
|
{
|
|
Inform.Dispatch(eInformId.TipWaitClose);
|
|
}
|
|
}
|
|
|
|
|
|
public class TipData
|
|
{
|
|
public eTipType m_type = eTipType.None;
|
|
public string m_text = string.Empty;
|
|
|
|
public TipData(string _str)
|
|
{
|
|
m_text = _str;
|
|
}
|
|
}
|
|
|
|
public class DialogData : TipData
|
|
{
|
|
public string m_title = string.Empty;
|
|
public DialogData(string _str, string _title = "提示") : base(_str)
|
|
{
|
|
m_type = eTipType.Dialog;
|
|
m_title = _title;
|
|
}
|
|
}
|
|
|
|
public enum eHintType
|
|
{
|
|
Info = 1, // 普通 绿色
|
|
Warn, // 警告 黄色
|
|
Error, // 错误 红色
|
|
}
|
|
|
|
public class HintData : TipData
|
|
{
|
|
private eHintType m_HintType;
|
|
|
|
public eHintType p_HintType {
|
|
get { return m_HintType; }
|
|
}
|
|
|
|
|
|
public HintData(string _str, eHintType _type = eHintType.Info):base(_str)
|
|
{
|
|
m_type = eTipType.Hint;
|
|
m_HintType = _type;
|
|
}
|
|
}
|
|
|
|
public class ChoiceData : DialogData
|
|
{
|
|
public Action m_YesCall;
|
|
public Action m_NoCall;
|
|
|
|
public ChoiceData(string _str, Action _Call, Action _NoCall = null, string _title = "提示") : base(_str, _title)
|
|
{
|
|
m_type = eTipType.Choice;
|
|
m_YesCall += _Call;
|
|
|
|
if (_NoCall != null)
|
|
m_NoCall += _NoCall;
|
|
}
|
|
}
|
|
|
|
public class WaitData:TipData
|
|
{
|
|
public float m_waitTimeMax;
|
|
|
|
public WaitData(string _str, float _waitTimeMax = 15f):base(_str)
|
|
{
|
|
m_type = eTipType.Wait;
|
|
m_waitTimeMax = _waitTimeMax;
|
|
}
|
|
|
|
}
|
|
|
|
public class TipActivityData : DialogData
|
|
{
|
|
public Action m_YesCall;
|
|
//public Action m_NoCall;
|
|
|
|
public int m_ActivityyCid; // 目前代表的是活动日历配置编号
|
|
//public ActivityBookCfg mCfg;
|
|
public TipActivityData(/*ActivityBookCfg _cfg, */string _title = "活动名称", string _str = "开启倒计时:{0}", Action _Call = null) : base(_str, _title)
|
|
{
|
|
m_type = eTipType.Choice;
|
|
//mCfg = _cfg;
|
|
//m_ActivityyCid = _activityCid;
|
|
|
|
if(_Call != null)
|
|
m_YesCall += _Call;
|
|
|
|
//if (_NoCall != null)
|
|
// m_NoCall += _NoCall;
|
|
}
|
|
} |