dialog.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { _decorator, Component, Label, Node } from 'cc';
  2. import { gameManager } from '../gameManager';
  3. const { ccclass, property } = _decorator;
  4. @ccclass('dialog')
  5. export class dialog extends Component {
  6. @property(Node) lab_name;
  7. @property(Node) btn_yes;
  8. @property(Node) btn_one_yes;
  9. @property(Node) btn_not;
  10. private m_call_yes = null;
  11. private m_call_not = null;
  12. public show(text:string,call_yes,call_not){
  13. this.m_call_yes = call_yes;
  14. this.m_call_not = call_not;
  15. this.btn_yes.on(Node.EventType.TOUCH_START,()=>{
  16. gameManager.playBtnSound()
  17. if(this.m_call_yes!=null){
  18. this.m_call_yes()
  19. }
  20. this.close()
  21. },this);
  22. this.btn_not.on(Node.EventType.TOUCH_START,()=>{
  23. gameManager.playBtnSound()
  24. if(this.m_call_not!=null){
  25. this.m_call_not()
  26. }
  27. this.close()
  28. },this);
  29. this.lab_name.getComponent(Label).string = text;
  30. }
  31. public showOne(text:string,call_yes){
  32. this.m_call_yes = call_yes;
  33. this.btn_not.active = false;
  34. this.btn_yes.active = false;
  35. this.btn_one_yes.active = true;
  36. this.btn_one_yes.on(Node.EventType.TOUCH_START,()=>{
  37. gameManager.playBtnSound()
  38. if(this.m_call_yes!=null){
  39. this.m_call_yes()
  40. }
  41. this.close()
  42. },this);
  43. this.lab_name.getComponent(Label).string = text;
  44. }
  45. close(){
  46. this.node.removeFromParent()
  47. }
  48. }