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.
222 lines
6.9 KiB
222 lines
6.9 KiB
|
|
//UI窗体的父类
|
|
/*
|
|
*功能:定义所有UI窗体的父类
|
|
* 定义4个生命周期
|
|
* 1,Display //显示状态
|
|
* 2,Hiding //隐藏状态
|
|
* 3,ReDisplay //再显示状态
|
|
* 4,Freeze //冻结状态
|
|
*/
|
|
import { _decorator, BlockInputEvents, Node, Sprite, tween, v3, Vec3, Widget,Component } from "cc";
|
|
import { SysDefine, UIFromShowType, UIFromType } from "./Config/SysDefine";
|
|
import { UIMaskMgr } from "./Helps/UIMaskMgr";
|
|
import UIParse from "./UIParse";
|
|
import UIType from "./UIType";
|
|
import { PREVIEW } from "cc/env";
|
|
import { MainConfig } from "../../Launch/_MainConfig";
|
|
import { EGlobalEvent } from "../MesEvent/EGlobalEvent";
|
|
import GuideData from "../Mgr_Guide/GuideData";
|
|
import MesMgr from "../MesEvent/MesMgr";
|
|
import CocosUtils from "../ExCUtils/CocosUtils";
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
const PropList:UIFromType[] = [UIFromType.PopUp,UIFromType.Tips];
|
|
const CheckOpen = (Type:UIFromType)=>{return PropList.includes(Type)}
|
|
const bigScale = v3(1.2,1.2,1.2);
|
|
const orgScale = v3(1,1,1);
|
|
export type NodeAndCompType = Node |Component;
|
|
|
|
@ccclass
|
|
export default abstract class BaseUIForm extends UIParse {
|
|
/**打开UI的时间戳 */
|
|
private _OpenTime:number = 0;
|
|
/**获取UI存在的时间毫秒 */
|
|
get ExistTime(){ return Date.now() - this._OpenTime;}
|
|
/**UI所在包 */
|
|
UIBundle: string;
|
|
get tuuid(){
|
|
return this.node["_prefab"]["asset"]["uuid"];
|
|
}
|
|
@property({ displayName: '是否屏蔽事件' })
|
|
mBlockInput:boolean = false;
|
|
/**是否缓存 */
|
|
@property({displayName: '是否缓存' })
|
|
misCache: boolean = false;
|
|
@property({type : UIType ,visible:false})
|
|
private _UIType: UIType = new UIType();
|
|
/*属性*/
|
|
//当前UI窗体类型
|
|
@property({type : UIType , displayName : '当前UI窗体类型'})
|
|
public get mUIType(): UIType {
|
|
return this._UIType;
|
|
}
|
|
public set mUIType(value: UIType) {
|
|
this._UIType = value;
|
|
}
|
|
|
|
@property({visible: function () { return this._UIType.FromsType == UIFromType.PopUp || this._UIType.FromsType == UIFromType.Tips }
|
|
,displayName:"窗口弹出动画"})
|
|
OpenAni:boolean = true;
|
|
|
|
/**传入的参数 */
|
|
protected param:any = null;
|
|
/**视图节点 */
|
|
protected _View:Node;
|
|
protected _UIView:Node;
|
|
protected _onCloseCheckUI:string[]=[];
|
|
|
|
protected onLoad(): void {
|
|
this.UIBundle = CocosUtils.GetResBundle(this.tuuid).name;
|
|
if (this.node.layer != SysDefine.SYS_GROUP) { ConsoleEx.Error("层级错误"); }
|
|
PREVIEW && ConsoleEx.Log("UI路径:", CocosUtils.GetResBundlePath(this.tuuid), this.UIBundle)
|
|
super.onLoad();
|
|
this._View = this.views.get("View");
|
|
this._UIView = this.views.get("UIView");
|
|
this.mBlockInput && this.setBlockInput();
|
|
(MainConfig.isMiniGame || PREVIEW) && this._miniGameAdapter();
|
|
this._PlayAnimation();
|
|
this._OpenTime = Date.now();
|
|
MesMgr.on(EGlobalEvent.E_UI_TIME_REFRESH,this.time_refresh,this);
|
|
MesMgr.on(EGlobalEvent.E_UI_CLOSE_CALL_BACK,this.OtherCloseUI,this)
|
|
}
|
|
/**设置时间屏蔽 */
|
|
private setBlockInput(){
|
|
if(!this.node.getComponent(BlockInputEvents)){
|
|
this.node.addComponent(BlockInputEvents)
|
|
}
|
|
}
|
|
/**播放进入动画 */
|
|
private _PlayAnimation() {
|
|
const play = this.OpenAni && this._View && !GuideData.isGuide && CheckOpen(this.mUIType.FromsType) && this.mUIType.FromsShowType != UIFromShowType.HideOther
|
|
if (play) {
|
|
this._View.setScale(0, 0, 0);
|
|
tween(this._View).to(0.2, { scale: bigScale }).to(0.1, { scale: orgScale }).call(() => {
|
|
this._PopUpCallBack();
|
|
}).start();
|
|
}
|
|
}
|
|
/**进入动画播放完成 */
|
|
protected _PopUpCallBack() { }
|
|
/**设置小游戏适配 */
|
|
private _miniGameAdapter() {
|
|
let tWidget = this._View?.getComponent(Widget);
|
|
if (tWidget) {
|
|
tWidget.top = tWidget.top + 60;
|
|
tWidget.updateAlignment();
|
|
}
|
|
|
|
let tWidget2 = this._UIView?.getComponent(Widget);
|
|
if (tWidget2) {
|
|
tWidget2.top = tWidget2.top + 60;
|
|
tWidget2.updateAlignment();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 每天 每周 每月刷新时调用
|
|
* @param type
|
|
* EveryDay
|
|
* Week
|
|
* Month
|
|
*/
|
|
protected time_refresh(type:string){
|
|
|
|
}
|
|
|
|
private OtherCloseUI(uiname:string){
|
|
if(this._onCloseCheckUI.includes(uiname)){
|
|
this.onOtherCloseUI();
|
|
}
|
|
}
|
|
protected onOtherCloseUI(){
|
|
|
|
}
|
|
|
|
/**传递参数 */
|
|
public onShow(m_param?: any) {this.param = m_param;}
|
|
/// <summary>
|
|
/// 显示状态
|
|
/// </summary>
|
|
Display() {
|
|
this.node.active = true;
|
|
//设置模态窗体调用(必须是弹出窗体)
|
|
if (this._UIType.FromsType == UIFromType.PopUp) {
|
|
UIMaskMgr.Ins.SetMaskWindow(this.node, this._UIType.FormsLucenyType);
|
|
}
|
|
this.onDisplay();
|
|
}
|
|
protected onDisplay(){};
|
|
/// <summary>
|
|
/// 隐藏状态
|
|
/// </summary>
|
|
Hideing() {
|
|
this.node.active = false;
|
|
//取消模态窗体调用
|
|
if (this._UIType.FromsType == UIFromType.PopUp) {
|
|
UIMaskMgr.Ins.CancelMaskWindow();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 重新显示状态
|
|
/// </summary>
|
|
ReDisplay() {
|
|
this.node.active = true;
|
|
//设置模态窗体调用(必须是弹出窗体)
|
|
if (this._UIType.FromsType == UIFromType.PopUp) {
|
|
UIMaskMgr.Ins.SetMaskWindow(this.node, this._UIType.FormsLucenyType);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 冻结状态
|
|
/// </summary>
|
|
Freeze() {
|
|
this.node.active = true;
|
|
}
|
|
|
|
/**移动节点 */
|
|
MoveNodeList(list: NodeAndCompType[],Offset:Vec3,time:number = 0.2){
|
|
for (let i = 0; i < list.length; i++) {
|
|
const target = list[i]
|
|
let tNode: Node = target instanceof Component ? target.node : target;
|
|
let Pos = tNode.position.clone();
|
|
tNode.setPosition(Pos.x + Offset.x, Pos.y + Offset.y, Pos.z);
|
|
tween(tNode).to(time, { position: Pos },{
|
|
easing:"quadInOut",
|
|
}).start();
|
|
}
|
|
}
|
|
|
|
protected onDestroy(): void {
|
|
super.onDestroy();
|
|
}
|
|
|
|
onClick_closeBtn(btn?:Node){
|
|
this.CloseUI(btn);
|
|
}
|
|
|
|
onClick_bgCloseBtn(btn?:Node){
|
|
this.CloseUI(btn);
|
|
}
|
|
|
|
onClick_btn_close(btn?:Node){
|
|
this.CloseUI(btn);
|
|
}
|
|
|
|
protected CloseUI(btn?:Node){
|
|
MesMgr.event(EGlobalEvent.E_CLOSE_UIFORMS,this);
|
|
}
|
|
|
|
/**清除Sprite引用 */
|
|
public ClearSpriteFrame(){
|
|
let list = this.node.getComponentsInChildren(Sprite);
|
|
for (let i = 0; i < list.length; i++) {
|
|
const tSprite = list[i];
|
|
if(tSprite["MY_ADD"] && tSprite.spriteFrame){
|
|
tSprite.spriteFrame.decRef();
|
|
tSprite.spriteFrame = null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|