mirror of
https://gitee.com/dgflash/oops-plugin-framework.git
synced 2026-05-08 03:16:49 +08:00
1. CommonPrompt对象修改为PromptBase,并优化代码,适合继承使用
2. 添加PromptSkip,继承PromptBase实现可指定时间跳过提示的窗口 3. 框架内使用的本地存储Key统一存放到GameStorage中
This commit is contained in:
@@ -5,8 +5,7 @@ import { AudioEffectPool } from "./AudioEffectPool";
|
||||
import { AudioEffectType } from "./AudioEnum";
|
||||
import { AudioMusic } from "./AudioMusic";
|
||||
import { IAudioData, IAudioParams } from "./IAudio";
|
||||
|
||||
const LOCAL_STORE_KEY = "game_audio";
|
||||
import { GameStorage } from "db://oops-framework/module/common/GameStorage";
|
||||
|
||||
/**
|
||||
* 音频管理
|
||||
@@ -66,7 +65,7 @@ export class AudioManager extends Component {
|
||||
|
||||
/** 保存音乐音效的音量、开关配置数据到本地 */
|
||||
save() {
|
||||
oops.storage.set(LOCAL_STORE_KEY, this.data);
|
||||
oops.storage.set(GameStorage.Audio, this.data);
|
||||
}
|
||||
|
||||
/** 本地加载音乐音效的音量、开关配置数据并设置到游戏中 */
|
||||
@@ -74,7 +73,7 @@ export class AudioManager extends Component {
|
||||
this.music = new AudioMusic();
|
||||
this.music.parent = this.node;
|
||||
|
||||
this.data = oops.storage.getJson(LOCAL_STORE_KEY);
|
||||
this.data = oops.storage.getJson(GameStorage.Audio);
|
||||
if (this.data) {
|
||||
this.setState();
|
||||
}
|
||||
|
||||
@@ -1,99 +0,0 @@
|
||||
import { Component, _decorator } from "cc";
|
||||
import { LanguageLabel } from "../../../libs/gui/language/LanguageLabel";
|
||||
import { oops } from "../../Oops";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/** 公共提示窗口 */
|
||||
@ccclass("CommonPrompt")
|
||||
export class CommonPrompt extends Component {
|
||||
/** 窗口标题多语言组件 */
|
||||
@property(LanguageLabel)
|
||||
private lab_title: LanguageLabel | null = null;
|
||||
|
||||
/** 提示内容多语言组件 */
|
||||
@property(LanguageLabel)
|
||||
private lab_content: LanguageLabel | null = null;
|
||||
|
||||
/** 确认按钮文本多语言组件 */
|
||||
@property(LanguageLabel)
|
||||
private lab_ok: LanguageLabel | null = null
|
||||
|
||||
/** 取消按钮文本多语言组件 */
|
||||
@property(LanguageLabel)
|
||||
private lab_cancel: LanguageLabel | null = null;
|
||||
|
||||
private config: any = {};
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param params 参数
|
||||
* {
|
||||
* title: 标题
|
||||
* content: 内容
|
||||
* okWord: ok按钮上的文字
|
||||
* okFunc: 确认时执行的方法
|
||||
* cancelWord: 取消按钮的文字
|
||||
* cancelFunc: 取消时执行的方法
|
||||
* needCancel: 是否需要取消按钮
|
||||
* }
|
||||
*/
|
||||
onAdded(params: any): boolean {
|
||||
this.config = params || {};
|
||||
this.setTitle();
|
||||
this.setContent();
|
||||
this.setBtnOkLabel();
|
||||
this.setBtnCancelLabel();
|
||||
this.node.active = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
private setTitle() {
|
||||
this.lab_title!.dataID = this.config.title;
|
||||
}
|
||||
|
||||
private setContent() {
|
||||
this.lab_content!.dataID = this.config.content;
|
||||
}
|
||||
|
||||
private setBtnOkLabel() {
|
||||
this.lab_ok!.dataID = this.config.okWord;
|
||||
}
|
||||
|
||||
private setBtnCancelLabel() {
|
||||
if (this.lab_cancel) {
|
||||
this.lab_cancel.dataID = this.config.cancelWord;
|
||||
this.lab_cancel.node.parent!.active = this.config.needCancel || false;
|
||||
}
|
||||
}
|
||||
|
||||
private onOk() {
|
||||
if (typeof this.config.okFunc == "function") {
|
||||
this.config.okFunc();
|
||||
}
|
||||
this.close();
|
||||
}
|
||||
|
||||
private onClose() {
|
||||
if (typeof this.config.closeFunc == "function") {
|
||||
this.config.closeFunc();
|
||||
}
|
||||
this.close();
|
||||
}
|
||||
|
||||
private onCancel() {
|
||||
if (typeof this.config.cancelFunc == "function") {
|
||||
this.config.cancelFunc();
|
||||
}
|
||||
this.close();
|
||||
}
|
||||
|
||||
private close() {
|
||||
oops.gui.removeByNode(this.node);
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
this.config = null;
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "653bff15-3c2e-459f-8f73-14916a5d5831",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"moduleId": "project:///assets/script/core/gui/prompt/CommonPrompt.js",
|
||||
"importerSettings": 4,
|
||||
"simulateGlobals": []
|
||||
}
|
||||
}
|
||||
9
assets/libs/gui/window.meta
Normal file
9
assets/libs/gui/window.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "26bbcb1a-b407-4d25-b9e9-8676f614312a",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
89
assets/libs/gui/window/PromptBase.ts
Normal file
89
assets/libs/gui/window/PromptBase.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
import { _decorator } from "cc";
|
||||
import { GameComponent } from "db://oops-framework/module/common/GameComponent";
|
||||
import { LanguageLabel } from "../language/LanguageLabel";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/**
|
||||
* 基础提示窗口
|
||||
* 1. 自定义提示标题、按钮名
|
||||
* 2. 自定义确认、取消事件回调
|
||||
* 3. 自定义提示内容
|
||||
* 4. 支持文本多语言
|
||||
*/
|
||||
@ccclass("PromptBase")
|
||||
export class PromptBase extends GameComponent {
|
||||
/** 窗口标题多语言组件 */
|
||||
@property(LanguageLabel)
|
||||
private labTitle: LanguageLabel = null!;
|
||||
|
||||
/** 提示内容多语言组件 */
|
||||
@property(LanguageLabel)
|
||||
private labContent: LanguageLabel = null!;
|
||||
|
||||
/** 确认按钮文本多语言组件 */
|
||||
@property(LanguageLabel)
|
||||
private labOk: LanguageLabel = null!;
|
||||
|
||||
/** 取消按钮文本多语言组件 */
|
||||
@property(LanguageLabel)
|
||||
private labCancel: LanguageLabel = null!;
|
||||
|
||||
/** 窗口配置 */
|
||||
protected config: any = null!;
|
||||
|
||||
/**
|
||||
* 窗口打开事件
|
||||
* @param params 参数
|
||||
* {
|
||||
* title: 标题
|
||||
* content: 内容
|
||||
* okWord: ok按钮上的文字
|
||||
* okFunc: 确认时执行的方法
|
||||
* cancelWord: 取消按钮的文字
|
||||
* cancelFunc: 取消时执行的方法
|
||||
* needCancel: 是否需要取消按钮
|
||||
* }
|
||||
*/
|
||||
onAdded(params: any): boolean {
|
||||
this.config = params;
|
||||
if (this.config == null) return false;
|
||||
|
||||
this.labTitle.dataID = this.config.title; // 窗口标题
|
||||
this.labContent.dataID = this.config.content; // 提示内容
|
||||
this.labOk.dataID = this.config.okWord; // 确定按钮文字
|
||||
if (this.labCancel) {
|
||||
this.labCancel.dataID = this.config.cancelWord || ""; // 取消按钮文字
|
||||
this.labCancel.node.parent!.active = this.config.needCancel || false;
|
||||
}
|
||||
this.node.active = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected onLoad(): void {
|
||||
this.setButton();
|
||||
}
|
||||
|
||||
private btnOk() {
|
||||
if (typeof this.config.onOk == "function") {
|
||||
this.config.onOk();
|
||||
}
|
||||
this.remove();
|
||||
}
|
||||
|
||||
private btnCancel() {
|
||||
if (typeof this.config.onCancel == "function") {
|
||||
this.config.onCancel();
|
||||
}
|
||||
this.remove();
|
||||
}
|
||||
|
||||
private btnClose() {
|
||||
this.remove();
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
this.config = null!;
|
||||
super.onDestroy();
|
||||
}
|
||||
}
|
||||
9
assets/libs/gui/window/PromptBase.ts.meta
Normal file
9
assets/libs/gui/window/PromptBase.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "62d1c492-8247-4e77-8216-462f64c6a296",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
47
assets/libs/gui/window/PromptSkip.ts
Normal file
47
assets/libs/gui/window/PromptSkip.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { _decorator, Toggle } from "cc";
|
||||
import { oops } from "db://oops-framework/core/Oops";
|
||||
import { GameStorage } from "db://oops-framework/module/common/GameStorage";
|
||||
import { PromptBase } from "./PromptBase";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/** 不同类型的提示窗口状态数据 */
|
||||
var content: any = null;
|
||||
|
||||
/** 可设置指定时间内跳过提示 */
|
||||
@ccclass("PromptSkip")
|
||||
export class PromptSkip extends PromptBase {
|
||||
/** 是否可提示 */
|
||||
static isPrompt(id: string): boolean {
|
||||
if (content == null) content = oops.storage.getJson(GameStorage.PromptSkip, {}); // 第一次打开窗口从本地数据中获取窗口状态信息
|
||||
|
||||
let r = content[id];
|
||||
let c = oops.timer.getClientTime();
|
||||
if (r == null || c > r) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected start(): void {
|
||||
// 界面打开,删除昨天调协的不提示时间
|
||||
if (content[this.config.id]) {
|
||||
delete content[this.config.id];
|
||||
oops.storage.set(GameStorage.PromptSkip, JSON.stringify(content));
|
||||
}
|
||||
}
|
||||
|
||||
/** 设置是否今天日内不提示 */
|
||||
private onSetSkip(toggle: Toggle) {
|
||||
if (toggle.isChecked) {
|
||||
const t = oops.timer.getClientDate();
|
||||
t.setDate(t.getDate() + this.config.skipDay);
|
||||
t.setHours(0, 0, 0, 0);
|
||||
content[this.config.id] = t.getTime();
|
||||
}
|
||||
else {
|
||||
content[this.config.id] = null;
|
||||
}
|
||||
oops.storage.set(GameStorage.PromptSkip, JSON.stringify(content));
|
||||
}
|
||||
}
|
||||
9
assets/libs/gui/window/PromptSkip.ts.meta
Normal file
9
assets/libs/gui/window/PromptSkip.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "ae0c193b-a70c-474f-8e66-eeb20024039e",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
7
assets/module/common/GameStorage.ts
Normal file
7
assets/module/common/GameStorage.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
/** 框架内本地存储键值 */
|
||||
export enum GameStorage {
|
||||
/** 设置音频音量、开关 */
|
||||
Audio = "OopsFrameworkAudio",
|
||||
/** 可设置指定时间内跳过提示 */
|
||||
PromptSkip = "OopsFrameworkPromptSkip",
|
||||
}
|
||||
9
assets/module/common/GameStorage.ts.meta
Normal file
9
assets/module/common/GameStorage.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "7cefb56b-a388-4cd0-9952-209b7554c044",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user