This commit is contained in:
dgflash
2024-03-09 15:11:13 +08:00
9 changed files with 71 additions and 73 deletions

View File

@@ -16,7 +16,7 @@ import { GameManager } from "./game/GameManager";
import { GUI } from "./gui/GUI";
import { LayerManager } from "./gui/layer/LayerManager";
const { ccclass, property } = _decorator;
const { property } = _decorator;
var isInited = false;
@@ -27,7 +27,7 @@ export class Root extends Component {
type: Node,
tooltip: "游戏层"
})
game: Node = null!;
game: Node = null!; // 可使用多摄像机自定义二维或三维游戏场景
/** 界面层节点 */
@property({
@@ -37,7 +37,7 @@ export class Root extends Component {
gui: Node = null!;
/** 持久根节点 */
persistRootNode: Node = null!
private persistRootNode: Node = null!
onLoad() {
if (!isInited) {

View File

@@ -41,7 +41,7 @@ export class StorageManager {
console.error("存储的key不能为空");
return;
}
if (!PREVIEW) {
if (this.encrypted) {
keywords = EncryptUtil.md5(keywords);
}
if (null == value) {
@@ -66,7 +66,7 @@ export class StorageManager {
value = value + "";
}
if (!PREVIEW && null != this._key && null != this._iv) {
if (this.encrypted && null != this._key && null != this._iv) {
value = EncryptUtil.aesEncrypt(`${value}`, this._key, this._iv);
}
sys.localStorage.setItem(keywords, value);
@@ -86,12 +86,12 @@ export class StorageManager {
key = this.getKey(key);
if (!PREVIEW) {
if (this.encrypted) {
key = EncryptUtil.md5(key);
}
let str: string | null = sys.localStorage.getItem(key);
if (null != str && '' !== str && !PREVIEW && null != this._key && null != this._iv) {
if (null != str && '' !== str && this.encrypted && null != this._key && null != this._iv) {
str = EncryptUtil.aesDecrypt(str, this._key, this._iv);
}
@@ -133,9 +133,9 @@ export class StorageManager {
return;
}
var keywords = `${key}_${this._id}`;
var keywords = this.getKey(key);
if (!PREVIEW) {
if (this.encrypted) {
keywords = EncryptUtil.md5(keywords);
}
sys.localStorage.removeItem(keywords);
@@ -146,10 +146,16 @@ export class StorageManager {
sys.localStorage.clear();
}
/** 获取数据分组关键字 */
private getKey(key: string): string {
if (this._id == null || this._id == "") {
return key;
}
return `${this._id}_${key}`;
}
/** 数据加密开关 */
private get encrypted(): boolean {
return !PREVIEW
}
}

View File

@@ -4,7 +4,7 @@
* @LastEditors: dgflash
* @LastEditTime: 2023-01-19 14:37:19
*/
import { Component } from "cc";
import { Component, game } from "cc";
import { StringUtil } from "../../utils/StringUtil";
import { Timer } from "./Timer";
@@ -12,13 +12,11 @@ import { Timer } from "./Timer";
export class TimerManager extends Component {
/** 倒计时数据 */
private times: any = {};
/** 当前游戏进入的时间毫秒值 */
private initTime: number = (new Date()).getTime();
/** 服务器时间与本地时间同步 */
private serverTime: number = 0;
/** 后台管理倒计时完成事件 */
update(dt: number) {
// 后台管理倒计时完成事件
for (let key in this.times) {
let data = this.times[key];
var timer = data.timer as Timer;
@@ -111,56 +109,26 @@ export class TimerManager extends Component {
/**
* 服务器时间与本地时间同步
* @param val 服务器时间刻度
*
* @param value 服务器时间刻度
*/
setServerTime(val?: number): number {
if (val) {
this.serverTime = val;
}
return this.serverTime;
setServerTime(value: number): void {
this.serverTime = value;
}
/** 获取写服务器同步的时间刻度 */
getServerTime(): number {
return this.serverTime + this.getTime();
}
/**
* 格式化日期显示
* @param format 格式化字符串yyyy-MM-dd hh:mm:ss
* @param date 时间对象
*/
format(format: string, date: Date): string {
let o: any = {
"M+": date.getMonth() + 1, // month
"d+": date.getDate(), // day
"h+": date.getHours(), // hour
"m+": date.getMinutes(), // minute
"s+": date.getSeconds(), // second
"q+": Math.floor((date.getMonth() + 3) / 3), // quarter
"S": date.getMilliseconds() // millisecond
}
if (/(y+)/.test(format)) {
format = format.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
}
for (let k in o) {
if (new RegExp("(" + k + ")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
}
}
return format;
}
/** 获取游戏开始到现在逝去的时间 */
getTime(): number {
return this.getLocalTime() - this.initTime;
}
/** 获取本地时间刻度 */
getLocalTime(): number {
return Date.now();
}
/** 获取游戏开始到现在逝去的时间 */
getTime(): number {
return game.totalTime;
}
/** 游戏最小化时记录时间数据 */
save() {
for (let key in this.times) {

View File

@@ -0,0 +1,25 @@
declare global {
interface Date {
format(format: string): string;
}
}
/** 格式化时间字符串 */
Date.prototype.format = function (format: string): string {
const year: number = this.getFullYear();
const month: number = this.getMonth() + 1;
const day: number = this.getDate();
const hours: number = this.getHours();
const minutes: number = this.getMinutes();
const seconds: number = this.getSeconds();
return format
.replace('yy', year.toString())
.replace('mm', (month < 10 ? '0' : '') + month)
.replace('dd', (day < 10 ? '0' : '') + day)
.replace('hh', (hours < 10 ? '0' : '') + hours)
.replace('mm', (minutes < 10 ? '0' : '') + minutes)
.replace('ss', (seconds < 10 ? '0' : '') + seconds);
};
export { };

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "80ebb073-f1eb-41e6-a8a3-59d62b5361c7",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -4,18 +4,14 @@
* @LastEditors: dgflash
* @LastEditTime: 2023-01-19 14:52:40
*/
import { Camera, Component, ResolutionPolicy, UITransform, _decorator, math, screen, view } from "cc";
import { Component, ResolutionPolicy, UITransform, _decorator, math, screen, view } from "cc";
import { oops } from "../Oops";
const { ccclass, menu } = _decorator;
const { ccclass } = _decorator;
/** 游戏界面屏幕自适应管理 */
@ccclass('GUI')
export class GUI extends Component {
/** 界面层矩形信息组件 */
transform!: UITransform;
/** 游戏二维摄像机 */
camera!: Camera;
/** 是否为竖屏显示 */
portrait!: boolean;
@@ -23,6 +19,8 @@ export class GUI extends Component {
private portraitDrz: math.Size = null!;
/** 横屏设计尺寸 */
private landscapeDrz: math.Size = null!;
/** 界面层矩形信息组件 */
private transform: UITransform = null!;
onLoad() {
this.init();
@@ -31,7 +29,6 @@ export class GUI extends Component {
/** 初始化引擎 */
protected init() {
this.transform = this.getComponent(UITransform)!;
this.camera = this.getComponentInChildren(Camera)!;
if (view.getDesignResolutionSize().width > view.getDesignResolutionSize().height) {
this.landscapeDrz = view.getDesignResolutionSize();

View File

@@ -59,9 +59,7 @@ export class LayerDialog extends LayerPopUp {
if (onRemove_Source) {
onRemove_Source(node, params);
}
setTimeout(() => {
this.next();
}, 0);
setTimeout(this.next.bind(this), 0);
};
viewParams.params = params || {};

View File

@@ -10,7 +10,7 @@ import { UIMap } from "./UIMap";
/** 界面层类型 */
export enum LayerType {
/** 游戏层 */
/** 二维游戏层 */
Game = "LayerGame",
/** 主界面层 */
UI = "LayerUI",

View File

@@ -91,13 +91,15 @@ export class LayerUI extends Node {
bundle = bundle || oops.res.defaultBundleName;
oops.res.load(bundle, viewParams.prefabPath, (err: Error | null, res: Prefab) => {
if (err) {
error(err);
this.ui_nodes.delete(viewParams.uuid);
error(`路径为【${viewParams.prefabPath}】的预制加载失败`);
return;
}
let childNode: Node = instantiate(res);
viewParams.node = childNode;
let comp: DelegateComponent = childNode.addComponent(DelegateComponent);
let comp = childNode.addComponent(DelegateComponent);
comp.viewParams = viewParams;
this.createNode(viewParams);
@@ -112,11 +114,9 @@ export class LayerUI extends Node {
protected createNode(viewParams: ViewParams) {
viewParams.valid = true;
let comp: DelegateComponent = viewParams.node.getComponent(DelegateComponent)!;
let comp = viewParams.node.getComponent(DelegateComponent)!;
comp.add();
viewParams.node.parent = this;
return viewParams.node;
}
/**
@@ -257,11 +257,6 @@ export class LayerUI extends Node {
return result;
}
/** 层节点数量 */
size(): number {
return this.children.length;
}
/**
* 清除所有节点,队列当中的也删除
* @param isDestroy 移除后是否释放