single_ui_widget_info.ts 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. @property(Node) btn_clear_res:Node = null;
  18. private call_back = null;
  19. private m_data:ui_att_item = null;
  20. protected start(): void {
  21. this.btn_clear_res.on(Node.EventType.TOUCH_END, ()=> {
  22. this.m_data.res = '';
  23. this.m_data.res_name = '';
  24. this.updateInfo(this.m_data)
  25. this.change()
  26. })
  27. }
  28. public initView(call){
  29. this.call_back = call;
  30. this.ui_x.on('editing-did-ended', this.change, this);
  31. this.ui_y.on('editing-did-ended', this.change, this);
  32. this.ui_width.on('editing-did-ended', this.change, this);
  33. this.ui_height.on('editing-did-ended', this.change, this);
  34. ClientEvent.on(config.Event.DragResEndOnCheck,this.DragResEndOnCheck,this)
  35. }
  36. protected onDestroy(): void {
  37. ClientEvent.off(config.Event.DragResEndOnCheck,this.DragResEndOnCheck,this)
  38. }
  39. DragResEndOnCheck(v2:Vec2,node:Node){
  40. if(this.getRect().contains(v2)){
  41. let type = node.getComponent(base_res).getType()
  42. if(type===config.select_res_btn_type.SOUND_LIST){
  43. }else{
  44. let temp_data = node.getComponent(img_item).getData()
  45. this.m_data.res = temp_data.url;
  46. this.m_data.res_name = temp_data.name;
  47. this.updateInfo(this.m_data)
  48. this.change()
  49. }
  50. }
  51. }
  52. updateInfo(data:ui_att_item){
  53. this.m_data = data;
  54. this.ui_x.getComponent(EditBox).string = this.m_data.x.toString()
  55. this.ui_y.getComponent(EditBox).string = this.m_data.y.toString()
  56. this.ui_width.getComponent(EditBox).string = this.m_data.width.toString()
  57. this.ui_height.getComponent(EditBox).string = this.m_data.height.toString()
  58. this.ui_lab_res.getComponent(Label).string = this.m_data.res_name;
  59. }
  60. public getRect(){
  61. let size = this.ui_res.getComponent(UITransform).contentSize;
  62. let pos = this.ui_res.parent.getComponent(UITransform).convertToWorldSpaceAR(this.ui_res.position);
  63. let rect = new Rect(pos.x-size.width/2,pos.y-size.height/2,size.width,size.height)
  64. return rect;
  65. }
  66. change(){
  67. this.m_data.x = parseInt(this.ui_x.getComponent(EditBox).string)
  68. this.m_data.y = parseInt(this.ui_y.getComponent(EditBox).string)
  69. this.m_data.width = parseInt(this.ui_width.getComponent(EditBox).string)
  70. this.m_data.height = parseInt(this.ui_height.getComponent(EditBox).string)
  71. if(this.call_back!=null){
  72. this.call_back(this.m_data)
  73. }
  74. }
  75. }