StarHandbookDesc.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. const GameModule = require("../utils/GameModule");
  2. const DWTool = require("../utils/DWTool");
  3. const StarApi = require('../net/StarApi');
  4. const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
  5. cc.Class({
  6. extends: cc.Component,
  7. properties: {
  8. nameLabel: cc.Label,
  9. conditionLabel: cc.Label,
  10. figure: cc.Sprite, //明星图片
  11. defaultFigureSpriteFrame: cc.SpriteFrame,
  12. countLabel: cc.Label,
  13. roomCountLabel: cc.Label,
  14. restCountLabel: cc.Label
  15. },
  16. // LIFE-CYCLE CALLBACKS:
  17. onLoad () {
  18. this.isDoing = false;
  19. },
  20. start () {
  21. },
  22. configData(starInfo) {
  23. this.starInfo = starInfo;
  24. //获取到配置表的明星数据
  25. let imageId = 50000 + starInfo.starId;
  26. this.figure.spriteFrame = this.defaultFigureSpriteFrame;
  27. DWTool.loadResSpriteFrame(`./textures/star_stand/stand_${imageId}`)
  28. .then((spriteFrame) => {
  29. this.figure.spriteFrame = spriteFrame;
  30. }).catch((err) => {
  31. console.log(err);
  32. });
  33. let star = GameGlobal.BuildingManager.getStarInfo(starInfo.starId);
  34. this.nameLabel.string = star.name;
  35. if (star.starDesc) {
  36. this.conditionLabel.string = star.starDesc;
  37. } else {
  38. let roomName = GameGlobal.BuildingManager.getRoomName(star.roomId);
  39. if (roomName) {
  40. var descString = `需要 开启${roomName}`;
  41. }
  42. let buyStarCount = GameModule.userInfo.buyStarCount;
  43. let needStarCount = starInfo.itemCount;
  44. if (needStarCount > 0) {
  45. descString += `\n需要 ${star.desc}`;
  46. }
  47. if (descString) {
  48. this.conditionLabel.string = descString;
  49. } else {
  50. this.conditionLabel.string = '';
  51. }
  52. }
  53. this.countLabel.string = `${starInfo.starCount}人`;
  54. this.roomCountLabel.string = `${starInfo.starRoomCount}人`;
  55. let restCount = starInfo.starCount - starInfo.starRoomCount;
  56. if (restCount > 0) {
  57. this.restCountLabel.string = `${restCount}人`;
  58. } else {
  59. this.restCountLabel.string = "0人";
  60. }
  61. },
  62. refreshStarCount() {
  63. this.roomCountLabel.string = `${this.starInfo.starRoomCount}人`;
  64. let restCount = this.starInfo.starCount - this.starInfo.starRoomCount;
  65. if (restCount > 0) {
  66. this.restCountLabel.string = `${restCount}人`;
  67. } else {
  68. this.restCountLabel.string = "0人";
  69. }
  70. },
  71. dispatchToRoom() {
  72. if (this.isDoing) { return; }
  73. if (this.starInfo.starRoomCount >= this.starInfo.starCount) { return; } //判断没有可派出明星数量
  74. StarApi.dispatchStar(this.starInfo.starId, (respondData) => {
  75. this.isDoing = false;
  76. if (respondData.roomId > 0) {
  77. this.starInfo.starRoomCount += 1;
  78. this.refreshStarCount();
  79. GameEvent.fire(GameNotificationKey.StarEnterRoom, respondData.starId, respondData.roomId);
  80. } else {
  81. GameGlobal.commonAlert.showCommonErrorAlert("派出失败 \n没有空余的房间");
  82. }
  83. }, (code, msg) => {
  84. this.isDoing = false;
  85. GameGlobal.commonAlert.showCommonErrorAlert(`派出失败 \n${msg}`);
  86. })
  87. },
  88. recallFromRoom() {
  89. if (this.isDoing) { return; }
  90. if (this.starInfo.starRoomCount <= 0) { return; } //判断没有可召回明星数量
  91. StarApi.recallStar(this.starInfo.starId, (respondData) => {
  92. this.isDoing = false;
  93. this.starInfo.starRoomCount -= 1;
  94. this.refreshStarCount();
  95. GameEvent.fire(GameNotificationKey.StarLeaveRoom, respondData.starId, respondData.roomId);
  96. }, (code, msg) => {
  97. this.isDoing = false;
  98. GameGlobal.commonAlert.showCommonErrorAlert(`召回失败 \n${msg}`);
  99. })
  100. }
  101. // update (dt) {},
  102. });