mirror of
https://github.com/Gongxh0901/kunpolibrary
synced 2025-11-05 13:55:44 +00:00
first commit
This commit is contained in:
18
src/condition/node/ConditionAllNode.ts
Normal file
18
src/condition/node/ConditionAllNode.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* @Author: Gongxh
|
||||
* @Date: 2025-02-14
|
||||
* @Description: 满足所有条件显示
|
||||
*/
|
||||
import { GObject } from "fairygui-cc";
|
||||
import { ConditionMode } from "../ConditionMode";
|
||||
import { ConditionFGUINode } from "./ConditionFGUINode";
|
||||
export class ConditionAllNode extends ConditionFGUINode {
|
||||
/**
|
||||
* 构建红点节点
|
||||
* @param {GObject} node 关联节点
|
||||
* @param {...number[]} conditionTypes 条件类型
|
||||
*/
|
||||
public constructor(node: GObject, ...conditionTypes: number[]) {
|
||||
super(node, ConditionMode.All, ...conditionTypes);
|
||||
}
|
||||
}
|
||||
18
src/condition/node/ConditionAnyNode.ts
Normal file
18
src/condition/node/ConditionAnyNode.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* @Author: Gongxh
|
||||
* @Date: 2025-02-14
|
||||
* @Description: 满足任意条件显示
|
||||
*/
|
||||
import { GObject } from "fairygui-cc";
|
||||
import { ConditionMode } from "../ConditionMode";
|
||||
import { ConditionFGUINode } from "./ConditionFGUINode";
|
||||
export class ConditionAnyNode extends ConditionFGUINode {
|
||||
/**
|
||||
* 构建红点节点
|
||||
* @param {GObject} node 关联节点
|
||||
* @param {...number[]} conditionTypes 条件类型
|
||||
*/
|
||||
public constructor(node: GObject, ...conditionTypes: number[]) {
|
||||
super(node, ConditionMode.Any, ...conditionTypes);
|
||||
}
|
||||
}
|
||||
54
src/condition/node/ConditionBase.ts
Normal file
54
src/condition/node/ConditionBase.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* @Author: Gongxh
|
||||
* @Date: 2025-02-14
|
||||
* @Description: 条件基类
|
||||
*/
|
||||
|
||||
import { ConditionManager } from "../ConditionManager";
|
||||
|
||||
export abstract class ConditionBase {
|
||||
/** 初始化 */
|
||||
public _init(): void {
|
||||
this.onInit();
|
||||
}
|
||||
|
||||
/** 条件类型 */
|
||||
public type: number;
|
||||
|
||||
private _canNotify: boolean;
|
||||
/**
|
||||
* 是否可以通知
|
||||
* @returns {boolean}
|
||||
*/
|
||||
public canNotify(): boolean {
|
||||
return this._canNotify;
|
||||
}
|
||||
|
||||
public tryUpdate(): void {
|
||||
ConditionManager._addUpdateCondition(this.type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新条件
|
||||
* @returns {boolean} 是否发生变化
|
||||
*/
|
||||
public _updateCondition(): boolean {
|
||||
let canNotify = this.evaluate();
|
||||
if (canNotify == this._canNotify) {
|
||||
return;
|
||||
}
|
||||
this._canNotify = canNotify;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
protected abstract onInit(): void;
|
||||
|
||||
/**
|
||||
* 返回条件结果 子类实现
|
||||
* @returns {boolean}
|
||||
*/
|
||||
protected abstract evaluate(): boolean;
|
||||
}
|
||||
52
src/condition/node/ConditionFGUINode.ts
Normal file
52
src/condition/node/ConditionFGUINode.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* @Author: Gongxh
|
||||
* @Date: 2025-02-17
|
||||
* @Description:
|
||||
*/
|
||||
|
||||
import { GObject } from "fairygui-cc";
|
||||
import { ConditionManager } from "../ConditionManager";
|
||||
import { ConditionMode } from "../ConditionMode";
|
||||
import { ConditionNode } from "./ConditionNode";
|
||||
export class ConditionFGUINode extends ConditionNode {
|
||||
/**
|
||||
* 红点节点
|
||||
* @protected
|
||||
* @type {GObject | Node} fgui节点 或 node节点
|
||||
* @memberof NotityFGUINode
|
||||
*/
|
||||
protected node: GObject;
|
||||
|
||||
private _oldRemoveFromParent: () => void;
|
||||
|
||||
/**
|
||||
* 构建红点节点
|
||||
* @param {GObject} node 关联节点
|
||||
* @param {...number[]} conditionTypes 条件类型
|
||||
*/
|
||||
public constructor(node: GObject, modeType: ConditionMode, ...conditionTypes: number[]) {
|
||||
super(modeType, ...conditionTypes);
|
||||
this.node = node;
|
||||
const oldRemoveFromParent = (this._oldRemoveFromParent = node.removeFromParent);
|
||||
node.removeFromParent = (): void => {
|
||||
super.destroy();
|
||||
oldRemoveFromParent.call(node);
|
||||
this.node.removeFromParent = this._oldRemoveFromParent;
|
||||
this.node = null;
|
||||
};
|
||||
// 立即更新一次
|
||||
ConditionManager._nowUpdateConditionNode(this);
|
||||
}
|
||||
|
||||
public destroy(): void {
|
||||
super.destroy();
|
||||
if (this.node) {
|
||||
this.node.removeFromParent = this._oldRemoveFromParent;
|
||||
this.node = null;
|
||||
}
|
||||
}
|
||||
|
||||
public notify(visible: boolean): void {
|
||||
this.node.visible = visible;
|
||||
}
|
||||
}
|
||||
36
src/condition/node/ConditionNode.ts
Normal file
36
src/condition/node/ConditionNode.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* @Author: Gongxh
|
||||
* @Date: 2025-02-14
|
||||
* @Description: 条件节点
|
||||
*/
|
||||
|
||||
import { ConditionManager } from "../ConditionManager";
|
||||
import { ConditionMode } from "../ConditionMode";
|
||||
|
||||
export abstract class ConditionNode {
|
||||
/** 条件类型 */
|
||||
public _modeType: ConditionMode;
|
||||
|
||||
/**
|
||||
* 构建红点节点
|
||||
* @param {GObject} node 关联节点
|
||||
* @param {...number[]} conditionTypes 条件类型
|
||||
*/
|
||||
public constructor(modeType: ConditionMode, ...conditionTypes: number[]) {
|
||||
this._modeType = modeType;
|
||||
for (const conditionType of conditionTypes) {
|
||||
ConditionManager._addConditionNode(this, conditionType);
|
||||
}
|
||||
}
|
||||
|
||||
/** 移除节点 */
|
||||
public destroy(): void {
|
||||
ConditionManager._removeConditionNode(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通知节点更新
|
||||
* @param {boolean} visible 节点显示状态
|
||||
*/
|
||||
public abstract notify(visible: boolean): void;
|
||||
}
|
||||
Reference in New Issue
Block a user