import { _decorator, assetManager, Component, ImageAsset, instantiate, Node, Prefab, Size, Sprite, SpriteFrame, Texture2D, tween, Vec3 } from 'cc';
import { view_game_play_zhao_bu_tong } from './view_game_play_zhao_bu_tong';
import { circle } from '../circle';
const { ccclass, property } = _decorator;

@ccclass('diff_child_item')
export class diff_child_item extends Component {
    private m_click_call = null;
    private m_id:string = "1";
    private _isFinish:boolean = false;
    @property(Prefab) prefab_select:Prefab = null;
    @property(Node) spr_err_img:Node = null;
    private spr_select:Node =null;
    public initView(click_call,id){
        this.m_id = id;
        this.m_click_call = click_call;
        // this.node.on(Node.EventType.TOUCH_END,()=>{
   
        // },this)

        this.spr_select = instantiate(this.prefab_select)
        this.spr_select.position = new Vec3(0,0,0)
        this.spr_select.parent = this.node;
        this.spr_select.getComponent(circle).initMeiNvView(parseInt(this.m_id),new Size(50,50),()=>{
            if(this.m_click_call!=null){
                this.m_click_call(this,this.m_id)
            }
        })
        this.unselect()
        this.draw_img();
        // this.spr_select.getComponent(circle).show()
    }

    public showErrStatus(){
        this.spr_err_img.active = true;
        tween(this.spr_err_img).delay(0.5).call(()=>{
            this.spr_err_img.active = false;
        }).start();
    }

    public show(){
        this.spr_select.getComponent(circle).show()
    }
    public Finish(){
        this.spr_select.getComponent(circle).Finish()
    }

    public blinkShow(){
        this.spr_select.getComponent(circle).blinkShow()
    }

    public draw_img(){
        let sf = view_game_play_zhao_bu_tong.sfList.get(this.m_id);
        if(this.m_id==="100"){
            if(this._isFinish){
                this.spr_select.getComponent(circle).show()
            }else{
                this.spr_select.getComponent(circle).hide()
            }
            
        }else{
            this.spr_select.getComponent(circle).hide()
        }
        this.node.getComponent(Sprite).spriteFrame = sf;
    }

    public getId(){
        return this.m_id;
    }


    public isRight(){
        return this.m_id==="100";
    }
    public unselect(){
        this.spr_select.getComponent(circle).hide()
    }

}


