attributes_x_y.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { _decorator, Component, EditBox, Node, Vec2, Vec3 } from 'cc';
  2. import { slider_widget } from './slider_widget';
  3. const { ccclass, property } = _decorator;
  4. @ccclass('attributes_x_y')
  5. export class attributes_x_y extends Component {
  6. @property(EditBox) edit_x:EditBox = null;
  7. @property(EditBox) edit_y:EditBox = null;
  8. @property(EditBox) edit_z:EditBox = null;
  9. @property(Node) slider_x:Node = null;
  10. @property(Node) slider_y:Node = null;
  11. private _x:number = 0;
  12. private _y:number = 0;
  13. private call_back = null;
  14. private slider_status:boolean = false;
  15. public update_att(x:number,y:number,z:number){
  16. this.edit_x.string = x.toString()
  17. this.edit_y.string = y.toString()
  18. this.edit_z.string = z.toString()
  19. this._x = x;
  20. this._y = y;
  21. }
  22. protected start(): void {
  23. this.edit_x.node.on('editing-did-ended', this.change, this);
  24. this.edit_y.node.on('editing-did-ended', this.change, this);
  25. this.edit_z.node.on('editing-did-ended', this.change, this);
  26. }
  27. public initView(call){
  28. this.call_back = call;
  29. this.slider_x.getComponent(slider_widget).initView((scale:number)=>{
  30. if(!this.slider_status){
  31. this.slider_status = true;
  32. }
  33. this._x = parseInt(this.edit_x.string);
  34. let x =`${this._x +(scale>1?5:-5)}`
  35. this.edit_x.string = x;
  36. this.change()
  37. },()=>{
  38. console.log("end_call")
  39. this.slider_status = false;
  40. })
  41. this.slider_y.getComponent(slider_widget).initView((scale:number)=>{
  42. if(!this.slider_status){
  43. this.slider_status = true;
  44. }
  45. this._y = parseInt(this.edit_y.string);
  46. let y =`${this._y +(scale>1?5:-5)}`
  47. this.edit_y.string = y;
  48. this.change()
  49. },()=>{
  50. this.slider_status = false;
  51. })
  52. }
  53. change(){
  54. if(this.call_back!=null){
  55. this.call_back(new Vec3(parseInt(this.edit_x.string),parseInt(this.edit_y.string),parseInt(this.edit_z.string)))
  56. }
  57. }
  58. }