import { _decorator, Animation, Color, Component, Node, Size, Sprite, tween, UITransform } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('circle')
export class circle extends Component {
    @property(Node) spr_icon:Node;
    @property(Node) spr_icon_anim:Node;
    private m_call_back:any = null;
    private m_relative_node:circle = null;
    private _isFinish:boolean = false;
    private m_id:number = -1;
    public initView(relative_node:circle,call_back){
        this.m_call_back = call_back;
        this.m_relative_node = relative_node;
        this.node.on(Node.EventType.TOUCH_END,()=>{
            if(this.m_call_back!=null&&this.m_relative_node!=null){
                this.m_call_back(this,this.m_relative_node)
            }
        },this)
        this.hide();
    }

    public initMeiNvView(id:number,size:Size,call_back){
        this.m_call_back = call_back;
        this.m_id = id;
        this.node.getComponent(UITransform).contentSize = size;
        this.spr_icon.getComponent(UITransform).contentSize = size;
        this.node.on(Node.EventType.TOUCH_END,()=>{
            if(this.m_call_back!=null&&this.m_id!=-1){
                this.m_call_back(this,this.m_id)
            }
        },this)
        this.hide();
    }

    public initXiangTongView(id:number,relative_node:circle,size:Size,call_back){
        this.m_call_back = call_back;
        this.m_id = id;
        this.m_relative_node = relative_node;
        this.node.getComponent(UITransform).contentSize = size;
        this.spr_icon.getComponent(UITransform).contentSize = size;
        this.node.on(Node.EventType.TOUCH_END,()=>{
            if(this.m_call_back!=null&&this.m_id!=-1){
                this.m_call_back(this,this.m_id,this.m_relative_node)
            }
        },this)
        // this.show();
        this.hide();
    }


    public show(){
        this.spr_icon.active = true;
        this.spr_icon.getComponent(Sprite).fillRange=0;
        this.schedule(()=>{
            this.spr_icon.getComponent(Sprite).fillRange+=0.1;
            if(this.spr_icon.getComponent(Sprite).fillRange>=1){
                this.unscheduleAllCallbacks()
            }
        }
        ,0.05)
    }

    hide(){
        this.spr_icon.active = false;
        this.spr_icon.getComponent(Sprite).fillRange = 0;
    }

    public Finish(){
        this.spr_icon_anim.getComponent(Animation).stop();
        this.spr_icon_anim.active = false;
        this._isFinish = true;
    }

    public isFinish():boolean{
        return this._isFinish;
    }

    blinkShow(){
        this.spr_icon_anim.active = true;
        this.spr_icon.active = false;
        this.spr_icon_anim.getComponent(Animation).play();
    }

    rewardShow(){
        this.spr_icon_anim.active = true;
        this.spr_icon.active = false;
        this.spr_icon_anim.getComponent(Sprite).spriteFrame = this.spr_icon.getComponent(Sprite).spriteFrame;
        this.spr_icon_anim.getComponent(Animation).play();
    }

    public get_relative_node(){
        return this.m_relative_node;
    }
}


