import { _decorator, Component, Node } from 'cc';
import { gameManager } from '../gameManager';
import { ClientEvent } from '../../clientEvent';
import { config } from '../../config';
const { ccclass, property } = _decorator;

@ccclass('yinyue')
export class yinyue extends Component {
    @property(Node) btn_on:Node = null;
    @property(Node) btn_off:Node = null;
    private isOpen:boolean = true;
    protected start(): void {
        this.node.on(Node.EventType.TOUCH_START,()=>{
            this.isOpen = !this.isOpen;
            this.changeStatus()
        })
    }

    public initView(){
        this.isOpen = gameManager.getUserData().isOpenYinYue;
        this.changeStatus()
    }

    public changeStatus(){
        if(this.isOpen){
            this.btn_on.active = true;
            this.btn_off.active = false;
        }else{
            this.btn_on.active = false;
            this.btn_off.active = true;
        }
        gameManager.getStaticUserData().isOpenYinYue = this.isOpen;
        gameManager.saveUserData()
        ClientEvent.dispatchEvent(config.EventRun.TOGGLE_YIN_YUE)
    }
}


