DialogSay.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import i18n from "../../../i18n/i18n";
  2. const {ccclass, property} = cc._decorator;
  3. /**
  4. * 对话框 - 对话
  5. */
  6. @ccclass
  7. export default class DialogSay extends cc.Component {
  8. @property(cc.Label)
  9. mContent: cc.Label = null;
  10. /**
  11. * 对话框
  12. */
  13. @property(cc.Node)
  14. mDialog: cc.Node = null;
  15. public index:number = 0;
  16. /**
  17. * 对话内容
  18. */
  19. private contents:Array<string> = null;
  20. public setContents(contents:Array<string>){
  21. this.contents = contents;
  22. this.mContent.string = i18n.t(this.contents[0]);
  23. this.index = 0;
  24. }
  25. /**
  26. * 对话结束回调
  27. */
  28. public endCallback:()=>void;
  29. public close(){
  30. this.node.destroy();
  31. }
  32. public setEndCallback(endCallback:()=>void){
  33. this.endCallback = endCallback;
  34. }
  35. public onclick(){
  36. this.index ++;
  37. if(this.index >= this.contents.length){
  38. this.endCallback();
  39. this.close();
  40. return;
  41. }
  42. this.mContent.string = i18n.t(this.contents[this.index]);
  43. }
  44. }