single_ui_widget_info.ts 3.3 KB

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