import { _decorator, Component, Node, Sprite, Label, Toggle, ImageAsset, SpriteFrame, Texture2D, director } from 'cc'; import { DataSystem } from '../core/data/DataSystem'; import { Http } from '../core/net/Http'; import { ResourceLoader } from '../core/resourceManager/ResourceLoader'; import { SoundSystem } from '../core/sound/SoundSystem'; import { ISJSB, platform } from '../data/jsb/platform'; import { UserData } from '../data/UserData'; const { ccclass, property, requireComponent } = _decorator; @ccclass('SetUpUI') @requireComponent(Http) export class SetUpUI extends Component { @property({ tooltip: "头像", type: Sprite }) private headIcon: Sprite; @property({ tooltip: "玩家昵称", type: Label }) private playName: Label; @property({ tooltip: "玩家id", type: Label }) private playId: Label; @property({ tooltip: "累计提现金额", type: Label }) private withdrawalMoney: Label; @property({ tooltip: "音效按键", type: Toggle }) private soundEffectsBtn: Toggle; @property({ tooltip: "音乐按键", type: Toggle }) private musicBtn: Toggle; public playerID = 0; private get soundSystem(): SoundSystem { return director.getSystem(SoundSystem.ID) as SoundSystem; } start() { this.initUI(); } private async initUI() { let http = this.getComponent(Http); // let reult = http.send(""); this.playName.string = DataSystem.getData(UserData).nickName; this.playId.string = "ID:" + DataSystem.getData(UserData).id; this.playerID = DataSystem.getData(UserData).id; let avator = DataSystem.getData(UserData).avator; if (ISJSB() && avator) { let img = await await this.getComponent(ResourceLoader).loadRemote(avator, { ext: ".png" }); const spriteFrame = new SpriteFrame(); const texture = new Texture2D(); texture.image = img; spriteFrame.texture = texture; this.headIcon.spriteFrame = spriteFrame; } !this.soundSystem.effectVolumeScale && (this.soundEffectsBtn.isChecked = false); !this.soundSystem.musicVolumeScale && (this.musicBtn.isChecked = false); } private soundEffectsBtnEvent() { this.soundSystem.effectVolumeScale = this.soundEffectsBtn.isChecked ? 1 : 0; localStorage.setItem("effectVolumeScale", this.soundSystem.effectVolumeScale + ""); } private musicBtnEvent() { this.soundSystem.musicVolumeScale = this.musicBtn.isChecked ? 1 : 0; let sounds = this.soundSystem.getSounds(); for (let i = 0; i < sounds.length; i++) { let sound = sounds[i]; if (sound.soundName == "bgm") { sound.setVolumeAll(); break; } } localStorage.setItem("musicVolumeScale", this.soundSystem.musicVolumeScale + ""); } private copy() { platform.copyText(this.playerID + ""); // console.log("复制id:" + this.playerID); } }