HallTitleBar.ts 5.4 KB

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