HallTitleBar.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. import RankM, { RankDto } from "../../scripts/api/RankM";
  26. import { PageRank } from "./PageRank";
  27. import ConfigM from "../../scripts/api/ConfigM";
  28. import { Sprite } from "cc";
  29. import AB from "../../scripts/base/AB";
  30. import { SpriteFrame } from "cc";
  31. import FamilyM from "../../scripts/api/FamilyM";
  32. const { ccclass, property } = _decorator;
  33. @ccclass("HallTitleBar")
  34. export class HallTitleBar extends BaseUI {
  35. private t: Label;
  36. private _pog: number;
  37. private _gem: number;
  38. onLoad() {
  39. super.onLoad();
  40. this.setText("lbl_title_player_name", UserM.ins.getUserName());
  41. this._pog = UserM.ins.getGoodsCount(GoodsId.POG);
  42. this._gem = UserM.ins.getGoodsCount(GoodsId.GEM);
  43. let self = this;
  44. setInterval(() => {
  45. self.setText(
  46. "lbl_hall_title_season_time",
  47. UserM.ins.getSeasonEndTimeText()
  48. );
  49. }, 1000);
  50. ItemsM.ins.on(GoodsId.POG, this.onPogChange, this);
  51. ItemsM.ins.on(GoodsId.GEM, this.onGemChange, this);
  52. this.refreshUI();
  53. EV.ins.on(EV_TYPE.USER_GOOD_REFRESH, this.onUserGoodRefresh, this);
  54. EV.ins.on(EV_TYPE.FAMILY_STATUS_UPDATE, this.setFamilyInfo, this);
  55. }
  56. onUserGoodRefresh(goodList: GoodInfo[]) {
  57. this._pog = UserM.ins.getGoodsCount(GoodsId.POG);
  58. this._gem = UserM.ins.getGoodsCount(GoodsId.GEM);
  59. this.refreshUI();
  60. }
  61. onPogChange(count: number) {
  62. this._pog += count;
  63. if (this._pog < 0) {
  64. this._pog = 0;
  65. }
  66. this.refreshUI();
  67. }
  68. onGemChange(count: number) {
  69. this._gem += count;
  70. if (this._gem < 0) {
  71. this._gem = 0;
  72. }
  73. this.refreshUI();
  74. }
  75. refreshUI() {
  76. this.setText(
  77. "lbl_hall_title_season_time",
  78. UserM.ins.getSeasonEndTimeText()
  79. );
  80. this.setText("lbl_pog", UserM.ins.getPogDisplay());
  81. this.setText("lbl_gem", Utils.formatNumber(this._gem, 1));
  82. let gamePassCount = UserM.ins.getGamePassCount();
  83. this.FindNode("lbl_game_pass_count").active = gamePassCount > 0;
  84. if (gamePassCount > 0) {
  85. this.setText("lbl_game_pass_count", "x" + gamePassCount);
  86. }
  87. this.setFamilyInfo();
  88. this.setGradeIcon();
  89. }
  90. async setFamilyInfo() {
  91. if (UserM.ins.data.familyId != null && UserM.ins.data.familyId != "") {
  92. let family = await FamilyM.ins.getFamilyInfo(UserM.ins.data.familyId);
  93. if (UserM.ins.data.userId == family?.ownerDto?.ownerId) {
  94. this.setText("lbl_title_player_family_name", "👑" + family.familyName);
  95. } else {
  96. this.setText("lbl_title_player_family_name", "👤" + family.familyName);
  97. }
  98. } else {
  99. this.setText("lbl_title_player_family_name", "");
  100. }
  101. }
  102. async setGradeIcon() {
  103. let data: RankDto = await RankM.ins.rankData(PageRank.RankTypeSeason);
  104. let grade = data.rankInfo.badgeId;
  105. // grade=3
  106. if (grade <= 0 || grade > 7) {
  107. return;
  108. }
  109. let a = await AB.ins.loadSpriteFrame("texture/common/grade" + grade + "");
  110. let f = a as SpriteFrame;
  111. this.FindAs("icon_my_grade", Sprite).spriteFrame = f;
  112. }
  113. protected async simpleOnBtnClick(name: string): Promise<void> {
  114. switch (name) {
  115. case "btn_gem":
  116. GemRechargeLayer.show();
  117. break;
  118. case "btn_title_game_pass":
  119. // Tips.show("Game Pass");
  120. Hall.ins.switchPage(Hall.PageShop);
  121. // RewardLayer.mock();
  122. break;
  123. case "btn_game_pass":
  124. let page = await Hall.ins.switchPage(Hall.PageShop);
  125. if (!page) {
  126. return;
  127. }
  128. let shop = page.getComponent(PageShop);
  129. shop.switchTab(PageShop.TAB_GAME_PASS);
  130. if (UserM.ins.getGamePassCount() <= 0) {
  131. return;
  132. }
  133. setTimeout(() => {
  134. let ts = page.node.getComponentsInChildren(GamePassItem);
  135. for (let i = 0; i < ts.length; i++) {
  136. if (ts[i].node.parent.name == "content") {
  137. ts[i].showAnim(this.FindNode(name));
  138. break;
  139. }
  140. }
  141. }, 500);
  142. break;
  143. }
  144. }
  145. }