SetUpUI.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { _decorator, Component, Node, Sprite, Label, Toggle, ImageAsset, SpriteFrame, Texture2D, director } from 'cc';
  2. import { DataSystem } from '../core/data/DataSystem';
  3. import { Http } from '../core/net/Http';
  4. import { ResourceLoader } from '../core/resourceManager/ResourceLoader';
  5. import { SoundSystem } from '../core/sound/SoundSystem';
  6. import { ISJSB, platform } from '../data/jsb/platform';
  7. import { UserData } from '../data/UserData';
  8. const { ccclass, property, requireComponent } = _decorator;
  9. @ccclass('SetUpUI')
  10. @requireComponent(Http)
  11. export class SetUpUI extends Component {
  12. @property({ tooltip: "头像", type: Sprite }) private headIcon: Sprite;
  13. @property({ tooltip: "玩家昵称", type: Label }) private playName: Label;
  14. @property({ tooltip: "玩家id", type: Label }) private playId: Label;
  15. @property({ tooltip: "累计提现金额", type: Label }) private withdrawalMoney: Label;
  16. @property({ tooltip: "音效按键", type: Toggle }) private soundEffectsBtn: Toggle;
  17. @property({ tooltip: "音乐按键", type: Toggle }) private musicBtn: Toggle;
  18. public playerID = 0;
  19. private get soundSystem(): SoundSystem {
  20. return director.getSystem(SoundSystem.ID) as SoundSystem;
  21. }
  22. start() {
  23. this.initUI();
  24. }
  25. private async initUI() {
  26. let http = this.getComponent(Http);
  27. // let reult = http.send("");
  28. this.playName.string = DataSystem.getData(UserData).nickName;
  29. this.playId.string = "ID:" + DataSystem.getData(UserData).id;
  30. this.playerID = DataSystem.getData(UserData).id;
  31. let avator = DataSystem.getData(UserData).avator;
  32. if (ISJSB() && avator) {
  33. let img = await await this.getComponent(ResourceLoader).loadRemote<ImageAsset>(avator, { ext: ".png" });
  34. const spriteFrame = new SpriteFrame();
  35. const texture = new Texture2D();
  36. texture.image = img;
  37. spriteFrame.texture = texture;
  38. this.headIcon.spriteFrame = spriteFrame;
  39. }
  40. !this.soundSystem.effectVolumeScale && (this.soundEffectsBtn.isChecked = false);
  41. !this.soundSystem.musicVolumeScale && (this.musicBtn.isChecked = false);
  42. }
  43. private soundEffectsBtnEvent() {
  44. this.soundSystem.effectVolumeScale = this.soundEffectsBtn.isChecked ? 1 : 0;
  45. localStorage.setItem("effectVolumeScale", this.soundSystem.effectVolumeScale + "");
  46. }
  47. private musicBtnEvent() {
  48. this.soundSystem.musicVolumeScale = this.musicBtn.isChecked ? 1 : 0;
  49. let sounds = this.soundSystem.getSounds();
  50. for (let i = 0; i < sounds.length; i++) {
  51. let sound = sounds[i];
  52. if (sound.soundName == "bgm") {
  53. sound.setVolumeAll();
  54. break;
  55. }
  56. }
  57. localStorage.setItem("musicVolumeScale", this.soundSystem.musicVolumeScale + "");
  58. }
  59. private copy() {
  60. platform.copyText(this.playerID + "");
  61. // console.log("复制id:" + this.playerID);
  62. }
  63. }