HallTitleBar.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import {
  2. _decorator,
  3. Component,
  4. Node,
  5. tween,
  6. Vec3,
  7. Color,
  8. UIOpacity,
  9. RichText,
  10. } from "cc";
  11. import BaseUI from "../../scripts/base/BaseUI";
  12. import UserM, { GoodInfo } from "../../scripts/api/UserM";
  13. import Utils from "../../scripts/utils/Utils";
  14. import { Label } from "cc";
  15. import { Event } from "cc";
  16. import { Tips } from "../../scripts/mgr/Tips";
  17. import { GemRechargeLayer } from "../layer/GemRechargeLayer";
  18. import { Hall } from "./Hall";
  19. import { RewardLayer } from "../layer/RewardLayer";
  20. import { GoodsId } from "../../scripts/api/GoodsId";
  21. import ItemsM from "../../scripts/mgr/ItemsM";
  22. import EV, { EV_TYPE } from "../../scripts/mgr/EV";
  23. import { PageShop } from "./PageShop";
  24. import { GamePassItem } from "../item/GamePassItem";
  25. const { ccclass, property } = _decorator;
  26. @ccclass("HallTitleBar")
  27. export class HallTitleBar extends BaseUI {
  28. private t: Label;
  29. private _pog: number;
  30. private _gem: number;
  31. onLoad() {
  32. super.onLoad();
  33. this.setText("lbl_title_player_name", UserM.ins.getUserName());
  34. this._pog = UserM.ins.getGoodsCount(GoodsId.POG);
  35. this._gem = UserM.ins.getGoodsCount(GoodsId.GEM);
  36. let self = this;
  37. setInterval(() => {
  38. self.setText(
  39. "lbl_hall_title_season_time",
  40. UserM.ins.getSeasonEndTimeText()
  41. );
  42. }, 1000);
  43. ItemsM.ins.on(GoodsId.POG, this.onPogChange, this);
  44. ItemsM.ins.on(GoodsId.GEM, this.onGemChange, this);
  45. EV.ins.on(EV_TYPE.USER_GOOD_REFRESH, this.onUserGoodRefresh, this);
  46. this.refreshUI();
  47. }
  48. onUserGoodRefresh(goodList: GoodInfo[]) {
  49. this._pog = UserM.ins.getGoodsCount(GoodsId.POG);
  50. this._gem = UserM.ins.getGoodsCount(GoodsId.GEM);
  51. this.refreshUI();
  52. }
  53. onPogChange(count: number) {
  54. this._pog += count;
  55. if (this._pog < 0) {
  56. this._pog = 0;
  57. }
  58. this.refreshUI();
  59. }
  60. onGemChange(count: number) {
  61. this._gem += count;
  62. if (this._gem < 0) {
  63. this._gem = 0;
  64. }
  65. this.refreshUI();
  66. }
  67. refreshUI() {
  68. this.setText(
  69. "lbl_hall_title_season_time",
  70. UserM.ins.getSeasonEndTimeText()
  71. );
  72. this.setText("lbl_pog", Utils.formatNumber(this._pog, 0));
  73. this.setText("lbl_gem", Utils.formatNumber(this._gem, 0));
  74. let gamePassCount = UserM.ins.getGamePassCount();
  75. this.FindNode("lbl_game_pass_count").active = gamePassCount > 0;
  76. if (gamePassCount > 0) {
  77. this.setText("lbl_game_pass_count", "x" + gamePassCount);
  78. }
  79. }
  80. protected async simpleOnBtnClick(name: string): Promise<void> {
  81. switch (name) {
  82. case "btn_gem":
  83. GemRechargeLayer.show();
  84. break;
  85. case "btn_title_game_pass":
  86. // Tips.show("Game Pass");
  87. Hall.ins.switchPage(Hall.PageShop);
  88. // RewardLayer.mock();
  89. break;
  90. case "btn_game_pass":
  91. let page = await Hall.ins.switchPage(Hall.PageShop);
  92. if(UserM.ins.getGamePassCount()<=0){
  93. return;
  94. }
  95. setTimeout(() => {
  96. let ts = page.node.getComponentsInChildren(GamePassItem);
  97. for (let i = 0; i < ts.length; i++) {
  98. if (ts[i].node.parent.name == "content") {
  99. ts[i].showAnim(this.FindNode(name));
  100. break;
  101. }
  102. }
  103. }, 500);
  104. break;
  105. }
  106. }
  107. }