import { _decorator, Component, Node, Size, UITransform } from 'cc';
import { config } from '../config';
const { ccclass, property } = _decorator;

@ccclass('slide')
export class slide extends Component {
    @property(Node) left:Node = null;
    @property(Node) right:Node = null;
    @property(Node) up:Node = null;
    @property(Node) down:Node = null;
    public updateDistance(dir:number,distance:number){

        if(dir===config.slide_type.down||dir===config.slide_type.up||dir===config.slide_type.up_down){
            this.node.getComponent(UITransform).contentSize = new Size( this.node.getComponent(UITransform).contentSize.width, distance)
        }else{
            this.node.getComponent(UITransform).contentSize = new Size( distance, this.node.getComponent(UITransform).contentSize.height)
        }
        this.updateDir(dir)
    }

    public updateDir(dir:number){
        this.left.active = false;
        this.right.active = false;
        this.up.active = false;
        this.down.active = false;
        switch(dir){
            case config.slide_type.down:
                this.down.active = true;
                break;
            case config.slide_type.up:
                this.up.active = true;
                break;
            case config.slide_type.left:
                this.left.active = true;
                break;
            case config.slide_type.right:
                this.right.active = true;
                break;
            case config.slide_type.up_down:
                this.down.active = true;
                this.up.active = true;
                break;
            case config.slide_type.left_right:
                this.left.active = true;
                this.right.active = true;
                break;
        }
    }
}


