attributes_w_h.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { _decorator, Component, EditBox, Node, Size } from 'cc';
  2. import { ClientEvent } from '../../clientEvent';
  3. import { config } from '../../config';
  4. import { slider_widget } from './slider_widget';
  5. import { Attributes } from '../Attributes';
  6. const { ccclass, property } = _decorator;
  7. @ccclass('attributes_w_h')
  8. export class attributes_w_h extends Component {
  9. @property(EditBox) edit_w:EditBox = null;
  10. @property(EditBox) edit_h:EditBox = null;
  11. @property(Node) slace_W_h:Node = null;
  12. private _w:number = 0;
  13. private _h:number = 0;
  14. private call_back = null;
  15. private slider_status:boolean = false;
  16. public update_att(w:number,h:number){
  17. this.edit_w.string = w.toFixed()
  18. this.edit_h.string = h.toFixed()
  19. this._w = 0;
  20. this._h = 0;
  21. }
  22. public initView(call){
  23. this.call_back = call;
  24. this.edit_w.node.on('editing-did-ended', this.change, this);
  25. this.edit_h.node.on('editing-did-ended', this.change, this);
  26. this.slace_W_h.getComponent(slider_widget).initView((scale:number)=>{
  27. if(!this.slider_status){
  28. this._w = parseInt(this.edit_w.string);
  29. this._h = parseInt(this.edit_h.string);
  30. this.slider_status = true;
  31. }
  32. let w =`${this._w*scale}`
  33. let h =`${this._h*scale}`
  34. this.edit_w.string = w;
  35. this.edit_h.string = h;
  36. this.change()
  37. },()=>{
  38. this.slider_status = false;
  39. })
  40. }
  41. change(){
  42. if(this.call_back!=null){
  43. this.call_back(new Size(parseInt(this.edit_w.string),parseInt(this.edit_h.string)))
  44. }
  45. }
  46. }