| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- /*
- * @Author: mojunshou 1637302775@qq.com
- * @Date: 2025-03-20 15:40:20
- * @LastEditors: mojunshou 1637302775@qq.com
- * @LastEditTime: 2025-04-23 15:50:37
- * @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";
- import { smc } from "../SingletonModuleComp";
- import { CocosHandler } from "../manager/CocosHandler";
- import { LoginHandler } from "../manager/LoginHandler";
- import { UITransform } from "cc";
- import { Size } from "cc";
- import { GameEvent } from "../config/GameEvent";
- import { DCHandler } from "../manager/DCHandler";
- 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();
- DCHandler.inst.reportData(3001000);
- }
- /** 视图对象通过 ecs.Entity.remove(SettingViewComp) 删除组件是触发组件处理自定义释放逻辑 */
- reset() {
- this.node.destroy();
- }
- private btn_about() {
- oops.gui.open(UIID.AboutUs);
- DCHandler.inst.reportData(3001004);
- }
- private btn_close() {
- oops.gui.remove(UIID.Setting);
- oops.message.dispatchEvent(GameEvent.updateGameState, "playing");
- DCHandler.inst.reportData(3001001);
- }
- //更新按钮状态
- private 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() {
- this.data.uid = smc.account.AccountModel.uid;
- let url = smc.account.AccountModel.headUrl;
- let spriteNode = this.node.getChildByPath("Bg/btn_head/Mask/sp_head");
- if (spriteNode) {
- const uiTransform = spriteNode.getComponent(UITransform);
- uiTransform?.setContentSize(new Size(110, 110))
- let sprite = spriteNode.getComponent(Sprite);
- if (sprite) {
- console.log("更新头像啦")
- 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;
- if (this._musicState) {
- DCHandler.inst.reportData(3001002);
- } else {
- DCHandler.inst.reportData(3001003);
- }
- 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() {
- smc.game.GameModel.protocolType = 1;
- LoginHandler.inst.openAgreement();
- }
- //用户协议
- private btn_protocol() {
- smc.game.GameModel.protocolType = 2;
- LoginHandler.inst.openAgreement();
- }
- }
|