You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
122 lines
4.3 KiB
122 lines
4.3 KiB
/***
|
|
*
|
|
* Title: "SUIFW" UI框架项目
|
|
* 主题: UI遮罩管理器
|
|
* Description:
|
|
* 功能: 负责“弹出窗体”模态显示实现
|
|
*
|
|
* Date: 2017
|
|
* Version: 0.1版本
|
|
* Modify Recoder:
|
|
*
|
|
*
|
|
*/
|
|
|
|
import { _decorator, Component, Camera, error, Color,Node, Sprite, BlockInputEvents } from "cc";
|
|
import { SysDefine, UIFormLucenyType, UIFromType } from "../Config/SysDefine";
|
|
|
|
|
|
const { ccclass, property, menu } = _decorator;
|
|
@ccclass
|
|
@menu("UIScript/UIMaskMgr")
|
|
export class UIMaskMgr extends Component {
|
|
/* 字段 */
|
|
//本脚本私有单例
|
|
private static _Instance: UIMaskMgr = null;
|
|
//UI根节点对象
|
|
private _GoCanvasRoot: Node = null;
|
|
//遮罩面板
|
|
private _GoMaskPanel: Node;
|
|
/**事件屏蔽组件 */
|
|
private _BlockInputEvents:BlockInputEvents;
|
|
|
|
protected onLoad(): void {
|
|
UIMaskMgr._Instance = this.node.getComponent(UIMaskMgr);
|
|
this.init_node();
|
|
}
|
|
|
|
//得到实例
|
|
public static get Ins(): UIMaskMgr {
|
|
return this._Instance;
|
|
}
|
|
|
|
private init_node() {
|
|
//得到UI根节点对象、脚本节点对象
|
|
this._GoCanvasRoot = this.node.getChildByName(SysDefine.SYS_PATH_CANVAS);
|
|
this._GoMaskPanel = this._GoCanvasRoot.getChildByName(SysDefine.SYS_PATH_MASK);
|
|
let PopRoot = this._GoCanvasRoot.getChildByName("PopUp");
|
|
this._GoMaskPanel.setParent(PopRoot);
|
|
this._GoMaskPanel.active = false;
|
|
this._BlockInputEvents = this._GoMaskPanel.getComponent(BlockInputEvents);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置遮罩状态
|
|
/// </summary>
|
|
/// <param name="goDisplayUIForms">需要显示的UI窗体</param>
|
|
/// <param name="lucenyType">显示透明度属性</param>
|
|
public SetMaskWindow(goDisplayUIForms: Node, lucenyType: UIFormLucenyType = UIFormLucenyType.Luceny) {
|
|
if (!this._GoCanvasRoot) return;
|
|
//启用遮罩窗体以及设置透明度
|
|
switch (lucenyType) {
|
|
//完全透明,不能穿透
|
|
case UIFormLucenyType.Luceny:
|
|
this._GoMaskPanel.active = true;
|
|
this._BlockInputEvents.enabled = true;
|
|
this._GoMaskPanel.getComponent(Sprite).color = SysDefine.SYS_UIMASK_LUCENCY_COLOR_RGB;
|
|
break;
|
|
//半透明,不能穿透
|
|
case UIFormLucenyType.Translucence:
|
|
this._GoMaskPanel.active = true;
|
|
this._BlockInputEvents.enabled = true;
|
|
this._GoMaskPanel.getComponent(Sprite).color = SysDefine.SYS_UIMASK_TRANS_LUCENCY_COLOR_RGB;
|
|
break;
|
|
//低透明,不能穿透
|
|
case UIFormLucenyType.ImPenetrable:
|
|
this._GoMaskPanel.active = true;
|
|
this._BlockInputEvents.enabled = true;
|
|
this._GoMaskPanel.getComponent(Sprite).color = SysDefine.SYS_UIMASK_IMPENETRABLE_COLOR_RGB;
|
|
break;
|
|
//可以穿透
|
|
case UIFormLucenyType.Pentrate:
|
|
this._BlockInputEvents.enabled = false;
|
|
if (this._GoMaskPanel.active) {
|
|
this._GoMaskPanel.active = false;
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
//遮罩窗体下移
|
|
const layers = this._GoMaskPanel.parent.children.length;
|
|
this._GoMaskPanel.setSiblingIndex(this._GoMaskPanel.getSiblingIndex() + (layers - 1))
|
|
//显示窗体的下移
|
|
goDisplayUIForms.setSiblingIndex(goDisplayUIForms.getSiblingIndex() + layers)
|
|
}
|
|
|
|
/// <summary>
|
|
/// 取消遮罩状态
|
|
/// </summary>
|
|
public CancelMaskWindow() {
|
|
if (!this._GoCanvasRoot) return;
|
|
let childs = this._GoMaskPanel.parent.children;
|
|
for (let i = childs.length - 2; i >= 0; i--) {
|
|
const tNodeClass = childs[i].getComponent("BaseUIForm");
|
|
//@ts-ignore
|
|
if (childs[i] != this._GoMaskPanel && tNodeClass && tNodeClass.mUIType.FromsType == UIFromType.PopUp) {
|
|
//@ts-ignore
|
|
this.SetMaskWindow(childs[i], tNodeClass.mUIType.FormsLucenyType);
|
|
return;
|
|
}
|
|
}
|
|
|
|
//禁用遮罩窗体
|
|
if (this._GoMaskPanel.active) {
|
|
//隐藏
|
|
this._GoMaskPanel.active = false;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|