StarHandbookDesc.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 = Global.BuildingManager.getStarInfo(starInfo.starId);
  34. this.nameLabel.string = star.name;
  35. let roomName = Global.BuildingManager.getRoomName(star.roomId);
  36. if (roomName) {
  37. var descString = `需要 开启${roomName}`;
  38. }
  39. let buyStarCount = GameModule.userInfo.buyStarCount;
  40. let needStarCount = starInfo.itemCount;
  41. if (needStarCount > 0) {
  42. descString += `\n需要 ${star.desc}`;
  43. } else {
  44. }
  45. if (descString) {
  46. this.conditionLabel.string = descString;
  47. } else {
  48. this.conditionLabel.string = '';
  49. }
  50. this.countLabel.string = `${starInfo.starCount}人`;
  51. this.roomCountLabel.string = `${starInfo.starRoomCount}人`;
  52. let restCount = starInfo.starCount - starInfo.starRoomCount;
  53. if (restCount > 0) {
  54. this.restCountLabel.string = `${restCount}人`;
  55. } else {
  56. this.restCountLabel.string = "0人";
  57. }
  58. },
  59. refreshStarCount() {
  60. this.roomCountLabel.string = `${this.starInfo.starRoomCount}人`;
  61. let restCount = this.starInfo.starCount - this.starInfo.starRoomCount;
  62. if (restCount > 0) {
  63. this.restCountLabel.string = `${restCount}人`;
  64. } else {
  65. this.restCountLabel.string = "0人";
  66. }
  67. },
  68. dispatchToRoom() {
  69. if (this.isDoing) { return; }
  70. if (this.starInfo.starRoomCount >= this.starInfo.starCount) { return; } //判断没有可派出明星数量
  71. StarApi.dispatchStar(this.starInfo.starId, (respondData) => {
  72. this.isDoing = false;
  73. if (respondData.roomId > 0) {
  74. this.starInfo.starRoomCount += 1;
  75. this.refreshStarCount();
  76. GameEvent.fire(GameNotificationKey.StarEnterRoom, respondData.starId, respondData.roomId);
  77. } else {
  78. Global.commonAlert.showCommonErrorAlert("派出失败 \n没有空余的房间");
  79. }
  80. }, (code, msg) => {
  81. this.isDoing = false;
  82. Global.commonAlert.showCommonErrorAlert(`派出失败 \n${msg}`);
  83. })
  84. },
  85. recallFromRoom() {
  86. if (this.isDoing) { return; }
  87. if (this.starInfo.starRoomCount <= 0) { return; } //判断没有可召回明星数量
  88. StarApi.recallStar(this.starInfo.starId, (respondData) => {
  89. this.isDoing = false;
  90. this.starInfo.starRoomCount -= 1;
  91. this.refreshStarCount();
  92. GameEvent.fire(GameNotificationKey.StarLeaveRoom, respondData.starId, respondData.roomId);
  93. }, (code, msg) => {
  94. this.isDoing = false;
  95. Global.commonAlert.showCommonErrorAlert(`召回失败 \n${msg}`);
  96. })
  97. }
  98. // update (dt) {},
  99. });