import FSprite from "../../../object/FSprite";
import BaseEvent from "../../base/BaseEvent";
import FPick1_3 from "./FPick1_3";

/**
 * 摘果子任务中的果子
 */
const {ccclass, property} = cc._decorator;

@ccclass
export default class FFruit1_3 extends BaseEvent {

    @property({
        type:cc.ProgressBar,
        displayName: '进度条'
    })
    public mProgressBar:cc.ProgressBar = null;

    @property({
        displayName: '提示图标',
        type: cc.SpriteFrame
    })
    mTipsIcon: cc.SpriteFrame = null;

    public pick26:FPick1_3;
    onLoad() {
        super.onLoad()
        this.mProgressBar.node.active = false;
    }
    public setPick26(pick26:FPick1_3){
        this.pick26 = pick26;
    }
   
    /**
     * 主角进入碰撞区域
     *  @param tag 碰撞组件编号
     */
    public onBegin(tag:number){
        if(this.pick26 && this.pick26.state == 1){
            this.showOpt(this.mTipsIcon,()=>{
                this.pick();
            })
        }
    }
    /**
     * 主角离开碰撞区域
     * @param tag 碰撞组件编号
     */
    public onEnd(tag:number){
        this.closeOpt()
    }
  
    /**
     * 摘取果子
     */
    public pick(){
        this.closeOpt()
        this.mProgressBar.node.active = true;
        this.mProgressBar.progress = 0;
        this.ff.mBlockInputEvents.active = true;
        this.schedule(this.pupdate,0.1);

    }
    public pupdate(){
        let progress = this.mProgressBar.progress;
        progress += 0.1;
        this.mProgressBar.progress = progress;
        if(progress >= 1){
            this.ff.mBlockInputEvents.active = false;
            this.unschedule(this.pupdate);
            this.ff.mFFheader.addTmpGood(this.pick26.goodId,1);
            this.node.removeComponent(cc.PhysicsBoxCollider);
            
            cc.tween(this.node).sequence(
                cc.fadeOut(0.5),
                cc.destroySelf()
            ).start()
        }
    }


}
