import { _decorator, Color, Component, Graphics, Label, Mask, Node, Size, Sprite, SpriteFrame, UITransform } from 'cc'; import { aa } from '../../scripts/aa'; import { ch } from '../../ch/ch'; const { ccclass, property } = _decorator; const tSize = new Size(54, 54) @ccclass('ui_rank_item') export class ui_rank_item extends Component { @property(Node) private star1: Node; @property(Node) private star2: Node; @property(Node) private star3: Node; @property(Node) private star4: Node; @property(Node) private my: Node; @property(Label) private rank_txt: Label; @property(Label) private name_txt: Label; @property(Label) private type1_txt: Label; @property(Sprite) private head: Sprite; @property(SpriteFrame) private def_head: SpriteFrame; start() { } getNickName: Function = () => " " showInfo(index: number, type: number, data: any): void { index++; this.star1.active = index == 1; this.star2.active = index == 2; this.star3.active = index == 3; this.star4.active = index > 3; this.my.active = false if (index <= 3) { this.rank_txt.node.active = false; // 前三名隐藏文本 } else { this.rank_txt.node.active = true; // 其他名次显示 this.rank_txt.string = index.toString(); } //this.rank_txt.string = index.toString(); this.name_txt.string = this.getNickName(data); this.type1_txt.string = data.score; if (data.head && data.head != "image") { this.head.getComponent(UITransform).setContentSize(tSize) aa.Util.headIconMgr.showIcon(data.userId, data.head, this.head); } else { this.adaptationIcon(this.head, this.def_head, tSize) } } showMe(index: number, data: any) { let rankTxt = "未上榜" this.star1.active = false; this.star2.active = false; this.star3.active = false; this.star4.active = false; this.my.active = true if (index > 0) { rankTxt = index.toString() } this.rank_txt.string = rankTxt; this.name_txt.string = this.getNickName(data); this.type1_txt.string = data.score; // if (data.head && data.head != "image") { this.head.getComponent(UITransform).setContentSize(tSize) aa.Util.headIconMgr.showIcon(data.userId, data.head, this.head); } else { this.adaptationIcon(this.head, this.def_head, tSize) } } adaptationIcon(icon: Sprite, spriteFrameIcon: SpriteFrame, tSize: Size) { if (icon.spriteFrame != spriteFrameIcon) { if (spriteFrameIcon) { let size = spriteFrameIcon.originalSize //适配图片 let iconSize = new Size() let raito = size.width / size.height if (raito < 1) { iconSize.height = tSize.height iconSize.width = tSize.height * raito } else { iconSize.width = tSize.width iconSize.height = tSize.width / raito } icon.spriteFrame = spriteFrameIcon icon.getComponent(UITransform).setContentSize(iconSize) } } } protected onDestroy(): void { this.getNickName = (data: any) => "" } }