优化加载显示

This commit is contained in:
2025-09-11 15:01:03 +08:00
parent 7ed18b410d
commit d6a9898c8d
13 changed files with 4532 additions and 2238 deletions
@@ -1,4 +1,4 @@
import { _decorator, Component, Node, Label } from "cc";
import { _decorator, Component, Node, Label, UITransform, Sprite } from "cc";
import li_BaseView from "../../../Main/Common/li_BaseView";
import { GButton } from "../../../Main/Common/GButton";
import Utils from "../../../Main/Common/Utils";
@@ -11,6 +11,7 @@ import proto from "db://assets/Scripts/proto/proto.pb.js";
import LanguageUtils from "../../../Main/Common/LanguageUtils";
import { ImagePopup } from "../components/ImagePopup";
import { TipsPanel } from "./TipsPanel";
import ResManager from "../../../Main/Manager/ResManager";
const { ccclass, property } = _decorator;
@ccclass("PopupGirlDetailPanel")
@@ -24,6 +25,9 @@ export class PopupGirlDetailPanel extends li_BaseView {
private base: DetailImageItem | ImagePopup;
private desc: Label;
img: Sprite;
uitransform: UITransform;
openUIDataCT(data) {
this.category = data.category;
this.resId = data.resId;
@@ -34,12 +38,15 @@ export class PopupGirlDetailPanel extends li_BaseView {
onLoadCT() {
Utils.parseNode(this.node, this._nodeTab);
this.desc = this._nodeTab.content.getComponent(Label);
this.uitransform = this._nodeTab.Img_Frame.getComponent(UITransform);
this.img = this._nodeTab.img.getComponent(Sprite);
let descText = LanguageUtils.getText("popupgirldetailpanel.content");
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
// 价格
this.priceLabel = this._nodeTab.Price.getComponent(Label);
let url = "";
if (this.type === proto.cs.EnmResType.ERT_Image) {
// 图片
this.priceLabel.string = girlData
@@ -49,6 +56,11 @@ export class PopupGirlDetailPanel extends li_BaseView {
this.resId
)
.toString();
url = girlData.getGrilPhotoPic(
this.category.toString(),
this.girlId,
this.resId
);
} else if (this.type === proto.cs.EnmResType.ERT_Video) {
// 视频
this.priceLabel.string = girlData
@@ -58,8 +70,16 @@ export class PopupGirlDetailPanel extends li_BaseView {
this.resId
)
.toString();
url = girlData.getGrilVideoPath(
this.category.toString(),
this.girlId,
this.resId
);
}
const path = url + "_thumbnail_blur";
ResManager.I.changeBundleSpriteFrame(this.img, path, "Girls", () => {
this.scaleToFillItem();
});
this.desc.string = descText.replace("{price}", this.priceLabel.string);
this.registerListener();
@@ -108,4 +128,44 @@ export class PopupGirlDetailPanel extends li_BaseView {
TipsPanel.show("Insufficient balance, need to purchase");
}
}
scaleToFillItem() {
if (!this.img || !this.img.spriteFrame) return;
// 延迟一帧确保UI布局完成
this.doScaleToFill();
}
doScaleToFill() {
if (!this.img || !this.img.spriteFrame) return;
if (!this.uitransform)
this.uitransform = this.node.getComponent(UITransform);
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(scaleY, scaleY);
// 设置Sprite的sizeMode为CUSTOM,允许自定义大小
this.img.sizeMode = Sprite.SizeMode.CUSTOM;
// 获取图片节点的UITransform并设置大小
const imgTransform = this.img.node.getComponent(UITransform);
if (imgTransform) {
imgTransform.setContentSize(
imageSize.width * scale,
imageSize.height * scale
);
}
}
}