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

@ccclass
@disallowMultiple()
@menu('对话剧情/DH_46')
export default class DH_46 extends DHBase {
    chatConfig = [
        { effectUrl: 'DH/DH_46/sound/汉升哥哥,你过来!', delayTime: 1.5, str: '汉升哥哥,你过来!', posi: 'qipao2' },
        { effectUrl: 'DH/DH_46/sound/什么事啊,瑶瑶,直接说就是啊。', delayTime: 2.57, str: '什么事啊,瑶瑶,直接说就是啊。', posi: '-1' },
        { effectUrl: 'DH/DH_46/sound/汉升哥哥,这首饰你拿去了吧。我们争取尽快到市区去。', delayTime: 4.57, str: '汉升哥哥,这首饰你拿去卖了吧。我们争取尽快到市区去。', posi: 'qipao2' },
        { effectUrl: 'DH/DH_46/sound/这是你母亲留给你唯一的东西了,之前龙哥那样威胁你都没拿出来。我不能要。', delayTime: 4.57, str: '这是你母亲留给你唯一的东西了,之前龙哥那样威胁你都没拿出来。我不能要。', posi: '-1' },
        { effectUrl: 'DH/DH_46/sound/哎呀,到时候去了市区再赎回来就是嘛!', delayTime: 3.57, str: '哎呀,到时候去了市区再赎回来就是嘛!', posi: 'qipao2' },
    ]

    @property(sp.Skeleton)
    spine: sp.Skeleton = null

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

    start() {
        User.setStatistics("isJoinDH46", 1)
        // Common5.playRemoteAudioMusic("remotesound/effect/轻快-10秒", true)
        Common5.preLoadRemoteAudioByChatConfig(this.chatConfig);
        //换摆摊车
        // if (!TanWeiManager.getLockById(5)) {
        //     this.m_bg.getChildByName("车豪华").active = true
        //     this.m_bg.getChildByName("车").active = false
        // } else {
        // this.m_bg.getChildByName("车豪华").active = false
        // this.m_bg.getChildByName("车").active = true
        // }
        super.start();
        this.continueStory();
        // this.scheduleOnce(() => {
        //     PrefabManage.preloadPrefabByType(GameType.DH_469)
        // })
    }

    // 继续剧情
    continueStory() {
        // this.scheduleOnce(() => {
        //     PrefabManage.preloadPrefabByType(GameType.DH_4)
        // })

        const dialogEvents = [
            (func) => {
                // this.spine.setAnimation(0, "女主拉男主", false)
                // this.spine.setCompleteListener(() => {
                //     this.spine.setCompleteListener(null)
                this.spine.setAnimation(0, "关盒待机", true)
                this.showQiPao(this.chatConfig[this.dialogIndex++], func, () => {
                    this.spine.setAnimation(0, "关盒女主说话", true)
                });
                // })
            },
            (func) => {
                this.spine.setAnimation(0, "关盒待机", true)
                this.showClickDialog(this.chatConfig[this.dialogIndex++], func, () => {
                    this.spine.setAnimation(0, "关盒男主说话", true)
                });
            },
            (func) => {
                this.spine.setAnimation(0, "开盒", false)
                this.spine.setCompleteListener(() => {
                    this.spine.setCompleteListener(null)
                    this.spine.setAnimation(0, "开盒待机", true)
                })
                this.showQiPao(this.chatConfig[this.dialogIndex++], func, () => {
                    this.spine.setAnimation(0, "开盒女主说话", true)
                });
            },
            (func) => {
                this.showClickDialog(this.chatConfig[this.dialogIndex++], func, () => {
                    this.spine.setAnimation(0, "男主推说话", true)
                });
            },
            (func) => {
                this.spine.setAnimation(0, "男主推待机", true)
                func()
            },
            (func) => {
                this.showQiPao(this.chatConfig[this.dialogIndex++], func, () => {
                    this.spine.setAnimation(0, "男主推女说话", true)
                });
            },
            (func) => {
                this.spine.setAnimation(0, "开盒待机", true)
                PrefabManage.loadPrefabByType(GameType.selectButtons, this.node, (node) => {
                    let strs = ['拿走价值10亿的珠宝首饰', '不要这珠宝首饰']
                    let actives = [true, true]
                    let funcs = [
                        () => {
                            UserManager.addMoney(1000000000, this.node)
                            PrefabManage.showBlackGuoDu(() => {
                                this.node.removeFromParent()
                                this.node.destroy()
                                PrefabManage.loadPrefabByType(GameType.MainHall)
                            })
                        },
                        () => {
                            PrefabManage.showBlackGuoDu(() => {
                                this.node.removeFromParent()
                                this.node.destroy()
                                PrefabManage.loadPrefabByType(GameType.MainHall)
                            })
                        },
                    ]
                    let isvideo = [true, false]
                    node.getComponent(selectButtons).init(strs, actives, funcs, isvideo)
                })
                // PrefabManage.loadPrefabByType(GameType.selectButtons, this.node, (node) => {
                //     let strs = ['拿走价值2亿的珠宝首饰', '不要这珠宝首饰']
                //     let actives = [true, true]
                //     let funcs = [
                //         () => {
                //             PrefabManage.loadPrefabByType(GameType.SuccessGetMoney_customMoney, null, (prefab) => {
                //                 prefab.getComponent('SuccessGetMoney_customMoney').setViewDate("", 200000000, 1000000000, () => {
                //                     PrefabManage.showBlackGuoDu(() => {
                //                         this.node.removeFromParent()
                //                         this.node.destroy()
                //                         PrefabManage.loadPrefabByType(GameType.MainHall)
                //                     })
                //                 }, () => {
                //                     PrefabManage.showBlackGuoDu(() => {
                //                         this.node.removeFromParent()
                //                         this.node.destroy()
                //                         PrefabManage.loadPrefabByType(GameType.MainHall)
                //                     })
                //                 })
                //             })

                //         },
                //         () => {
                //             PrefabManage.showBlackGuoDu(() => {
                //                 this.node.removeFromParent()
                //                 this.node.destroy()
                //                 PrefabManage.loadPrefabByType(GameType.MainHall)
                //             })
                //         },
                //     ]
                //     let isvideo = [false, false]
                //     node.getComponent(selectButtons).init(strs, actives, funcs, isvideo)
                // })
            },
        ]
        const dialogCallFunc = (logEvents: any[]) => {
            logEvents.shift()(() => {
                if (logEvents.length > 0) {
                    dialogCallFunc(logEvents);
                } else {
                    // TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_536)
                    // TaskManager.setCurTask(MainTaskIdEnum.MainTask_537)
                    // 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_469")
                    //         // 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()
    }
}