123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- /**
- * 视图基类
- */
- import ViewEvent from "./ViewEvent";
- import { ViewManager } from "../manager/ViewManager";
- import UIUtils, { UIContainer } from "../../util/UIUtils";
- import NotificationManager from "../manager/NotificationManager";
- import BaseMediator from "./BaseMediator";
- import SdkManager from "../../../resources/sdk/script/SdkManager";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export class BaseView extends cc.Component {
- /** 当前视图的事件对象 */
- private __event__: ViewEvent;
- /** UI节点引用 */
- public ui: UIContainer;
- public __init__(): void {
- this.__event__ = new ViewEvent();
- this.ui = UIUtils.seekAllSubView(this.node);
- this.init();
- }
- /**
- * view 创建时会被调用,子类可以重写.
- */
- public init(): void {
-
- }
- /**
- * 发送UI事件
- * @param {string} event 事件名称
- * @param {Object} body 事件参数
- */
- public sendEvent(event: string, body?: any): void {
- this.__event__.emit(event, body)
- }
- /**
- * 绑定UI事件
- * @param {string} name 事件名称
- * @param {(body: any)=>void} cb 事件回调
- * @param {BaseMediator} target 事件回调绑定对象
- * @private 私有函数,不得调用。
- */
- public __bindEvent__(name: string, cb: (body: any) => void, target): void {
- this.__event__.on(name, cb, target);
- }
- /**
- * 关闭当前的界面
- */
- public closeView(): void {
- let bgname = "blackBg" + this.node.name;
- if (this.node.parent && this.node.parent.getChildByName(bgname))
- this.node.parent.getChildByName(bgname).destroy();
- ViewManager.getInstance().__closeView__(this);
- this.__onClose__();
- }
- /**
- * 关闭所有弹出的界面
- */
- public closeAllPopView(): void {
- ViewManager.getInstance().__closeAllPopView__();
- }
- private __onClose__(): void {
- this.__event__.destroy();
- this.onClose();
- this.node.destroy();
- }
- /**
- * 当界面被关闭时会被调用,子类可以重写该方法。
- * @override
- */
- public onClose(): void {
- }
- /**
- * 子类覆盖,返回UI的prefab路径
- * 路径第一个目录为子包名称如:aa/bb/ccc;aa为子包名 bb/ccc为子包内的prefab路径;
- * 如果放在resources的prefab;则路径去掉子包名/bb/ccc
- * @return {string}
- */
- public static path(): string {
- return "";
- }
- /**
- * 注册mediator
- */
- public registerMediator(mediator: { new(): BaseMediator }, view: BaseView,data?:any) {
- let viewMediator: BaseMediator = new mediator();
- viewMediator["__init__"]();
- viewMediator.view = view;
- viewMediator.view.__init__();
- viewMediator.init(data);
- }
- }
|