123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- import { _decorator, Component, Node, Size, Sprite, SpriteFrame, UITransform, Vec2 } from 'cc';
- import { ch } from '../../../ch/ch';
- import { Hall } from '../../hall/Hall';
- const { ccclass, property } = _decorator;
- @ccclass('UI_Head_Icon')
- export class UI_Head_Icon extends Component {
- @property(Sprite)
- private head: Sprite;
- @property([SpriteFrame])
- private default_head: SpriteFrame[] = [];
- start() {
- }
- update(deltaTime: number) {
- }
- show(uid: string, head: string | null): void {
- const rc = this.default_head[ch.util.getRandomInt(0, this.default_head.length - 1)];
- Hall.getInstance().head_icon.showIcon(uid, head, this.head, rc).then((spf)=>{
- if(spf != null)
- this.adaptationIcon(this.head, spf, new Size(55,55));
- });
-
- }
- adaptationIcon(icon: Sprite, spriteFrameIcon: SpriteFrame, tSize: Size) {
- 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)
- }
- }
- }
|