UIDialogView.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import { gameMethod } from "../../../common/gameMethod";
  2. import auto_dialogView from "../../../data/autoui/dialogView/auto_dialogView";
  3. import { WindowEvent } from "../../../data/const/EventConst";
  4. import { ViewZOrder } from "../../../data/const/ViewZOrder";
  5. import EventMng from "../../../manager/EventMng";
  6. import AssetMgr from "../../../utils/AssetMgr";
  7. import { I18n } from "../../../utils/I18nUtil";
  8. import { uiCommon } from "../../../utils/UICommon";
  9. import UIBase, { BASE_POP } from "../UIBase";
  10. import UIHelp, { DialogParams } from "../UIHelp";
  11. const { ccclass, menu, property } = cc._decorator;
  12. @ccclass
  13. @menu("UI/dialogView/UIDialogView")
  14. export default class UIDialogView extends UIBase {
  15. ui: auto_dialogView = null;
  16. dialogParams: DialogParams;// 外部传入的参数
  17. protected static prefabUrl = "dialogView/dialogView";
  18. protected static className = "UIDialogView";
  19. protected static pop = BASE_POP.UI;
  20. onUILoad() {
  21. this.ui = this.node.addComponent(auto_dialogView);
  22. }
  23. onShow() {
  24. this.node.zIndex = ViewZOrder.POP_SYSTEM;
  25. EventMng.on(WindowEvent.SHOW_SYS_DIALOG, this.showDialog, this);
  26. uiCommon.onRegisterEvent(this.ui.imgMask, this.OnClickMask, this);
  27. uiCommon.onRegisterEvent(this.ui.btnClose, this.OnClickMask, this);
  28. uiCommon.onRegisterEvent(this.ui.btnConfirm, this.OnClickConfirmBtn, this);
  29. uiCommon.onRegisterEvent(this.ui.btnCancel, this.OnClickCancelBtn, this);
  30. }
  31. onHide() {
  32. EventMng.off(WindowEvent.SHOW_SYS_DIALOG, this.showDialog, this);
  33. uiCommon.unRegisterEvent(this.ui.imgMask);
  34. uiCommon.unRegisterEvent(this.ui.btnClose);
  35. uiCommon.unRegisterEvent(this.ui.btnConfirm);
  36. uiCommon.unRegisterEvent(this.ui.btnCancel);
  37. }
  38. onStart() {
  39. }
  40. showDialog(data: DialogParams) {
  41. if (gameMethod.isEmpty(data)) return;
  42. this.dialogParams = data;
  43. this.ui.imgMask.active = true;
  44. uiCommon.setLabel(this.ui.title, this.dialogParams.title || I18n?.getI18nText("common_dialogtitle_1"));
  45. uiCommon.setLabel(this.ui.DescLabel, this.dialogParams.content || I18n?.getI18nText("common_dialogtitle_1"));
  46. // 确定、取消
  47. uiCommon.setLabel(this.ui.txtConfirm, this.dialogParams.txtConfirm || I18n?.getI18nText("common_confirm_11"));
  48. if (this.dialogParams.onlyConfirm) {
  49. this.ui.btnCancel.active = false;
  50. } else {
  51. this.ui.btnCancel.active = true;
  52. uiCommon.setLabel(this.ui.txtCancel, this.dialogParams.txtCancel || I18n?.getI18nText("common_cancel_1"));
  53. }
  54. }
  55. // 确定
  56. OnClickConfirmBtn(): void {
  57. if (this.dialogParams?.cbConfirm != null) {
  58. this.dialogParams?.cbConfirm();
  59. }
  60. this.closeDialog();
  61. }
  62. // 取消
  63. OnClickCancelBtn(): void {
  64. if (this.dialogParams?.cbCancel != null) {
  65. this.dialogParams?.cbCancel();
  66. }
  67. this.closeDialog();
  68. }
  69. OnClickMask() {
  70. if (this.dialogParams.onlyConfirm && this.dialogParams?.cbConfirm != null) {
  71. this.dialogParams?.cbConfirm();
  72. }
  73. this.closeDialog();
  74. }
  75. closeDialog() {
  76. this.ui.imgMask.active = false;
  77. }
  78. onClose() {
  79. }
  80. }