ArtistResidentItem.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. const Api = require('../net/Api');
  2. const { GameNotificationKey } = require("../utils/GameEnum");
  3. const HomeApi = require("../net/HomeApi");
  4. const AlertManager = require("../utils/AlertManager");
  5. cc.Class({
  6. extends: cc.Component,
  7. properties: {
  8. bgSpriteFrames: [cc.SpriteFrame],
  9. headSprite: cc.Sprite,
  10. nickRichText: cc.RichText,
  11. jobLevelLabel: cc.Label,
  12. jobTitleLabel: cc.Label,
  13. effectLabel: cc.Label,
  14. cancelResidentBtn: cc.Button,
  15. recallArtistBtn: cc.Button,
  16. bgSprite: {
  17. get: function() {
  18. if (!this._bgSprite) {
  19. this._bgSprite = this.getComponent(cc.Sprite);
  20. }
  21. return this._bgSprite;
  22. },
  23. set: function(value) {
  24. this._bgSprite = value;
  25. }
  26. }
  27. },
  28. init(uid, buildingInfo, isSelf, artistData, selectedCallback) {
  29. this.uid = uid;
  30. this.buildingInfo = buildingInfo;
  31. this.artistData = artistData;
  32. this.isSelf = isSelf;
  33. this.selectedCallback = selectedCallback;
  34. this.jobLevelLabel.string = this.artistData.jobLevel;
  35. this.jobTitleLabel.string = this.artistData.jobName;
  36. if (this.artistData.isStationed === 0) { // 没有任何驻场艺人
  37. this.cancelResidentBtn.node.active = false;
  38. this.recallArtistBtn.node.active = false;
  39. this.bgSprite.spriteFrame = this.bgSpriteFrames[0];
  40. } else if (this.artistData.isStationed === 1) { // 入驻了自己家园
  41. this.cancelResidentBtn.node.active = true;
  42. this.recallArtistBtn.node.active = false;
  43. this.bgSprite.spriteFrame = this.bgSpriteFrames[1];
  44. } else { // 入驻他人家园
  45. this.cancelResidentBtn.node.active = false;
  46. this.recallArtistBtn.node.active = true;
  47. }
  48. this.nickRichText.string = `<color=#584a47>${this.artistData.nick}</c> <img src='50002'/>`;
  49. this.effectLabel.string = `加成效果: 收益增加${this.artistData.addition}%`;
  50. Api.createImageFromUrl(this.artistData.head, (spriteFrame) => {
  51. this.headSprite.spriteFrame = spriteFrame;
  52. }, null);
  53. },
  54. cancelResident() {
  55. this.cancelResidentEvent();
  56. } ,
  57. // 召回自己艺人
  58. recallArtist() {
  59. this.recallArtistEvent();
  60. },
  61. onLoad () {
  62. this.bgSprite = this.getComponent(cc.Sprite);
  63. this.node.on(cc.Node.EventType.TOUCH_END, function () {
  64. this._bgSprite.spriteFrame = this.bgSpriteFrames[1];
  65. this.selectedCallback(this.artistData);
  66. GameEvent.fire(GameNotificationKey.ChangeArtistResidentState, this.artistData.jobId)
  67. }, this);
  68. GameEvent.on(GameNotificationKey.ChangeArtistResidentState, this, (jobId) => {
  69. if (this.artistData.jobId != jobId) {
  70. this._bgSprite.spriteFrame = this.bgSpriteFrames[0];
  71. }
  72. });
  73. this.recallArtistEvent = _.debounce(() => {
  74. AlertManager.showArtistOperationAlert(this.buildingInfo, this.uid, this.isSelf, this.artistData);
  75. }, 1000, true);
  76. this.cancelResidentEvent = _.debounce(() => {
  77. HomeApi.friendExpelRecall(this.artistData.id || this.artistData.uid, (responseData) => {
  78. this.cancelResidentBtn.node.active = false;
  79. // 取消入驻要收取所有金币
  80. GameEvent.fire(GameNotificationKey.RefreshResidentArtistList);
  81. GameEvent.fire(GameNotificationKey.ResidentArtist, this.uid, this.buildingInfo.buildingId);
  82. GameEvent.fire(GameNotificationKey.NoticeRoleOpt, this.uid, 6);
  83. }, (code, msg) => {
  84. console.log(msg);
  85. });
  86. }, 1000, true);
  87. },
  88. onDestroy() {
  89. GameEvent.off(GameNotificationKey.ChangeArtistResidentState, this);
  90. },
  91. start () {
  92. },
  93. // update (dt) {},
  94. });