ArtistResidentItem.js 4.1 KB

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