119 lines
3.2 KiB
TypeScript
119 lines
3.2 KiB
TypeScript
import { _decorator, Component, math, Node, Sprite, UITransform } from "cc";
|
|
import { Config18x } from "db://assets/Scripts/Main/Config/Config18x";
|
|
import ResManager from "db://assets/Scripts/Main/Manager/ResManager";
|
|
import { ViewManager } from "db://assets/Scripts/Main/Manager/ViewManager";
|
|
import { GButton } from "db://assets/Scripts/Main/Common/GButton";
|
|
import { GirlDetailPanel } from "../ui/panels/GirlDetailPanel";
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass("DetailImageItem")
|
|
export class DetailImageItem extends Component {
|
|
@property(Sprite)
|
|
img: Sprite;
|
|
|
|
@property(Node)
|
|
lock: Node;
|
|
@property(Node)
|
|
question: Node;
|
|
|
|
base: GirlDetailPanel;
|
|
url: string;
|
|
|
|
uitransform: UITransform;
|
|
|
|
onLoad() {
|
|
GButton.BandClick(this.node, this.onClickThis, this);
|
|
this.uitransform = this.node.getComponent(UITransform);
|
|
}
|
|
|
|
onClickThis() {
|
|
let data = {
|
|
url: this.url,
|
|
closeFunc: () => {
|
|
this.base.setVideEnable(true);
|
|
},
|
|
};
|
|
if (this.url) {
|
|
ViewManager.I.openBundlesView("ShowPanel", data);
|
|
this.base.setVideEnable(false);
|
|
}
|
|
}
|
|
|
|
scaleToFillItem() {
|
|
if (!this.img || !this.img.spriteFrame) return;
|
|
|
|
// 延迟一帧确保UI布局完成
|
|
this.scheduleOnce(() => {
|
|
this.doScaleToFill();
|
|
}, 0);
|
|
}
|
|
|
|
doScaleToFill() {
|
|
if (!this.img || !this.img.spriteFrame) return;
|
|
|
|
const itemSize = this.uitransform.contentSize;
|
|
const imageSize = this.img.spriteFrame.originalSize;
|
|
|
|
console.log("DetailImageItem doScaleToFill:", {
|
|
itemSize,
|
|
imageSize,
|
|
url: this.url
|
|
});
|
|
|
|
if (
|
|
itemSize.width === 0 ||
|
|
itemSize.height === 0 ||
|
|
imageSize.width === 0 ||
|
|
imageSize.height === 0
|
|
) {
|
|
console.log("DetailImageItem: Invalid size, skipping scale");
|
|
return;
|
|
}
|
|
|
|
const scaleX = itemSize.width / imageSize.width;
|
|
const scaleY = itemSize.height / imageSize.height;
|
|
const scale = Math.max(scaleX, scaleY);
|
|
|
|
console.log("DetailImageItem scale values:", { scaleX, scaleY, finalScale: scale });
|
|
|
|
// 设置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);
|
|
console.log("DetailImageItem: Set image size to", imgTransform.contentSize);
|
|
}
|
|
}
|
|
refresh(path: string, base: GirlDetailPanel) {
|
|
this.base = base;
|
|
this.lock.active = false;
|
|
this.question.active = false;
|
|
|
|
if (true) {
|
|
this.url = path;
|
|
// if (info.imageState !== ImageState.Release) {
|
|
// this.url += '_blured';
|
|
// if (info.imageState === ImageState.Lock)
|
|
// this.img.color = new math.Color(127, 127, 127, 255);
|
|
// else
|
|
// this.img.color = new math.Color(50, 50, 50, 255);
|
|
|
|
// } else {
|
|
// this.img.color = new math.Color(255, 255, 255, 255);
|
|
// }
|
|
|
|
ResManager.I.changeBundleSpriteFrame(
|
|
this.img,
|
|
this.url,
|
|
"Chat18x",
|
|
() => {
|
|
this.scaleToFillItem();
|
|
}
|
|
);
|
|
}
|
|
}
|
|
}
|