single_ui_widget_info.ts 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { _decorator, Component, EditBox, Label, Node, Rect, UITransform, Vec2 } from 'cc';
  2. import { ui_att_item } from '../../../data/data';
  3. import { ClientEvent } from '../../clientEvent';
  4. import { config } from '../../config';
  5. import { base_res } from '../base_res';
  6. import { img_item } from '../img_item';
  7. import { Attributes } from '../Attributes';
  8. const { ccclass, property } = _decorator;
  9. @ccclass('single_ui_widget_info')
  10. export class single_ui_widget_info extends Component {
  11. @property(Node) ui_x:Node = null;
  12. @property(Node) ui_y:Node = null;
  13. @property(Node) ui_width:Node = null;
  14. @property(Node) ui_height:Node = null;
  15. @property(Node) ui_res:Node = null;
  16. @property(Node) ui_lab_res:Node = null;
  17. private call_back = null;
  18. private m_data:ui_att_item = null;
  19. public initView(call){
  20. this.call_back = call;
  21. this.ui_x.on('editing-did-ended', this.change, this);
  22. this.ui_y.on('editing-did-ended', this.change, this);
  23. this.ui_width.on('editing-did-ended', this.change, this);
  24. this.ui_height.on('editing-did-ended', this.change, this);
  25. ClientEvent.on(config.Event.DragResEndOnCheck,this.DragResEndOnCheck,this)
  26. }
  27. protected onDestroy(): void {
  28. ClientEvent.off(config.Event.DragResEndOnCheck,this.DragResEndOnCheck,this)
  29. }
  30. DragResEndOnCheck(v2:Vec2,node:Node){
  31. if(this.getRect().contains(v2)){
  32. let type = node.getComponent(base_res).getType()
  33. if(type===config.select_res_btn_type.SOUND_LIST){
  34. }else{
  35. let temp_data = node.getComponent(img_item).getData()
  36. this.m_data.res = temp_data.url;
  37. this.m_data.res_name = temp_data.name;
  38. this.updateInfo(this.m_data)
  39. this.change()
  40. }
  41. }
  42. }
  43. updateInfo(data:ui_att_item){
  44. this.m_data = data;
  45. this.ui_x.getComponent(EditBox).string = this.m_data.x.toString()
  46. this.ui_y.getComponent(EditBox).string = this.m_data.y.toString()
  47. this.ui_width.getComponent(EditBox).string = this.m_data.width.toString()
  48. this.ui_height.getComponent(EditBox).string = this.m_data.height.toString()
  49. this.ui_lab_res.getComponent(Label).string = this.m_data.res_name;
  50. }
  51. public getRect(){
  52. let size = this.ui_res.getComponent(UITransform).contentSize;
  53. let pos = this.ui_res.parent.getComponent(UITransform).convertToWorldSpaceAR(this.ui_res.position);
  54. let rect = new Rect(pos.x-size.width/2,pos.y-size.height/2,size.width,size.height)
  55. return rect;
  56. }
  57. change(){
  58. this.m_data.x = parseInt(this.ui_x.getComponent(EditBox).string)
  59. this.m_data.y = parseInt(this.ui_y.getComponent(EditBox).string)
  60. this.m_data.width = parseInt(this.ui_width.getComponent(EditBox).string)
  61. this.m_data.height = parseInt(this.ui_height.getComponent(EditBox).string)
  62. if(this.call_back!=null){
  63. this.call_back(this.m_data)
  64. }
  65. }
  66. }