优化加载显示

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,13 @@
import { _decorator, Button, Component, Node, Label, View } from "cc";
import {
_decorator,
Button,
Component,
Node,
Label,
View,
Sprite,
UITransform,
} from "cc";
import li_BaseView from "../../../Main/Common/li_BaseView";
import Utils from "../../../Main/Common/Utils";
import { GButton } from "../../../Main/Common/GButton";
@@ -12,6 +21,7 @@ import proto from "db://assets/Scripts/proto/proto.pb.js";
import LanguageUtils from "../../../Main/Common/LanguageUtils";
import { ViewManager } from "../../../Main/Manager/ViewManager";
import { TipsPanel } from "./TipsPanel";
import ResManager from "../../../Main/Manager/ResManager";
const { ccclass, property } = _decorator;
@ccclass("GirlListPopupPanel")
@@ -25,6 +35,8 @@ export class GirlListPopupPanel extends li_BaseView {
private girlTag: Label;
base: GirlListItem;
img: Sprite;
uitransform: UITransform;
openUIDataCT(data) {
this.category = data.category;
this.girlId = data.id;
@@ -32,6 +44,8 @@ export class GirlListPopupPanel extends li_BaseView {
}
onLoadCT() {
Utils.parseNode(this.node, this._nodeTab);
this.img = this._nodeTab.img.getComponent(Sprite);
this.uitransform = this._nodeTab.Img_Frame.getComponent(UITransform);
this.girlName = this._nodeTab.Name.getComponent(Label);
this.girlTag = this._nodeTab.Tag.getComponent(Label);
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
@@ -48,6 +62,13 @@ export class GirlListPopupPanel extends li_BaseView {
this.girlTag.string = LanguageUtils.getText(
girlData.getGrilTagKey(this.category.toString(), this.girlId)
);
const path = girlData.getGrilAvatar(this.category.toString(), this.girlId);
//console.log(path);
ResManager.I.changeBundleSpriteFrame(this.img, path, "Girls", () => {
this.scaleToFillItem();
});
}
registerListener() {
GButton.BandClick(this._nodeTab.BuyBtn, this.buyCharacter, this);
@@ -83,4 +104,44 @@ export class GirlListPopupPanel 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
);
}
}
}
@@ -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
);
}
}
}
@@ -53,7 +53,7 @@ export class ThemePanel extends li_BaseView {
this.coinNum = this._nodeTab.coinNum.getComponent(Label);
this.uid = this._nodeTab.uid.getComponent(Label);
this.recName = this._nodeTab.characterNameText.getComponent(Label);
this.recSprite = this._nodeTab.recPicSlot.getComponent(Sprite);
this.recSprite = this._nodeTab.recPic.getComponent(Sprite);
this.vipLeftTime = this._nodeTab.vipText.getComponent(Label);
this.registerListener();
@@ -66,6 +66,7 @@ export class ThemePanel extends li_BaseView {
rectNameKey: string;
async Show() {
this._nodeTab.loadingRec.active = true;
//some temp data
this.refreshCoinNum();
this.refreshVipExpire();
@@ -121,6 +122,7 @@ export class ThemePanel extends li_BaseView {
}
);
}
this._nodeTab.loadingRec.active = false;
// 获取商品列表,提前把数据拿下来
this.reqShopList();