This commit is contained in:
2025-09-09 19:21:05 +08:00
parent f9f2077665
commit 90a986a79c
5 changed files with 283 additions and 159 deletions
+130 -29
View File
@@ -8,7 +8,7 @@ import { GirlUnlockData } from "./GirlUnlockData";
import { GirlChatData } from "./GirlChatData"; import { GirlChatData } from "./GirlChatData";
import { GirlFavorabilityData } from "./GirlFavorabilityData"; import { GirlFavorabilityData } from "./GirlFavorabilityData";
import { DataId } from "./DataManager"; import { DataId } from "./DataManager";
import proto from 'db://assets/Scripts/proto/proto.pb.js'; import proto from "db://assets/Scripts/proto/proto.pb.js";
// 分类的数据结构 // 分类的数据结构
interface CategoryBucket { interface CategoryBucket {
@@ -79,7 +79,10 @@ export class GirlData extends BaseData {
} }
/** 保存技师列表 */ /** 保存技师列表 */
public setGirlList(categoryId: string, data: proto.cs.ICSGetGirlListRes): void { public setGirlList(
categoryId: string,
data: proto.cs.ICSGetGirlListRes
): void {
if (!data) return; if (!data) return;
this.setGirlBrief(categoryId, data.girls); this.setGirlBrief(categoryId, data.girls);
this.setGirlUnlock(categoryId, data.girls); this.setGirlUnlock(categoryId, data.girls);
@@ -90,9 +93,12 @@ export class GirlData extends BaseData {
} }
/** 保存技师详细数据 */ /** 保存技师详细数据 */
public setGirlDetailData(categoryId: string, data: proto.cs.ICSGetGirlDetailRes): void { public setGirlDetailData(
categoryId: string,
data: proto.cs.ICSGetGirlDetailRes
): void {
if (!data) return; if (!data) return;
let details = [] let details = [];
details.push(data.girl); details.push(data.girl);
this.setGirlBrief(categoryId, details); this.setGirlBrief(categoryId, details);
this.setGirlDetail(categoryId, details); this.setGirlDetail(categoryId, details);
@@ -126,7 +132,10 @@ export class GirlData extends BaseData {
/** /**
* 合并一批简要数据到指定分类;并维护 girlIds 顺序(去重追加) * 合并一批简要数据到指定分类;并维护 girlIds 顺序(去重追加)
*/ */
private mergeBriefs(categoryId: string, respOrList: proto.cs.IGirlData[]): void { private mergeBriefs(
categoryId: string,
respOrList: proto.cs.IGirlData[]
): void {
if (!respOrList) return; if (!respOrList) return;
const bucket = this.ensureBucket(categoryId); const bucket = this.ensureBucket(categoryId);
// 用一个临时 Set 保存已有的 id,加速去重 // 用一个临时 Set 保存已有的 id,加速去重
@@ -158,7 +167,10 @@ export class GirlData extends BaseData {
} }
/** 取某分类 + girlId 的简要数据 */ /** 取某分类 + girlId 的简要数据 */
private getGrilBrief(categoryId: string, girlId: number): GirlBriefData | null { private getGrilBrief(
categoryId: string,
girlId: number
): GirlBriefData | null {
const b = this.ensureCategories().get(categoryId); const b = this.ensureCategories().get(categoryId);
if (!b) return null; if (!b) return null;
return b.briefs.get(girlId) ?? null; return b.briefs.get(girlId) ?? null;
@@ -245,7 +257,9 @@ export class GirlData extends BaseData {
/** --------------------------------------------------------- 技师的详细数据 --------------------------------------------------------- */ /** --------------------------------------------------------- 技师的详细数据 --------------------------------------------------------- */
// 解析技师详细数据,一个 // 解析技师详细数据,一个
private parseOneGirlDetail(data: proto.cs.IGirlsDetail): GirlDetailData | null { private parseOneGirlDetail(
data: proto.cs.IGirlsDetail
): GirlDetailData | null {
if (!data) return null; if (!data) return null;
let oneData = new GirlDetailData(); let oneData = new GirlDetailData();
oneData.init?.(DataId.GirlDetail); oneData.init?.(DataId.GirlDetail);
@@ -265,7 +279,10 @@ export class GirlData extends BaseData {
} }
/** 取某分类 + girlId 的详细数据 */ /** 取某分类 + girlId 的详细数据 */
public getGrilDetail(categoryId: string, girlId: number): GirlDetailData | null { public getGrilDetail(
categoryId: string,
girlId: number
): GirlDetailData | null {
const b = this.ensureCategories().get(categoryId); const b = this.ensureCategories().get(categoryId);
if (!b) return null; if (!b) return null;
return b.details.get(girlId) ?? null; return b.details.get(girlId) ?? null;
@@ -293,7 +310,10 @@ export class GirlData extends BaseData {
} }
/** 获取所有用来展示在列表的技师图片的id */ /** 获取所有用来展示在列表的技师图片的id */
public getAllDisplayGrilPhotoId(categoryId: string, girlId: number): number[] { public getAllDisplayGrilPhotoId(
categoryId: string,
girlId: number
): number[] {
let oneData = this.getGrilDetail(categoryId, girlId); let oneData = this.getGrilDetail(categoryId, girlId);
if (!oneData) return []; if (!oneData) return [];
// 所有id // 所有id
@@ -307,17 +327,17 @@ export class GirlData extends BaseData {
let price = oneData.getGrilPhotoPrice(id); let price = oneData.getGrilPhotoPrice(id);
if (price <= 0) { if (price <= 0) {
// 价格为0,代表免费 // 价格为0,代表免费
displayIds.push(id); displayIds.push({ id: id });
} else { } else {
// 价格大于0,代表付费 // 价格大于0,代表付费
let isUnlock = this.isImageUnlock(categoryId, girlId, id); let isUnlock = this.isImageUnlock(categoryId, girlId, id);
if (isUnlock) { if (isUnlock) {
// 已经解锁 // 已经解锁
displayIds.push(id); displayIds.push({ id: id });
} else { } else {
// 总聊天次数 大于等于 触发次数 // 总聊天次数 大于等于 触发次数
if (chatTotalCount >= unlockCounts) { if (chatTotalCount >= unlockCounts) {
displayIds.push(id); displayIds.push({ id: id });
} }
} }
} }
@@ -338,28 +358,44 @@ export class GirlData extends BaseData {
} }
/** 获取技师图片的类型 */ /** 获取技师图片的类型 */
public getGrilPhotoType(categoryId: string, girlId: number, id: number): number { public getGrilPhotoType(
categoryId: string,
girlId: number,
id: number
): number {
let oneData = this.getGrilDetail(categoryId, girlId); let oneData = this.getGrilDetail(categoryId, girlId);
if (!oneData) return 0; if (!oneData) return 0;
return oneData.getGrilPhotoType(id); return oneData.getGrilPhotoType(id);
} }
/** 获取技师图片的聊天触发次数 */ /** 获取技师图片的聊天触发次数 */
public getGrilPhotoUnlockCounts(categoryId: string, girlId: number, id: number): number { public getGrilPhotoUnlockCounts(
categoryId: string,
girlId: number,
id: number
): number {
let oneData = this.getGrilDetail(categoryId, girlId); let oneData = this.getGrilDetail(categoryId, girlId);
if (!oneData) return 0; if (!oneData) return 0;
return oneData.getGrilPhotoUnlockCounts(id); return oneData.getGrilPhotoUnlockCounts(id);
} }
/** 获取技师图片的价格 */ /** 获取技师图片的价格 */
public getGrilPhotoPrice(categoryId: string, girlId: number, id: number): number { public getGrilPhotoPrice(
categoryId: string,
girlId: number,
id: number
): number {
let oneData = this.getGrilDetail(categoryId, girlId); let oneData = this.getGrilDetail(categoryId, girlId);
if (!oneData) return 0; if (!oneData) return 0;
return oneData.getGrilPhotoPrice(id); return oneData.getGrilPhotoPrice(id);
} }
/** 获取技师图片的资源路径 */ /** 获取技师图片的资源路径 */
public getGrilPhotoPic(categoryId: string, girlId: number, id: number): string { public getGrilPhotoPic(
categoryId: string,
girlId: number,
id: number
): string {
let oneData = this.getGrilDetail(categoryId, girlId); let oneData = this.getGrilDetail(categoryId, girlId);
if (!oneData) return ""; if (!oneData) return "";
return oneData.getGrilPhotoPath(id); return oneData.getGrilPhotoPath(id);
@@ -380,7 +416,10 @@ export class GirlData extends BaseData {
} }
/** 获取所有用来展示在列表的技师视频的id */ /** 获取所有用来展示在列表的技师视频的id */
public getAllDisplayGrilVideoId(categoryId: string, girlId: number): number[] { public getAllDisplayGrilVideoId(
categoryId: string,
girlId: number
): number[] {
let oneData = this.getGrilDetail(categoryId, girlId); let oneData = this.getGrilDetail(categoryId, girlId);
if (!oneData) return []; if (!oneData) return [];
// 所有id // 所有id
@@ -404,6 +443,29 @@ export class GirlData extends BaseData {
return displayIds; return displayIds;
} }
/** 获取所有用来展示在列表的技师视频的id */
public getGirlVideosData(categoryId: string, girlId: number): any[] {
let oneData = this.getGrilDetail(categoryId, girlId);
if (!oneData) return [];
// 所有id
let allId = oneData.getAllGrilVideoId();
// 用来展示的id
let displayIds = [];
for (let id of allId) {
let price = oneData.getGrilVideoPrice(id);
let isUnlock = true;
if (price <= 0) {
// 价格为0,代表免费
//displayIds.push(id);
} else {
// 价格大于0,代表付费
isUnlock = this.isVideoUnlock(categoryId, girlId, id);
}
displayIds.push({ id: id, isUnlock: isUnlock, price: price });
}
return displayIds;
}
/** 获取第一个技师视频的资源路径 */ /** 获取第一个技师视频的资源路径 */
public getFirstGrilVideoPath(categoryId: string, girlId: number): string { public getFirstGrilVideoPath(categoryId: string, girlId: number): string {
let oneData = this.getGrilDetail(categoryId, girlId); let oneData = this.getGrilDetail(categoryId, girlId);
@@ -417,21 +479,33 @@ export class GirlData extends BaseData {
} }
/** 获取技师视频的资源路径 */ /** 获取技师视频的资源路径 */
public getGrilVideoPath(categoryId: string, girlId: number, id: number): string { public getGrilVideoPath(
categoryId: string,
girlId: number,
id: number
): string {
let oneData = this.getGrilDetail(categoryId, girlId); let oneData = this.getGrilDetail(categoryId, girlId);
if (!oneData) return ""; if (!oneData) return "";
return oneData.getGrilVideoPath(id); return oneData.getGrilVideoPath(id);
} }
/** 获取技师视频的关联情绪 */ /** 获取技师视频的关联情绪 */
public getGrilVideoEmotion(categoryId: string, girlId: number, id: number): number { public getGrilVideoEmotion(
categoryId: string,
girlId: number,
id: number
): number {
let oneData = this.getGrilDetail(categoryId, girlId); let oneData = this.getGrilDetail(categoryId, girlId);
if (!oneData) return 0; if (!oneData) return 0;
return oneData.getGrilVideoEmotion(id); return oneData.getGrilVideoEmotion(id);
} }
/** 获取技师视频的价格 */ /** 获取技师视频的价格 */
public getGrilVideoPrice(categoryId: string, girlId: number, id: number): number { public getGrilVideoPrice(
categoryId: string,
girlId: number,
id: number
): number {
let oneData = this.getGrilDetail(categoryId, girlId); let oneData = this.getGrilDetail(categoryId, girlId);
if (!oneData) return 0; if (!oneData) return 0;
return oneData.getGrilVideoPrice(id); return oneData.getGrilVideoPrice(id);
@@ -475,7 +549,10 @@ export class GirlData extends BaseData {
} }
/** 取某分类 + girlId 的解锁数据 */ /** 取某分类 + girlId 的解锁数据 */
private getGrilUnlock(categoryId: string, girlId: number): GirlUnlockData | null { private getGrilUnlock(
categoryId: string,
girlId: number
): GirlUnlockData | null {
const b = this.ensureCategories().get(categoryId); const b = this.ensureCategories().get(categoryId);
if (!b) return null; if (!b) return null;
return b.unlocks.get(girlId) ?? null; return b.unlocks.get(girlId) ?? null;
@@ -489,7 +566,11 @@ export class GirlData extends BaseData {
} }
/** 判断图片是否解锁 */ /** 判断图片是否解锁 */
public isImageUnlock(categoryId: string, girlId: number, id: number): boolean { public isImageUnlock(
categoryId: string,
girlId: number,
id: number
): boolean {
let oneData = this.getGrilUnlock(categoryId, girlId); let oneData = this.getGrilUnlock(categoryId, girlId);
if (!oneData) return false; if (!oneData) return false;
return oneData.isImageUnlock(id); return oneData.isImageUnlock(id);
@@ -510,7 +591,11 @@ export class GirlData extends BaseData {
} }
/** 判断视频是否解锁 */ /** 判断视频是否解锁 */
public isVideoUnlock(categoryId: string, girlId: number, id: number): boolean { public isVideoUnlock(
categoryId: string,
girlId: number,
id: number
): boolean {
let oneData = this.getGrilUnlock(categoryId, girlId); let oneData = this.getGrilUnlock(categoryId, girlId);
if (!oneData) return false; if (!oneData) return false;
return oneData.isVideoUnlock(id); return oneData.isVideoUnlock(id);
@@ -569,7 +654,11 @@ export class GirlData extends BaseData {
} }
/** 保存总聊天次数 */ /** 保存总聊天次数 */
public setChatTotalCount(categoryId: string, girlId: number, value: number): void { public setChatTotalCount(
categoryId: string,
girlId: number,
value: number
): void {
let oneData = this.getGrilChat(categoryId, girlId); let oneData = this.getGrilChat(categoryId, girlId);
if (!oneData) return; if (!oneData) return;
return oneData.setChatTotalCount(value); return oneData.setChatTotalCount(value);
@@ -583,7 +672,11 @@ export class GirlData extends BaseData {
} }
/** 保存剩余聊天次数 */ /** 保存剩余聊天次数 */
public setChatRemainCount(categoryId: string, girlId: number, value: number): void { public setChatRemainCount(
categoryId: string,
girlId: number,
value: number
): void {
let oneData = this.getGrilChat(categoryId, girlId); let oneData = this.getGrilChat(categoryId, girlId);
if (!oneData) return; if (!oneData) return;
return oneData.setChatRemainCount(value); return oneData.setChatRemainCount(value);
@@ -599,7 +692,9 @@ export class GirlData extends BaseData {
/** --------------------------------------------------------- 技师的好感度数据 --------------------------------------------------------- */ /** --------------------------------------------------------- 技师的好感度数据 --------------------------------------------------------- */
// 解析技师好感度数据,一个 // 解析技师好感度数据,一个
private parseOneGirlFavorability(data: proto.cs.IGirlData): GirlFavorabilityData | null { private parseOneGirlFavorability(
data: proto.cs.IGirlData
): GirlFavorabilityData | null {
if (!data) return null; if (!data) return null;
let oneData = new GirlFavorabilityData(); let oneData = new GirlFavorabilityData();
oneData.init?.(DataId.GirlFavorability); oneData.init?.(DataId.GirlFavorability);
@@ -609,7 +704,10 @@ export class GirlData extends BaseData {
} }
/** 保存技师的好感度数据 */ /** 保存技师的好感度数据 */
private setGirlFavorability(categoryId: string, data: proto.cs.IGirlData[]): void { private setGirlFavorability(
categoryId: string,
data: proto.cs.IGirlData[]
): void {
if (!data) return; if (!data) return;
const bucket = this.ensureBucket(categoryId); const bucket = this.ensureBucket(categoryId);
for (const g of data) { for (const g of data) {
@@ -620,7 +718,10 @@ export class GirlData extends BaseData {
} }
/** 取某分类 + girlId 的好感度数据 */ /** 取某分类 + girlId 的好感度数据 */
private getGrilFavorability(categoryId: string, girlId: number): GirlFavorabilityData | null { private getGrilFavorability(
categoryId: string,
girlId: number
): GirlFavorabilityData | null {
const b = this.ensureCategories().get(categoryId); const b = this.ensureCategories().get(categoryId);
if (!b) return null; if (!b) return null;
return b.favorability.get(girlId) ?? null; return b.favorability.get(girlId) ?? null;
@@ -649,7 +750,7 @@ export class GirlData extends BaseData {
const girlIds = bucket.girlIds; const girlIds = bucket.girlIds;
const length = girlIds.length; const length = girlIds.length;
if (length <= 0) return 0; if (length <= 0) return 0;
return girlIds[length-1]; return girlIds[length - 1];
} }
/** 获取每日推荐的简要数据 */ /** 获取每日推荐的简要数据 */
@@ -188,26 +188,26 @@ export class GirlDetailPanel extends li_BaseView {
bindVideoToggle() { bindVideoToggle() {
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl); const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
let resIds = girlData.getAllDisplayGrilVideoId(this.category.toString(), this.id); let videoDatas = girlData.getGirlVideosData(this.category.toString(), this.id);
this.refreshImgs(2, this.category, this.id, resIds); this.refreshImgs(2, this.category, this.id, videoDatas);
} }
refreshImgs( refreshImgs(
type: number, type: number,
category: number, category: number,
id: number, id: number,
resIds: number[] datas: any[]
) { ) {
for (let i = this.imgsLayout.children.length - 1; i >= 0; i--) { for (let i = this.imgsLayout.children.length - 1; i >= 0; i--) {
this.imgsLayout.children[i].destroy(); this.imgsLayout.children[i].destroy();
} }
let count = resIds.length; let count = datas.length;
for (let i = 0; i < count; i++) { for (let i = 0; i < count; i++) {
let newNode = instantiate(this.imgItemInst.node); let newNode = instantiate(this.imgItemInst.node);
let item = newNode.getComponent(DetailImageItem); let item = newNode.getComponent(DetailImageItem);
let resId = resIds[i]; let data = datas[i];
item.refresh(this, type, category, id, resId); item.refresh(this, type, category, id, data);
newNode.active = true; newNode.active = true;
this.imgsLayout.addChild(newNode); this.imgsLayout.addChild(newNode);
} }
@@ -2,6 +2,7 @@ import { _decorator, Component, Node } from "cc";
import li_BaseView from "../../../Main/Common/li_BaseView"; import li_BaseView from "../../../Main/Common/li_BaseView";
import { GButton } from "../../../Main/Common/GButton"; import { GButton } from "../../../Main/Common/GButton";
import Utils from "../../../Main/Common/Utils"; import Utils from "../../../Main/Common/Utils";
import { DetailImageItem } from "../../uiitems/DetailImageItem";
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
@ccclass("PopupGirlDetailPanel") @ccclass("PopupGirlDetailPanel")
@@ -10,10 +11,11 @@ export class PopupGirlDetailPanel extends li_BaseView {
private girlId: number; private girlId: number;
private resId: number; private resId: number;
private base: DetailImageItem;
openUIDataCT(data) { openUIDataCT(data) {
this.resId = data.resId; this.resId = data.resId;
this.girlId = data.girlId; this.girlId = data.girlId;
this.base = data.base;
} }
onLoadCT() { onLoadCT() {
Utils.parseNode(this.node, this._nodeTab); Utils.parseNode(this.node, this._nodeTab);
@@ -29,5 +31,11 @@ export class PopupGirlDetailPanel extends li_BaseView {
buyCharacter() { buyCharacter() {
// 购买id为girlId的女生 // 购买id为girlId的女生
console.log(this.girlId + "---" + this.resId); console.log(this.girlId + "---" + this.resId);
const success = true;
if (success) {
this.close();
this.base.refreshVideoBuy(true);
}
} }
} }
@@ -4,6 +4,7 @@ import {
Label, Label,
math, math,
Node, Node,
randomRange,
Sprite, Sprite,
UITransform, UITransform,
View, View,
@@ -60,18 +61,26 @@ export class DetailImageItem extends Component {
}, },
}; };
//判断是否已经解锁此资源 if (!this.isImage) {
const isRelease = false; //判断是否已经解锁此资源
if (isRelease) { const isRelease = randomRange(0, 1) > 0.5;
if (isRelease) {
if (this.url) {
ViewManager.I.openBundlesView("ShowPanel", data);
this.base.setVideEnable(false);
}
} else {
ViewManager.I.openBundlesView("PopupGirlDetailPanel", {
resId: this.resId,
girlId: this.girlId,
base: this,
});
}
} else {
if (this.url) { if (this.url) {
ViewManager.I.openBundlesView("ShowPanel", data); ViewManager.I.openBundlesView("ShowPanel", data);
this.base.setVideEnable(false); this.base.setVideEnable(false);
} }
} else {
ViewManager.I.openBundlesView("PopupGirlDetailPanel", {
resId: this.resId,
girlId: this.girlId,
});
} }
} }
@@ -114,19 +123,20 @@ export class DetailImageItem extends Component {
); );
} }
} }
refresh( refresh(
base: GirlDetailPanel, base: GirlDetailPanel,
type: number, type: number,
category: number, category: number,
id: number, id: number,
resId: number data: any
) { ) {
this.base = base; this.base = base;
this.type = type; this.type = type;
this.category = category; this.category = category;
this.girlId = id; this.girlId = id;
this.resId = resId; this.resId = data.id;
this.question.active = true; // 显示问号,表示加载中 this.question.active = true; // 显示问号,表示加载中
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl); const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
@@ -150,25 +160,20 @@ export class DetailImageItem extends Component {
this.girlId, this.girlId,
this.resId this.resId
); );
let videoPrice = girlData.getGrilVideoPrice(
this.category.toString(),
this.girlId,
this.resId
);
this.url = girlData.getGrilVideoPath( this.url = girlData.getGrilVideoPath(
this.category.toString(), this.category.toString(),
this.girlId, this.girlId,
this.resId this.resId
); );
if (videoPrice > 0) { if (!data.isUnlock) {
imgPath = this.url + "_thumbnail_blur"; imgPath = this.url + "_thumbnail_blur";
} else { } else {
imgPath = this.url + "_thumbnail"; imgPath = this.url + "_thumbnail";
} }
this.priceFrame.active = videoPrice > 0; this.priceFrame.active = data.price > 0;
this.videoPrice.string = videoPrice.toString(); this.videoPrice.string = data.price.toString();
} }
ResManager.I.changeBundleSpriteFrame(this.img, imgPath, "Chat18x", () => { ResManager.I.changeBundleSpriteFrame(this.img, imgPath, "Chat18x", () => {
@@ -176,4 +181,14 @@ export class DetailImageItem extends Component {
this.scaleToFillItem(); this.scaleToFillItem();
}); });
} }
refreshVideoBuy(success: boolean) {
if (success) {
const imgPath = this.url + "_thumbnail";
ResManager.I.changeBundleSpriteFrame(this.img, imgPath, "Chat18x", () => {
this.question.active = false; // 图片加载成功后隐藏问号
this.scaleToFillItem();
});
}
}
} }
@@ -148,7 +148,7 @@ export class GirlListItem extends Component {
} }
onClickDetail() { onClickDetail() {
if (false) { if (true) {
NavigationManager.Instance.navigateToGirlDetail(this.id); NavigationManager.Instance.navigateToGirlDetail(this.id);
ViewManager.I.closeView(this.baseNode); ViewManager.I.closeView(this.baseNode);
} else { } else {