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

209 lines
5.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { Node } from "cc";
import { RedCondEvent } from "./RedPointCoust";
import { IRedTreeCond } from "./RedPointTree";
import RedPointTrees from "./RedPointTrees";
import { RedPointTreeNode } from "./RedPointTreeNode";
import { RedPointInfo } from "./RedPointInfo";
export class RedPoint {
private static _Inst: RedPoint;
public static get Inst(): RedPoint {
if (!RedPoint._Inst) {
RedPoint._Inst = new RedPoint();
}
return RedPoint._Inst;
}
public static initId: number = 0;
/**
* 所有红点
*/
private mRedPoint: RedPointTrees = new RedPointTrees();
/**
* 每个条件一个key 对应tree上的条件key列表
*/
private mRedCondKeys: Map<string, Array<RedPointTreeNode>> = new Map<string, Array<RedPointTreeNode>>();
/**
* 页面刷新列表
*/
private mRedUINodeMap: Map<string, Array<RedPointTreeNode>> = new Map<string, Array<RedPointTreeNode>>();
/**
* 插入key
* @param key
* @param showType
* @returns
*/
public insertRedPoint(key: RedPointTreeNode, parentTree: RedPointTreeNode, callBack: Function): RedPointTreeNode {
let item = this.mRedPoint.getRedPointTree(key.Id);
if (item == null) {
if (this.mRedPoint != null) {
this.mRedPoint.insertPoint(key, parentTree, callBack);
return key;
}
}
return key;
}
/**
*
* @param key 唯一值
* @param isShow false 不显示true 显示
* @param showCount 数字展示时显示的数字
*/
public updateRedPoint(key: RedPointTreeNode, isShow: boolean = false, showCount: number = 0) {
let value = this.mRedPoint.getRedPointTree(key.Id);
if (value) {
value.updateRedPoint(isShow, showCount);
}
}
/**
* @param key 绑定节点
* @param node
* @param showType 展示类型
* @param showCount 展示数量
*/
public bind(key: RedPointTreeNode, node: Node, showType: number = 0) {
let item = this.mRedPoint.getRedPointTree(key.Id)
if (item == null) {
console.warn('节点树未初始化', key);
} else {
let info = node.getChildByName('RedPoint').getComponent(RedPointInfo);
item.bindInfo(info, showType);
}
}
/**
* 增加判断条件
* @param key
* @param redCondition
*/
public AddRedCondition(key: RedPointTreeNode, node: RedPointTreeNode, redCondition: IRedTreeCond) {
let treeNode = this.mRedPoint.mChildrenNode.get(key.Id);
if (treeNode) {
treeNode.addCond(redCondition);
}
this.AddRedCondKeys(redCondition.condEvent, node)
}
/**
*
* @param UIId 页面Id用来查找在什么树节点上的UI
* @param key 要刷新节点绑定节点的key值
* @param isClean 是否清理
*/
public addRefresh(UIId: string, node: RedPointTreeNode, isClean: boolean = false) {
if (isClean) {
this.mRedUINodeMap.set(UIId, []);
}
let data = this.mRedUINodeMap.get(UIId);
if (data == null) {
data = new Array<RedPointTreeNode>();
}
data.push(node);
this.mRedUINodeMap.set(UIId, data);
}
/**
* 刷新页面红点
* @param uikey 页面Id用来查找在什么树节点上的UI
*/
public refrashLayer(uikey: string) {
let data = this.mRedUINodeMap.get(uikey)
for (let index = 0; index < data.length; index++) {
const value = data[index];
if (value) {
value.refresh();
}
}
}
/**
* 添加key到条件树
* @param event 条件类型
* @param key 节点树key值
*/
private AddRedCondKeys(event: RedCondEvent, key: RedPointTreeNode) {
let keysData = this.mRedCondKeys.get(event);
if (keysData == null) {
keysData = new Array<RedPointTreeNode>();
}
keysData.push(key)
this.mRedCondKeys.set(event, keysData);
}
/**
* 更新条件
* @param event 条件
* @param currValue 更新当前值
*/
public updateCondition(event: IRedTreeCond) {
let keysData = this.mRedCondKeys.get(event.condEvent);
if (keysData) {
for (const key in keysData) {
if (Object.prototype.hasOwnProperty.call(keysData, key)) {
const element = keysData[key];
if (element) {
element.updateCondCount(event);
}
}
}
} else {
console.warn("没有条件", event);
}
}
/**
* 删除判断条件
* @param key 删除判断条件的节点树key
* @param redEvent 条件类型
*/
public removeRedCondition(key: RedPointTreeNode, redEvent: string) {
let treeNode = this.mRedPoint.mChildrenNode.get(key.Id);
if (treeNode) {
treeNode.removeCond(redEvent);
}
}
// /**
// * 获取父节点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;
// }
}
let RedTools: RedPoint = RedPoint.Inst;
export default RedTools;