// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import { ryw_Event } from "../../FrameWork/Event/EventEnum";
import EventMgr from "../../FrameWork/Event/EventMgr";
import User from "../../FrameWork/User/User";
import Common5 from "../../Platform/th/Common5";
import ChatManager from "../JuQingChat/ChatManager";

const {ccclass, property} = cc._decorator;

@ccclass
export default class BlackTransition extends cc.Component {

    gameLimitConfig = [

        {descLab:'是啊,这世上还有亲人和朋友在关心我,不能只顾自己复仇而忽视身边的人。',  function:'nextWX11Func'},
        {descLab:'你你干什么...我怎么好热,幼楚你在汤里放了什么东西',  function:'nextWX40Func'},
        {descLab:'哎!没想到我在他眼中是这种人,难道我给他的还不够吗',  function:'nextWX46Func'},
        {descLab:'第一天你被一个好心的姑娘收留暂且住下了',  function:'next502Func'},
        {descLab:'哎呀!你怎么还来啊',  function:'next594_1_Func'},
    
    
    ]

    @property(cc.Label)
    desclabel: cc.Label = null;

    chooseIndex = -1
    // onLoad () {}
    next502Func(){
        this.scheduleOnce(()=>{
   
            this.node.removeFromParent()
            this.node.destroy()
   
        },2.0)
    }
    next594_1_Func(){
        this.scheduleOnce(()=>{
            // ChatManager.setSingleChatStatus('WX','WX_JiangZhongQin', 'WX_106', false)
            // User.setCurJuQingUnLockIndex('WX_106')

            this.node.removeFromParent()
            this.node.destroy()
   
        },2.0) 
    }

    nextWX46Func(){
        this.scheduleOnce(()=>{
            
            this.node.removeFromParent()
            this.node.destroy()
    
            ChatManager.setSingleChatStatus('WX','WX_ZhangHeng', 'WX_46', false)
            User.setCurJuQingUnLockIndex('WX_46')

            EventMgr.emitEvent_custom(ryw_Event.RefreshJuQingDuiHua);
        },2.0)

    }

    nextWX11Func(){
        this.scheduleOnce(()=>{
            this.node.removeFromParent()
            this.node.destroy()
            ChatManager.setSingleChatStatus('WX','WX_LuoQingCheng', 'WX_11', false)
            User.setCurJuQingUnLockIndex('WX_11')
            EventMgr.emitEvent_custom(ryw_Event.RefreshJuQingDuiHua);
        },2.0)

    }
    
    nextWX40Func(){
        this.scheduleOnce(()=>{
    
            ChatManager.setSingleChatStatus('WX','WX_WangWei', 'WX_40', false)
            User.setCurJuQingUnLockIndex('WX_40')
            EventMgr.emitEvent_custom(ryw_Event.RefreshJuQingDuiHua);
            this.node.removeFromParent()
            this.node.destroy()
        },2.0)

    }
    start () {
        if(this.chooseIndex == -1){
            this.node.removeFromParent()
            this.node.destroy()
            return

        }
        let chooseIndex = this.chooseIndex
        let str = this.gameLimitConfig[chooseIndex].descLab
        let endFunc = this.gameLimitConfig[chooseIndex].function
        let func = () => {
       
            if(this[endFunc]){
                this[endFunc]()
            }
        }
        if(this.chooseIndex == 4){
            
            Common5.playRemoteAudioEffect('sound/common/亲嘴')
        }
        this.showDialogStr(str, this.desclabel, func)
    
    }

    initViewData(chooseIndex){
    
        this.chooseIndex = chooseIndex
     
    }

    showDialogStr(str, desclabel, finishFunc?) {
        let curStr = ""
        let curIndex = 0
        let callFunc = () => {
            curStr += str[curIndex++]
            desclabel.string = curStr
            if (curIndex >= str.length) {
                finishFunc && finishFunc()
            }
        }
        this.schedule(callFunc, 0.07, str.length - 1)
    }

    // update (dt) {}
}