Files
18xchat/assets/Scripts/chat18x/uiitems/ThemeItem.ts
T

111 lines
3.1 KiB
TypeScript
Raw Normal View History

2025-08-11 16:08:59 +08:00
import { _decorator, Component, Label, Node, Sprite, UITransform } from "cc";
import { GButton } from "db://assets/Scripts/Main/Common/GButton";
import ResManager from "db://assets/Scripts/Main/Manager/ResManager";
import Utils from "db://assets/Scripts/Main/Common/Utils";
2025-09-18 14:06:53 +08:00
import {
NavigationManager,
PageTransitionType,
} from "../manager/NavigationManager";
import LanguageUtils from "../../Main/Common/LanguageUtils";
import { InnerMsgCode } from "../../Main/Config/InnerMsgCode";
2025-09-02 11:33:44 +08:00
import { DataManager, DataId } from "../data/DataManager";
import { ThemeData } from "../data/ThemeData";
2025-09-21 20:18:24 +08:00
import { logger } from "db://assets/Scripts/Main/Common/Logger";
2025-08-11 16:08:59 +08:00
const { ccclass, property } = _decorator;
@ccclass("ThemeItem")
export class ThemeItem extends Component {
@property(Sprite)
lockImg: Sprite;
2025-08-13 15:37:15 +08:00
@property(Sprite)
lockCover: Sprite;
2025-08-11 16:08:59 +08:00
@property(Label)
titleName: Label;
2025-09-18 14:06:53 +08:00
@property(UITransform)
titleNameBg: UITransform;
2025-08-11 16:08:59 +08:00
2025-09-11 15:01:03 +08:00
@property(Node)
loading: Node;
2025-08-11 16:08:59 +08:00
@property(Sprite)
img: Sprite;
2025-08-12 16:58:02 +08:00
private category: number;
2025-08-11 16:08:59 +08:00
private isLocked: boolean;
2025-08-12 19:49:50 +08:00
private baseNode: any;
2025-09-11 17:07:29 +08:00
2025-08-12 19:49:50 +08:00
key: string;
protected onLoad(): void {
Utils.addInnerEL(InnerMsgCode.LanguageChange, this, () => {
2025-09-18 14:06:53 +08:00
this.updateTitle();
2025-08-12 19:49:50 +08:00
});
}
protected onDestroy(): void {
Utils.removeInnerEL(InnerMsgCode.LanguageChange, this, () => {
2025-09-18 14:06:53 +08:00
this.updateTitle();
2025-08-12 19:49:50 +08:00
});
}
2025-09-20 11:43:13 +08:00
protected onEnable(): void {
this.updateTitle();
}
2025-08-12 19:49:50 +08:00
2025-09-18 14:06:53 +08:00
updateTitle() {
this.titleName.string = LanguageUtils.getText(this.key);
this.scheduleOnce(() => {
const size = this.titleName.getComponent(UITransform).contentSize;
this.titleNameBg.setContentSize(
size.x + 65,
this.titleNameBg.contentSize.y
);
}, 0);
}
refresh(themeId: number, parentPanel?: Node) {
2025-09-18 14:06:53 +08:00
if (this.loading) this.loading.active = true;
this.baseNode = parentPanel;
2025-09-02 11:33:44 +08:00
// 主题数据
const themeData = DataManager.I.getDataById<ThemeData>(DataId.Theme);
2025-08-13 15:37:15 +08:00
this.lockImg.node.active = this.lockCover.node.active =
2025-09-02 11:33:44 +08:00
!themeData.getIsReleaseById(themeId);
this.isLocked = !themeData.getIsReleaseById(themeId);
this.key = themeData.getLanKeyById(themeId);
2025-09-18 14:06:53 +08:00
this.updateTitle();
2025-09-02 11:33:44 +08:00
this.category = themeData.getCategoryById(themeId);
2025-08-11 16:08:59 +08:00
ResManager.I.changeBundleSpriteFrame(
this.img,
2025-09-02 11:33:44 +08:00
themeData.getPathById(themeId),
2025-08-11 16:08:59 +08:00
"Chat18x",
() => {
let sizeTran = this.img.node.parent.getComponent(UITransform);
2025-08-25 20:15:42 +08:00
Utils.adjustBgPixelRatioToSize(sizeTran.contentSize, this.img.node, 3);
2025-09-18 14:06:53 +08:00
if (this.loading) this.loading.active = false;
2025-08-11 16:08:59 +08:00
}
);
GButton.RemoveAndBandClick(this.node, this.OnClickThis, this);
}
OnClickThis() {
if (this.isLocked) {
return;
}
2025-09-11 17:07:29 +08:00
2025-09-21 20:18:24 +08:00
logger.log(
2025-09-18 14:06:53 +08:00
"[ThemeItem] Opening GirlListPanel for category:",
this.category
);
NavigationManager.Instance.setSelectedCategoryId(this.category);
2025-09-21 16:04:51 +08:00
NavigationManager.Instance.openSubPanel(
"GirlListPanel",
this.baseNode,
null,
{
openAnimation: PageTransitionType.SLIDE_LEFT,
closeAnimation: PageTransitionType.SLIDE_RIGHT,
}
);
2025-08-11 16:08:59 +08:00
}
}