LevelHomeArtistItem.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. const { LevelHomeArtistItemStyle, ArtistOperation } = require('../utils/GameEnum')
  2. const Api = require('../net/Api');
  3. const DWTool = require('../utils/DWTool');
  4. const AlertManager = require('../utils/AlertManager');
  5. cc.Class({
  6. extends: cc.Component,
  7. properties: {
  8. // 0是自己, 1是好友
  9. artistBgSpriteFrames: [cc.SpriteFrame],
  10. bgSprite: cc.Sprite,
  11. addBtn: cc.Button,
  12. artistNode: cc.Node,
  13. headSprite: cc.Sprite,
  14. tipNode: cc.Node,
  15. topSprite: cc.Sprite,
  16. bototomSprite: cc.Sprite,
  17. },
  18. // LIFE-CYCLE CALLBACKS:
  19. initWithBuildingInfo(buildingInfo, uid, isSelf, showTop = false, showBottom = false) {
  20. this.setStyle(LevelHomeArtistItemStyle.Add);
  21. this.buildingInfo = buildingInfo;
  22. this.uid = uid;
  23. this.isSelf = isSelf;
  24. this.topSprite.node.active = showTop;
  25. this.bototomSprite.node.active = showBottom;
  26. },
  27. initWithArtistData(buildingInfo, uid, isSelf, artistData, showTop = false, showBottom = false) {
  28. this.setStyle(LevelHomeArtistItemStyle.Artist);
  29. this.artistData = artistData;
  30. this.buildingInfo = buildingInfo;
  31. this.uid = uid;
  32. this.isSelf = isSelf;
  33. // 自己艺人
  34. if (this.artistData.role === 2) {
  35. this.bgSprite.spriteFrame = this.artistBgSpriteFrames[0];
  36. } else {
  37. this.bgSprite.spriteFrame = this.artistBgSpriteFrames[1];
  38. }
  39. Api.createImageFromUrl(this.artistData.head, (spriteFrame) => {
  40. this.headSprite.spriteFrame = spriteFrame;
  41. }, null);
  42. this.topSprite.node.active = showTop;
  43. this.bototomSprite.node.active = showBottom;
  44. },
  45. onLoad () {
  46. this.artistNode.on(cc.Node.EventType.TOUCH_END, _.debounce(() => {
  47. // 去好友家园, 并且这个艺人是该家园主人的艺人, 不能点击
  48. if (!this.isSelf && this.artistData.role === 2) { return; }
  49. // 是自己的家园, 并且是自己的艺人, 弹出自己的艺人列表, 可以切换驻场艺人
  50. if (this.isSelf && this.artistData.role === 2) {
  51. AlertManager.showArtistResident(this.buildingInfo, this.uid, this.isSelf);
  52. } else {
  53. AlertManager.showArtistOperationAlert(this.buildingInfo, this.uid, this.isSelf, this.artistData);
  54. }
  55. }, 1000, true), this);
  56. this.handleAddArtist = _.debounce(() => {
  57. AlertManager.showArtistResident(this.buildingInfo, this.uid, this.isSelf);
  58. }, 1000, true);
  59. },
  60. setStyle(style) {
  61. if (this.style === style) {
  62. return;
  63. }
  64. switch (style) {
  65. case LevelHomeArtistItemStyle.Add:
  66. this.addBtn.node.active = true;
  67. this.artistNode.active = false;
  68. break;
  69. case LevelHomeArtistItemStyle.Artist:
  70. this.addBtn.node.active = false;
  71. this.artistNode.active = true;
  72. break;
  73. default:
  74. break;
  75. }
  76. this.style = style;
  77. },
  78. addArtist() {
  79. this.handleAddArtist();
  80. },
  81. update (dt) {
  82. if (this.style === LevelHomeArtistItemStyle.Artist
  83. && this.artistData
  84. && this.artistData.role === 4
  85. && this.isSelf) {
  86. let time = (Date.parse(new Date()) - this.artistData.stationTime) / 1000;
  87. if (time < 900) { // 入驻15分钟才可以召回
  88. this.tipNode.active = false;
  89. } else {
  90. this.tipNode.active = true;
  91. }
  92. }
  93. },
  94. });