import User from "../../FrameWork/User/User";
import Common5 from "../../Platform/th/Common5";
import GameBaseScript from "../GameRoomRes/GameBaseScript";
import TaskManager, { MainTaskIdEnum } from "../JuQingChat/TaskManager";
import UserManager from "../Manager/UserManager";
import NewGuideScript from "../NewGuide/NewGuideScript";
import PrefabManage, { GameType } from "../PrefabManager/PrefabManage";
import GetAward from "../SCommon/GetAward";
import DHBase from "./DHBase";
const { ccclass, property, disallowMultiple, menu } = cc._decorator;

@ccclass
@disallowMultiple()
@menu('对话剧情/DH_1')
export default class DH_1 extends DHBase {
    chatConfig = [
        { effectUrl: 'DH/DH_1/sound/这是夏芸家吗?', delayTime: 6.21, str: '这是夏芸家吗?', posi: 'qipao1' },
        { effectUrl: 'DH/DH_1/sound/是的,我是夏芸前夫,你是?', delayTime: 4.59, str: '是的,我是夏芸前夫,你是?', posi: '-1' },
        { effectUrl: 'DH/DH_1/sound/管你什么前夫后夫,夏芸用这房子抵押借了500万高利贷。', delayTime: 4.59, str: '管你什么前夫后夫,夏芸用这房子抵押借了500万高利贷。', posi: '-1' },
        { effectUrl: 'DH/DH_1/sound/现在找不到她人,我们是过来收房子的。', delayTime: 4.59, str: '现在找不到她人,我们是过来收房子的。', posi: '-1' },
        { effectUrl: 'DH/DH_1/sound/什么?500万?我跟她已经离婚了,房子跟她没一毛钱关系。', delayTime: 4.59, str: '什么?500万?我跟她已经离婚了,房子跟她没一毛钱关系。', posi: '-1' },
        { effectUrl: 'DH/DH_1/sound/三天内拿不出500万,就乖乖把房子交出来。', delayTime: 4.59, str: '三天内拿不出500万,就乖乖把房子交出来。', posi: '-1' },
    ]

    @property(sp.Skeleton)
    nanzhu: sp.Skeleton = null
    @property(sp.Skeleton)
    heishehui: sp.Skeleton = null

    @property(cc.Node)
    m_bg: cc.Node = null
    @property(cc.Node)
    MoveNodes: cc.Node = null
    // @property(cc.Camera)
    // m_camera: cc.Camera = null

    start() {
        // Common5.playRemoteAudioMusic("remotesound/effect/小美满-8秒", true)
        // Common5.preLoadRemoteAudioByChatConfig(this.chatConfig);
        super.start();
        // this.node.getChildByName("guide").active = false
        this.continueStory();
        // this.scheduleOnce(() => {
        //     PrefabManage.preloadPrefabByType(GameType.DH_29)
        // })
    }

    // 继续剧情
    continueStory() {
        // this.scheduleOnce(() => {
        //     PrefabManage.preloadPrefabByType(GameType.DH_2)
        // })
        // this.nanzhu.setAnimation(0, "下面持续", true)
        // this.heishehui.setAnimation(0, "小弟待机", true)
        const dialogEvents = [
            (func) => {
                this.showQiPao(this.chatConfig[this.dialogIndex++], func, () => {
                    // this.heishehui.setAnimation(0, "小弟说话", true)
                });
            },
            (func) => {
                // this.heishehui.setAnimation(0, "小弟待机", true)
                this.showClickDialog(this.chatConfig[this.dialogIndex++], func, () => {
                    // this.nanzhu.setAnimation(0, "侧头笑说话", true)
                });
            },
            (func) => {
                this.showQiPao(this.chatConfig[this.dialogIndex++], func, () => {
                    // this.heishehui.setAnimation(0, "小弟说话", true)
                });
            },
            (func) => {
                this.showQiPao(this.chatConfig[this.dialogIndex++], func, () => {
                });
            },
            (func) => {
                // this.heishehui.setAnimation(0, "小弟待机", true)
                this.showClickDialog(this.chatConfig[this.dialogIndex++], func, () => {
                    // this.nanzhu.setAnimation(0, "侧头笑说话", true)
                });
            },
            (func) => {
                this.showQiPao(this.chatConfig[this.dialogIndex++], func, () => {
                    // this.heishehui.setAnimation(0, "小弟说话", true)
                });
            },
            // (func) => {
            //     this.xiaojiuzi.setAnimation(0, "撞人", false)
            //     this.xiaojiuzi.setCompleteListener(() => {
            //         this.xiaojiuzi.setCompleteListener(null)
            //         this.heiping.node.active = true
            //         this.heiping.setAnimation(0, "animation", false)
            //         this.xiaojiuzi.setCompleteListener(() => {
            //             this.xiaojiuzi.setCompleteListener(null)
            //             func()
            //         })
            //     })
            // },
        ]
        const dialogCallFunc = (logEvents: any[]) => {
            logEvents.shift()(() => {
                if (logEvents.length > 0) {
                    dialogCallFunc(logEvents);
                } else {
                    TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_501)
                    TaskManager.setCurTask(MainTaskIdEnum.MainTask_502)
                    PrefabManage.showBlackGuoDu(() => {
                        PrefabManage.loadPrefabByType(GameType.MainHall)
                        this.node.removeFromParent()
                        this.node.destroy()
                    })
                    // PrefabManage.loadPrefabByType(GameType.GetAward, null, (prefabNode) => {
                    //     let goods = [{ goodId: 1733, goodNum: 1 }];
                    //     prefabNode.getComponent(GetAward).initView(goods, () => {
                    //         // TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_530)
                    //         // User.setRoomGoodStatus("DH_29")
                    //         // UserManager.clearAndaddStructureFlash("cf_FengRenYuan")
                    //     });
                    // });
                    // TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_202)
                    // TaskManager.setCurUnLockMainTaskInfo(MainTaskIdEnum.MainTask_203)
                    // this.node.destroy()
                }
            });
        }
        dialogCallFunc(dialogEvents);
    }

    guideView(nodeArray, opacity = -1) {
        PrefabManage.loadPrefabByType(GameType.GuideMskNode, this.node, (prefab) => {
            // prefab.zIndex = 199
            let guideNodeArray = nodeArray
            let firstNode = guideNodeArray.shift()
            prefab.getComponent(NewGuideScript).setBindNode(firstNode, guideNodeArray)
            if (opacity != -1) {
                prefab.getComponent(NewGuideScript).setOpacityMaskNode(opacity)
            }
        })
    }

    runBg(time, scale, endnode, callFunc) {
        cc.tween(this.m_bg)
            .to(time, { scale: scale })
            .start()
        cc.tween(this.m_bg)
            .sequence(
                cc.tween().to(time, { position: cc.v2(-endnode.position.x * scale, -endnode.position.y * scale) }),
                cc.tween().call(() => {
                    callFunc()
                })
            )
            .start()
    }
}