squidGame/tgx-games-client/assets/module_basic/red/RedPointTrees.ts

150 lines
3.9 KiB
TypeScript
Raw Normal View History

2025-02-17 21:36:37 +08:00
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;
// }
}