import FF from "../FF";
import FSprite from "../object/FSprite";
import FDialogBox from "./dialog/FDialogBox";

/**
 * 对话测试
 */
const {ccclass, property} = cc._decorator;

@ccclass
export default class FDialogTest extends cc.Component {

    @property(cc.Prefab)
    mDialog: cc.Prefab = null;

    private ff:FF;
    private count = 0;
    /**
     * 对话框
     */
    private dialogBox:FDialogBox;

    onBeginContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider){
        if(other.node.group == 'A'){
            this.count ++;
            let obj = other.node.getComponent(FSprite);
            this.ff = obj.ff;
            this.showButton();
        }
    }

    onEndContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider){
        if(other.node.group == 'A'){
            this.count --;
            if(this.count <= 0){
                this.closeButton();
            }
        }
    }

    public showButton(){
        this.ff.control.mEventButton.node.active = true;
        // this.ff.mSpeedUp.node.active = false;

        this.ff.control.mEventButton.setCallback(()=>{
            this.showDialog();
        });

    }
    public closeButton(){
        this.ff.control.mEventButton.node.active = false;
        // this.ff.mSpeedUp.node.active = true;
    }

    public exitDialog(){

    }

    public showDialog(){
        let node = cc.instantiate(this.mDialog);
        this.ff.main.viewManage.popView(node);

    }


}
