import { _decorator, AssetManager, Component, Label, Node, randomRangeInt, Sprite, UITransform, } from "cc"; import ResManager from "db://assets/Scripts/Main/Manager/ResManager"; import Utils from "db://assets/Scripts/Main/Common/Utils"; import { NavigationManager, PanelType, PageTransitionType, } from "../manager/NavigationManager"; import { PriceType } from "../../schema/schema"; import LanguageUtils from "../../Main/Common/LanguageUtils"; import { InnerMsgCode } from "../../Main/Config/InnerMsgCode"; import { DataManager, DataId } from "../data/DataManager"; import { GirlData } from "../data/GirlData"; import { EnvData } from "../data/EnvData"; import { logger } from "db://assets/Scripts/Main/Common/Logger"; import { GButton } from "../../Main/Common/GButton"; import { GirlListPanel } from "../ui/panels/GirlListPanel"; const { ccclass, property } = _decorator; @ccclass("GirlListItem") export class GirlListItem extends Component { @property(Sprite) avatar: Sprite; @property(Label) girlName: Label; @property(Label) tags: Label; @property(Node) chatIcon: Node; @property(Node) detailBtn: Node; @property(Node) starParent: Node; @property(Node) loading: Node; stars: Sprite[]; id: number = -1; nameKey: string; tagKey: string; category: number; private onLanguageChangeCallback = () => { if (!this.girlName || !this.tags) return; this.girlName.string = LanguageUtils.getText(this.nameKey); let desc = ""; const tags = LanguageUtils.getText(this.tagKey).split("|"); for (let i = 0; i < tags.length; i++) { if (i != 0) desc += "\n"; desc += tags[i]; } this.tags.string = desc; }; protected onLoad(): void { Utils.addInnerEL( InnerMsgCode.LanguageChange, this, this.onLanguageChangeCallback ); GButton.BandClick(this.chatIcon, this.onClickChat, this); GButton.BandClick(this.detailBtn, this.onClickDetail, this); } protected onDestroy(): void { Utils.removeInnerEL( InnerMsgCode.LanguageChange, this, this.onLanguageChangeCallback ); } baseNode: GirlListPanel; refreshData(category: number, girlId: number, baseNode: GirlListPanel) { if (!this.stars) { this.stars = this.starParent.getComponentsInChildren(Sprite); } this.category = category; this.baseNode = baseNode; this.id = girlId; // 数据 const girlData = DataManager.I.getDataById(DataId.Girl); this.nameKey = girlData.getGrilName(this.category.toString(), this.id); this.girlName.string = LanguageUtils.getText(this.nameKey); this.tagKey = girlData.getGrilTagKey(this.category.toString(), this.id); this.tags.string = LanguageUtils.getText(this.tagKey); this.starParent.active = true; this.chatIcon.active = true; let avatarPath = girlData.getGrilAvatar(this.category.toString(), this.id); this.loading.active = true; const envData = DataManager.I.getDataById(DataId.Env); let newPath = envData.cdn + "/" + "Girls/" + avatarPath + ".png"; //listAvatarPath = listAvatarPath.replace("Avatar", "avatar"); //临时 ResManager.I.changeRemoteSpriteFrame(this.avatar, newPath, () => { let sizeTran = this.avatar.node.parent.getComponent(UITransform); Utils.adjustBgPixelRatioToSize(sizeTran.contentSize, this.avatar.node, 1); this.loading.active = false; }); const star = girlData.getStar(this.category.toString(), this.id); logger.log("好感度:" + star); for (let i = 0; i < this.stars.length; i++) { const element = this.stars[i]; if (star > i) { ResManager.I.changeResourceSpriteFrame( element, "ui/common/heart/heart" ); } else { ResManager.I.changeResourceSpriteFrame( element, "ui/common/heart/heart_empty" ); } } } refreshBuy(success: boolean) { if (success) { this.refreshData(this.category, this.id, this.baseNode); } } reset() { this.id = -1; this.category = 0; this.nameKey = ""; this.tagKey = ""; this.baseNode = null; // 重置UI状态 this.node.active = false; this.loading.active = false; // 清理文本内容 if (this.girlName) this.girlName.string = ""; if (this.tags) this.tags.string = ""; if (this.starParent) this.starParent.active = false; if (this.chatIcon) this.chatIcon.active = false; // 清理头像 if (this.avatar) { this.avatar.spriteFrame = null; } // 清理星级显示 if (this.stars) { for (let star of this.stars) { star.spriteFrame = null; } } } onClickDetail() { const girlData = DataManager.I.getDataById(DataId.Girl); // 是否已经解锁 NavigationManager.Instance.setSelectedGirlId(this.id); NavigationManager.Instance.setSelectedCategoryId(this.category); // 以subpanel方式打开GirlDetailPanel const currentPanel = NavigationManager.Instance.getCurrentActivePanelNode(); if (currentPanel) { NavigationManager.Instance.openSubPanel( "GirlDetailPanel", currentPanel, this.id, { openAnimation: PageTransitionType.SLIDE_LEFT, closeAnimation: PageTransitionType.SLIDE_RIGHT, hideBasePanel: true, // 隐藏底层panel,实现全屏显示 } ); } else { logger.warn("[GirlListItem] 无法获取当前激活的主页面"); } this.baseNode.close(); } onClickChat() { const girlData = DataManager.I.getDataById(DataId.Girl); NavigationManager.Instance.setSelectedGirlId(this.id); NavigationManager.Instance.setSelectedCategoryId( girlData.getGrilCategoryById(this.id) ); NavigationManager.Instance.switchToPanel( PanelType.PAST_GIRL_LIST, false, (base) => { const chatData = { girlId: this.id, base: base }; NavigationManager.Instance.openSubPanel("ChatPanel", base, chatData, { openAnimation: PageTransitionType.SLIDE_LEFT, closeAnimation: PageTransitionType.SLIDE_RIGHT, }); } ); } }