import { _decorator, Component, Label, Node, Sprite, UITransform } from "cc"; import Utils from "../../Main/Common/Utils"; import { GButton } from "../../Main/Common/GButton"; import { DataManager, DataId } from "../data/DataManager"; import { GirlData } from "../data/GirlData"; import LanguageUtils from "../../Main/Common/LanguageUtils"; import ResManager from "../../Main/Manager/ResManager"; import { EnvData } from "../data/EnvData"; import { NavigationManager, PanelType, PageTransitionType, } from "../manager/NavigationManager"; import { logger } from "../../Main/Common/Logger"; const { ccclass, property } = _decorator; @ccclass("RecomandItem") export class RecomandItem extends Component { private _nodeTab: any = {}; private recPic: Sprite; private girlName: Label; private tag: Label; private heartParent: Node; private hearts: Sprite[] = []; private chatBtn: Node; private id: number; init() { Utils.parseNode(this.node, this._nodeTab); this.recPic = this._nodeTab.recPic.getComponent(Sprite); this.girlName = this._nodeTab.name.getComponent(Label); this.tag = this._nodeTab.tag.getComponent(Label); this.heartParent = this._nodeTab.heartBg; this.heartParent.children.forEach((a) => this.hearts.push(a.getComponent(Sprite)) ); this.chatBtn = this._nodeTab.chatBtn; GButton.BandClick(this.chatBtn, this.chatToHer, this); GButton.BandClick(this._nodeTab.detailBtn, this.gotoDetail, this); } refresh(girlId: number) { this.id = girlId; const girlData = DataManager.I.getDataById(DataId.Girl); const category = girlData.getGrilCategoryById(girlId); const rectNameKey = girlData.getRecommendGrilName(); this.girlName.string = LanguageUtils.getText(rectNameKey); const tagkey = girlData.getGrilTagKey(category.toString(), girlId); this.tag.string = LanguageUtils.getText(tagkey); let avatarPath = girlData.getRecommendGrilAvatar(); const starCount = girlData.getStar(category.toString(), girlId); for (let i = 0; i < this.hearts.length; i++) { const element = this.hearts[i]; if (starCount > i) { ResManager.I.changeResourceSpriteFrame( element, "ui/common/heart/heart" ); } else { ResManager.I.changeResourceSpriteFrame( element, "ui/common/heart/heart_empty" ); } } // 加载远程资源 const envData = DataManager.I.getDataById(DataId.Env); let newPath = envData.cdn + "/" + "Girls/" + avatarPath + ".png"; ResManager.I.changeRemoteSpriteFrame(this.recPic, newPath, () => { let sizeTran = this.recPic.node.parent.getComponent(UITransform); Utils.adjustBgPixelRatioToSize(sizeTran.contentSize, this.recPic.node, 1); }); } chatToHer() { 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, }); } ); } gotoDetail() { const girlData = DataManager.I.getDataById(DataId.Girl); NavigationManager.Instance.setSelectedGirlId(this.id); NavigationManager.Instance.setSelectedCategoryId( girlData.getGrilCategoryById(this.id) ); // 以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("[RecomandItem] 无法获取当前激活的主页面"); } } }