import { _decorator, Component, Label, Node } from 'cc';
import { event_item, guo_ju_qing_data } from '../../../data/data';
import { tools } from '../../tools';
import { Attributes } from '../Attributes';
const { ccclass, property } = _decorator;

@ccclass('task_guo_ren_wu')
export class task_guo_ren_wu extends Component {
    @property(Node) btn_setting:Node = null;
    @property(Node) lab_event_id:Node = null;
    @property(Node) btn_clear:Node = null;
    protected m_data:guo_ju_qing_data = null;
    public updateView(data:guo_ju_qing_data){
        this.m_data = data;
        this.btn_setting.off(Node.EventType.TOUCH_END);
        this.btn_setting.on(Node.EventType.TOUCH_END,()=>{
            let list = Attributes.Singleton.getEventList()
            tools.show_select_evele_list(list,(data:event_item)=>{
                this.m_data.binding_event_id = data.event_id;
                this.updateStatus()
            })
        })

        this.btn_clear.off(Node.EventType.TOUCH_END);
        this.btn_clear.on(Node.EventType.TOUCH_END,()=>{
            tools.show_dialog("是否删除触发条件？",()=>{
                this.m_data.binding_event_id = -1;
                this.updateStatus()
            })

        })
        this.updateStatus()
    }

    updateStatus(){
        if(this.m_data==undefined){
            return
        }
        if(this.m_data.binding_event_id!=-1){
            this.btn_clear.active = true;
        }else{
            this.btn_clear.active = false;
        }
        this.lab_event_id.getComponent(Label).string = this.m_data.binding_event_id!=-1?`事件id:${this.m_data.binding_event_id}`:"设置剧情的规则的触发条件"
    }
}


