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, PageTransitionType, } from "../manager/NavigationManager"; import LanguageUtils from "../../Main/Common/LanguageUtils"; import { InnerMsgCode } from "../../Main/Config/InnerMsgCode"; import { DataManager, DataId } from "../data/DataManager"; import { ThemeData } from "../data/ThemeData"; import { logger } from "db://assets/Scripts/Main/Common/Logger"; const { ccclass, property } = _decorator; @ccclass("ThemeItem") export class ThemeItem extends Component { @property(Sprite) lockImg: Sprite; @property(Sprite) lockCover: Sprite; @property(Label) titleName: Label; @property(UITransform) titleNameBg: UITransform; @property(Node) loading: Node; @property(Sprite) img: Sprite; private category: number; private isLocked: boolean; private baseNode: any; key: string; protected onLoad(): void { Utils.addInnerEL(InnerMsgCode.LanguageChange, this, () => { this.updateTitle(); }); } protected onDestroy(): void { Utils.removeInnerEL(InnerMsgCode.LanguageChange, this, () => { this.updateTitle(); }); } protected onEnable(): void { this.updateTitle(); } 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) { if (this.loading) this.loading.active = true; this.baseNode = parentPanel; // 主题数据 const themeData = DataManager.I.getDataById(DataId.Theme); this.lockImg.node.active = this.lockCover.node.active = !themeData.getIsReleaseById(themeId); this.isLocked = !themeData.getIsReleaseById(themeId); this.key = themeData.getLanKeyById(themeId); this.updateTitle(); this.category = themeData.getCategoryById(themeId); ResManager.I.changeBundleSpriteFrame( this.img, themeData.getPathById(themeId), "Chat18x", () => { let sizeTran = this.img.node.parent.getComponent(UITransform); Utils.adjustBgPixelRatioToSize(sizeTran.contentSize, this.img.node, 3); if (this.loading) this.loading.active = false; } ); GButton.RemoveAndBandClick(this.node, this.OnClickThis, this); } OnClickThis() { if (this.isLocked) { return; } logger.log( "[ThemeItem] Opening GirlListPanel for category:", this.category ); NavigationManager.Instance.setSelectedCategoryId(this.category); NavigationManager.Instance.openSubPanel( "GirlListPanel", this.baseNode, null, { openAnimation: PageTransitionType.SLIDE_LEFT, closeAnimation: PageTransitionType.SLIDE_RIGHT, } ); } }