caaee378-16a8-45e0-b985-9c83f8cd4539.js 3.21 KB
"use strict";
cc._RF.push(module, 'caaeeN4FqhF4LmFnIP4zUU5', 'ToastManager');
// script/common/gameplay/managers/ToastManager.ts

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ToastManager = void 0;
const NodePoolFactory_1 = require("../../utils/NodePoolFactory");
const AnimationUtils_1 = require("../../utils/AnimationUtils");
const SpecialToast_1 = require("../../../game/ui/SpecialToast");
var ToastManager;
(function (ToastManager) {
    const path = "prefab/ui/Toast";
    const specialPath = "prefab/ui/SpecialToast";
    let nodeCount = 0;
    let initialized = false;
    async function init() {
        if (!initialized) {
            await NodePoolFactory_1.NodePoolFactory.createPool(path, 3);
            await NodePoolFactory_1.NodePoolFactory.createPool(specialPath, 3);
            initialized = true;
        }
    }
    ToastManager.init = init;
    function addToast(parent, content, time = 0.6) {
        let node = typeof content === "string" ? NodePoolFactory_1.NodePoolFactory.getNode(path) : content;
        if (node) {
            nodeCount++;
            if (typeof content === "string") {
                let textComp = node.getChildByName("text").getComponent(cc.RichText);
                textComp.string = content;
                node.height = textComp.node.height + 10;
            }
            node.stopAllActions();
            node.x = 0;
            node.y = 0;
            node.scaleX = 0;
            node.scaleY = 0;
            node.opacity = 255;
            node.parent = parent;
            AnimationUtils_1.AnimationUtils.runAction(node, cc.sequence(cc.scaleTo(0.2, 1, 1), cc.delayTime(0.2), cc.spawn(cc.moveBy(0.8, 0, 100), cc.sequence(cc.delayTime(time), cc.fadeOut(0.2))))).then(() => {
                if (node) {
                    if (node._path) {
                        NodePoolFactory_1.NodePoolFactory.putNode(node);
                    }
                    else {
                        node.removeFromParent(true);
                    }
                }
                nodeCount--;
            });
        }
    }
    ToastManager.addToast = addToast;
    function addSpecialToast(parent, type, time = 0.6) {
        let node = NodePoolFactory_1.NodePoolFactory.getNode(specialPath);
        if (node) {
            node.getComponent(SpecialToast_1.default).setData(type);
            ;
            node.stopAllActions();
            node.x = 0;
            node.y = 0;
            node.scaleX = 0;
            node.scaleY = 0;
            node.opacity = 255;
            node.parent = parent;
            AnimationUtils_1.AnimationUtils.runAction(node, cc.sequence(cc.scaleTo(0.2, 1, 1), cc.delayTime(0.2), cc.spawn(cc.moveBy(0.8, 0, 100), cc.sequence(cc.delayTime(time), cc.fadeOut(0.2))))).then(() => {
                if (node) {
                    if (node._path) {
                        NodePoolFactory_1.NodePoolFactory.putNode(node);
                    }
                    else {
                        node.removeFromParent(true);
                    }
                }
                nodeCount--;
            });
        }
    }
    ToastManager.addSpecialToast = addSpecialToast;
})(ToastManager = exports.ToastManager || (exports.ToastManager = {}));

cc._RF.pop();