receive_widget_item.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { _decorator, Component, EditBox, Node } from 'cc';
  2. import { ui_att_item } from '../../../data/data';
  3. import { Attributes } from '../Attributes';
  4. import { config } from '../../config';
  5. import { ClientEvent } from '../../clientEvent';
  6. const { ccclass, property } = _decorator;
  7. @ccclass('receive_widget_item')
  8. export class receive_widget_item extends Component {
  9. private m_data:ui_att_item = null;
  10. private widget_type = config.attributes_list_type.top;
  11. private call_back = null;
  12. public initView(call){
  13. this.call_back = call;
  14. }
  15. updateView(data:ui_att_item,type=config.attributes_list_type.top){
  16. this.widget_type = type;
  17. if(this.m_data===null){
  18. this.node.getChildByName("x").on('editing-did-ended',()=>{
  19. this.change()
  20. })
  21. this.node.getChildByName("y").on('editing-did-ended',()=>{
  22. this.change()
  23. })
  24. this.node.getChildByName("w").on('editing-did-ended',()=>{
  25. this.change()
  26. })
  27. this.node.getChildByName("h").on('editing-did-ended',()=>{
  28. this.change()
  29. })
  30. }
  31. this.m_data = data;
  32. let x= this.getX()
  33. let y = this.getY()
  34. let width = this.getWidth();
  35. let height = this.getHeight();
  36. x.string = this.m_data.x.toString();
  37. y.string = this.m_data.y.toString();
  38. width.string = this.m_data.width.toString();
  39. height.string = this.m_data.height.toString();
  40. }
  41. change(){
  42. this.m_data.x = parseInt(this.getX().string)
  43. this.m_data.y = parseInt(this.getY().string)
  44. this.m_data.width = parseInt(this.getWidth().string)
  45. this.m_data.height = parseInt(this.getHeight().string)
  46. // if(this.call_back!=null){
  47. // // this.scheduleOnce(()=>{
  48. // // },0.5)
  49. // this.call_back(this.m_data)
  50. // }else{
  51. // }
  52. ClientEvent.dispatchEvent(config.Event.UpdateAttributesToView,Attributes.Singleton.get_cur_att_data(),this.widget_type)
  53. }
  54. getX():EditBox{
  55. return this.node.getChildByName("x").getComponent(EditBox);
  56. }
  57. getY(){
  58. return this.node.getChildByName("y").getComponent(EditBox);
  59. }
  60. getWidth(){
  61. return this.node.getChildByName("w").getComponent(EditBox);
  62. }
  63. getHeight(){
  64. return this.node.getChildByName("h").getComponent(EditBox);
  65. }
  66. }