import { _decorator, Component, Node, Button, tween, Widget, UITransform, Vec3, Label, Sprite, ImageAsset, SpriteFrame, Texture2D, JsonAsset } from 'cc'; import { Http } from '../core/net/Http'; import { ResourcesUtils } from '../core/resourceManager/ResourcesUtils'; import { Sound } from '../core/sound/Sound'; import { WindowManager } from '../core/ui/window/WindowManager'; import { ConfigData } from '../Data/ConfigData'; import { g } from '../Data/g'; import { ISJSB, platform } from '../Data/platform'; import { SoundSystem } from './SoundSystem'; const { ccclass, property } = _decorator; @ccclass('SetUp') export class SetUp extends Component { @property({ tooltip: "设置开启按钮", type: Button }) public setUpBtn: Button; @property({ tooltip: "设置界面", type: Node }) public setUpWindow: Node; @property({ tooltip: "设置界面背景", type: Node }) public setUpBg: Node; @property({ tooltip: "音效设置按键", type: Node }) public setUpSoundBtn: Node; @property({ tooltip: "玩家昵称", type: Label }) public nameTxt: Label; @property({ tooltip: "玩家UID", type: Label }) public IDTxt: Label; @property({ tooltip: "玩家等级", type: Label }) public lvTxt: Label; @property({ tooltip: "玩家头像", type: Sprite }) public avator: Sprite; @property({ tooltip: "背景", type: Button }) public bg: Button; @property({ tooltip: "http服务", type: Http }) public http: Http; @property({ tooltip: "声音开启显示文本(深)", type: Node }) public soundOpenTxt: Node; @property({ tooltip: "声音开启显示文本(浅)", type: Node }) public soundOpenTxt0: Node; @property({ tooltip: "声音关闭显示文本(深)", type: Node }) public soundCloseTxt: Node; @property({ tooltip: "声音关闭显示文本(浅)", type: Node }) public soundCloseTxt0: Node; private lvConfig; start() { this.initUI(); } public async initUI() { this.nameTxt.string = g.userData.nickName; this.IDTxt.string = "UID:" + g.userData.id; this.lvConfig = ConfigData.configMap.get("generalBase"); // this.lvConfig = await (await ResourcesUtils.load("Configs/generalBase", JsonAsset, this.node)).json;//测试 this.initLv(); if (ISJSB && 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.avator.spriteFrame = spriteFrame; } } //重置等级 public initLv() { let _lv = ""; if (g.userData.lv >= 1) { _lv = this.lvConfig["" + g.userData.lv].name; } this.lvTxt.string = "LV." + g.userData.lv + _lv; } //打开设置窗口 public setUpBtnEven() { this.initLv(); this.setUpBtn.interactable = false; this.bg.interactable = false; let endX = this.setUpBg.active ? 0 : this.setUpWindow.getComponent(UITransform).width; this.setUpBg.active = false; let t = tween(this.setUpWindow); t.to(0.2, { position: new Vec3(endX) }) .call(() => { this.bg.interactable = true; this.setUpBtn.interactable = true; this.setUpBg.active = this.setUpWindow.position.x == 0 ? false : true; }) .start(); } //设置音效 public setUpSound() { if (Sound.volumeScale == 0) { Sound.volumeScale = 1; SoundSystem.setVolume(1); this.setUpSoundBtn.setPosition(new Vec3(-30)); this.initSoundTxt(true); } else { Sound.volumeScale = 0; SoundSystem.setVolume(0) this.setUpSoundBtn.setPosition(new Vec3(33)); this.initSoundTxt(false); } } public initSoundTxt(isOpen: boolean) { this.soundOpenTxt.active = isOpen; this.soundOpenTxt0.active = !isOpen; this.soundCloseTxt.active = !isOpen; this.soundCloseTxt0.active = isOpen; } public async onInvite() { //邀请 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("分享信息获取失败,请稍后再试"); } } }