event_active_event.ts 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { _decorator, Component, instantiate, Label, Node, Prefab } 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. import { edit_event_more_item } from './edit_event_more_item';
  8. const { ccclass, property } = _decorator;
  9. @ccclass('event_active_event')
  10. export class event_active_event extends Component {
  11. private m_data:event_active_event_item = null;
  12. @property(Node) btn_select_ui:Node = null;
  13. @property(Node) lab_name:Node = null;
  14. @property(Node) btn_more:Node = null;
  15. @property(Node) content:Node = null;
  16. @property(Prefab) item_more_prefab:Prefab = null;
  17. protected start(): void {
  18. this.btn_more.on(Node.EventType.TOUCH_END, ()=> {
  19. let list = Attributes.Singleton.get_cur_scene_all_only_widget()
  20. if(list.length<=0){
  21. return tools.showToast("当前场景没有添控件!")
  22. }
  23. tools.show_select_widget_list(list,(item:widget_item_data)=>{
  24. console.log('item.att')
  25. let index = this.m_data.binding_widget_list_id.indexOf(item.att.id)
  26. if(index!=-1) {
  27. this.m_data.binding_widget_list_id.splice(index,1)
  28. }
  29. this.m_data.binding_widget_list_id.push(item.att.id)
  30. this.updateMoreListStatus()
  31. })
  32. },this)
  33. }
  34. public initView(data:event_active_event_item){
  35. this.m_data = data;
  36. this.btn_select_ui.on(Node.EventType.TOUCH_END,()=>{
  37. let list = Attributes.Singleton.get_cur_scene_all_only_widget()
  38. if(list.length<=0){
  39. return tools.showToast("当前场景没有添控件!")
  40. }
  41. tools.show_select_widget_list(list,(item:widget_item_data)=>{
  42. this.m_data.binding_widget_id = item.att.id;
  43. this.updateStatus()
  44. },this.m_data.binding_widget_id)
  45. })
  46. this.updateStatus()
  47. this.updateMoreListStatus()
  48. ClientEvent.on(config.Event.UpdateAttributesToView,this.UpdateAttributesToView,this)
  49. }
  50. protected onDestroy(): void {
  51. ClientEvent.off(config.Event.UpdateAttributesToView,this.UpdateAttributesToView,this)
  52. }
  53. UpdateAttributesToView(data:attributes_data,update_type:string){
  54. if(this.m_data.binding_widget_id===data.id&&update_type===config.attributes_list_type.delete){
  55. console.log('激活清空 激活清空')
  56. this.m_data.binding_widget_id = -1;
  57. this.updateStatus()
  58. }
  59. }
  60. updateStatus(){
  61. this.lab_name.getComponent(Label).string = this.m_data.binding_widget_id===-1?"当前选择激活的控件":`当前选择激活的控件id:${this.m_data.binding_widget_id}`
  62. }
  63. updateMoreListStatus() {
  64. if(this.m_data.binding_widget_list_id==undefined) {
  65. this.m_data.binding_widget_list_id = []
  66. }
  67. this.content.removeAllChildren()
  68. for(let index = 0; index < this.m_data.binding_widget_list_id.length; index ++) {
  69. const element = this.m_data.binding_widget_list_id[index]
  70. let item = instantiate(this.item_more_prefab);
  71. item.parent = this.content;
  72. item.getComponent(edit_event_more_item).initView(element, ()=>{
  73. this.m_data.binding_widget_list_id.splice(index,1)
  74. this.updateMoreListStatus()
  75. })
  76. }
  77. }
  78. }