OtherActor.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. const DWTool = require('../utils/DWTool');
  2. const Notikey = require('../utils/GameEnum').GameNotificationKey;
  3. const HomeApi = require("../net/HomeApi");
  4. cc.Class({
  5. extends: cc.Component,
  6. properties: {
  7. noActorTipLabel: cc.Label,
  8. confirmButton: cc.Button,
  9. scrollView: cc.ScrollView,
  10. _otherActorItem: cc.Prefab,
  11. },
  12. onLoad() {
  13. this.artists = [];
  14. this.itemPool = new cc.NodePool();
  15. this.getNetwoekData();
  16. },
  17. init(artists) {
  18. this.artists = artists;
  19. if (this.artists === undefined || this.artists.length === 0) {
  20. this.noActorTipLabel.node.active = true;
  21. this.scrollView.node.active = false;
  22. } else {
  23. this.noActorTipLabel.node.active = false;
  24. this.scrollView.node.active = true;
  25. this.setNodePool().then(this.layout.bind(this));
  26. }
  27. },
  28. setNodePool() {
  29. return new Promise((resolve, reject) => {
  30. DWTool.loadResPrefab("./prefabs/other_actor_item")
  31. .then((prefab) => {
  32. this._otherActorItem = prefab;
  33. for (let index = 0; index < 21; index++) {
  34. let item = cc.instantiate(this._otherActorItem);
  35. this.itemPool.put(item);
  36. }
  37. resolve();
  38. });
  39. });
  40. },
  41. getNetwoekData() {
  42. HomeApi.friendGetArtists(this.uid, (responseData) => {
  43. console.log(responseData);
  44. this.init(responseData.list);
  45. }, (err) => {
  46. console.log(err);
  47. })
  48. },
  49. layout() {
  50. for (let i = 0; i < this.artists.length; i++) {
  51. let item = null;
  52. if (this.itemPool.size() > 0) {
  53. item = this.itemPool.get();
  54. } else {
  55. item = cc.instantiate(this._otherActorItem);
  56. }
  57. this.scrollView.content.addChild(item);
  58. item.getComponent('OtherActorItem').updateItem(this.artists[i], i);
  59. }
  60. },
  61. close() {
  62. this.node.destroy();
  63. }
  64. });