import { _decorator, Component, Sprite, Label, Toggle, find, SpriteFrame, Texture2D, ImageAsset, Button } from 'cc'; import { Http } from '../../core/net/Http'; import { ResourcesUtils } from '../../core/resourceManager/ResourcesUtils'; import { Sound } from '../../core/sound/Sound'; import { BitmapFont } from '../../core/ui/BitmapFont'; import { WindowManager } from '../../core/ui/window/WindowManager'; import { WindowOpenMode } from '../../core/ui/window/WindowOpenMode'; import { ConfigData } from '../../Data/ConfigData'; import { g } from '../../Data/g'; import { platform } from '../../Data/platform'; const { ccclass, property } = _decorator; @ccclass('UserInfoWindow') export class UserInfoWindow extends Component { @property({ type: Sprite, tooltip: "头像Icon" }) headIcon: Sprite; @property({ type: Label, tooltip: "昵称" }) title: Label; @property({ type: Label, tooltip: "昵称" }) nickNameLabel: Label; @property({ type: BitmapFont, tooltip: "等级" }) lvLabel: BitmapFont; @property({ type: Label, tooltip: "用户ID" }) IDLabel: Label; @property({ type: BitmapFont, tooltip: "红包" }) bonusLabel: BitmapFont; @property({ type: Label, tooltip: "可提现数字" }) moneyLabel: Label; @property({ type: Toggle, tooltip: "音乐开关" }) musicToggle: Toggle; @property({ type: Toggle, tooltip: "音效开关" }) soundToggle: Toggle; @property({ type: Http, tooltip: "http组件" }) http: Http; @property({ type: Button, tooltip: "用户协议" }) yonghu: Button; @property({ type: Button, tooltip: "隐私保护政策" }) yinsi: Button; private bgm: Sound; start() { this.bgm = find("逻辑节点").getComponent(Sound); this.nickNameLabel.string = g.userData.nickName; this.lvLabel.string = g.userData.getLevel() + ""; this.IDLabel.string = "UID:" + g.userData.id; this.bonusLabel.string = g.userData.bonus + ""; this.moneyLabel.string = g.userData.bonus / 10000 + ""; this.musicToggle.isChecked = this.bgm.volume == 1 ? true : false; this.soundToggle.isChecked = Sound.volumeScale == 1 ? true : false; this.loadAvatar(); //更改称号 let configArray = ConfigData.configMap.get("lvlreward"); for (let i = 0; i < configArray.length; i++) { if (g.userData.getLevel() > configArray[0].lvl) { if (g.userData.getLevel() < configArray[i].lvl) { this.title.string = configArray[i - 1].des; break; } } else { this.title.string = configArray[0].des; break; } } } async loadAvatar() { if (g.userData.avator) { let img = await ResourcesUtils.loadRemote(g.userData.avator, { ext: ".png" }, this); const spriteFrame = new SpriteFrame(); const texture = new Texture2D(); texture.image = img; spriteFrame.texture = texture; this.headIcon.spriteFrame = spriteFrame; } } public onXieyi(e: TouchEvent, type: string): void { WindowManager.open("Prefabs/WebWindow",WindowOpenMode.NotCloseAndAdd,type); } public onToggleCheck(e: Toggle, type: number): void { if (type == 0) { //音乐 this.bgm.volume = e.isChecked ? 1 : 0; } else { Sound.volumeScale = e.isChecked ? 1 : 0; } e.getComponent(Sprite).enabled = !e.isChecked; } public async share() { let result = await this.http.send("/api/app/share", {}); if (result.code == 0) { platform.wxShare(result.data.url, result.data.title, result.data.descroption); } else { WindowManager.showTips("分享信息获取失败,请稍后再试"); } } }