import { _decorator, Color, Component, Label, Node, UITransform } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('ColorLabel')
export class ColorLabel extends Label {
    @property({ type: [Color] })
    private _colors: Color[] = [];
    @property({ type: [Color] })
    public get colors(): Color[] {
        return this._colors;
    }
    public set colors(value: Color[]) {
        this._colors = value;
    }

    start() {
    }
    public colorInit(color?) {
        if (color) {
            this.color = color
        } else {
            this.color = new Color('#ffffff')
        }
        this._updateColor(color)
    }
    protected _updateColor(colorState?) {
        super._updateColor();
        const vData = this._renderData!.chunk.vb
        let colorOffset = 5
        let color = this.color;
        for (let i = 0; i < 4; i++) {
            if (!colorState || colorState == null) {
                color = this.colors[i];
            }
            const colorR = color.r / 255;
            const colorG = color.g / 255;
            const colorB = color.b / 255;
            const colorA = color.a / 255;

            vData![colorOffset] = colorR
            vData![colorOffset + 1] = colorG
            vData![colorOffset + 2] = colorB
            vData![colorOffset + 3] = colorA
            colorOffset += 9;
        }
    }
    update(deltaTime: number) {

    }
}

