home_bottom_rank_item.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { _decorator, Component, Label, Node, Sprite, tween, UITransform, Vec3 } from 'cc';
  2. import { uiManager } from '../../manager/uiManager';
  3. import { rankData } from '../../data';
  4. import { GameManager } from '../../GameManager';
  5. import { tools } from '../../tools';
  6. import { dataManager } from '../../manager/dataManager';
  7. const { ccclass, property } = _decorator;
  8. @ccclass('home_bottom_rank_item')
  9. export class home_bottom_rank_item extends Component {
  10. @property(Node) img_car:Node = null
  11. @property(Node) lab_nickname:Node = null
  12. @property(Node) lab_score:Node = null
  13. @property(Node) lab_jiancheng:Node = null
  14. private m_data:rankData = null
  15. private m_cb = null
  16. protected start(): void {
  17. uiManager.Instance().onButtonListen(this.node, ()=>{
  18. if(this.m_cb!=null) {
  19. this.m_cb(this)
  20. }
  21. })
  22. }
  23. public initView(data:rankData, cb) {
  24. this.m_data = data
  25. this.m_cb = cb
  26. this.img_car.getComponent(Sprite).spriteFrame = dataManager.getUserRankCarSf(data.car_id, data.user_id)
  27. tools.labelCutString(this.lab_nickname,data.nickName,5)
  28. this.lab_score.getComponent(Label).string = data.score + '分'
  29. this.lab_jiancheng.getComponent(Label).string = data.province_code
  30. }
  31. public getData():rankData {
  32. return this.m_data
  33. }
  34. public startAnimation(timeout:number) {
  35. let origin_pos = this.node.getPosition()
  36. let y = origin_pos.y - this.node.getComponent(UITransform).height - 80
  37. let init_pos = new Vec3(origin_pos.x,y,0)
  38. this.node.setPosition(init_pos)
  39. setTimeout(()=>{
  40. tween(this.node).to(0.25,{position: new Vec3(origin_pos.x,origin_pos.y,0)}).start()
  41. },timeout)
  42. }
  43. }