event_active_event.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { _decorator, Component, Label, Node } from 'cc';
  2. import { attributes_data, event_active_event_item, 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_active_event')
  9. export class event_active_event extends Component {
  10. private m_data:event_active_event_item = null;
  11. @property(Node) btn_select_ui:Node = null;
  12. @property(Node) lab_name:Node = null;
  13. public initView(data:event_active_event_item){
  14. this.m_data = data;
  15. this.btn_select_ui.on(Node.EventType.TOUCH_END,()=>{
  16. let list = Attributes.Singleton.get_cur_scene_all_only_widget()
  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. }