import { _decorator, Color, Component, Label, Node, Sprite, SpriteFrame, UITransform } from 'cc';
import { att_count_down } from '../../../data/data';
import { view_ui_att_item } from './view_ui_att_item';
const { ccclass, property } = _decorator;

@ccclass('count_down')
export class count_down extends Component {
    private m_data:att_count_down = null;
    @property(Node) ProgressBar_Bg:Node = null;
    @property(Node) ProgressBar_Bar:Node = null;
    @property(Node) img_text:Node = null;
    @property(Node) lab_time:Node = null;
    @property(SpriteFrame) sf_ProgressBar_Bg_default:SpriteFrame = null;
    @property(SpriteFrame) sf_ProgressBar_Bar_default:SpriteFrame = null;
    @property(SpriteFrame) sf_img_text_default:SpriteFrame = null;
    public initView(data:att_count_down){
        this.m_data = data;
        this.updateView(this.m_data)
    }

    public updateView(data:att_count_down){
        this.m_data = data;
        this.ProgressBar_Bar.getComponent(view_ui_att_item).updateAtt(this.m_data.ProgressBar_Bar)
        this.m_data.ProgressBar_Bar = this.ProgressBar_Bar.getComponent(view_ui_att_item).getData()
   
        this.ProgressBar_Bg.getComponent(view_ui_att_item).updateAtt(this.m_data.ProgressBar_Bg)
        this.m_data.ProgressBar_Bg = this.ProgressBar_Bg.getComponent(view_ui_att_item).getData()

        this.img_text.getComponent(view_ui_att_item).updateAtt(this.m_data.img_text)
        this.m_data.img_text = this.img_text.getComponent(view_ui_att_item).getData()

        if(this.m_data.ProgressBar_Bar.res.length==0||this.m_data.ProgressBar_Bar.res_name.length==0) {
            this.ProgressBar_Bar.getComponent(view_ui_att_item).getComponent(Sprite).spriteFrame = this.sf_ProgressBar_Bar_default
        }
        if(this.m_data.ProgressBar_Bg.res.length==0||this.m_data.ProgressBar_Bg.res_name.length==0) {
            this.ProgressBar_Bg.getComponent(view_ui_att_item).getComponent(Sprite).spriteFrame = this.sf_ProgressBar_Bg_default
        }
        if(this.m_data.img_text.res.length==0||this.m_data.img_text.res_name.length==0) {
            this.img_text.getComponent(view_ui_att_item).getComponent(Sprite).spriteFrame = this.sf_img_text_default
        }
        
        if(this.m_data.time_count>0){
            this.lab_time.getComponent(Label).string = `${this.m_data.time_count}秒`
            this.lab_time.active = true;
        }else{
            this.lab_time.active = false;
        }

        if(this.m_data.font_info!=undefined){
            this.lab_time.getComponent(Label).fontSize = this.m_data.font_info.font_size;
            this.lab_time.getComponent(Label).lineHeight = this.m_data.font_info.font_size;
            this.lab_time.getComponent(Label).color = new Color(this.m_data.font_info.font_color.r,this.m_data.font_info.font_color.g,this.m_data.font_info.font_color.b)
        }
    }
}


