LevelHomeArtistItem.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. const GameModule = require("../utils/GameModule");
  6. cc.Class({
  7. extends: cc.Component,
  8. properties: {
  9. // 0是自己, 1是好友
  10. artistBgSpriteFrames: [cc.SpriteFrame],
  11. bgSprite: cc.Sprite,
  12. addBtn: cc.Button,
  13. artistNode: cc.Node,
  14. headSprite: cc.Sprite,
  15. tipNode: cc.Node,
  16. topSprite: cc.Sprite,
  17. bototomSprite: cc.Sprite,
  18. },
  19. /**
  20. *
  21. * @param {*} buildingInfo
  22. * @param {number} uid 目标的uid
  23. * @param {boolean} isSelf 判断是不是自己的界面,false是好友界面,true是自己界面
  24. * @param {*} showTop
  25. * @param {*} showBottom
  26. */
  27. initWithBuildingInfo(buildingInfo, uid, isSelf, showTop = false, showBottom = false) {
  28. this.setStyle(LevelHomeArtistItemStyle.Add);
  29. this.buildingInfo = buildingInfo;
  30. this.uid = uid;
  31. this.isSelf = isSelf;
  32. this.topSprite.node.active = showTop;
  33. this.bototomSprite.node.active = showBottom;
  34. },
  35. /**
  36. *
  37. * @param {*} buildingInfo
  38. * @param {number} uid 目标的uid
  39. * @param {boolean} isSelf 判断是不是自己的界面,false是好友界面,true是自己界面
  40. * @param {*} artistData
  41. * @param {*} showTop
  42. * @param {*} showBottom
  43. */
  44. initWithArtistData(buildingInfo, uid, isSelf, artistData, showTop = false, showBottom = false) {
  45. this.setStyle(LevelHomeArtistItemStyle.Artist);
  46. this.artistData = artistData;
  47. this.buildingInfo = buildingInfo;
  48. this.uid = uid;
  49. this.isSelf = isSelf;
  50. // 自己艺人
  51. if (this.artistData.role === 2) {
  52. this.bgSprite.spriteFrame = this.artistBgSpriteFrames[0];
  53. } else {
  54. this.bgSprite.spriteFrame = this.artistBgSpriteFrames[1];
  55. }
  56. Api.createImageFromUrl(this.artistData.head, (spriteFrame) => {
  57. this.headSprite.spriteFrame = spriteFrame;
  58. }, null);
  59. this.topSprite.node.active = showTop;
  60. this.bototomSprite.node.active = showBottom;
  61. },
  62. onLoad () {
  63. this.artistNode.on(cc.Node.EventType.TOUCH_END, _.debounce(() => {
  64. // 去好友家园, 并且这个艺人是该家园主人的艺人, 不能点击
  65. if (!this.isSelf && this.artistData.role === 2) { return; }
  66. // 是自己的家园, 并且是自己的艺人, 弹出自己的艺人列表, 可以切换驻场艺人
  67. if (this.isSelf && this.artistData.role === 2) {
  68. AlertManager.showArtistResident(this.buildingInfo, this.uid, this.isSelf);
  69. } else {
  70. // 自己家园,驱赶好友的驻场艺人
  71. // 获取引导对象及引导状态
  72. let guide = GameModule.homeGuide.getComponent('HomeGuide')
  73. let guidePass = guide.guideState.state35.pass
  74. if(!guidePass) {
  75. // 如果没有触发过引导事件state35,
  76. // 立即触发该引导事件
  77. guide.handleState('state35');
  78. // 监听state35的点击回调,
  79. // 立即显示驱赶驻场艺人弹窗
  80. GameModule.homeGuide.on('Fire_state35', () => {
  81. AlertManager.showArtistOperationAlert(this.buildingInfo, this.uid, this.isSelf, this.artistData);
  82. // 同时显示state36的引导驱赶艺人提示
  83. setTimeout(() => {
  84. guide.handleState('state36');
  85. }, 400);
  86. })
  87. } else {
  88. // 如果已经触发过引导事件state35,
  89. // 跳过引导系统,直接显示弹窗内容
  90. AlertManager.showArtistOperationAlert(this.buildingInfo, this.uid, this.isSelf, this.artistData);
  91. }
  92. }
  93. }, 1000, true), this);
  94. this.handleAddArtist = _.debounce(() => {
  95. AlertManager.showArtistResident(this.buildingInfo, this.uid, this.isSelf);
  96. }, 1000, true);
  97. },
  98. setStyle(style) {
  99. if (this.style === style) {
  100. return;
  101. }
  102. switch (style) {
  103. case LevelHomeArtistItemStyle.Add:
  104. this.addBtn.node.active = true;
  105. this.artistNode.active = false;
  106. break;
  107. case LevelHomeArtistItemStyle.Artist:
  108. this.addBtn.node.active = false;
  109. this.artistNode.active = true;
  110. break;
  111. default:
  112. break;
  113. }
  114. this.style = style;
  115. },
  116. addArtist() {
  117. this.handleAddArtist();
  118. },
  119. update (dt) {
  120. if (this.style === LevelHomeArtistItemStyle.Artist
  121. && this.artistData
  122. && this.artistData.role === 4
  123. && this.isSelf) {
  124. let time = (Date.parse(new Date()) - this.artistData.stationTime) / 1000;
  125. if (time < 900) { // 入驻15分钟才可以召回
  126. this.tipNode.active = false;
  127. } else {
  128. this.tipNode.active = true;
  129. }
  130. }
  131. },
  132. });