Files
oops-plugin-framework/assets/core/gui/layer/LayerNotify.ts
dgflash f2fe9d47b6 1. 存储模块全面优化,修复跨平台兼容性问题,完美支持所有Unicode字符
2. 存储模块性能提升,添加LRU缓存、批量操作支持,优化内存使用
3. 多语言模块性能与内存管理优化,组件查询性能提升
4. 时间模块类型安全与性能优化,使用泛型替代any,对象池机制减少内存分配
5. 事件系统修复双重注册、重复注册等严重问题,实现EventData对象池减少GC压力
6. RandomManager修复4个逻辑BUG,包括边界问题和越界问题
7. 音频模块内存与性能优化,避免重复加载,优化数据结构,添加完整清理机制
8. CCView与CCViewVM合并,支持按需启用MVVM
9. Collection模块优化,AsyncQueue添加队列容量限制,Collection查询性能提升
10. ECS系统全面优化,对象池复用减少内存分配,循环性能提升
11. 优化MVVM组件性能
2026-01-09 21:54:05 +08:00

119 lines
3.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* @Author: dgflash
* @Date: 2022-08-15 10:06:47
* @LastEditors: dgflash
* @LastEditTime: 2022-09-02 13:44:12
*/
import { BlockInputEvents, Node, instantiate } from 'cc';
import { EDITOR } from 'cc/env';
import { ViewUtil } from '../../utils/ViewUtil';
import { PromptResType } from '../GuiEnum';
import { Notify } from '../prompt/Notify';
import { LayerHelper } from './LayerHelper';
/* 滚动消息提示层 */
export class LayerNotify extends Node {
private black!: BlockInputEvents;
/** 等待提示资源 */
private wait: Node = null!;
/** 自定义弹出提示资源 */
private notify: Node = null!;
/** 自定义弹出提示内容资源 */
private notifyItem: Node = null!;
constructor(name: string) {
super(name);
LayerHelper.setFullScreen(this);
this.black = this.addComponent(BlockInputEvents);
this.black.enabled = false;
}
/** 打开等待提示 */
async waitOpen() {
if (this.wait == null) {
// 兼容编辑器预览模式
if (EDITOR) {
this.wait = await ViewUtil.createPrefabNodeAsync(PromptResType.Wait);
}
else {
this.wait = ViewUtil.createPrefabNode(PromptResType.Wait);
}
}
if (this.wait.parent == null) {
this.wait.parent = this;
this.black.enabled = true;
}
}
/** 关闭等待提示 */
waitClose() {
if (this.wait && this.wait.parent) {
this.wait.parent = null;
this.black.enabled = false;
}
}
/**
* 渐隐飘过提示
* @param content 文本表示
* @param useI18n 是否使用多语言
*/
async toast(content: string, useI18n: boolean) {
if (this.notify == null) {
// 兼容编辑器预览模式
if (EDITOR) {
this.notify = await ViewUtil.createPrefabNodeAsync(PromptResType.Toast);
}
else {
this.notify = ViewUtil.createPrefabNode(PromptResType.Toast);
}
this.notifyItem = this.notify.children[0];
this.notifyItem.parent = null;
}
this.notify.parent = this;
const childNode = instantiate(this.notifyItem);
const prompt = childNode.getChildByName('prompt')!;
const toastCom = prompt.getComponent(Notify)!;
childNode.parent = this.notify;
toastCom.onComplete = () => {
if (this.notify.children.length == 0) {
this.notify.parent = null;
}
};
toastCom.toast(content, useI18n);
// 超过3个提示就释放第一个提示
if (this.notify.children.length > 3) {
this.notify.children[0].destroy();
}
}
/** 销毁时释放资源 */
onDestroy() {
// 清理等待提示节点
if (this.wait) {
this.wait.destroy();
this.wait = null!;
}
// 清理通知提示节点
if (this.notify) {
this.notify.destroy();
this.notify = null!;
}
// 清理通知项模板节点
if (this.notifyItem) {
this.notifyItem.destroy();
this.notifyItem = null!;
}
// 清理事件阻挡组件
this.black = null!;
}
}