LevelHomeArtistItem.js 3.3 KB

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