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";
import selectButtons from "./selectButtons";
import taskState from "./taskState";
const { ccclass, property, disallowMultiple, menu } = cc._decorator;

@ccclass
@disallowMultiple()
@menu('对话剧情/DH_25')
export default class DH_25 extends DHBase {
    chatConfig = [
        { effectUrl: 'DH/DH_25/sound/汉升哥哥,要去市区开店了吧,这次也会带我吗?', delayTime: 5.45, str: '汉升哥哥,要去市区开店了吧,这次也会带我吗?', posi: 'qipao2' },
        { effectUrl: 'DH/DH_25/sound/怎么会不带你呢,肯定带你一起去市区。', delayTime: 2.85, str: '怎么会不带你呢,肯定带你一起去市区。', posi: '-1' },
        { effectUrl: 'DH/DH_25/sound/瑶瑶,还是分开住吧,住一起容易让人误会。', delayTime: 3.52, str: '瑶瑶,还是分开住吧,住一起容易让人误会。', posi: '-1' },
        { effectUrl: 'DH/DH_25/sound/那汉升哥哥,住在一起,我们是什么关系啊?', delayTime: 5.53, str: '那汉升哥哥,住在一起,我们是什么关系啊?', posi: 'qipao2' },
        { effectUrl: 'DH/DH_25/sound/谁是你女朋友?你跟我表白了吗', delayTime: 3.15, str: '谁是你女朋友?你跟我表白了吗', posi: 'qipao2' },
        { effectUrl: 'DH/DH_25/sound/当我是你妹妹,哼,才不要当你妹妹。', delayTime: 3.28, str: '当我是你妹妹,哼,才不要当你妹妹。', posi: 'qipao2' },
        { effectUrl: 'DH/DH_25/sound/合伙人,我就只是你的合伙人。', delayTime: 2.91, str: '合伙人,我就只是你的合伙人。', posi: 'qipao2' },
        { effectUrl: 'DH/DH_25/sound/瑶瑶,你愿意做我的女朋友吗?', delayTime: 2.44, str: '瑶瑶,你愿意做我的女朋友吗?', posi: '-1' },
        { effectUrl: 'DH/DH_25/sound/汉升哥哥,我愿意。这项链好漂亮啊,你帮我带上吧。', delayTime: 5.19, str: '汉升哥哥,我愿意。这项链好漂亮啊,你帮我带上吧。', posi: 'qipao2' },
        { effectUrl: 'DH/DH_25/sound/汉升哥哥,我漂亮吗?', delayTime: 2.37, str: '汉升哥哥,我漂亮吗?', posi: 'qipao3' },
    ]

    @property(sp.Skeleton)
    nanzhu: sp.Skeleton = null
    @property(sp.Skeleton)
    suyao: sp.Skeleton = null
    @property(sp.Skeleton)
    suyao_big: sp.Skeleton = null

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

    @property(cc.Node)
    touchnode: cc.Node = null
    @property(cc.Node)
    chouti: cc.Node = null

    start() {
        Common5.playRemoteAudioMusic("remotesound/effect/轻快-10秒", true)
        Common5.preLoadRemoteAudioByChatConfig(this.chatConfig);
        super.start();
        this.continueStory();
        // this.scheduleOnce(() => {
        //     PrefabManage.preloadPrefabByType(GameType.DH_259)
        // })
    }

    // 继续剧情
    continueStory() {
        this.scheduleOnce(() => {
            PrefabManage.preloadPrefabByType(GameType.DH_26)
        })
        this.suyao.setAnimation(0, "待机", true)
        this.suyao_big.node.active = false
        this.touchnode.active = false
        const dialogEvents = [
            (func) => {
                this.showQiPao(this.chatConfig[0], func, () => {
                    this.suyao.setAnimation(0, "说话", true)
                });
            },
            (func) => {
                this.suyao.setAnimation(0, "待机", true)
                PrefabManage.loadPrefabByType(GameType.selectButtons, this.node, (node) => {
                    let strs = ['会的', '不会']
                    let actives = [true, true]
                    let funcs = [
                        () => {
                            this.showQiPao(this.chatConfig[1], func, () => {
                            });
                        },
                        () => {
                            this.showQiPao(this.chatConfig[2], () => {
                                // PrefabManage.showTextTips("任务失败,苏瑶离开了你,去往外地了。重新开始")
                                PrefabManage.loadPrefabByType(GameType.taskState, this.node, (node) => {
                                    node.getComponent(taskState).showFail("任务失败,苏瑶离开了你,去往外地了。重新开始", () => {
                                        this.continueStory()
                                    }, () => {
                                        this.showQiPao(this.chatConfig[1], func, () => {
                                        });
                                    })
                                })
                            }, () => {
                            });
                        }
                    ]
                    let isvideo = [false, false]
                    node.getComponent(selectButtons).init(strs, actives, funcs, isvideo)
                })
            },
            (func) => {
                this.showQiPao(this.chatConfig[3], func, () => {
                    this.suyao.setAnimation(0, "害羞说话", true)
                });
            },
            (func) => {
                this.suyao.setAnimation(0, "害羞", true)
                PrefabManage.loadPrefabByType(GameType.selectButtons, this.node, (node) => {
                    let strs = ['女朋友', '妹妹', '合伙人', '都不选,我要表白']
                    let actives = [true, true, true, true]
                    let funcs = [
                        () => {
                            this.showQiPao(this.chatConfig[4], () => {
                                PrefabManage.loadPrefabByType(GameType.taskState, this.node, (node) => {
                                    node.getComponent(taskState).showFail("任务失败,重新开始", () => {
                                        this.continueStory()
                                    }, () => {
                                        func()
                                    })
                                })
                                // PrefabManage.showTextTips("任务失败,重新开始")
                                // this.continueStory()
                            }, () => {
                                this.suyao.setAnimation(0, "害羞说话", true)
                            });
                        },
                        () => {
                            this.showQiPao(this.chatConfig[5], () => {
                                PrefabManage.loadPrefabByType(GameType.taskState, this.node, (node) => {
                                    node.getComponent(taskState).showFail("任务失败,重新开始", () => {
                                        this.continueStory()
                                    }, () => {
                                        func()
                                    })
                                })
                                // PrefabManage.showTextTips("任务失败,重新开始")
                                // this.continueStory()
                            }, () => {
                                this.suyao.setAnimation(0, "生气说话", true)
                            });
                        },
                        () => {
                            this.showQiPao(this.chatConfig[6], () => {
                                PrefabManage.loadPrefabByType(GameType.taskState, this.node, (node) => {
                                    node.getComponent(taskState).showFail("任务失败,重新开始", () => {
                                        this.continueStory()
                                    }, () => {
                                        func()
                                    })
                                })
                                // PrefabManage.showTextTips("任务失败,重新开始")
                                // this.continueStory()
                            }, () => {
                                this.suyao.setAnimation(0, "沮丧说话", true)
                            });
                        },
                        () => {
                            func()
                        },
                    ]
                    let isvideo = [false, false, false, true]
                    node.getComponent(selectButtons).init(strs, actives, funcs, isvideo)
                })
            },
            (func) => {
                // this.touchnode.active = true
                this.onTouch()
                this.guideView([this.chouti])
            },
        ]
        const dialogCallFunc = (logEvents: any[]) => {
            logEvents.shift()(() => {
                if (logEvents.length > 0) {
                    dialogCallFunc(logEvents);
                } else {
                    // TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_527)
                    // TaskManager.setCurTask(MainTaskIdEnum.MainTask_528)
                    // PrefabManage.showBlackGuoDu(() => {
                    //     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_259")
                    //         // 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()
    }

    onTouch() {
        this.touchnode.active = false
        this.chouti.active = true
    }

    onTouchxianglian() {
        Common5.playRemoteAudioMusic('remotesound/effect/暧昧-10秒', false)
        this.chouti.active = false
        this.suyao_big.node.active = true
        this.suyao_big.setAnimation(0, "出现项链", false)
        this.suyao_big.setCompleteListener(() => {
            this.suyao_big.setCompleteListener(null)
            this.suyao_big.setAnimation(0, "项链待机", true)
            this.showQiPao(this.chatConfig[7], () => {
                this.showQiPao(this.chatConfig[8], () => {
                    this.suyao.node.active = false
                    this.suyao_big.setAnimation(0, "待机", true)
                    Common5.playRemoteAudioEffect('remotesound/effect/心跳')
                    this.scheduleOnce(()=>{
                        Common5.playRemoteAudioEffect('remotesound/effect/心跳')
                    },3)
                    this.scheduleOnce(() => {
                        this.suyao_big.setAnimation(0, "戴项链", false)
                        this.suyao_big.setCompleteListener(() => {
                            this.suyao_big.setCompleteListener(null)
                            this.suyao_big.setAnimation(0, "有项链待机", true)
                            this.showQiPao(this.chatConfig[9], () => {
                                this.suyao_big.setAnimation(0, "有项链待机", true)
                                TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_529)
                                TaskManager.setCurTask(MainTaskIdEnum.MainTask_530)
                                PrefabManage.showBlackGuoDu(() => {
                                    this.node.removeFromParent()
                                    this.node.destroy()
                                    PrefabManage.loadPrefabByType(GameType.MainHall)
                                })
                            }, () => {
                                this.suyao_big.setAnimation(0, "有项链说话", true)
                            })
                        })
                    }, 1)
                }, () => {
                    this.suyao.setAnimation(0, "害羞说话", true)
                });
            }, () => {
            });
        })
    }
}