UI_Hall.ts 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. import { _decorator, color, Color, Component, director, instantiate, Node, Scheduler, Skeleton, sp, Sprite, tween, UIOpacity, Vec3 } 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_Hall } from './Layout_Hall';
  6. import { Hall } from '../../hall/Hall';
  7. import { UI_Settings } from '../UI_Settings/UI_Settings';
  8. import { UI_Skin } from '../UI_Skin/UI_Skin';
  9. import { UI_Life } from '../UI_Life/UI_Life';
  10. import { UI_Main } from '../main/UI_Main';
  11. import { ResUtil } from 'db://assets/core/util/ResUtil';
  12. import { SceneDef } from 'db://assets/Script/SceneDef';
  13. import { LvData } from '../../game/LvData/LvData';
  14. import ch_audio from 'db://assets/ch/audio/audio';
  15. import { sleep } from 'db://assets/core/util_comp/Game';
  16. import { data_type } from '../../game/PlayerData';
  17. import { UI_rank } from '../UI_rank/UI_rank';
  18. import { audioManager } from '../../Audio/AudioManager';
  19. import { ch } from 'db://assets/ch/ch';
  20. import { LvDir } from '../../game/LvData/LvData';
  21. interface event_guanBtn {
  22. LLK(): void;//llk
  23. XXl(): void;//xxl
  24. }
  25. const { ccclass, property } = _decorator;
  26. @ccclass('UI_Hall')
  27. export class UI_Hall extends ui_base {
  28. // 预加载状态标记(静态变量确保全局唯一)
  29. //static isUIMainPreloaded = false;
  30. life = Hall.getInstance().player.get_life();
  31. public evt = ch.get_new_event<event_guanBtn>();
  32. constructor() {
  33. super(ModuleDef.GAME, 'ui/UI_Hall/Hall', GameUILayers.GAME, Layout_Hall);
  34. }
  35. lv = Hall.getInstance().player.data.get(data_type.max_floor)
  36. protected onCreated() {
  37. const layout = this.getLayout<Layout_Hall>();
  38. let currentLevel = this.lv; // 从存档读取当前关卡
  39. //进入LLK
  40. // console.log("hall start11111111111111111")
  41. if (currentLevel <= 0) {
  42. currentLevel = 1;
  43. }
  44. layout.llkLabel.string = "第 " + currentLevel.toString() + " 关";
  45. this.onButtonEvent(layout.LLK_Btn, async () => {
  46. // 首先检查生命值是否耗尽
  47. if (LvData.instance.life == 0) {
  48. // 生命值为0时显示生命值面板并阻止后续操作
  49. gui.show(UI_Life);
  50. return;
  51. }
  52. audioManager.playOneShot('sound/click_Btn');
  53. //layout.lifejian.active = true;
  54. this.lifejianAnim()
  55. LvData.instance.life = LvData.instance.life - 1;
  56. Hall.getInstance().sceneChanging = false;
  57. await sleep(0.5)
  58. Hall.getInstance().to_main();
  59. });
  60. //进入XXL
  61. this.onButtonEvent(layout.XXL_Btn, async () => {
  62. // 首先检查生命值是否耗尽
  63. if (LvData.instance.life == 0) {
  64. // 生命值为0时显示生命值面板并阻止后续操作
  65. gui.show(UI_Life);
  66. return;
  67. }
  68. audioManager.playOneShot('sound/click_Btn');
  69. //layout.lifejian.active = true;
  70. this.lifejianAnim()
  71. LvData.instance.life = LvData.instance.life - 1;
  72. Hall.getInstance().sceneChanging = false;
  73. await sleep(0.5)
  74. Hall.getInstance().to_main();
  75. });
  76. //皮肤Dlg
  77. this.onButtonEvent(layout.Skin_Btn, () => {
  78. audioManager.playOneShot('sound/click_Btn');
  79. gui.show(UI_Skin);
  80. });
  81. //排行榜Dlg
  82. this.onButtonEvent(layout.Rank_Btn, async () => {
  83. audioManager.playOneShot('sound/click_Btn');
  84. // debugger
  85. await Hall.getInstance().player.loadPfInfo();//授权
  86. gui.show(UI_rank);
  87. console.log("排行榜");
  88. });
  89. //设置Dlg
  90. this.onButtonEvent(layout.Settings_Btn, () => {
  91. audioManager.playOneShot('sound/click_Btn');
  92. gui.show(UI_Settings);
  93. })
  94. //获取生命值
  95. this.onButtonEvent(layout.Life_Btn, () => {
  96. audioManager.playOneShot('sound/click_Btn');
  97. gui.show(UI_Life);
  98. });
  99. //设置生命值
  100. layout.Life_Num.string = LvData.instance.life.toString();
  101. let role = layout.role.getComponent(sp.Skeleton)
  102. let skinId = LvData.instance.rwpf;
  103. this.changeSkin(skinId, layout.SkeletonData, role);
  104. LvData.instance.lifeContor.evt.on('valueChange', this.set_Life, this);
  105. }
  106. lifejianAnim() {
  107. const layout = this.getLayout<Layout_Hall>();
  108. const initialHeight = 100; // 向上飞行高度
  109. // 生命值减1,透明渐变向上飘
  110. layout.lifejian.active = true;
  111. const currentPos = layout.lifejian.position.clone();
  112. const targetPos = new Vec3(currentPos.x, currentPos.y + initialHeight, currentPos.z);
  113. let lifeColor = layout.Life_Num.getComponent(Sprite);
  114. tween(layout.lifejian.getComponent(UIOpacity)).to(0.2, { opacity: 0 }).start();
  115. tween(layout.lifejian)
  116. .to(0.2, { position: targetPos })
  117. .call(() => {
  118. layout.lifejian.active = false; // 动画结束后隐藏
  119. })
  120. .start();
  121. console.log("lifejianAnim")
  122. }
  123. protected onDispose(): void {
  124. LvData.instance.lifeContor.evt.off('valueChange', this.set_Life, this);
  125. }
  126. //设置大厅显示生命值
  127. set_Life(value: number) {
  128. const layout = this.getLayout<Layout_Hall>();
  129. layout.Life_Num.string = value.toString();
  130. }
  131. public changeSkin(newSkinId: number, SkeletonData, spineSkeleton): void {
  132. if (newSkinId - 1 >= 0 && newSkinId - 1 < SkeletonData.length) {
  133. spineSkeleton.skeletonData = SkeletonData[newSkinId - 1]
  134. spineSkeleton.setAnimation(0, "anim_jiemian", true);
  135. }
  136. else {
  137. console.error("骨骼资源索引l越界")
  138. }
  139. }
  140. }