| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- 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) => ""
- }
- }
|