150 lines
3.8 KiB
TypeScript
150 lines
3.8 KiB
TypeScript
|
import { _decorator, Node } from 'cc';
|
|||
|
import { RedPointInfo } from './RedPointInfo';
|
|||
|
import { RedPointTreeNode } from './RedPointTreeNode';
|
|||
|
const { ccclass, property } = _decorator;
|
|||
|
|
|||
|
@ccclass('RedPointTrees')
|
|||
|
export default class RedPointTrees {
|
|||
|
|
|||
|
public mChildrenNode: Map<number, RedPointTreeNode> = new Map<number, RedPointTreeNode>();
|
|||
|
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* 插入一个未绑定的红点
|
|||
|
* @param key 唯一Id
|
|||
|
* @param showType (展示类型)
|
|||
|
* @returns
|
|||
|
*/
|
|||
|
public insertPoint(key: RedPointTreeNode, parent: RedPointTreeNode, call: Function): RedPointTreeNode {
|
|||
|
|
|||
|
let redTree: RedPointTreeNode = this.mChildrenNode.get(key.Id);
|
|||
|
if (redTree != null) {
|
|||
|
key.data.mParentNode = parent;
|
|||
|
key.callFunc = call;
|
|||
|
}
|
|||
|
this.mChildrenNode.set(key.Id, key);
|
|||
|
|
|||
|
return key;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* 根据Id创建节点
|
|||
|
* @param key 唯一Id
|
|||
|
* @returns
|
|||
|
*/
|
|||
|
// public addChild(key: number, callFunc: Function) {
|
|||
|
// let children = this.mChildrenNode.get(key);
|
|||
|
// if (children != null) {
|
|||
|
// return children;
|
|||
|
// }
|
|||
|
// children = new RedPointTreeNode();
|
|||
|
// children.callFunc = callFunc;
|
|||
|
// this.mChildrenNode.set(key, children);
|
|||
|
// return children;
|
|||
|
// }
|
|||
|
|
|||
|
// /**
|
|||
|
// * 获取子节点,如果不存在就添加
|
|||
|
// * @param key
|
|||
|
// * @returns
|
|||
|
// */
|
|||
|
// public getOrAddChild(key: number, parent: RedPointTreeNode, callFunc: Function): RedPointTreeNode {
|
|||
|
// let children = this.mChildrenNode.get(key);
|
|||
|
// if (children != null) {
|
|||
|
// return children;
|
|||
|
// }
|
|||
|
// children = this.addChild(key, callFunc);
|
|||
|
// children.data.mParentNode = parent;
|
|||
|
// return children;
|
|||
|
// }
|
|||
|
|
|||
|
|
|||
|
// /**
|
|||
|
// * 查找Key值对应的对象
|
|||
|
// * @param _key
|
|||
|
// * @returns
|
|||
|
// */
|
|||
|
// public findChild(_key: number) {
|
|||
|
// let childTree = this.mChildrenNode.get(_key);
|
|||
|
// if (childTree != null) {
|
|||
|
// return childTree;
|
|||
|
// }
|
|||
|
// return null;
|
|||
|
// }
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* 更新节点红点,向上传递
|
|||
|
* @param key
|
|||
|
* @param isShow
|
|||
|
* @param showCount
|
|||
|
*/
|
|||
|
public updateRedPoint(key: number, isShow: boolean, showCount: number) {
|
|||
|
|
|||
|
let redPointInfo = this.mChildrenNode.get(key);
|
|||
|
if (redPointInfo != null) {
|
|||
|
redPointInfo.updateRedPoint(isShow, showCount);
|
|||
|
} else {
|
|||
|
console.warn("updateRedPoint error, key:" + key);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* 获取节点树
|
|||
|
* @param key
|
|||
|
* @returns
|
|||
|
*/
|
|||
|
public getRedPointTree(key: number): RedPointTreeNode {
|
|||
|
let redTree = this.mChildrenNode.get(key);
|
|||
|
if (redTree != null) {
|
|||
|
return redTree;
|
|||
|
}
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
*
|
|||
|
* 绑定一个红点
|
|||
|
* @param key
|
|||
|
* @param node
|
|||
|
* @param showType
|
|||
|
*/
|
|||
|
public bindRedPoint(key: number, node: Node, showType: number = 0,) {
|
|||
|
let redTree = this.mChildrenNode.get(key);
|
|||
|
if (redTree != null) {
|
|||
|
|
|||
|
redTree.data.mRedNode = node;
|
|||
|
let info = node.getChildByName('RedPoint').getComponent(RedPointInfo);
|
|||
|
redTree.bindInfo(info, showType);
|
|||
|
} else {
|
|||
|
|
|||
|
console.warn("bindRedPoint 没有节点树, key:" + key);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* 获取父节点key值
|
|||
|
* @param key key
|
|||
|
*
|
|||
|
* @returns
|
|||
|
*/
|
|||
|
// public getParentKey(key: string): string {
|
|||
|
// let keys = key.split('_');
|
|||
|
// let _key: string = keys[0];
|
|||
|
// if (keys.length > 1) {
|
|||
|
// for (let id = 1; id < keys.length - 1; id++) {
|
|||
|
// const element = keys[id];
|
|||
|
// _key += '_' + element;
|
|||
|
// }
|
|||
|
// }
|
|||
|
// return _key;
|
|||
|
// }
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|