Files
18xchat/assets/Scripts/Sub/UI/SceneBgLayer.ts
T

87 lines
2.4 KiB
TypeScript
Raw Normal View History

2025-07-17 17:18:21 +08:00
import { _decorator, isValid, Label, Node, Sprite, UITransform, view } from 'cc';
import Utils from '../../Main/Common/Utils';
import { InnerMsgCode } from '../../Main/Config/InnerMsgCode';
import li_BaseView from '../../Main/Common/li_BaseView';
import ResManager from '../../Main/Manager/ResManager';
import GlobalValue from '../../Main/Common/GlobalValue';
const { ccclass, property } = _decorator;
//场景背景层
@ccclass('SceneBgLayer')
export class SceneBgLayer extends li_BaseView {
private _nodeTab: any = {};
private _data;
private sceneBg: Sprite = null;
private sceneRole: Sprite = null;
private curBgPath: string = '';
private curRolePath: string = '';
//----重写父类接口---------------------------------------
onLoadCT() {
this.registerListenner();
Utils.parseNode(this.node, this._nodeTab)
this.sceneBg = this._nodeTab.sceneBg.getComponent(Sprite)!;
this.sceneRole = this._nodeTab.sceneRole.getComponent(Sprite)!;
}
openUIDataCT(data: any): void {
this._data = data
}
registerListenner() {
Utils.addInnerEL(InnerMsgCode.SceneLayerBgUp, this, this.resiveBgUp)
}
start() {
}
update(deltaTime: number) {
}
//刷新场景背景消息
resiveBgUp(data) {
if (GlobalValue.NpcVideoMod) {
return
}
if (data) {
this.refreshBg(data.bgPath, data.rolePath)
}
}
//刷新背景图,npc肖像
refreshBg(bgPath:string, rolePath:string) {
//背景图
if (isValid(this.sceneBg)) {
if (!this.sceneBg.node.active) {
this.sceneBg.node.active = true;
}
if (bgPath && bgPath != this.curBgPath) {
this.curBgPath = bgPath;
ResManager.I.changeBundleSpriteFrame(this.sceneBg, bgPath, "Raw", ()=>{
//调整背景图适配
Utils.adjustBgPixelRatio(this.sceneBg.node, 1)
})
}
}
//npc肖像
if (isValid(this.sceneRole)) {
if (!this.sceneRole.node.active) {
this.sceneRole.node.active = true;
}
if (rolePath && rolePath != this.curRolePath) {
this.curRolePath = rolePath;
ResManager.I.changeBundleSpriteFrame(this.sceneRole, rolePath, "Raw")
}
}
}
}