event_text_sound.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { _decorator, Component, Label, Node } from 'cc';
  2. import { attributes_data, event_item_text_sound, widget_item_data } from '../../../data/data';
  3. import { Attributes } from '../Attributes';
  4. import { config } from '../../config';
  5. import { tools } from '../../tools';
  6. import { ClientEvent } from '../../clientEvent';
  7. const { ccclass, property } = _decorator;
  8. @ccclass('event_text_sound')
  9. export class event_text_sound extends Component {
  10. private m_data:event_item_text_sound = null;
  11. @property(Node) btn_select_ui:Node = null;
  12. @property(Node) lab_name:Node = null;
  13. public initView(data:event_item_text_sound){
  14. this.m_data = data;
  15. this.btn_select_ui.on(Node.EventType.TOUCH_END,()=>{
  16. let list = Attributes.Singleton.get_cur_scene_widget_by_type(config.Widget_Type_List.TEXT_SOUND)
  17. if(list.length<=0){
  18. return tools.showToast("当前场景没有添加文本和音效!")
  19. }
  20. tools.show_select_widget_list(list,(item:widget_item_data)=>{
  21. this.m_data.binding_widget_id = item.att.id;
  22. this.updateStatus()
  23. },this.m_data.binding_widget_id)
  24. })
  25. this.updateStatus()
  26. ClientEvent.on(config.Event.UpdateAttributesToView,this.UpdateAttributesToView,this)
  27. }
  28. protected onDestroy(): void {
  29. ClientEvent.off(config.Event.UpdateAttributesToView,this.UpdateAttributesToView,this)
  30. }
  31. UpdateAttributesToView(data:attributes_data,update_type:string){
  32. if(this.m_data.binding_widget_id===data.id&&update_type===config.attributes_list_type.delete){
  33. this.m_data.binding_widget_id = -1;
  34. this.updateStatus()
  35. }
  36. }
  37. updateStatus(){
  38. this.lab_name.getComponent(Label).string = this.m_data.binding_widget_id===-1?"添加文本和音效":`当前绑定的文本和音效id:${this.m_data.binding_widget_id}`
  39. }
  40. }