猫史档案馆


【对话框】这个缓缓出来的对话不会卡

用户:迷失冷光迷失冷光查看:5 回复:3 评论:5 创建时间:2022-07-16T20:14:35


Box喵layer.prototype.graduallyText = function(content/*文本*/,time/*浮动时间*/,property = {}/*其他参数,如title*/){
    const interval = time / content.length;
    for(let i = 0;i < content.length;i++){
        const result = this.dialog(Object.assign(property,{
            type: Box3DialogType.TEXT,
            content: content.substring(0,i + 1),
        }))
        if(i < content.length - 1){
            setTimeout(result.cancel,interval * (i + 1));
        }
    }
}
//使用例子
world.onPlayerJoin(({entity})=>{
    entity.player.graduallyText('一键三连加关注',500);
})


回复

上一页1 页 / 共 1下一页
星星上的雪花星星上的雪花

https://shequ.codemao.cn/community/425344

点赞0


评论


yee剑走天下yee剑走天下

沙发()()

点赞0


评论


星星上的雪花星星上的雪花

给你看看我的私藏(什)代码,点右上角×就能跳过,还支持select和input并获取数据。

Box喵layer.prototype.print = async function (...script) {
    /** Box3EventChannel[] */
    var events = []; //用于储存对话框事件event的处理器handler, 方便获取用于取消事件的token
    for (const dialog of script) { //遍历每个对话属性
        let save = dialog.content + ''; //保存这个对话的内容
        dialog.content = ""; //清空对话框的内容
        for (let i = 0; i < save.length; i++) { //遍历这个对话框的所有内容
            dialog.content += save[i]; //打字
            events.push( //往事件数组中加入新事件
                Object.assign(this.dialog(Object.assign({}, dialog, {
                    type: "text",
                    contentTextColor: dialog.contentTextColor ? dialog.contentTextColor : [0, 1, 0, 1],
                    contentBackgroundColor: dialog.contentBackgroundColor ? dialog.contentBackgroundColor : [0, 0, 0, 0.8],
                    titleTextColor: dialog.titleTextColor ? dialog.titleTextColor : [1, 1, 1, 1],
                    titleBackgroundColor: dialog.titleBackgroundColor ? dialog.titleBackgroundColor : [0, 0, 0, 0.5],
                })), { canceled: false/*这个后面有用*/ }) //不用await是因为要获取[object Promise](什
            )
        }
    };
    for (let handler of events) { //遍历每个事件
        handler.cancel; //这个函数是用于取消事件的token, 在该事件中是关闭对话框
        handler.finally(() => handler.canceled = true);//玩家手动关闭对话框
    };
    for (let handler of events) { //遍历每个事件
        await sleep(喵);
        if (handler.canceled) { //如果玩家手动关闭
            return; //结束
        };
        handler.cancel(); //关闭该对话框
    };
    const dialog = await this.dialog(Object.assign(script[script.length - 1], {
        type: "select",
        options: script[script.length - 1].options ? script[script.length - 1].options : [">"],
        contentTextColor: script[script.length - 1].contentTextColor ? script[script.length - 1].contentTextColor : [0, 1, 0, 1],
        contentBackgroundColor: script[script.length - 1].contentBackgroundColor ? script[script.length - 1].contentBackgroundColor : [0, 0, 0, 0.8],
        titleTextColor: script[script.length - 1].titleTextColor ? script[script.length - 1].titleTextColor : [1, 1, 1, 1],
        titleBackgroundColor: script[script.length - 1].titleBackgroundColor ? script[script.length - 1].titleBackgroundColor : [0, 0, 0, 0.5],
    }));
    return dialog;
};

点赞0


评论