HallScrollView.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. // Learn TypeScript:
  2. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
  7. import EventName from "../EventName/EventName";
  8. import HTTPS, { NetPost } from "../Template/HTTPS";
  9. import LocalData from "../Template/LocalData";
  10. import MyComponent from "../Template/MyComponent";
  11. import PopManger from "./PopManger";
  12. interface ResponseData {
  13. Version: string;
  14. Code: number;
  15. Message: string;
  16. Data: RoleData[];
  17. DataCount: number;
  18. PageCount: number;
  19. Mac: string;
  20. Timestamp: string;
  21. }
  22. interface RoleData {
  23. Id: number;
  24. Name: string;
  25. TotalNumber: number;
  26. List: UserData[];
  27. }
  28. interface UserData {
  29. UserId: number;
  30. Picture: string | null; // 可能是 null
  31. CollectId: number;
  32. CollectPicture: string;
  33. FullBodyPhoto: string;
  34. }
  35. const { ccclass, property } = cc._decorator;
  36. @ccclass
  37. export default class HallScrollView extends MyComponent {
  38. @property(cc.Node)
  39. content: cc.Node = null
  40. MyScrollView: cc.ScrollView = null
  41. onLoad() {
  42. super.onLoad();
  43. this.MyScrollView = this.node.getComponent(cc.ScrollView)
  44. this.regEvent(EventName.WhereMy, this.WhereMy, this)
  45. // this.content.children.forEach((e, index) => {
  46. // e.children.forEach((e1) => {
  47. // console.error(index);
  48. // if (index == 13) {
  49. // } else {
  50. // this.ddddd(e1)
  51. // }
  52. // })
  53. // })
  54. }
  55. start() {
  56. this.req()
  57. }
  58. Retrycount = 5
  59. req() {
  60. HTTPS.Instance.post(NetPost.GetPositionLevelRanking,
  61. {}).then((resp: ResponseData) => {
  62. for (let index = 0; index < resp.Data.length; index++) {
  63. const Data = resp.Data[index];
  64. const Node = this.content.children[index];
  65. for (let k = 0; k < Node.children.length; k++) {
  66. const RoleNode = Node.children[k];
  67. const RoleInfo = Data.List[k];
  68. if (RoleInfo) {
  69. // CollectPicture 半身
  70. // FullBodyPhoto 全身
  71. cc.assetManager.loadRemote(RoleInfo.FullBodyPhoto, (err, res: cc.Texture2D) => {
  72. if (!err) {
  73. RoleNode.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(res);
  74. RoleNode.active = true
  75. }
  76. })
  77. } else {
  78. RoleNode.active = false
  79. }
  80. }
  81. }
  82. })
  83. .catch((error) => {
  84. console.error('error');
  85. console.error(error);
  86. if (this.Retrycount-- > 0) {
  87. this.req()
  88. }
  89. })
  90. }
  91. WhereMy() {
  92. this.MyScrollView.stopAutoScroll()
  93. let contentNode = this.node.getChildByName("view").getChildByName("content")
  94. contentNode.height
  95. let index = LocalData.getInstance().getMyWorkplaceLevel()
  96. const y = contentNode.getChildByName(index + '').getPosition().y
  97. this.MyScrollView.scrollToOffset(cc.v2(0, Math.abs(y)), 0.3)
  98. }
  99. // ddddd(node: cc.Node) {
  100. // let path = 'Texture/Start/Desk/1/CEO' + this.getRandomNumber(1, 28)
  101. // PopManger.getInstance().LoadAssets<cc.Texture2D>(path).then((sp) => {
  102. // if (sp) {
  103. // node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(sp)
  104. // }
  105. // }).catch((error) => {
  106. // // 加载失败的处理
  107. // });
  108. // }
  109. // getRandomNumber(min: number, max: number): number {
  110. // return Math.floor(Math.random() * (max - min + 1)) + min;
  111. // }
  112. // update (dt) {}
  113. }