This commit is contained in:
Bob.Song
2026-03-25 17:07:05 +08:00
parent 09540ad1a8
commit 830cf3c354
141 changed files with 537 additions and 197 deletions

View File

@@ -0,0 +1,131 @@
using System.Collections.Generic;
using FairyGUI;
using NBC;
namespace NBF
{
public class Alert : INoticeComponent
{
private static bool _init;
private const int Gap = 8;
private const int ItemWidth = 300;
private const int ItemHeight = 42;
private float _startY;
private float _startX;
private const int LimitCount = 6; //显示条数上限
private GObjectPool _noticePool;
private static readonly Queue<string> _msgArr = new();
protected GComponent ContentPane;
public static void Show(string msg)
{
if (string.IsNullOrEmpty(msg)) return;
Log.Info($"显示一个notice={msg}");
if (!_init)
{
NoticesPanel.TryAddNoticeComponent(new Alert());
}
_msgArr.Enqueue(msg);
}
public void OnInit(GComponent root)
{
_init = true;
ContentPane = root;
_noticePool = new GObjectPool(ContentPane.container.cachedTransform);
_startY = GRoot.inst.height - ItemHeight - Gap - 90;
_startX = GRoot.inst.width * 0.5f - ItemWidth * 0.5f;
}
public void OnUpdate()
{
if (_msgArr.Count > 0)
{
var msg = _msgArr.Dequeue();
ShowOnceNotice(msg);
//旧的向上移动
var count = ContentPane.numChildren - 1;
for (int i = 0; i < count; i++)
{
GObject obj = ContentPane.GetChildAt(i);
if (obj != null)
{
SetObjRise(obj);
}
}
RemoveLimitMsg();
}
}
public void OnDestroy()
{
_noticePool.Clear();
}
private void ShowOnceNotice(string msg)
{
var item = GetFromPool(AlertItem.URL) as AlertItem;
if (item == null) return;
item.SetData(msg);
item.x = _startX;
item.y = _startY;
item.alpha = 1;
//显示在固定区域 两秒后消失
item.TweenFade(0, 0.5f).SetDelay(5).OnComplete(() => { ReturnToPool(item); });
}
private void SetObjRise(GObject item)
{
item.TweenMoveY(item.y - item.height - 10, 0.2f).SetEase(EaseType.QuintInOut);
}
private void RemoveLimitMsg()
{
var count = ContentPane.numChildren;
if (count > LimitCount)
{
for (int i = 0; i < count - LimitCount; i++)
{
GObject obj = ContentPane.GetChildAt(i);
if (obj != null)
{
if (GTween.IsTweening(obj))
{
GTween.Kill(obj, true);
}
else
{
ReturnToPool(obj);
}
}
}
}
}
private GObject GetFromPool(string url)
{
var ret = _noticePool.GetObject(url);
if (ret == null) return null;
ret.visible = true;
ContentPane.AddChild(ret);
GTween.GetTween(ret, TweenPropType.Y)?.Kill();
return ret;
}
private void ReturnToPool(GObject obj)
{
ContentPane.RemoveChild(obj);
_noticePool.ReturnObject(obj);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 02c8803ebf5f404da737ff0f699f5866
timeCreated: 1774402864

View File

@@ -0,0 +1,11 @@
using FairyGUI;
namespace NBF
{
public interface INoticeComponent
{
void OnInit(GComponent root);
void OnUpdate();
void OnDestroy();
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c5292036b17c4e4988a2d5bf383737ab
timeCreated: 1774403415

View File

@@ -0,0 +1,42 @@
/**本脚本为自动生成每次生成会覆盖请勿手动修改生成插件文档及项目地址https://git.whoot.com/whoot-games/whoot.fguieditorplugin**/
using FairyGUI;
using FairyGUI.Utils;
using NBC;
using System.Collections.Generic;
namespace NBF
{
/// <summary> </summary>
public partial class MessageBox
{
public GObject this[string aKey] => ContentPane.GetChild(aKey);
public override string UIPackName => "Common";
public override string UIResName => "MessageBox";
[AutoFind(Name = "style")]
public Controller style;
[AutoFind(Name = "back_full")]
public GImage back_full;
[AutoFind(Name = "Modal")]
public GLabel Modal;
[AutoFind(Name = "TextContent")]
public GTextField TextContent;
[AutoFind(Name = "BtnConfirm1")]
public GButton BtnConfirm1;
[AutoFind(Name = "BtnCancel")]
public GButton BtnCancel;
[AutoFind(Name = "BtnConfirm2")]
public GButton BtnConfirm2;
[AutoFind(Name = "show")]
public Transition show;
public override string[] GetDependPackages(){ return new string[] {}; }
public static void Show(object param = null){ UI.Inst.OpenUI<MessageBox>(param); }
public static void Hide(){ UI.Inst.HideUI<MessageBox>(); }
public static void Del(){ UI.Inst.DestroyUI<MessageBox>(); }
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 7ce689c460bfe8245948899939807a59

View File

@@ -0,0 +1,97 @@
// 本脚本只在不存在时会生成一次。已存在不会再次生成覆盖
using System;
using FairyGUI;
using UnityEngine;
using NBC;
using UIPanel = NBC.UIPanel;
namespace NBF
{
public partial class MessageBox : UIPanel
{
private static string _confirmText;
private static string _cancelText;
private static string _title;
private static string _content;
private static Action<bool> _callback;
private static int _style;
public static void Show(string msg, Action<bool> callback, string title = "", int style = 0,
string confirm = "", string cancel = "")
{
if (string.IsNullOrEmpty(title))
{
title = "TEXT_NOTE";
}
if (string.IsNullOrEmpty(confirm))
{
confirm = "TEXT_CONFIRM";
}
if (string.IsNullOrEmpty(cancel))
{
cancel = "TEXT_CANCEL";
}
_confirmText = confirm;
_cancelText = cancel;
_callback = callback;
_content = msg;
_title = title;
_style = style;
Show();
}
protected override void OnInit()
{
this.AutoAddClick(OnClick);
IsModal = true;
HideAnim = UIPanelAnimation.GetCenterPopScaleFade(this, true);
InputManager.OnUICanceled += OnUICanceled;
}
protected override void OnShow()
{
BtnConfirm1.SetLanguage(_confirmText);
BtnConfirm2.SetLanguage(_confirmText);
BtnCancel.SetLanguage(_cancelText);
style.selectedIndex = _style;
Modal.SetLanguage(_title);
TextContent.SetLanguage(_content);
}
private void OnUICanceled(string action)
{
if (!IsShowing) return;
if (!IsTop) return;
if (action == InputDef.UI.Enter)
{
ClosePanel(true);
}
else if (action == InputDef.UI.Back)
{
ClosePanel(false);
}
}
protected override void OnDestroy()
{
base.OnDestroy();
InputManager.OnUICanceled -= OnUICanceled;
}
private void OnClick(GComponent btn)
{
ClosePanel(btn == BtnConfirm1 || btn == BtnConfirm2);
}
private void ClosePanel(bool ret)
{
_callback?.Invoke(ret);
Hide();
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 8e4609ff88d94fa8ad77c3cb17641809

View File

@@ -0,0 +1,159 @@
using System.Collections.Generic;
using FairyGUI;
using NBC;
namespace NBF
{
public class Notices : INoticeComponent
{
public enum NoticeType
{
Info = 0,
Success,
Error,
Warning,
}
class NoticeData
{
public NoticeType Type;
public string Text;
}
private static bool _init;
private const int Gap = 8;
private const int ItemWidth = 330;
private float _startY;
private float _startX;
private const int LimitCount = 6; //显示条数上限
private GObjectPool _noticePool;
private static readonly Queue<NoticeData> _msgArr = new();
protected GComponent ContentPane;
public static void Info(string msg, NoticeType noticeType = NoticeType.Info)
{
if (string.IsNullOrEmpty(msg)) return;
Log.Info($"显示一个notice={msg}");
if (!_init)
{
NoticesPanel.TryAddNoticeComponent(new Notices());
}
_msgArr.Enqueue(new NoticeData { Type = noticeType, Text = msg });
}
public static void Success(string msg)
{
Info(msg, NoticeType.Success);
}
public static void Warning(string msg)
{
Info(msg, NoticeType.Warning);
}
public static void Error(string msg)
{
Info(msg, NoticeType.Error);
}
public void OnInit(GComponent root)
{
_init = true;
ContentPane = root;
_noticePool = new GObjectPool(ContentPane.container.cachedTransform);
_startY = Gap + 140;
_startX = GRoot.inst.width - ItemWidth - Gap;
}
public void OnUpdate()
{
if (_msgArr.Count > 0)
{
var msg = _msgArr.Dequeue();
ShowOnceNotice(msg);
//旧的向上移动
var count = ContentPane.numChildren - 1;
for (int i = 0; i < count; i++)
{
GObject obj = ContentPane.GetChildAt(i);
if (obj != null)
{
SetObjRise(obj);
}
}
RemoveLimitMsg();
}
}
public void OnDestroy()
{
_noticePool.Clear();
}
private void ShowOnceNotice(NoticeData notice)
{
var item = GetFromPool(NotificationItem.URL) as NotificationItem;
if (item == null) return;
item.SetData(notice.Text, notice.Type);
item.x = _startX;
item.y = _startY;
item.alpha = 1;
//显示在固定区域 两秒后消失
item.TweenFade(0, 0.5f).SetDelay(3).OnComplete(() => { ReturnToPool(item); });
}
private void SetObjRise(GObject item)
{
item.TweenMoveY(item.y + item.height + Gap, 0.2f).SetEase(EaseType.QuintInOut);
}
private void RemoveLimitMsg()
{
var count = ContentPane.numChildren;
if (count > LimitCount)
{
for (int i = 0; i < count - LimitCount; i++)
{
GObject obj = ContentPane.GetChildAt(i);
if (obj != null)
{
if (GTween.IsTweening(obj))
{
GTween.Kill(obj, true);
}
else
{
ReturnToPool(obj);
}
}
}
}
}
private GObject GetFromPool(string url)
{
var ret = _noticePool.GetObject(url);
if (ret == null) return null;
ret.visible = true;
ContentPane.AddChild(ret);
GTween.GetTween(ret, TweenPropType.Y)?.Kill();
return ret;
}
private void ReturnToPool(GObject obj)
{
ContentPane.RemoveChild(obj);
_noticePool.ReturnObject(obj);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5a2c129ec53a45f29b5a3ad6d4869d8a
timeCreated: 1774402966

View File

@@ -0,0 +1,28 @@
/**本脚本为自动生成每次生成会覆盖请勿手动修改生成插件文档及项目地址https://git.whoot.com/whoot-games/whoot.fguieditorplugin**/
using FairyGUI;
using FairyGUI.Utils;
using NBC;
using System.Collections.Generic;
namespace NBF
{
/// <summary> </summary>
public partial class NoticesPanel
{
public GObject this[string aKey] => ContentPane.GetChild(aKey);
public override string UIPackName => "Common";
public override string UIResName => "NoticesPanel";
[AutoFind(Name = "show")]
public Controller show;
public override string[] GetDependPackages(){ return new string[] {}; }
public static void Show(object param = null){ UI.Inst.OpenUI<NoticesPanel>(param); }
public static void Hide(){ UI.Inst.HideUI<NoticesPanel>(); }
public static void Del(){ UI.Inst.DestroyUI<NoticesPanel>(); }
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: d3ebf93e99f31f245ae973b663ba39b7

View File

@@ -0,0 +1,82 @@
// 本脚本只在不存在时会生成一次。已存在不会再次生成覆盖
using System.Collections.Generic;
using System.Linq;
using FairyGUI;
using UnityEngine;
using NBC;
using UIPanel = NBC.UIPanel;
namespace NBF
{
public partial class NoticesPanel : UIPanel
{
private static HashSet<INoticeComponent> _noticeComponents = new();
private static Queue<INoticeComponent> _waitAddComponents = new();
private static bool _isOpen;
public static void TryAddNoticeComponent(INoticeComponent noticeComponent)
{
if (!_isOpen)
{
Show();
}
if (_noticeComponents.Any(iNoticeComponent => iNoticeComponent.GetType() == noticeComponent.GetType()))
{
return;
}
if (_waitAddComponents.Any(waitAddComponent => waitAddComponent.GetType() == noticeComponent.GetType()))
{
return;
}
_waitAddComponents.Enqueue(noticeComponent);
}
protected override void OnInit()
{
ContentPane.sortingOrder = UIDef.UIOrder.Notices;
}
protected override void OnShow()
{
_isOpen = true;
}
protected override void OnUpdate()
{
foreach (var noticeComponent in _noticeComponents)
{
noticeComponent?.OnUpdate();
}
if (_waitAddComponents.Count > 0)
{
var com = _waitAddComponents.Dequeue();
var noticeComponent = UIPackage.CreateObject(UIDef.Pack.Common, "CommonContainer") as GComponent;
noticeComponent.width = ContentPane.width;
noticeComponent.height = ContentPane.height;
ContentPane.AddChild(noticeComponent);
com.OnInit(noticeComponent);
_noticeComponents.Add(com);
}
}
protected override void OnHide()
{
_isOpen = false;
}
protected override void OnDestroy()
{
foreach (var noticeComponent in _noticeComponents)
{
noticeComponent?.OnDestroy();
}
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 599ea11cfee0f394bbd7f053c3914f05