|
|
@@ -2,7 +2,7 @@
|
|
|
* @Author: mojunshou 1637302775@qq.com
|
|
|
* @Date: 2025-03-20 15:40:20
|
|
|
* @LastEditors: mojunshou 1637302775@qq.com
|
|
|
- * @LastEditTime: 2025-03-31 17:09:16
|
|
|
+ * @LastEditTime: 2025-04-03 15:38:50
|
|
|
* @Description:设置界面
|
|
|
*/
|
|
|
import { _decorator } from "cc";
|
|
|
@@ -15,6 +15,7 @@ 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;
|
|
|
|
|
|
@@ -28,11 +29,24 @@ export class SettingViewComp extends CCVMParentComp {
|
|
|
music_state: true,
|
|
|
effect_state: true
|
|
|
}
|
|
|
+
|
|
|
+ @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.updateHead();
|
|
|
+ this.updateBtnState();
|
|
|
}
|
|
|
|
|
|
/** 视图对象通过 ecs.Entity.remove(SettingViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
|
|
@@ -51,50 +65,49 @@ export class SettingViewComp extends CCVMParentComp {
|
|
|
}
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * @description: 设置音乐开关
|
|
|
- * @param {Toggle} toggle
|
|
|
- * @return {*}
|
|
|
- */
|
|
|
- private onMusicToggleContainerClick(toggle: Toggle) {
|
|
|
- switch (toggle.node.name) {
|
|
|
- case "On":
|
|
|
- this.data.music_state = true;
|
|
|
- break;
|
|
|
- case "Off":
|
|
|
- this.data.music_state = false;
|
|
|
- break;
|
|
|
+ //更新按钮状态
|
|
|
+ private updateBtnState() {
|
|
|
+ const music_state = oops.storage.get("music_state");
|
|
|
+ const effect_state = oops.storage.get("effect_state");
|
|
|
+ if (music_state == "" || 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;
|
|
|
}
|
|
|
- console.log("音乐状态", this.data.music_state);
|
|
|
- oops.audio.switchMusic = this.data.music_state;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @description: 设置音乐开关
|
|
|
- * @param {Toggle} toggle
|
|
|
- * @return {*}
|
|
|
- */
|
|
|
- private onEffectToggleContainerClick(toggle: Toggle) {
|
|
|
- switch (toggle.node.name) {
|
|
|
- case "On":
|
|
|
- this.data.effect_state = true;
|
|
|
- break;
|
|
|
- case "Off":
|
|
|
- this.data.effect_state = false;
|
|
|
- break;
|
|
|
+ if (effect_state == "" || 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;
|
|
|
}
|
|
|
- console.log("音效状态", this.data.effect_state);
|
|
|
- oops.audio.switchEffect = this.data.effect_state;
|
|
|
+ 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);
|
|
|
let sprite = this.node.getChildByPath("Bg/btn_head/sp_head")!.uiSprite;
|
|
|
// let url = account.AccountModel.head;
|
|
|
let url = "http://www.kuaipng.com/Uploads/pic/w/2020/07-16/89010/water_89010_698_698_.png"
|
|
|
- this.data.nickName = account.AccountModel.AccountName;
|
|
|
- this.data.uid = account.AccountModel.uid;
|
|
|
+ this.data.uid = account.AccountModel.Uid;
|
|
|
var opt: IRemoteOptions = { ext: ".png" };
|
|
|
var onComplete = (err: Error | null, data: ImageAsset) => {
|
|
|
const texture = new Texture2D();
|
|
|
@@ -108,6 +121,44 @@ export class SettingViewComp extends CCVMParentComp {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ //打开音乐
|
|
|
+ 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() {
|
|
|
|
|
|
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|