AwardGetLayer.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import { find, Node, _decorator } from 'cc';
  2. import { BaseLayer } from '../../common/BaseLayer';
  3. import { cocosUtil } from '../../utils/cocosUtil';
  4. import { constants } from '../data/constants';
  5. import { designManager } from '../manager/designManager';
  6. import { iconManager } from '../manager/iconManager';
  7. import { levelManager } from '../manager/levelManager';
  8. import { sdkManager } from '../manager/sdkManager';
  9. import { playerModel } from '../model/playerModel';
  10. const { ccclass, property } = _decorator;
  11. @ccclass('AwardGetLayer')
  12. export class AwardGetLayer extends BaseLayer {
  13. coinLayer: Node;
  14. skillLayer: Node;
  15. coinNumNode: Node;
  16. skillIcon: Node;
  17. skillNumNode: Node;
  18. btnAdGet: Node;
  19. isBoss: boolean;
  20. coin: number;
  21. skillId: number;
  22. skillNum: number;
  23. onLoad() {
  24. super.onLoad();
  25. this.coinLayer = this.getNodeByPath("info/coinLayer");
  26. this.skillLayer = this.getNodeByPath("info/skillLayer");
  27. this.coinNumNode = find("num", this.coinLayer);
  28. this.skillIcon = find("icon", this.skillLayer);
  29. this.skillNumNode = find("num", this.skillLayer);
  30. this.btnAdGet = this.getNodeByPath("btns/btnAdGet");
  31. this.isBoss = this.obj.isBoss;
  32. this.coin = this.obj.coin;
  33. this.skillId = this.obj.skillId;
  34. this.skillNum = 1;
  35. let titleNode1 = this.getNodeByPath("info/title1");
  36. let titleNode2 = this.getNodeByPath("info/title2");
  37. if (this.obj.isBox) {
  38. titleNode2.active = true;
  39. titleNode1.active = false;
  40. } else {
  41. titleNode1.active = true;
  42. titleNode2.active = false;
  43. }
  44. this.initUI();
  45. }
  46. initUI() {
  47. this.initEffect();
  48. if (this.coin > 0) {
  49. this.coinLayer.active = true;
  50. this.skillLayer.active = false;
  51. this.coinNumNode.active = true;
  52. this.skillIcon.active = false;
  53. this.skillNumNode.active = false;
  54. this.setString(this.coinNumNode, "+" + this.coin);
  55. } else if (this.skillId > 0) {
  56. this.coinLayer.active = false;
  57. this.skillLayer.active = true;
  58. this.coinNumNode.active = false;
  59. this.skillIcon.active = true;
  60. this.skillNumNode.active = true;
  61. this.setString(this.skillNumNode, "x" + this.skillNum);
  62. let row = designManager.instance.getRowById(constants.tableName.skill, this.skillId);
  63. iconManager.instance.setSprite(this.skillIcon, row.icon);
  64. }
  65. }
  66. initEffect() {
  67. cocosUtil.tweenScaleBreath(this.btnAdGet);
  68. }
  69. onButtonClick(node: Node, name: string) {
  70. switch (name) {
  71. case "btnAdGet":
  72. this.onClickBtnAdGet(node);
  73. break;
  74. case "btnGet":
  75. this.onClickBtnGet(node);
  76. break;
  77. default:
  78. break;
  79. }
  80. }
  81. closeLayer() {
  82. super.closeLayer();
  83. if (this["cb"]) {
  84. this["cb"]();
  85. }
  86. }
  87. onClickBtnGet(node: Node) {
  88. if (this.coin > 0) {
  89. playerModel.instance.addCoin(this.coin);
  90. this.openCoinGetEffectLayer(this.coinNumNode);
  91. } else if (this.skillId > 0) {
  92. playerModel.instance.addSkillNumById(this.skillId, this.skillNum);
  93. }
  94. this.closeLayer();
  95. if (this.isBoss) {
  96. levelManager.instance.bossBoxHasGet = true;
  97. levelManager.instance.judgeLevelSuccess();
  98. }
  99. }
  100. onClickBtnAdGet(node: Node) {
  101. sdkManager.instance.sendEvent("观看激励视频-双倍奖励");
  102. sdkManager.instance.openAd((st: number) => {
  103. if (st != 1) {
  104. return;
  105. }
  106. this.btnAdGet.active = false;
  107. if (this.coin > 0) {
  108. // 金币加倍
  109. this.coin *= 2;
  110. this.initUI();
  111. } else if (this.skillId > 0) {
  112. // 技能加倍
  113. this.skillNum++;
  114. this.initUI();
  115. }
  116. sdkManager.instance.sendEvent("观看完激励视频-双倍奖励");
  117. });
  118. }
  119. }