| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- /*
- * @Author: mojunshou 1637302775@qq.com
- * @Date: 2025-03-20 15:40:20
- * @LastEditors: mojunshou 1637302775@qq.com
- * @LastEditTime: 2025-04-03 16:31:43
- * @Description:设置界面
- */
- import { _decorator } from "cc";
- import { oops } from "db://oops-framework/core/Oops";
- import { ecs } from "db://oops-framework/libs/ecs/ECS";
- import { CCComp } from "db://oops-framework/module/common/CCComp";
- import { UIID } from "../config/GameUIConfig";
- import { CCVMParentComp } from "db://oops-framework/module/common/CCVMParentComp";
- import { Toggle } from "cc";
- import { Account } from "../../account/Account";
- import { ImageAsset, Texture2D, SpriteFrame, Sprite } from "cc";
- import { IRemoteOptions, resLoader } from "db://oops-framework/core/common/loader/ResLoader";
- import { Button } from "cc";
- const { ccclass, property } = _decorator;
- /** 视图层对象 */
- @ccclass('SettingViewComp')
- @ecs.register('SettingView', false)
- export class SettingViewComp extends CCVMParentComp {
- data: any = {
- head_url: "",
- uid: 100000,
- }
- @property(Button)
- private musicBtn: Button = null!;
- @property(Button)
- private effectBtn: Button = null!;
- private _musicState: boolean = true;
- private _effectState: boolean = true;
- /** 视图层逻辑代码分离演示 */
- start() {
- // const entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
- this.setButton();
- this.updateBtnState();
- this.updateHead();
- }
- /** 视图对象通过 ecs.Entity.remove(SettingViewComp) 删除组件是触发组件处理自定义释放逻辑 */
- reset() {
- this.node.destroy();
- }
- private btn_about() {
- oops.gui.open(UIID.AboutUs);
- }
- private btn_close() {
- oops.gui.remove(UIID.Setting);
- }
- //更新按钮状态
- private updateBtnState() {
- console.log("updateBtnState");
- const music_state = oops.storage.getBoolean("music_state");
- const effect_state = oops.storage.getBoolean("effect_state");
- oops.log.logView(music_state, "music_state");
- console.log("effect_state", effect_state);
- if (music_state == null) {
- oops.storage.set("music_state", true);
- this._musicState = true;
- } else {
- // 将字符串转换为布尔值
- let music_state_bool = music_state == true ? true : false;
- this._musicState = music_state_bool;
- }
- if (effect_state == null) {
- oops.storage.set("effect_state", true);
- this._effectState = true;
- } else {
- // 将字符串转换为布尔值
- let effect_state_bool = effect_state == true ? true : false;
- this._effectState = effect_state_bool;
- }
- oops.audio.switchMusic = this._musicState;
- oops.audio.switchEffect = this._effectState;
- const music_on = this.musicBtn.node.getChildByPath("btn_on")!;
- const music_off = this.musicBtn.node.getChildByPath("btn_off")!;
- music_on.active = this._musicState;
- music_off.active = !this._musicState;
- const btn_on = this.effectBtn.node.getChildByPath("btn_on")!;
- const btn_off = this.effectBtn.node.getChildByPath("btn_off")!;
- btn_on.active = this._effectState;
- btn_off.active = !this._effectState;
- }
- //更新头像
- private updateHead() {
- let account = ecs.getEntity<Account>(Account);
- this.data.uid = account.AccountModel.Uid;
- let url = account.AccountModel.HeadUrl;
- // let sprite = this.node.getChildByPath("Bg/btn_head/sp_head")!.uiSprite;
- // let url = "http://www.kuaipng.com/Uploads/pic/w/2020/07-16/89010/water_89010_698_698_.png"
- // var opt: IRemoteOptions = { ext: ".png" };
- // var onComplete = (err: Error | null, data: ImageAsset) => {
- // const texture = new Texture2D();
- // texture.image = data;
- // const spriteFrame = new SpriteFrame();
- // spriteFrame.texture = texture;
- // sprite.spriteFrame = spriteFrame;
- // }
- // resLoader.loadRemote<ImageAsset>(url, opt, onComplete);
- }
- //打开音乐
- private btn_music() {
- this._musicState = !this._musicState;
- oops.storage.set("music_state", this._musicState);
- oops.audio.switchMusic = this._musicState;
- const btn_on = this.musicBtn.node.getChildByPath("btn_on")!;
- const btn_off = this.musicBtn.node.getChildByPath("btn_off")!;
- btn_on.active = this._musicState;
- btn_off.active = !this._musicState;
- }
- //打开音效
- private btn_effect() {
- this._effectState = !this._effectState;
- oops.storage.set("effect_state", this._effectState);
- oops.audio.switchEffect = this._effectState;
- const btn_on = this.effectBtn.node.getChildByPath("btn_on")!;
- const btn_off = this.effectBtn.node.getChildByPath("btn_off")!;
- btn_on.active = this._effectState;
- btn_off.active = !this._effectState;
- }
- //隐私协议
- private btn_privacy() {
- }
- //用户协议
- private btn_protocol() {
- }
- }
|