import { Button, Component, Label, Node, NodeEventType, _decorator, find } from 'cc';
import { GameEvent } from '../Enum/GameEvent';
import { EventDispatcher } from 'db://assets/core_tgx/easy_ui_framework/EventDispatcher';
import { GlobalConfig } from 'db://assets/start/Config/GlobalConfig';
import { AdvertMgr } from 'db://assets/core_tgx/base/ad/AdvertMgr';
import { TYPE_ITEM } from '../StormSunderGlobalInstance';
import { tgxUIAlert } from 'db://assets/core_tgx/tgx';
import { StormSunderAudioMgr } from '../Manager/StormSunderAudioMgr';
const { ccclass, property } = _decorator;

/**
 * 底部按钮控制器
 */
@ccclass('ButtonComponent')
export class ButtonComponent extends Component {
    @property(Button) btnFillUp: Button = null!;
    @property(Button) btMoveOut: Button = null!;
    @property(Button) btRefresh: Button = null!;

    protected start(): void {
        this.addUIEvent();
    }

    private addUIEvent(): void {
        this.btnFillUp.node.on(NodeEventType.TOUCH_END, () => this.onClickHandler(TYPE_ITEM.UP_ATTACK), this);
        this.btMoveOut.node.on(NodeEventType.TOUCH_END, () => this.onClickHandler(TYPE_ITEM.UP_SPEED), this);
        this.btRefresh.node.on(NodeEventType.TOUCH_END, () => this.onClickHandler(TYPE_ITEM.UP_EXP), this);
    }

    private onClickHandler(type: TYPE_ITEM): void {
        console.log("onClickHandler", type);
        StormSunderAudioMgr.playOneShot(StormSunderAudioMgr.getMusicIdName(2), 1.0);
    }

}
