using Thousandto.Code.Center; using Thousandto.Core.Base; using Thousandto.Plugins.Common; using System; using System.Collections.Generic; using System.Text; using Thousandto.Code.Global; using Thousandto.Cfg.Data; using XLua; using CoreEventDefine = UnityEngine.Gonbest.MagicCube.CoreEventDefine; namespace Thousandto.Code.Logic { /// /// 消息提示系统 /// 1.对话框窗体 /// 2.走马的灯的公告窗体 /// 3.往上滚动的提示消息窗体 /// public class MsgPromptSystem { //初始化处理 public void Initialize() { //清除跑马灯信息 GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_MSG_MARQUEE_CLEAR); GameCenter.RegFixEventHandle(CoreEventDefine.EID_CORE_GLOBAL_SHOW_MESSAGE_BOX, OnGlobalShowMessageHandler); } //卸载处理 public void Uninitialize() { GameCenter.UnRegFixEventHandle(CoreEventDefine.EID_CORE_GLOBAL_SHOW_MESSAGE_BOX, OnGlobalShowMessageHandler); } /// /// 处理全局展示消息的句柄 /// /// /// private void OnGlobalShowMessageHandler(object param, object sender) { var ps = param as object[]; if (ps.Length > 1) { var method = ps[0] as string; if (!string.IsNullOrEmpty(method)) { method = method.Trim(); switch (method) { case "ShowMsgBox": //全局的显示Box,需要做一下翻译 var text = ps[1] as string; var btn1 = ps[2] as string; var bnt2 = ps[3] as string; if (!string.IsNullOrEmpty(text)) { text = GameCenter.LanguageConvertSystem.ConvertLan(text); } if (!string.IsNullOrEmpty(btn1)) { btn1 = GameCenter.LanguageConvertSystem.ConvertLan(btn1); } if (!string.IsNullOrEmpty(bnt2)) { bnt2 = GameCenter.LanguageConvertSystem.ConvertLan(bnt2); } //这里的消息提示参数为:new object[] { "ShowMsgBox"/*方法 字符串*/, msg/*提示信息 字符串*/, btn1Str/*第一个按钮 字符串*/, btn2Str/*第二个按钮 字符串*/, callBackAction/*回调函数 类型为Action*/ } ShowMsgBox(text, btn1, bnt2, x => { var act = ps[4] as Action; if (act != null) { act((int)x); } }); break; } } } } /// /// 提示系统信息 /// /// 显示的文本消息 /// 优先级 public void ShowPrompt(string str, MsgInfoPriority pro = MsgInfoPriority.Highest) { if (string.IsNullOrEmpty(str)) return; MsgPromptInfo temp = new MsgPromptInfo(); temp.Msg = str; temp.Priority = pro; temp.ShowLifeTime = 2f; GameCenter.PushFixEvent((int)UIEventDefine.UISYSTEMINFO_SHOWINFO, temp); } /// /// 提示系统信息 /// /// messagestringid /// 参数 public void ShowPromptByMsgStrID(long msgStrId, params object[] parames) { string str = null; if(parames.Length > 0) { str = DeclareMessageString.Format((int)msgStrId, parames); } else { str = DeclareMessageString.Get((int)msgStrId); } if (string.IsNullOrEmpty(str)) return; MsgPromptInfo temp = new MsgPromptInfo(); temp.Msg = str; temp.Priority = MsgInfoPriority.Highest; temp.ShowLifeTime = 2f; GameCenter.PushFixEvent((int)UIEventDefine.UISYSTEMINFO_SHOWINFO, temp); } /// /// 提示系统信息(带Item的) /// /// 显示的文本消息 /// 优先级 public void ShowPrompt(ItemBase itemBase, MsgInfoPriority pro = MsgInfoPriority.Highest) { if (itemBase == null) return; MsgPromptInfo temp = new MsgPromptInfo(); //temp.Msg = str; temp.ItemBase = itemBase; temp.Priority = pro; temp.ShowLifeTime = 2f; GameCenter.PushFixEvent((int)UIEventDefine.UISYSTEMINFO_SHOWINFO, temp); } /// /// 走马灯 /// /// 消息文本 /// 速度 /// 显示次数 /// 优先级 public void ShowMarquee(string str, float speed = 50, int times = 1, MsgInfoPriority pro = MsgInfoPriority.Highest) { MsgMarqueeInfo temp = new MsgMarqueeInfo(); temp.Msg = str; temp.Priority = pro; temp.Speed = speed; temp.Times = times; GameCenter.PushFixEvent((int)UIEventDefine.UIMARQUEE_SHOWINFO, temp); } public void ShowYunYingMarquee(string str, float speed = 50, int times = 1, MsgInfoPriority pro = MsgInfoPriority.Highest) { MsgMarqueeInfo temp = new MsgMarqueeInfo(); temp.Msg = str; temp.Priority = pro; temp.Speed = speed; temp.Times = times; GameCenter.PushFixEvent((int)UIEventDefine.UIYunYingMarqueeForm_OPEN, temp); } //显示高阶公告 public void ShowHighOrderNotice(string str) { MsgHighLevelNotifyInfo temp = new MsgHighLevelNotifyInfo(); temp.Msg = str; GameCenter.PushFixEvent((int)LogicEventDefine.EID_EVENT_HIGHNOTIFY, temp); } /// /// 显示消息对话框 /// /// 消息文本 /// 第一个按钮的文本 /// 第二个按钮的文本 /// 回调函数 /// 点击背景就会关闭 /// 不操作情况下自动关闭 /// 生存期 /// 优先级 /// 第一个按钮的背景Sprite /// 第二个按钮的背景Sprite /// 隐藏后是否执行回调 public void ShowMsgBox(bool isDoCallBackHideAfter , string str, MyAction callBack, bool isClickBGClose = false, bool autoHide = false, float liftTime = 5, MsgInfoPriority pro = MsgInfoPriority.Highest, float alpha = 1, string btnSprite1 = null, string btnSprite2 = null, MsgBoxInfoTypeCode msgBoxInfoType = MsgBoxInfoTypeCode.None) { ShowMsgBox(str, DeclareMessageString.Get(DeclareMessageString.C_MSGBOX_CANCEL), DeclareMessageString.Get(DeclareMessageString.C_MSGBOX_OK), callBack, isClickBGClose, autoHide, liftTime, pro, alpha, btnSprite1, btnSprite2, msgBoxInfoType, isDoCallBackHideAfter); } /// /// 显示消息对话框 /// /// 消息文本 /// 第一个按钮的文本 /// 第二个按钮的文本 /// 回调函数 /// 点击背景就会关闭 /// 不操作情况下自动关闭 /// 生存期 /// 优先级 /// 第一个按钮的背景Sprite /// 第二个按钮的背景Sprite public void ShowMsgBox(string str, MyAction callBack, bool isClickBGClose = false, bool autoHide = false, float liftTime = 5, MsgInfoPriority pro = MsgInfoPriority.Highest, float alpha = 1, string btnSprite1 = null, string btnSprite2 = null,MsgBoxInfoTypeCode msgBoxInfoType = MsgBoxInfoTypeCode.None) { ShowMsgBox(str, DeclareMessageString.Get(DeclareMessageString.C_MSGBOX_CANCEL), DeclareMessageString.Get(DeclareMessageString.C_MSGBOX_OK), callBack, isClickBGClose, autoHide, liftTime, pro, alpha, btnSprite1, btnSprite2, msgBoxInfoType); } public void ShowMsgBox(string str, string btnText1 = null, string btnText2 = null, MyAction callBack = null, bool isClickBGClose = false, bool autoHide = false, float liftTime = 5, MsgInfoPriority pro = MsgInfoPriority.Highest, float alpha = 1, string btnSprite1 = null, string btnSprite2 = null,MsgBoxInfoTypeCode msgBoxInfoType = MsgBoxInfoTypeCode.None, bool isDoCallBackHideAfter = false) { MsgBoxSelectInfo temp = new MsgBoxSelectInfo(); temp.IsClickBGClose = isClickBGClose; temp.IsAutoHide = autoHide; temp.ShowLifeTime = liftTime; temp.Button1 = btnText1 == null ? null : new MsgBoxButton(btnText1, btnSprite1); temp.Button2 = btnText2 == null ? null : new MsgBoxButton(btnText2, btnSprite2); temp.Priority = pro; temp.Msg = str; temp.AlphaValue = alpha; temp.OnCallBack = callBack; temp.MsgBoxInfoType = msgBoxInfoType; temp.OnSelectCallBack = null; temp.SelectText = null; temp.IsMsgBoxSelect = false; temp.IsDoCallBackHideAfter = isDoCallBackHideAfter; GameCenter.PushFixEvent((int)UIEventDefine.UIMESSAGEBOX_SHOWINFO, temp); } public void ShowSelectMsgBox(string str, string btnText1 = null, string btnText2 = null, MyAction callBack = null,MyAction selectCallBack = null,string selectText = null, bool isClickBGClose = false, bool autoHide = false, float liftTime = 5, MsgInfoPriority pro = MsgInfoPriority.Highest, float alpha = 1, string btnSprite1 = null, string btnSprite2 = null, MsgBoxInfoTypeCode msgBoxInfoType = MsgBoxInfoTypeCode.None, bool isDoCallBackHideAfter = false) { MsgBoxSelectInfo temp = new MsgBoxSelectInfo(); temp.IsClickBGClose = isClickBGClose; temp.IsAutoHide = autoHide; temp.ShowLifeTime = liftTime; temp.Button1 = btnText1 == null ? null : new MsgBoxButton(btnText1, btnSprite1); temp.Button2 = btnText2 == null ? null : new MsgBoxButton(btnText2, btnSprite2); temp.Priority = pro; temp.Msg = str; temp.AlphaValue = alpha; temp.OnCallBack = callBack; temp.MsgBoxInfoType = msgBoxInfoType; temp.OnSelectCallBack = selectCallBack; temp.SelectText = selectText; temp.IsMsgBoxSelect = true; temp.IsDoCallBackHideAfter = isDoCallBackHideAfter; GameCenter.PushFixEvent((int)UIEventDefine.UIMESSAGEBOX_SHOWINFO, temp); } //显示msgbox,lua专用,用于降低GC public void ShowMsgBoxByMsgStrID(MyAction callBack, long btn1StrId, long btn2StrId, long msgStrId, params object[] parames) { string str = null; if (parames.Length > 0) { str = DeclareMessageString.Format((int)msgStrId, parames); } else { str = DeclareMessageString.Get((int)msgStrId); } string btn1Text = null; if(btn1StrId >= 0) { btn1Text = DeclareMessageString.Get((int)btn1StrId); } string btn2Text = null; if(btn2StrId >= 0) { btn2Text = DeclareMessageString.Get((int)btn2StrId); } ShowMsgBox(str, btn1Text, btn2Text, callBack); } //关闭消息框 public void CloseMsgBox() { GameCenter.PushFixEvent((int)UIEventDefine.UIMESSAGEBOX_CLOSE); } #region//静态函数 -- 提供工具函数 //把一个数据压倒一个堆栈中,通过优先级排序 public static void EnQueue(List msgQueue, T info) where T : MsgInfoBase { if (msgQueue.Count > 0) { for (int i = msgQueue.Count - 1; i >= 0; i--) { if (msgQueue[i].Priority >= info.Priority) { msgQueue.Insert(i + 1, info); break; } } } else { msgQueue.Add(info); } } public static void EnQueueMsgPromptInfo(List msgQueue, MsgPromptInfo info) { if (msgQueue.Count > 0) { for (int i = msgQueue.Count - 1; i >= 0; i--) { if (msgQueue[i].Priority >= info.Priority) { msgQueue.Insert(i + 1, info); break; } } } else { msgQueue.Add(info); } } //从消息队列中获取一个数据 public static T DeQueue(List msgQueue) where T : MsgInfoBase { if (msgQueue.Count > 0) { var item = msgQueue[0]; msgQueue.RemoveAt(0); return item; } return default(T); } public static MsgBoxInfo DeQueueMsgBoxInfo(List msgQueue) { if (msgQueue.Count > 0) { var item = msgQueue[0]; msgQueue.RemoveAt(0); return item; } return null; } public static MsgPromptInfo DeQueueMsgPromptInfo(List msgQueue) { if (msgQueue.Count > 0) { var item = msgQueue[0]; msgQueue.RemoveAt(0); return item; } return null; } #endregion } }