UIGetSkill.ts 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import { Widget, _decorator, Node, Sprite, Label, SpriteFrame } from 'cc';
  2. import { SkillType } from '../enum/SkillType';
  3. import { SkillMgr } from '../manager/SkillMgr';
  4. import { GameMgr } from '../manager/GameMgr';
  5. import { UIBase } from '../scriptBase/UIBase';
  6. import { CfgSkillInfo } from '../config/CfgSkillInfo';
  7. import { ResMgr } from '../manager/ResMgr';
  8. import { Bundle } from '../enum/Bundle';
  9. import { AdMgr } from '../manager/AdMgr';
  10. import { AdvertMgr } from '../manager/AdvertMgr';
  11. const { ccclass, property, requireComponent } = _decorator;
  12. @ccclass('UI/UIGetSkill')
  13. @requireComponent(Widget)
  14. export class UIGetSkill extends UIBase {
  15. private skill0Bg: Node = null
  16. private skill1Bg: Node = null
  17. private skill2Bg: Node = null
  18. private icon: Sprite = null
  19. private lbTitle: Label = null
  20. private lbDesc: Label = null
  21. private btnGet: Sprite = null
  22. private skill: SkillType = null
  23. protected onLoad(): void {
  24. this.skill0Bg = this.findNode('skill0_bg')
  25. this.skill1Bg = this.findNode('skill1_bg')
  26. this.skill2Bg = this.findNode('skill2_bg')
  27. this.icon = this.findComp('Icon', Sprite)
  28. this.btnGet = this.findComp('BtnGet', Sprite)
  29. // this.lbTitle = this.findComp('LbTitle', Label)
  30. // this.lbDesc = this.findComp('LbDesc', Label)
  31. }
  32. public onOpen(data?: unknown): void {
  33. GameMgr.Pause = true
  34. this.skill = data as SkillType
  35. const skillInfo = CfgSkillInfo[this.skill]
  36. // this.lbTitle.string = skillInfo.name
  37. // this.lbDesc.string = skillInfo.desc
  38. // this.icon.spriteFrame = ResMgr.getSpriteFrame(Bundle.Icon, skillInfo.icon)
  39. let currentBg = null;
  40. if (this.skill == SkillType.FreezeTime) {
  41. this.skill0Bg.active = true
  42. this.skill1Bg.active = false
  43. this.skill2Bg.active = false
  44. currentBg = this.skill0Bg
  45. } else if (this.skill == SkillType.EraseGroup) {
  46. this.skill0Bg.active = false
  47. this.skill1Bg.active = true
  48. this.skill2Bg.active = false
  49. currentBg = this.skill1Bg
  50. } else {
  51. this.skill0Bg.active = false
  52. this.skill1Bg.active = false
  53. this.skill2Bg.active = true
  54. currentBg = this.skill2Bg
  55. }
  56. currentBg.getChildByName('LbTitle').getComponent(Label).string = CfgSkillInfo[this.skill].name
  57. currentBg.getChildByName('LbDesc').getComponent(Label).string = CfgSkillInfo[this.skill].desc
  58. this.btnGet.spriteFrame = ResMgr.getSpriteFrame(Bundle.UI, skillInfo.btnIcon)
  59. }
  60. public onClose(data?: unknown): void {
  61. GameMgr.Pause = false
  62. }
  63. protected onBtnGetClick(): void {
  64. // AdMgr.showRewardedVideo(() => {
  65. // SkillMgr.addSkill(this.skill)
  66. // this.close()
  67. // })
  68. if (AdvertMgr.instance.openAd) {
  69. AdvertMgr.instance.showReawardVideo(() => {
  70. SkillMgr.addSkill(this.skill);
  71. this.close();
  72. })
  73. } else {
  74. SkillMgr.addSkill(this.skill);
  75. this.close();
  76. }
  77. }
  78. }