Files
18xchat/assets/Scripts/chat18x/ui/components/ImagePopup.ts
T

135 lines
3.8 KiB
TypeScript
Raw Normal View History

2025-09-10 21:49:39 +08:00
import {
_decorator,
Component,
Node,
Sprite,
Vec3,
tween,
UITransform,
2025-09-17 16:12:54 +08:00
view,
2025-09-10 21:49:39 +08:00
} from "cc";
2025-07-25 18:27:30 +08:00
import ResManager from "db://assets/Scripts/Main/Manager/ResManager";
import Utils from "db://assets/Scripts/Main/Common/Utils";
2025-09-10 21:49:39 +08:00
import { DataId, DataManager } from "../../data/DataManager";
import { GirlData } from "../../data/GirlData";
2025-09-16 15:58:44 +08:00
import { EnvData } from "../../data/EnvData";
2025-09-10 21:49:39 +08:00
import proto from "db://assets/Scripts/proto/proto.pb.js";
import { GButton } from "../../../Main/Common/GButton";
import { NavigationManager } from "../../manager/NavigationManager";
2025-07-25 18:27:30 +08:00
const { ccclass, property } = _decorator;
2025-09-10 21:49:39 +08:00
@ccclass("ImagePopup")
2025-07-25 18:27:30 +08:00
export class ImagePopup extends Component {
2025-09-10 21:49:39 +08:00
@property(Sprite)
image: Sprite;
2025-07-25 18:27:30 +08:00
2025-09-17 16:12:54 +08:00
private isAnimating: boolean = false;
2025-09-10 21:49:39 +08:00
start() {
2025-09-17 16:12:54 +08:00
this.node.setPosition(this.getOffscreenPosition());
2025-09-10 21:49:39 +08:00
GButton.BandClick(this.image.node, this.openImage, this);
2025-09-11 00:03:22 +08:00
this.node.active = false;
2025-09-10 21:49:39 +08:00
}
2025-07-25 18:27:30 +08:00
2025-09-10 21:49:39 +08:00
onDestroy() {
//this.image.node.off(Node.EventType.TOUCH_START,this.openImage);
}
categoryId: string;
girlId: number;
resId: number;
2025-09-17 16:12:54 +08:00
/**
* 获取屏幕外位置(完全在左侧屏幕外)
*/
private getOffscreenPosition(): Vec3 {
const visibleSize = view.getVisibleSize();
const x = -visibleSize.width; // 完全在屏幕左侧外
const y = visibleSize.height * 0.33; // 屏幕高度的1/3处
return new Vec3(x, y, 0);
}
/**
* 获取屏幕内位置(左侧边缘内侧)
*/
private getOnscreenPosition(): Vec3 {
const visibleSize = view.getVisibleSize();
2025-09-25 18:11:27 +08:00
const x = -visibleSize.width / 2 + 100; // 从左边缘向内100像素
2025-09-17 16:12:54 +08:00
const y = visibleSize.height * 0.33; // 屏幕高度的1/3处
return new Vec3(x, y, 0);
}
2025-09-10 21:49:39 +08:00
//url: string;
refresh(categoryId: string, girlId: number, resId: number, clear = false) {
2025-09-11 00:03:22 +08:00
this.node.active = true;
2025-09-10 21:49:39 +08:00
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
this.categoryId = categoryId;
this.girlId = girlId;
this.resId = resId;
const url = girlData.getGrilPhotoPic(categoryId, girlId, resId);
//this.url = path;
2025-09-16 15:58:44 +08:00
// 加载远程资源
const envData = DataManager.I.getDataById<EnvData>(DataId.Env);
let oldPath = url + (clear ? "" : "_thumbnail_blur");
let suffix = clear ? ".png" : ".jpg";
2025-09-25 18:11:27 +08:00
let newPath = envData.cdn + "/" + "Girls/" + oldPath + suffix;
ResManager.I.changeRemoteSpriteFrame(this.image, newPath, () => {
let sizeTran = this.image.node.parent.getComponent(UITransform);
Utils.adjustBgPixelRatioToSize(sizeTran.contentSize, this.image.node, 2);
this.popUp();
});
2025-09-10 21:49:39 +08:00
}
refreshSelf() {
this.refresh(this.categoryId, this.girlId, this.resId, true);
}
openImage() {
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
const isUnlock = girlData.isImageUnlock(
this.categoryId,
this.girlId,
this.resId
);
if (isUnlock) {
let data = {
url: girlData.getGrilPhotoPic(this.categoryId, this.girlId, this.resId),
isImg: true,
};
NavigationManager.Instance.openPopupPanel("ShowPanel", data);
2025-09-10 21:49:39 +08:00
} else {
NavigationManager.Instance.openPopupPanel("PopupGirlDetailPanel", {
2025-09-10 21:49:39 +08:00
category: this.categoryId,
resId: this.resId,
girlId: this.girlId,
base: this,
type: proto.cs.EnmResType.ERT_Image,
});
2025-07-25 18:27:30 +08:00
}
2025-09-10 21:49:39 +08:00
//
}
popUp() {
2025-09-17 16:12:54 +08:00
if (this.isAnimating) return;
this.isAnimating = true;
2025-09-10 21:49:39 +08:00
tween(this.node)
2025-09-17 16:12:54 +08:00
.to(0.5, { position: this.getOnscreenPosition() }, { easing: "backOut" })
.call(() => {
this.scheduleOnce(() => {
this.popDown();
}, 3);
})
2025-09-10 21:49:39 +08:00
.start();
}
popDown() {
tween(this.node)
2025-09-17 16:12:54 +08:00
.to(0.5, { position: this.getOffscreenPosition() }, { easing: "backIn" })
.call(() => {
this.isAnimating = false;
})
2025-09-10 21:49:39 +08:00
.start();
}
2025-07-25 18:27:30 +08:00
}