Layout_Rank.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { _decorator, Button, Component, Label, Node, SpriteFrame, Toggle } from 'cc';
  2. import { ui_rank_item } from './ui_rank_item';
  3. import List from '../../scripts/Component/List/List';
  4. import { Transmission } from '../../scripts/Component/data/Transmission';
  5. const { ccclass, property } = _decorator;
  6. type TransmissionType = {
  7. getRankByType:(type: number, cb?: (data: any, me: any) => void)=>void
  8. getNickName:(data: any)=>string
  9. }
  10. let type: number = 1;
  11. @ccclass('Layout_Rank')
  12. export class Layout_Rank extends Component {
  13. private _data: any;
  14. @property(Transmission)
  15. transmission: Transmission = null
  16. @property(Node)
  17. btnRank1: Node;
  18. @property(Node)
  19. btnRank2: Node;
  20. //列表
  21. @property(List)
  22. list: List = null;
  23. @property(ui_rank_item)
  24. me: ui_rank_item;
  25. onListRender(item: any, idx: number) {
  26. this.onList(item, idx);
  27. }
  28. showMe(data) {
  29. this.me.getNickName = this.transmission.data.getNickName
  30. this.me.node.active = true
  31. console.log("ME DATA:", data);
  32. this.me.showMe(data.rank, data)
  33. }
  34. protected start(): void {
  35. this.transmission.onSave(() => {
  36. this.btnRank1.on(Node.EventType.TOUCH_END, () => this.onType(2), this)
  37. this.btnRank2.on(Node.EventType.TOUCH_END, () => this.onType(1), this)
  38. this.showType();
  39. })
  40. }
  41. private onType(t: number): void {
  42. if (type == t) return;
  43. type = t;
  44. this.showType();
  45. }
  46. private showType(): void {
  47. //显示
  48. // let layout = this.layout as Layout_Rank;
  49. this.btnRank1.active = type == 1;
  50. this.btnRank2.active = type == 2;
  51. this.me.node.active = false;
  52. // //
  53. this.list.numItems = 0;
  54. let transmission = this.transmission.data as TransmissionType
  55. transmission.getRankByType(type,(data,me)=>{
  56. this._data = data;
  57. this.list.numItems = this._data.length;
  58. if(me){
  59. this.showMe(me)
  60. }
  61. })
  62. }
  63. public onList(item: Node, index: number) {
  64. let uiItem = item.getComponent(ui_rank_item)
  65. let transmission = this.transmission.data as TransmissionType
  66. uiItem.getNickName = transmission.getNickName;
  67. uiItem.showInfo(index, type, this._data[index]);
  68. };
  69. }