Files
18xchat/assets/Scripts/chat18x/uiitems/DetailImageItem.ts
T

227 lines
5.9 KiB
TypeScript
Raw Normal View History

import {
_decorator,
Component,
Label,
math,
Node,
2025-09-09 19:21:05 +08:00
randomRange,
Sprite,
UITransform,
2025-09-09 16:09:10 +08:00
View,
} from "cc";
2025-08-12 16:58:02 +08:00
import { Config18x } from "db://assets/Scripts/Main/Config/Config18x";
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 { ViewManager } from "db://assets/Scripts/Main/Manager/ViewManager";
import { GButton } from "db://assets/Scripts/Main/Common/GButton";
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-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;
@property(Node)
priceFrame: Node;
@property(Label)
videoPrice: Label;
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;
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-09-10 15:48:27 +08:00
test_resID: Node;
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) {
ViewManager.I.openBundlesView("ShowPanel", data);
this.base.setVideEnable(false);
}
2025-09-09 19:59:11 +08:00
} else {
ViewManager.I.openBundlesView("PopupGirlDetailPanel", {
2025-09-09 20:33:43 +08:00
category: this.category,
2025-09-09 19:59:11 +08:00
resId: this.resId,
girlId: this.girlId,
base: this,
2025-09-10 01:00:27 +08:00
type: this.type,
2025-09-09 19:59:11 +08:00
});
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;
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;
this.girlId = id;
2025-09-09 19:59:11 +08:00
this.resId = resId;
2025-08-27 16:35:26 +08:00
this.question.active = true; // 显示问号,表示加载中
2025-08-25 20:15:42 +08:00
2025-09-10 15:48:27 +08:00
this.test_resID = this.node.getChildByName("resID");
this.test_resID.getComponent(Label).string =
this.girlId.toString() + this.resId;
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-10 15:48:27 +08:00
price = girlData.getGrilPhotoOriginalPrice(
this.category.toString(),
this.girlId,
this.resId
);
2025-09-09 14:31:47 +08:00
this.url = girlData.getGrilPhotoPic(
this.category.toString(),
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-10 15:48:27 +08:00
price = girlData.getGrilVideoOriginalPrice(
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(),
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";
}
ResManager.I.changeBundleSpriteFrame(this.img, imgPath, "Girls", () => {
2025-08-27 16:35:26 +08:00
this.question.active = false; // 图片加载成功后隐藏问号
2025-08-25 20:15:42 +08:00
this.scaleToFillItem();
});
}
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-10 15:48:27 +08:00
ResManager.I.changeBundleSpriteFrame(this.img, imgPath, "Girls", () => {
2025-09-09 19:21:05 +08:00
this.question.active = false; // 图片加载成功后隐藏问号
this.scaleToFillItem();
});
}
}
2025-08-01 18:28:36 +08:00
}