PopupUI.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import { _decorator, instantiate, Node } from 'cc';
  2. import { UIBase } from '../GameFrameWork/UIBase';
  3. import { resMgr } from '../../Frames/ResourcesMgr';
  4. import { PopupUIDataConfig } from '../MyApp/GameScene/Data/PopupUIDataConfig';
  5. import { UIMgr } from '../../Frames/UIManager';
  6. import { GameInfo } from '../../GameInfo';
  7. import { Tip } from './Tip';
  8. const { ccclass, property } = _decorator;
  9. @ccclass('PopupUI')
  10. export class PopupUI extends UIBase {
  11. private _UIName: string = null;
  12. private _typeImg: string = null;
  13. private _typeMoney: string = null;
  14. private _label_1: string = null;
  15. private _label_2: string = null;
  16. private _label_3: string = null;
  17. private _consume: string = null;
  18. protected onEnable(): void {
  19. this._UIName = PopupUIDataConfig.Instance.getUIName()
  20. this._typeImg = PopupUIDataConfig.Instance.getTypeImg()
  21. this._typeMoney = PopupUIDataConfig.Instance.getTypeMoney();
  22. this._label_1 = PopupUIDataConfig.Instance.getLabel()[0];
  23. this._label_2 = PopupUIDataConfig.Instance.getLabel()[1];
  24. this._label_3 = PopupUIDataConfig.Instance.getLabel()[2];
  25. this._consume = PopupUIDataConfig.Instance.getLabel()[3];
  26. }
  27. onStart() {
  28. this.onBtnClick("_btnBack", this.onBtnBack, this);
  29. this.onBtnClick("_btnYes", this.onBtnYes, this);
  30. this.onBtnClick("_btnCancel", this.onBtnCancel, this);
  31. this.uiName();
  32. this.typeImg();
  33. this.label()
  34. }
  35. uiName() {
  36. this.getLabel("_uiName").string = this._UIName;
  37. }
  38. typeImg() {
  39. this.getSprite("_typeImg").spriteFrame = resMgr.getSpriteFrame(this._typeImg);
  40. this.getSprite("_typeMoney").spriteFrame = resMgr.getSpriteFrame(this._typeMoney);
  41. }
  42. label() {
  43. this.getLabel("_label-1").string = this._label_1;
  44. this.getLabel("_label-2").string = this._label_2;
  45. this.getLabel("_label-3").string = this._label_3;
  46. this.getLabel("_consume").string = `${this._consume}`;
  47. }
  48. //返回
  49. private onBtnBack() {
  50. this.hide(false);
  51. }
  52. //确定
  53. private onBtnYes() {
  54. // if (this._typeMoney === "Gold") {
  55. // if (Number(this._consume) > GameInfo.Instance.getGold()) {
  56. // const tip: Node = instantiate(resMgr.getPrefab("Tip"));
  57. // tip.getComponent(Tip).setContent("金币不足!");
  58. // tip.parent = this.node;
  59. // return;
  60. // }
  61. // } else if(this._typeMoney === "Diamond"){
  62. // if (Number(this._consume) > GameInfo.Instance.getDiamond()) {
  63. // const tip: Node = instantiate(resMgr.getPrefab("Tip"));
  64. // tip.getComponent(Tip).setContent("钻石不足!")
  65. // tip.parent = this.node;
  66. // return;
  67. // }
  68. // }
  69. const resourceMap = {
  70. "Gold":{
  71. getAmount: GameInfo.Instance.getGold(),
  72. message: "金币不足!",
  73. },
  74. "Diamond":{
  75. getAmount: GameInfo.Instance.getDiamond(),
  76. message: "钻石不足!",
  77. }
  78. };
  79. const resource = resourceMap[this._typeMoney];
  80. if(resource && Number(this._consume) > resource.getAmount){
  81. const tip: Node = instantiate(resMgr.getPrefab("Tip"));
  82. tip.getComponent(Tip).setContent(resource.message);
  83. tip.parent = this.node;
  84. return;
  85. }
  86. (PopupUIDataConfig.Instance.getFunction())();
  87. UIMgr.closeUI("PopupUI", true);
  88. PopupUIDataConfig.Instance.clearDt();
  89. }
  90. //取消
  91. private onBtnCancel() {
  92. this.hide(false);
  93. }
  94. }