UI_Revive.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { _decorator, Component, Node, sp, UI } from 'cc';
  2. import { GameUILayers, gui } from 'db://assets/core/ui/ui';
  3. import ui_base from 'db://assets/core/ui/ui_base';
  4. import { ModuleDef } from 'db://assets/Script/ModuleDef';
  5. import { Layout_Revive } from './Layout_Revive';
  6. import { UI_Hall } from '../UI_Hall/UI_Hall';
  7. import { SceneDef } from 'db://assets/Script/SceneDef';
  8. import { ResUtil } from 'db://assets/core/util/ResUtil';
  9. import { UI_Main } from '../main/UI_Main';
  10. import ch_audio from 'db://assets/ch/audio/audio';
  11. import { ani_ui } from '../../game/animation_utils';
  12. import { LvData } from '../../game/LvData/LvData';
  13. import { Block } from '../../game/link/block/Block';
  14. import { BlockLink } from '../../game/link/block/BlockLink';
  15. import { UI_Lose } from '../UI_Lose/UI_Lose';
  16. import { audioManager } from '../../Audio/AudioManager';
  17. const { ccclass, property } = _decorator;
  18. @ccclass('UI_Revive')
  19. export class UI_Revive extends ui_base {
  20. constructor() {
  21. super(ModuleDef.GAME, 'ui/UI_Revive/revive', GameUILayers.HUD, Layout_Revive);
  22. }
  23. protected async onCreated() {
  24. ani_ui(this.node);
  25. const layout = this.getLayout<Layout_Revive>();
  26. this.onButtonEvent(layout.returnBtn, async (button: any) => {
  27. audioManager.playOneShot('sound/click_Btn');
  28. //跳转场景回到主页
  29. await this.close();
  30. gui.show(UI_Lose);
  31. }, this);
  32. this.onButtonEvent(layout.reviveBtn, async (button: any) => {
  33. audioManager.playOneShot('sound/click_Btn');
  34. //TODO: 复活+50s
  35. let res = await chsdk.playRewardAd('复活');
  36. if (res) {
  37. gui.close(UI_Revive);
  38. UI_Main.lt.title.addTime(50);
  39. //执行复活移动
  40. const role = UI_Main.lt.role;
  41. if (role) {
  42. await role.reviveMove(); // 复活移动
  43. }
  44. }
  45. }, this);
  46. const completedBlocks = BlockLink.totalBlocks - BlockLink.remainingBlocks;
  47. const progress = completedBlocks / BlockLink.totalBlocks;
  48. layout.progressBar.progress = progress;
  49. layout.scrussNum.string = Math.floor(progress * 100) + '%';
  50. let role = layout.role.getComponent(sp.Skeleton)
  51. let skinId = LvData.instance.rwpf;
  52. this.changeSkin(skinId, layout.SkeletonData, role);
  53. }
  54. public changeSkin(newSkinId: number, SkeletonData, spineSkeleton): void {
  55. if (newSkinId - 1 >= 0 && newSkinId - 1 < SkeletonData.length) {
  56. spineSkeleton.skeletonData = SkeletonData[newSkinId - 1]
  57. spineSkeleton.setAnimation(0, "anim_jiemian", true);
  58. }
  59. else {
  60. console.error("骨骼资源索引l越界")
  61. }
  62. }
  63. }