2025-09-09 14:50:51 +08:00
|
|
|
import {
|
|
|
|
|
_decorator,
|
|
|
|
|
Component,
|
|
|
|
|
Label,
|
|
|
|
|
math,
|
|
|
|
|
Node,
|
2025-09-09 19:21:05 +08:00
|
|
|
randomRange,
|
2025-09-09 14:50:51 +08:00
|
|
|
Sprite,
|
|
|
|
|
UITransform,
|
2025-09-09 16:09:10 +08:00
|
|
|
View,
|
2025-09-09 14:50:51 +08:00
|
|
|
} from "cc";
|
2025-08-01 18:28:36 +08:00
|
|
|
import ResManager from "db://assets/Scripts/Main/Manager/ResManager";
|
2025-08-12 16:58:02 +08:00
|
|
|
import { GButton } from "db://assets/Scripts/Main/Common/GButton";
|
2025-08-13 11:31:21 +08:00
|
|
|
import { GirlDetailPanel } from "../ui/panels/GirlDetailPanel";
|
2025-09-09 14:31:47 +08:00
|
|
|
import proto from "db://assets/Scripts/proto/proto.pb.js";
|
2025-09-03 17:35:27 +08:00
|
|
|
import { DataManager, DataId } from "../data/DataManager";
|
|
|
|
|
import { GirlData } from "../data/GirlData";
|
2025-09-16 11:19:28 +08:00
|
|
|
import { EnvData } from "../data/EnvData";
|
2025-09-21 10:35:27 +08:00
|
|
|
import { NavigationManager } from "../manager/NavigationManager";
|
2025-08-01 18:28:36 +08:00
|
|
|
|
2025-08-12 16:58:02 +08:00
|
|
|
const { ccclass, property } = _decorator;
|
2025-08-01 18:28:36 +08:00
|
|
|
|
2025-08-12 16:58:02 +08:00
|
|
|
@ccclass("DetailImageItem")
|
2025-08-01 18:28:36 +08:00
|
|
|
export class DetailImageItem extends Component {
|
2025-08-12 16:58:02 +08:00
|
|
|
@property(Sprite)
|
|
|
|
|
img: Sprite;
|
2025-08-01 18:28:36 +08:00
|
|
|
|
2025-08-12 16:58:02 +08:00
|
|
|
@property(Node)
|
|
|
|
|
question: Node;
|
2025-08-01 18:28:36 +08:00
|
|
|
|
2025-09-09 14:31:47 +08:00
|
|
|
@property(Sprite)
|
|
|
|
|
video: Sprite;
|
|
|
|
|
|
2025-09-09 14:50:51 +08:00
|
|
|
@property(Node)
|
|
|
|
|
priceFrame: Node;
|
|
|
|
|
@property(Label)
|
|
|
|
|
videoPrice: Label;
|
2025-09-11 15:01:03 +08:00
|
|
|
@property(Node)
|
|
|
|
|
loading: Node;
|
2025-08-12 16:58:02 +08:00
|
|
|
base: GirlDetailPanel;
|
|
|
|
|
url: string;
|
2025-08-26 14:23:02 +08:00
|
|
|
isImage: boolean;
|
2025-08-13 16:17:44 +08:00
|
|
|
uitransform: UITransform;
|
2025-09-03 17:35:27 +08:00
|
|
|
category: number;
|
2025-09-09 14:50:51 +08:00
|
|
|
|
|
|
|
|
girlId: number;
|
2025-09-08 15:10:51 +08:00
|
|
|
resId: number;
|
2025-09-10 10:18:27 +08:00
|
|
|
type: proto.cs.EnmResType;
|
2025-08-13 16:17:44 +08:00
|
|
|
|
2025-08-12 16:58:02 +08:00
|
|
|
onLoad() {
|
|
|
|
|
GButton.BandClick(this.node, this.onClickThis, this);
|
2025-08-13 16:17:44 +08:00
|
|
|
this.uitransform = this.node.getComponent(UITransform);
|
2025-08-12 16:58:02 +08:00
|
|
|
}
|
2025-09-10 15:48:27 +08:00
|
|
|
isVisible: boolean;
|
2025-08-12 16:58:02 +08:00
|
|
|
onClickThis() {
|
2025-09-09 20:33:43 +08:00
|
|
|
// 数据
|
|
|
|
|
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
|
2025-09-10 01:00:27 +08:00
|
|
|
// 是否可见,不可见代表需要解锁
|
2025-09-10 15:48:27 +08:00
|
|
|
if (this.isVisible) {
|
2025-09-10 18:12:26 +08:00
|
|
|
let data = {
|
|
|
|
|
url: this.url,
|
|
|
|
|
isImg: this.isImage,
|
|
|
|
|
|
|
|
|
|
closeFunc: () => {
|
|
|
|
|
this.base.setVideEnable(true);
|
|
|
|
|
},
|
|
|
|
|
};
|
2025-09-09 16:09:10 +08:00
|
|
|
if (this.url) {
|
2025-09-21 12:05:34 +08:00
|
|
|
NavigationManager.Instance.openPopupPanel("ShowPanel", data);
|
2025-09-09 16:09:10 +08:00
|
|
|
this.base.setVideEnable(false);
|
|
|
|
|
}
|
2025-09-09 19:59:11 +08:00
|
|
|
} else {
|
2025-09-21 12:05:34 +08:00
|
|
|
NavigationManager.Instance.openPopupPanel("PopupGirlDetailPanel", {
|
|
|
|
|
category: this.category,
|
|
|
|
|
resId: this.resId,
|
|
|
|
|
girlId: this.girlId,
|
|
|
|
|
base: this,
|
|
|
|
|
type: this.type,
|
|
|
|
|
});
|
2025-09-21 10:35:27 +08:00
|
|
|
|
|
|
|
|
// ViewManager.I.openBundlesView("PopupGirlDetailPanel", {
|
|
|
|
|
// category: this.category,
|
|
|
|
|
// resId: this.resId,
|
|
|
|
|
// girlId: this.girlId,
|
|
|
|
|
// base: this,
|
|
|
|
|
// type: this.type,
|
|
|
|
|
// });
|
2025-08-01 18:28:36 +08:00
|
|
|
}
|
2025-09-09 19:59:11 +08:00
|
|
|
// if (!this.isImage) {
|
|
|
|
|
// //判断是否已经解锁此资源
|
|
|
|
|
// } else {
|
|
|
|
|
// if (this.url) {
|
|
|
|
|
// ViewManager.I.openBundlesView("ShowPanel", data);
|
|
|
|
|
// this.base.setVideEnable(false);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2025-08-12 16:58:02 +08:00
|
|
|
}
|
2025-08-13 16:17:44 +08:00
|
|
|
|
|
|
|
|
scaleToFillItem() {
|
|
|
|
|
if (!this.img || !this.img.spriteFrame) return;
|
|
|
|
|
|
|
|
|
|
// 延迟一帧确保UI布局完成
|
2025-08-27 16:35:26 +08:00
|
|
|
this.doScaleToFill();
|
2025-08-13 16:17:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
doScaleToFill() {
|
|
|
|
|
if (!this.img || !this.img.spriteFrame) return;
|
2025-09-09 14:50:51 +08:00
|
|
|
if (!this.uitransform)
|
|
|
|
|
this.uitransform = this.node.getComponent(UITransform);
|
2025-08-13 16:17:44 +08:00
|
|
|
const itemSize = this.uitransform.contentSize;
|
|
|
|
|
const imageSize = this.img.spriteFrame.originalSize;
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
itemSize.width === 0 ||
|
|
|
|
|
itemSize.height === 0 ||
|
|
|
|
|
imageSize.width === 0 ||
|
|
|
|
|
imageSize.height === 0
|
|
|
|
|
) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const scaleX = itemSize.width / imageSize.width;
|
|
|
|
|
const scaleY = itemSize.height / imageSize.height;
|
|
|
|
|
const scale = Math.max(scaleX, scaleY);
|
|
|
|
|
|
|
|
|
|
// 设置Sprite的sizeMode为CUSTOM,允许自定义大小
|
|
|
|
|
this.img.sizeMode = Sprite.SizeMode.CUSTOM;
|
2025-08-25 20:15:42 +08:00
|
|
|
|
2025-08-13 16:17:44 +08:00
|
|
|
// 获取图片节点的UITransform并设置大小
|
|
|
|
|
const imgTransform = this.img.node.getComponent(UITransform);
|
|
|
|
|
if (imgTransform) {
|
2025-08-25 20:15:42 +08:00
|
|
|
imgTransform.setContentSize(
|
|
|
|
|
imageSize.width * scale,
|
|
|
|
|
imageSize.height * scale
|
2025-08-13 16:17:44 +08:00
|
|
|
);
|
2025-08-01 18:28:36 +08:00
|
|
|
}
|
2025-08-12 16:58:02 +08:00
|
|
|
}
|
2025-09-09 19:59:11 +08:00
|
|
|
|
2025-08-29 16:23:59 +08:00
|
|
|
refresh(
|
2025-09-03 17:35:27 +08:00
|
|
|
base: GirlDetailPanel,
|
2025-09-10 10:18:27 +08:00
|
|
|
type: proto.cs.EnmResType,
|
2025-09-03 17:35:27 +08:00
|
|
|
category: number,
|
|
|
|
|
id: number,
|
2025-09-09 19:59:11 +08:00
|
|
|
resId: number
|
2025-08-29 16:23:59 +08:00
|
|
|
) {
|
2025-08-25 20:15:42 +08:00
|
|
|
this.base = base;
|
2025-09-03 17:35:27 +08:00
|
|
|
this.type = type;
|
|
|
|
|
this.category = category;
|
2025-09-09 14:50:51 +08:00
|
|
|
this.girlId = id;
|
2025-09-09 19:59:11 +08:00
|
|
|
this.resId = resId;
|
2025-09-11 15:01:03 +08:00
|
|
|
//this.question.active = true; // 显示问号,表示加载中
|
2025-08-25 20:15:42 +08:00
|
|
|
|
2025-09-11 15:01:03 +08:00
|
|
|
this.loading.active = true;
|
2025-09-10 15:48:27 +08:00
|
|
|
|
2025-09-03 17:35:27 +08:00
|
|
|
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
|
|
|
|
|
let imgPath = "";
|
2025-09-10 10:18:27 +08:00
|
|
|
this.video.enabled = type === proto.cs.EnmResType.ERT_Video;
|
|
|
|
|
this.priceFrame.active = type === proto.cs.EnmResType.ERT_Video;
|
2025-09-09 20:33:43 +08:00
|
|
|
let price = 0;
|
2025-09-10 01:00:27 +08:00
|
|
|
// 是否可见,不可见代表需要解锁
|
2025-09-10 15:48:27 +08:00
|
|
|
if (this.type === proto.cs.EnmResType.ERT_Image) {
|
|
|
|
|
// 图片
|
|
|
|
|
this.isVisible = girlData.isGirlPhotoVisible(
|
|
|
|
|
this.category.toString(),
|
|
|
|
|
this.girlId,
|
|
|
|
|
this.resId
|
|
|
|
|
);
|
|
|
|
|
} else if (this.type === proto.cs.EnmResType.ERT_Video) {
|
|
|
|
|
// 视频
|
|
|
|
|
this.isVisible = girlData.isGirlVideoVisible(
|
|
|
|
|
this.category.toString(),
|
|
|
|
|
this.girlId,
|
|
|
|
|
this.resId
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-09-10 10:18:27 +08:00
|
|
|
if (type === proto.cs.EnmResType.ERT_Image) {
|
2025-09-03 17:35:27 +08:00
|
|
|
// 图片
|
2025-09-26 11:57:33 +08:00
|
|
|
price = girlData.getGrilPhotoPrice(
|
2025-09-10 15:48:27 +08:00
|
|
|
this.category.toString(),
|
|
|
|
|
this.girlId,
|
|
|
|
|
this.resId
|
|
|
|
|
);
|
2025-09-09 14:31:47 +08:00
|
|
|
this.url = girlData.getGrilPhotoPic(
|
|
|
|
|
this.category.toString(),
|
2025-09-09 14:50:51 +08:00
|
|
|
this.girlId,
|
|
|
|
|
this.resId
|
2025-09-09 14:31:47 +08:00
|
|
|
);
|
2025-08-29 16:23:59 +08:00
|
|
|
this.isImage = true;
|
2025-09-10 10:18:27 +08:00
|
|
|
} else if (type === proto.cs.EnmResType.ERT_Video) {
|
2025-09-03 17:35:27 +08:00
|
|
|
// 视频
|
2025-09-26 11:57:33 +08:00
|
|
|
price = girlData.getGrilVideoPrice(
|
2025-09-10 15:48:27 +08:00
|
|
|
this.category.toString(),
|
|
|
|
|
this.girlId,
|
|
|
|
|
this.resId
|
|
|
|
|
);
|
2025-08-29 16:23:59 +08:00
|
|
|
this.isImage = false;
|
2025-09-09 14:31:47 +08:00
|
|
|
this.url = girlData.getGrilVideoPath(
|
|
|
|
|
this.category.toString(),
|
2025-09-09 14:50:51 +08:00
|
|
|
this.girlId,
|
|
|
|
|
this.resId
|
2025-09-09 14:31:47 +08:00
|
|
|
);
|
2025-08-25 20:15:42 +08:00
|
|
|
}
|
2025-08-29 16:23:59 +08:00
|
|
|
|
2025-09-10 15:48:27 +08:00
|
|
|
if (this.isVisible) {
|
|
|
|
|
imgPath = this.url + "_thumbnail";
|
2025-09-10 18:12:26 +08:00
|
|
|
|
|
|
|
|
this.priceFrame.active = false;
|
2025-09-10 15:48:27 +08:00
|
|
|
} else {
|
2025-09-10 18:12:26 +08:00
|
|
|
this.priceFrame.active = true;
|
|
|
|
|
this.videoPrice.string = price.toString();
|
2025-09-10 15:48:27 +08:00
|
|
|
imgPath = this.url + "_thumbnail_blur";
|
|
|
|
|
}
|
2025-09-16 11:19:28 +08:00
|
|
|
// 加载远程资源
|
|
|
|
|
const envData = DataManager.I.getDataById<EnvData>(DataId.Env);
|
|
|
|
|
let newPath = envData.cdn + "/" + "Girls/" + imgPath + ".jpg";
|
|
|
|
|
ResManager.I.changeRemoteSpriteFrame(this.img, newPath, () => {
|
2025-09-11 18:51:35 +08:00
|
|
|
this.question.active = false;
|
2025-08-25 20:15:42 +08:00
|
|
|
this.scaleToFillItem();
|
2025-09-11 15:01:03 +08:00
|
|
|
this.loading.active = false;
|
2025-08-25 20:15:42 +08:00
|
|
|
});
|
|
|
|
|
}
|
2025-09-09 19:21:05 +08:00
|
|
|
|
|
|
|
|
refreshVideoBuy(success: boolean) {
|
|
|
|
|
if (success) {
|
2025-09-10 18:12:26 +08:00
|
|
|
this.priceFrame.active = false;
|
|
|
|
|
this.isVisible = true;
|
2025-09-09 19:21:05 +08:00
|
|
|
const imgPath = this.url + "_thumbnail";
|
2025-09-16 11:19:28 +08:00
|
|
|
// 加载远程资源
|
|
|
|
|
const envData = DataManager.I.getDataById<EnvData>(DataId.Env);
|
|
|
|
|
let newPath = envData.cdn + "/" + "Girls/" + imgPath + ".jpg";
|
|
|
|
|
ResManager.I.changeRemoteSpriteFrame(this.img, newPath, () => {
|
2025-09-09 19:21:05 +08:00
|
|
|
this.question.active = false; // 图片加载成功后隐藏问号
|
|
|
|
|
this.scaleToFillItem();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-09-15 11:55:22 +08:00
|
|
|
|
|
|
|
|
reset() {
|
|
|
|
|
this.base = null;
|
|
|
|
|
this.url = "";
|
|
|
|
|
this.isImage = false;
|
|
|
|
|
this.category = 0;
|
|
|
|
|
this.girlId = 0;
|
|
|
|
|
this.resId = 0;
|
|
|
|
|
this.type = null;
|
|
|
|
|
this.isVisible = false;
|
2025-09-21 10:35:27 +08:00
|
|
|
|
2025-09-15 11:55:22 +08:00
|
|
|
this.question.active = true;
|
|
|
|
|
this.video.enabled = false;
|
|
|
|
|
this.priceFrame.active = false;
|
|
|
|
|
this.loading.active = false;
|
|
|
|
|
this.videoPrice.string = "";
|
2025-09-21 10:35:27 +08:00
|
|
|
|
2025-09-15 11:55:22 +08:00
|
|
|
if (this.img && this.img.spriteFrame) {
|
|
|
|
|
this.img.spriteFrame = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-08-01 18:28:36 +08:00
|
|
|
}
|