dialog_input.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { _decorator, Component, EditBox, Node } from 'cc';
  2. import { tools } from './tools';
  3. const { ccclass, property } = _decorator;
  4. @ccclass('dialog_input')
  5. export class dialog_input extends Component {
  6. @property(EditBox) editBox:EditBox = null;
  7. @property(Node) btn_cancel:Node = null;
  8. @property(Node) btn_sure:Node = null;
  9. private m_sure_call = null;
  10. private m_cancel_call = null;
  11. start() {
  12. this.editBox.node.on(EditBox.EventType.EDITING_DID_ENDED, ()=> {
  13. })
  14. this.btn_cancel.on(Node.EventType.TOUCH_END, ()=>{
  15. if(this.m_cancel_call!=null){
  16. this.m_cancel_call()
  17. }
  18. this.close()
  19. })
  20. this.btn_sure.on(Node.EventType.TOUCH_END, ()=>{
  21. let string = tools.trimLeftAndRightblank(this.editBox.string)
  22. if(string.length==0) {
  23. return tools.showToast('内容不能是空的')
  24. }
  25. if(this.m_sure_call!=null){
  26. this.m_sure_call(string)
  27. }
  28. this.close()
  29. })
  30. }
  31. public show(content:string,sure_call,cancel_call){
  32. this.m_sure_call = sure_call;
  33. this.m_cancel_call = cancel_call;
  34. this.editBox.string = content;
  35. }
  36. close(){
  37. this.node.removeFromParent()
  38. }
  39. }