| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- import { _decorator, color, Color, Component, director, instantiate, Node, Scheduler, Skeleton, sp, Sprite, tween, UIOpacity, Vec3 } from 'cc';
- import { GameUILayers, gui } from 'db://assets/core/ui/ui';
- import ui_base from 'db://assets/core/ui/ui_base';
- import { ModuleDef } from 'db://assets/Script/ModuleDef';
- import { Layout_Hall } from './Layout_Hall';
- import { Hall } from '../../hall/Hall';
- import { UI_Settings } from '../UI_Settings/UI_Settings';
- import { UI_Skin } from '../UI_Skin/UI_Skin';
- import { UI_Life } from '../UI_Life/UI_Life';
- import { UI_Main } from '../main/UI_Main';
- import { ResUtil } from 'db://assets/core/util/ResUtil';
- import { SceneDef } from 'db://assets/Script/SceneDef';
- import { LvData } from '../../game/LvData/LvData';
- import ch_audio from 'db://assets/ch/audio/audio';
- import { sleep } from 'db://assets/core/util_comp/Game';
- import { data_type } from '../../game/PlayerData';
- import { UI_rank } from '../UI_rank/UI_rank';
- import { audioManager } from '../../Audio/AudioManager';
- import { ch } from 'db://assets/ch/ch';
- import { LvDir } from '../../game/LvData/LvData';
- interface event_guanBtn {
- LLK(): void;//llk
- XXl(): void;//xxl
- }
- const { ccclass, property } = _decorator;
- @ccclass('UI_Hall')
- export class UI_Hall extends ui_base {
- // 预加载状态标记(静态变量确保全局唯一)
- //static isUIMainPreloaded = false;
- life = Hall.getInstance().player.get_life();
- public evt = ch.get_new_event<event_guanBtn>();
- constructor() {
- super(ModuleDef.GAME, 'ui/UI_Hall/Hall', GameUILayers.GAME, Layout_Hall);
- }
- lv = Hall.getInstance().player.data.get(data_type.max_floor)
- protected onCreated() {
- const layout = this.getLayout<Layout_Hall>();
- let currentLevel = this.lv; // 从存档读取当前关卡
- //进入LLK
- // console.log("hall start11111111111111111")
- if (currentLevel <= 0) {
- currentLevel = 1;
- }
- layout.llkLabel.string = "第 " + currentLevel.toString() + " 关";
- this.onButtonEvent(layout.LLK_Btn, async () => {
- // 首先检查生命值是否耗尽
- if (LvData.instance.life == 0) {
- // 生命值为0时显示生命值面板并阻止后续操作
- gui.show(UI_Life);
- return;
- }
- audioManager.playOneShot('sound/click_Btn');
- //layout.lifejian.active = true;
- this.lifejianAnim()
- LvData.instance.life = LvData.instance.life - 1;
- Hall.getInstance().sceneChanging = false;
- await sleep(0.5)
- Hall.getInstance().to_main();
- });
- //进入XXL
- this.onButtonEvent(layout.XXL_Btn, async () => {
- // 首先检查生命值是否耗尽
- if (LvData.instance.life == 0) {
- // 生命值为0时显示生命值面板并阻止后续操作
- gui.show(UI_Life);
- return;
- }
- audioManager.playOneShot('sound/click_Btn');
- //layout.lifejian.active = true;
- this.lifejianAnim()
- LvData.instance.life = LvData.instance.life - 1;
- Hall.getInstance().sceneChanging = false;
- await sleep(0.5)
- Hall.getInstance().to_main();
- });
- //皮肤Dlg
- this.onButtonEvent(layout.Skin_Btn, () => {
- audioManager.playOneShot('sound/click_Btn');
- gui.show(UI_Skin);
- });
- //排行榜Dlg
- this.onButtonEvent(layout.Rank_Btn, async () => {
- audioManager.playOneShot('sound/click_Btn');
- // debugger
- await Hall.getInstance().player.loadPfInfo();//授权
- gui.show(UI_rank);
- console.log("排行榜");
- });
- //设置Dlg
- this.onButtonEvent(layout.Settings_Btn, () => {
- audioManager.playOneShot('sound/click_Btn');
- gui.show(UI_Settings);
- })
- //获取生命值
- this.onButtonEvent(layout.Life_Btn, () => {
- audioManager.playOneShot('sound/click_Btn');
- gui.show(UI_Life);
- });
- //设置生命值
- layout.Life_Num.string = LvData.instance.life.toString();
- let role = layout.role.getComponent(sp.Skeleton)
- let skinId = LvData.instance.rwpf;
- this.changeSkin(skinId, layout.SkeletonData, role);
- LvData.instance.lifeContor.evt.on('valueChange', this.set_Life, this);
- }
- lifejianAnim() {
- const layout = this.getLayout<Layout_Hall>();
- const initialHeight = 100; // 向上飞行高度
- // 生命值减1,透明渐变向上飘
- layout.lifejian.active = true;
- const currentPos = layout.lifejian.position.clone();
- const targetPos = new Vec3(currentPos.x, currentPos.y + initialHeight, currentPos.z);
- let lifeColor = layout.Life_Num.getComponent(Sprite);
- tween(layout.lifejian.getComponent(UIOpacity)).to(0.2, { opacity: 0 }).start();
- tween(layout.lifejian)
- .to(0.2, { position: targetPos })
- .call(() => {
- layout.lifejian.active = false; // 动画结束后隐藏
- })
- .start();
- console.log("lifejianAnim")
- }
- protected onDispose(): void {
- LvData.instance.lifeContor.evt.off('valueChange', this.set_Life, this);
- }
- //设置大厅显示生命值
- set_Life(value: number) {
- const layout = this.getLayout<Layout_Hall>();
- layout.Life_Num.string = value.toString();
- }
- public changeSkin(newSkinId: number, SkeletonData, spineSkeleton): void {
- if (newSkinId - 1 >= 0 && newSkinId - 1 < SkeletonData.length) {
- spineSkeleton.skeletonData = SkeletonData[newSkinId - 1]
- spineSkeleton.setAnimation(0, "anim_jiemian", true);
- }
- else {
- console.error("骨骼资源索引l越界")
- }
- }
- }
|