UserInfoWindow.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { _decorator, Component, Sprite, Label, Toggle, find, SpriteFrame, Texture2D, ImageAsset, Button } from 'cc';
  2. import { Http } from '../../core/net/Http';
  3. import { ResourcesUtils } from '../../core/resourceManager/ResourcesUtils';
  4. import { Sound } from '../../core/sound/Sound';
  5. import { BitmapFont } from '../../core/ui/BitmapFont';
  6. import { WindowManager } from '../../core/ui/window/WindowManager';
  7. import { WindowOpenMode } from '../../core/ui/window/WindowOpenMode';
  8. import { ConfigData } from '../../Data/ConfigData';
  9. import { g } from '../../Data/g';
  10. import { platform } from '../../Data/platform';
  11. const { ccclass, property } = _decorator;
  12. @ccclass('UserInfoWindow')
  13. export class UserInfoWindow extends Component {
  14. @property({ type: Sprite, tooltip: "头像Icon" }) headIcon: Sprite;
  15. @property({ type: Label, tooltip: "昵称" }) title: Label;
  16. @property({ type: Label, tooltip: "昵称" }) nickNameLabel: Label;
  17. @property({ type: BitmapFont, tooltip: "等级" }) lvLabel: BitmapFont;
  18. @property({ type: Label, tooltip: "用户ID" }) IDLabel: Label;
  19. @property({ type: BitmapFont, tooltip: "红包" }) bonusLabel: BitmapFont;
  20. @property({ type: Label, tooltip: "可提现数字" }) moneyLabel: Label;
  21. @property({ type: Toggle, tooltip: "音乐开关" }) musicToggle: Toggle;
  22. @property({ type: Toggle, tooltip: "音效开关" }) soundToggle: Toggle;
  23. @property({ type: Http, tooltip: "http组件" }) http: Http;
  24. @property({ type: Button, tooltip: "用户协议" }) yonghu: Button;
  25. @property({ type: Button, tooltip: "隐私保护政策" }) yinsi: Button;
  26. private bgm: Sound;
  27. start() {
  28. this.bgm = find("逻辑节点").getComponent(Sound);
  29. this.nickNameLabel.string = g.userData.nickName;
  30. this.lvLabel.string = g.userData.getLevel() + "";
  31. this.IDLabel.string = "UID:" + g.userData.id;
  32. this.bonusLabel.string = g.userData.bonus + "";
  33. this.moneyLabel.string = g.userData.bonus / 10000 + "";
  34. this.musicToggle.isChecked = this.bgm.volume == 1 ? true : false;
  35. this.soundToggle.isChecked = Sound.volumeScale == 1 ? true : false;
  36. this.loadAvatar();
  37. //更改称号
  38. let configArray = ConfigData.configMap.get("lvlreward");
  39. for (let i = 0; i < configArray.length; i++) {
  40. if (g.userData.getLevel() > configArray[0].lvl) {
  41. if (g.userData.getLevel() < configArray[i].lvl) {
  42. this.title.string = configArray[i - 1].des;
  43. break;
  44. }
  45. } else {
  46. this.title.string = configArray[0].des;
  47. break;
  48. }
  49. }
  50. }
  51. async loadAvatar() {
  52. if (g.userData.avator) {
  53. let img = await ResourcesUtils.loadRemote<ImageAsset>(g.userData.avator, { ext: ".png" }, this);
  54. const spriteFrame = new SpriteFrame();
  55. const texture = new Texture2D();
  56. texture.image = img;
  57. spriteFrame.texture = texture;
  58. this.headIcon.spriteFrame = spriteFrame;
  59. }
  60. }
  61. public onXieyi(e: TouchEvent, type: string): void {
  62. WindowManager.open("Prefabs/WebWindow",WindowOpenMode.NotCloseAndAdd,type);
  63. }
  64. public onToggleCheck(e: Toggle, type: number): void {
  65. if (type == 0) { //音乐
  66. this.bgm.volume = e.isChecked ? 1 : 0;
  67. } else {
  68. Sound.volumeScale = e.isChecked ? 1 : 0;
  69. }
  70. e.getComponent(Sprite).enabled = !e.isChecked;
  71. }
  72. public async share() {
  73. let result = await this.http.send("/api/app/share", {});
  74. if (result.code == 0) {
  75. platform.wxShare(result.data.url, result.data.title, result.data.descroption);
  76. } else {
  77. WindowManager.showTips("分享信息获取失败,请稍后再试");
  78. }
  79. }
  80. }