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

68 lines
2.2 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";
import { NavigationManager } 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-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;
@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
key: string;
protected onLoad(): void {
Utils.addInnerEL(InnerMsgCode.LanguageChange, this, () => {
this.titleName.string = LanguageUtils.getText(this.key);
});
}
protected onDestroy(): void {
Utils.removeInnerEL(InnerMsgCode.LanguageChange, this, () => {
this.titleName.string = LanguageUtils.getText(this.key);
});
}
2025-09-02 11:33:44 +08:00
refresh(themeId: number) {
// 主题数据
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);
this.titleName.string = LanguageUtils.getText(themeData.getLanKeyById(themeId));
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-08-11 16:08:59 +08:00
}
);
GButton.RemoveAndBandClick(this.node, this.OnClickThis, this);
}
OnClickThis() {
if (this.isLocked) {
return;
}
2025-08-12 16:58:02 +08:00
NavigationManager.Instance.navigateToGirlList(this.category);
2025-08-11 16:08:59 +08:00
}
}