优化加载显示

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
);
}
}
}