CommonTips.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import { _decorator, Label, Node, tween, UIOpacity } from 'cc';
  2. import { BaseView } from '../../../framework/layer/BaseView';
  3. import { StringUtil } from '../../../framework/util/StringUtil';
  4. import { Framework } from '../../../framework/Framework';
  5. import { TipsOpereteEnum } from '../../common/InterfaceAddEnum';
  6. const { ccclass, property } = _decorator;
  7. @ccclass('CommonTips')
  8. export class CommonTips extends BaseView {
  9. @property({ type: Label, tooltip: "标题" })
  10. titleTx: Label = null;
  11. @property({ type: Label, tooltip: "提示内容" })
  12. contentTx: Label = null;
  13. @property({ type: Node, tooltip: "取消按钮" })
  14. cancelBtn: Node = null;
  15. @property({ type: Label, tooltip: "取消按钮文字" })
  16. cancelBtnTx: Label = null;
  17. @property({ type: Node, tooltip: "确定按钮" })
  18. confirmBtn: Node = null;
  19. @property({ type: Label, tooltip: "确定按钮文字" })
  20. confirmBtnTx: Label = null;
  21. @property({ type: Node, tooltip: "关闭按钮" })
  22. closeBtn: Node = null;
  23. @property({ type: Label, tooltip: "关闭按钮文字" })
  24. closeBtnTx: Label = null;
  25. private _callback = null;
  26. protected onLoad() {
  27. super.onLoad();
  28. this.titleTx.string = StringUtil.getLanguageData('提示');
  29. this.cancelBtnTx.string = StringUtil.getLanguageData('取消');
  30. this.confirmBtnTx.string = StringUtil.getLanguageData('确定');
  31. this.closeBtnTx.string = StringUtil.getLanguageData('关闭');
  32. }
  33. protected onDestroy() {
  34. }
  35. //UI开打时会调用,如果有初始化代码应该放到此函数
  36. onOpen(openType: TipsOpereteEnum, content: string, callback?:void) {
  37. this._callback = callback;
  38. this.contentTx.string = content;
  39. if (openType==TipsOpereteEnum.yes) {
  40. this.cancelBtn.active = false;
  41. this.confirmBtn.active = false;
  42. this.closeBtn.active = true;
  43. } else if (openType==TipsOpereteEnum.yes_no) {
  44. this.cancelBtn.active = true;
  45. this.confirmBtn.active = true;
  46. this.closeBtn.active = false;
  47. }
  48. }
  49. //UI关闭时会调用,该函数在onDestroy前调用
  50. onClose() {
  51. }
  52. //框架管理UI层级时会调用,可根据UI情况修改
  53. onShow() {
  54. super.onShow();
  55. }
  56. //框架管理UI层级时会调用,可根据UI情况修改
  57. onHide() {
  58. super.onHide();
  59. }
  60. //UI事件处理
  61. private onTouchButton(event: Event) {
  62. let target: any = event.target;
  63. if (target.name == 'close_btn') {
  64. Framework.layer.close(this);
  65. } else if (target.name == 'confirm_btn') {
  66. Framework.layer.close(this);
  67. if (this._callback) {
  68. this._callback();
  69. }
  70. Framework.layer.close(this);
  71. } else if (target.name == 'cancel_btn') {
  72. Framework.layer.close(this);
  73. }
  74. }
  75. }