// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import * as cc from "cc";
import cp_palette from "./cp_palette";

const { ccclass, property } = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    @property(cp_palette)
    cp_palette: cp_palette = null;

    @property(cc.Node)
    target: cc.Node = null;

    protected onLoad(): void {
        this.node.on("click", this.on_click_self, this);
    }

    on_click_self() {
        const sprite = this.target.getComponent(cc.Sprite);
        this.cp_palette.show({
            color: sprite.color,
            alpha: sprite.color.a,
            update_listener: (color: cc.Color, alpha: number) => {
                color.a = alpha;
                sprite.color = color;
            }
        });
    }

}
