import { _decorator, Component, Label, Node, Slider, Toggle } from 'cc'; import { bag_item_data, event_item_play_sound } from '../../../data/data'; import { tools } from '../../tools'; const { ccclass, property } = _decorator; @ccclass('event_play_sound') export class event_play_sound extends Component { @property(Node) btn_select_sound:Node = null; @property(Node) lab_name:Node = null; @property(Toggle) toggle:Toggle = null; @property(Slider) slider_volume:Slider = null; @property(Node) select_loop:Node = null; @property(Node) select_volume:Node = null; @property(Node) select_BGM:Node = null; @property(Toggle) BGM_toggle:Toggle = null; private m_data:event_item_play_sound = null; public initView(data:event_item_play_sound){ this.m_data = data; this.btn_select_sound.on(Node.EventType.TOUCH_END,()=>{ tools.select_sound_list((data:bag_item_data)=>{ this.m_data.sound_res.name = data.name; this.m_data.sound_res.url = data.url; this.updateStatus() }) }) this.updateStatus() this.toggle.node.on(Toggle.EventType.TOGGLE,()=>{ this.m_data.isLoop = this.toggle.isChecked }) this.BGM_toggle.node.on(Toggle.EventType.TOGGLE, ()=>{ this.m_data.isBGM = this.BGM_toggle.isChecked }) } onSlider(){ this.m_data.volume = this.slider_volume.progress; } updateStatus(){ if(this.m_data.sound_res.name.length>0){ this.lab_name.getComponent(Label).string = this.m_data.sound_res.name this.select_loop.active = true; this.select_volume.active = true; this.select_BGM.active = true; }else{ this.lab_name.getComponent(Label).string = "选择一个音频文件" this.select_loop.active = false; this.select_volume.active = false; this.select_BGM.active = false; } if(this.m_data.isLoop==undefined){ this.m_data.isLoop = false; } if( this.m_data.volume==undefined){ this.m_data.volume = 1; } if(this.m_data.isBGM==undefined) { this.m_data.isBGM = false; } this.toggle.isChecked = this.m_data.isLoop; this.slider_volume.progress = this.m_data.volume; this.BGM_toggle.isChecked = this.m_data.isBGM } }