StarHandbookDesc.js 3.8 KB

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