This commit is contained in:
2025-09-09 22:05:26 +08:00
parent 677b34ca15
commit e8ff82a475
6 changed files with 822 additions and 373 deletions
+268 -183
View File
@@ -1,4 +1,17 @@
import { _decorator, Node, Camera, Component, director, game, instantiate, Prefab, RenderTexture, view, resources, macro } from "cc";
import {
_decorator,
Node,
Camera,
Component,
director,
game,
instantiate,
Prefab,
RenderTexture,
view,
resources,
macro,
} from "cc";
import Utils from "../Common/Utils";
import GameRootUI from "../Common/GameRootUI";
import ResManager from "./ResManager";
@@ -6,204 +19,276 @@ import { CommonConfig } from "../Config/CommonConfig";
const { ccclass, property } = _decorator;
@ccclass('ViewManager')
@ccclass("ViewManager")
export class ViewManager extends Component {
private static _I: ViewManager = null;
public static get I(): ViewManager {
if (!ViewManager._I) {
ViewManager._I = new ViewManager();
private static _I: ViewManager = null;
public static get I(): ViewManager {
if (!ViewManager._I) {
ViewManager._I = new ViewManager();
}
return ViewManager._I;
}
private m_viewList = [];
private m_viewListData = {};
start() {}
update(deltaTime: number) {}
private openIdx = 0;
private openViewByPrefab(
err,
i_prefab: Prefab | Node,
i_openInfo,
callBack = null,
path,
type: string = ""
) {
if (err) {
Utils.Log("打开界面时加载资源出错:" + err, path);
return;
}
let t_node: any = instantiate(i_prefab);
if (!t_node.isValid) return;
//界面已打开
for (let i = this.m_viewList.length - 1; i >= 0; i--) {
let t_view: Node = this.m_viewList[i];
if (t_view) {
if (t_view.isValid && t_node.name == t_view.name) {
t_node.setSiblingIndex(999);
Utils.Log("已经打开的相同的界面:" + t_node.name);
return;
}
return ViewManager._I;
}
}
private m_viewList = [];
private m_viewListData = {};
start() {
//截屏纹理
if (i_openInfo && i_openInfo.blueBg === true) {
i_openInfo.screenShotTex = this.getScreenShot();
}
update(deltaTime: number) {
let viewSP = t_node.getComponent(t_node.name);
if (!viewSP) {
for (let index = 0; index < t_node["_components"].length; index++) {
const element = t_node["_components"][index];
if (element.isScriptComponent) {
viewSP = element;
break;
}
}
}
this.m_viewList.push(t_node);
this.m_viewListData[t_node.name] = {
path: path,
data: i_openInfo,
sort: this.openIdx++,
name: t_node.name,
uuid: t_node["_prefab"]["asset"]["_uuid"],
};
viewSP && viewSP.openUIData && viewSP.openUIData(i_openInfo);
callBack && callBack(t_node, i_openInfo);
if (type == "") {
GameRootUI.I.AddUIToLayer(
t_node,
CommonConfig.UILayerGroup.Layer_ui1,
this.m_viewList.length
);
} else if (type == "top") {
// t_node.sType = "top"
GameRootUI.I.AddUIToLayer(t_node, CommonConfig.UILayerGroup.Layer_top);
} else if (type == "tips") {
GameRootUI.I.AddUIToLayer(t_node, CommonConfig.UILayerGroup.Layer_tips);
}
}
private openIdx = 0;
private openViewByPrefab(err, i_prefab: Prefab | Node, i_openInfo, callBack = null, path, type: string = '') {
if (err) {
Utils.Log('打开界面时加载资源出错:' + err, path);
return;
}
let t_node:any = instantiate(i_prefab);
if (!t_node.isValid) return;
//检查是否有相同的View
private checkSameView(i_node: Node, path) {
// let t_com = i_node.getComponent('li_BaseView');
// if (t_com) {
// if (t_com.name == 'li_BaseView') return true;
// for (let i = this.m_viewList.length - 1; i >= 0; i--) {
// let t_view: Node = this.m_viewList[i];
// if (t_view) {
// if (t_view.isValid && t_com.node.name == t_view.name) {
// i_node.setSiblingIndex(999)
// return false;
// }
// }
// }
// i_node['path'] = path;
// this.m_viewList.push(i_node);
// return true;
// }
//界面已打开
for (let i = this.m_viewList.length - 1; i >= 0; i--) {
let t_view: Node = this.m_viewList[i];
if (t_view) {
if (t_view.isValid && t_node.name == t_view.name) {
t_node.setSiblingIndex(999)
Utils.Log('已经打开的相同的界面:' + t_node.name);
return;
}
}
}
return false;
}
//截屏纹理
if (i_openInfo && i_openInfo.blueBg===true){
i_openInfo.screenShotTex = this.getScreenShot()
}
//获取截屏纹理
private getScreenShot(): RenderTexture {
// let texture = new RenderTexture();
// let winSize = view.getViewportRect()
// let winSize1 = view.getVisibleSize()
// texture.reset({
// width: winSize.width,
// height: winSize.height,
// });
let viewSP = t_node.getComponent(t_node.name);
if (!viewSP) {
for (let index = 0; index < t_node['_components'].length; index++) {
const element = t_node['_components'][index];
if (element.isScriptComponent) {
viewSP = element;
break;
}
}
}
this.m_viewList.push(t_node);
this.m_viewListData[t_node.name] = { path: path, data: i_openInfo, sort: this.openIdx++, name: t_node.name, uuid: t_node["_prefab"]['asset']['_uuid'] };
viewSP && viewSP.openUIData && viewSP.openUIData(i_openInfo);
callBack && callBack(t_node, i_openInfo);
if (type == '') {
GameRootUI.I.AddUIToLayer(t_node, CommonConfig.UILayerGroup.Layer_ui1, this.m_viewList.length)
} else if (type == 'top') {
// t_node.sType = "top"
GameRootUI.I.AddUIToLayer(t_node, CommonConfig.UILayerGroup.Layer_top)
} else if (type == 'tips') {
GameRootUI.I.AddUIToLayer(t_node, CommonConfig.UILayerGroup.Layer_tips)
}
// let camera = director.getScene().getComponentInChildren(Camera);
// let oldTargetTexture = camera.targetTexture
// camera.targetTexture = texture;
// camera.render();
// camera.targetTexture = oldTargetTexture
// return texture
return null;
}
private getViewIndex(i_view: Node) {
for (let i = this.m_viewList.length - 1; i >= 0; i--) {
let t_view = this.m_viewList[i];
if (t_view == i_view) {
return i;
}
}
//检查是否有相同的View
private checkSameView(i_node: Node, path){
// let t_com = i_node.getComponent('li_BaseView');
// if (t_com) {
// if (t_com.name == 'li_BaseView') return true;
// for (let i = this.m_viewList.length - 1; i >= 0; i--) {
// let t_view: Node = this.m_viewList[i];
// if (t_view) {
// if (t_view.isValid && t_com.node.name == t_view.name) {
// i_node.setSiblingIndex(999)
// return false;
// }
// }
// }
// i_node['path'] = path;
// this.m_viewList.push(i_node);
// return true;
// }
return -1;
}
return false;
/**打开resources窗体 */
openMainView(
i_prefab: string | Prefab,
i_openData?,
callBack = null,
type: string = ""
) {
if (i_prefab instanceof Prefab) {
this.openViewByPrefab(
null,
i_prefab,
i_openData,
callBack,
i_prefab,
type
);
} else {
resources.load(i_prefab, (err, $prefab: Prefab) => {
this.openViewByPrefab(
err,
$prefab,
i_openData,
callBack,
i_prefab,
type
);
});
}
}
/**打开bundle窗体 */
openBundlesView(
i_prefab: string | Prefab,
i_openData?,
callBack = null,
type: string = ""
) {
if (i_prefab instanceof Prefab) {
this.openViewByPrefab(
null,
i_prefab,
i_openData,
callBack,
i_prefab,
type
);
} else {
console.log("打开界面:", i_prefab);
ResManager.I.getPrefab(
i_prefab,
(pb: Node) => {
this.openViewByPrefab(null, pb, i_openData, callBack, i_prefab, type);
},
null
);
}
}
/**打开bundle弹窗 */
openBundlesPopupView(
i_prefab: string | Prefab,
i_openData?,
callBack = null
) {
if (i_prefab instanceof Prefab) {
this.openViewByPrefab(
null,
i_prefab,
i_openData,
callBack,
i_prefab,
"tips"
);
} else {
console.log("打开界面:", i_prefab);
ResManager.I.getPrefab(
i_prefab,
(pb: Node) => {
this.openViewByPrefab(
null,
pb,
i_openData,
callBack,
i_prefab,
"tips"
);
},
null
);
}
}
/**关闭窗体 */
closeView(i_view: Node) {
let closeUIName = null;
let t_index = this.getViewIndex(i_view);
if (t_index > -1) {
let t_view = this.m_viewList[t_index];
if (t_view) {
closeUIName = t_view.name;
delete this.m_viewListData[t_view.name];
t_view.destroy();
t_view.removeFromParent();
}
this.m_viewList.splice(t_index, 1); //删除列表元素 参数1是指定位置,参数2是删除元素个数
} else {
if (!this.m_viewList.length) {
i_view.destroy();
}
Utils.Log("试图关闭一个队列中不存在的界面:", i_view.name);
}
}
/**关闭所有窗体 */
closeAllView(isR = false) {
for (let i = this.m_viewList.length - 1; i >= 0; i--) {
let t_view = this.m_viewList[i];
if (t_view) {
delete this.m_viewListData[t_view.name];
t_view.destroy();
t_view.removeFromParent();
}
}
//获取截屏纹理
private getScreenShot():RenderTexture {
// let texture = new RenderTexture();
// let winSize = view.getViewportRect()
// let winSize1 = view.getVisibleSize()
// texture.reset({
// width: winSize.width,
// height: winSize.height,
// });
// let camera = director.getScene().getComponentInChildren(Camera);
// let oldTargetTexture = camera.targetTexture
// camera.targetTexture = texture;
// camera.render();
// camera.targetTexture = oldTargetTexture
// return texture
return null
this.m_viewList = [];
this.m_viewListData = {};
this.openIdx = 0;
}
//是否在主界面,没有打开任何其他界面。主界面是在打开场景时直接创建的,不走这里的打开接口
isNotOpenAnyUI() {
if (this.m_viewList && this.m_viewList.length > 0) {
return false;
}
private getViewIndex(i_view: Node) {
for (let i = this.m_viewList.length - 1; i >= 0; i--) {
let t_view = this.m_viewList[i];
if (t_view == i_view) {
return i;
}
}
return -1;
}
/**打开resources窗体 */
openMainView(i_prefab: string | Prefab, i_openData?, callBack = null, type: string = '') {
if (i_prefab instanceof Prefab) {
this.openViewByPrefab(null, i_prefab, i_openData, callBack, i_prefab, type);
} else {
resources.load(i_prefab, (err, $prefab: Prefab) => {
this.openViewByPrefab(err, $prefab, i_openData, callBack, i_prefab, type);
});
}
}
/**打开bundle窗体 */
openBundlesView(i_prefab: string | Prefab, i_openData?, callBack = null, type: string = '') {
if (i_prefab instanceof Prefab) {
this.openViewByPrefab(null, i_prefab, i_openData, callBack, i_prefab, type);
} else {
console.log("打开界面:", i_prefab);
ResManager.I.getPrefab(i_prefab, (pb: Node) => {
this.openViewByPrefab(null, pb, i_openData, callBack, i_prefab, type);
}, null);
}
}
/**关闭窗体 */
closeView(i_view: Node) {
let closeUIName = null
let t_index = this.getViewIndex(i_view);
if (t_index > -1) {
let t_view = this.m_viewList[t_index];
if (t_view) {
closeUIName = t_view.name
delete this.m_viewListData[t_view.name];
t_view.destroy();
t_view.removeFromParent();
}
this.m_viewList.splice(t_index, 1); //删除列表元素 参数1是指定位置,参数2是删除元素个数
}
else {
if (!this.m_viewList.length) {
i_view.destroy();
}
Utils.Log('试图关闭一个队列中不存在的界面:', i_view.name);
}
}
/**关闭所有窗体 */
closeAllView(isR = false) {
for (let i = this.m_viewList.length - 1; i >= 0; i--) {
let t_view = this.m_viewList[i];
if (t_view) {
delete this.m_viewListData[t_view.name];
t_view.destroy();
t_view.removeFromParent();
}
}
this.m_viewList = [];
this.m_viewListData = {};
this.openIdx = 0;
}
//是否在主界面,没有打开任何其他界面。主界面是在打开场景时直接创建的,不走这里的打开接口
isNotOpenAnyUI() {
if (this.m_viewList && this.m_viewList.length > 0) {
return false
}
return true
}
}
return true;
}
}
+3 -3
View File
@@ -335,17 +335,17 @@ export class GirlData extends BaseData {
let price = oneData.getGrilPhotoPrice(id);
if (price <= 0) {
// 价格为0,代表免费
displayIds.push({ id: id });
displayIds.push(id);
} else {
// 价格大于0,代表付费
let isUnlock = this.isImageUnlock(categoryId, girlId, id);
if (isUnlock) {
// 已经解锁
displayIds.push({ id: id });
displayIds.push(id);
} else {
// 总聊天次数 大于等于 触发次数
if (chatTotalCount >= unlockCounts) {
displayIds.push({ id: id });
displayIds.push(id);
}
}
}
@@ -113,7 +113,7 @@ export class GirlDetailData extends BaseData {
if (!this.photoData) return null;
// 遍历数组找到匹配的资源
for (let oneData of this.photoData) {
if (oneData.id === id) {
if (oneData.id == id) {
return oneData;
}
}
@@ -158,7 +158,7 @@ export class GirlListItem extends Component {
ViewManager.I.closeView(this.baseNode);
} else {
//未解锁
ViewManager.I.openBundlesView("GirlListPopupPanel", {
ViewManager.I.openBundlesPopupView("GirlListPopupPanel", {
base: this,
category: this.category,
id: this.id,
File diff suppressed because it is too large Load Diff