PopupUI.ts 4.3 KB

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