POGClaimLayer.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { _decorator, Component, Node } from "cc";
  2. import Utils from "../../scripts/utils/Utils";
  3. import { Hall } from "../hall/Hall";
  4. import BaseUI from "../../scripts/base/BaseUI";
  5. import { RewardLayer } from "./RewardLayer";
  6. import { GoodsId } from "../../scripts/api/GoodsId";
  7. const { ccclass, property } = _decorator;
  8. export interface POGClaimLayerCallback {
  9. onClaim(isCritical: boolean): void;
  10. }
  11. @ccclass("POGClaimLayer")
  12. export class POGClaimLayer extends BaseUI {
  13. static async show(pogValue: number, cb: POGClaimLayerCallback) {
  14. if (!pogValue || pogValue <= 0) {
  15. pogValue = 500;
  16. }
  17. let layer = await Hall.ins.showLayer("prefab/layer/POGClaimLayer");
  18. layer.getComponent(POGClaimLayer).init(pogValue, cb);
  19. }
  20. private pogValue: number;
  21. private cb: POGClaimLayerCallback;
  22. init(pogValue: number, cb: POGClaimLayerCallback) {
  23. this.pogValue = pogValue;
  24. this.cb = cb;
  25. this.setText("lbl_count1", "x" + Utils.formatNumber(this.pogValue, 0));
  26. this.setText("lbl_count2", "x" + Utils.formatNumber(this.pogValue, 0));
  27. }
  28. protected simpleOnBtnClick(name: string): void {
  29. let isCritical = false;
  30. switch (name) {
  31. case "btn_claim":
  32. isCritical = false;
  33. break;
  34. case "btn_claim_critical":
  35. isCritical = true;
  36. break;
  37. }
  38. RewardLayer.show([
  39. {
  40. id: GoodsId.POG,
  41. count: isCritical ? this.pogValue * 2 : this.pogValue,
  42. },
  43. ]);
  44. this.cb.onClaim(isCritical);
  45. this.closePage();
  46. }
  47. }