import { _decorator, Component, find, Node } 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/Scripts/ModuleDef'; import { Layout_Main } from './Layout_Main'; import { UI_Settings } from '../UI_Settings/UI_Settings'; import { UI_GameRules } from '../UI_GameRules/UI_GameRules'; import { ch } from 'db://assets/ch/ch'; import { GameCtl } from 'db://assets/Scripts/GameCtl'; import { Container_Manager } from 'db://assets/Scripts/Container_Manager'; import { UI_Fail } from '../UI_Fail/UI_Fail'; import { UI_Win } from '../UI_Win/UI_Win'; import { Hall } from 'db://assets/Scripts/Hall'; import { UI_Idioms } from '../UI_Idioms/UI_Idioms'; const { ccclass, property } = _decorator; interface event_protocol { update_remain(): void; update_ui_idioms(): void; next_level(): void; } @ccclass('UI_Main') export class UI_Main extends ui_base { public evt = ch.get_new_event(); running = true; constructor() { super(ModuleDef.GAME, 'ui/UI_Main/Main', GameUILayers.GAME, Layout_Main); } protected async onCreated() { const layout = this.getLayout(); layout.Container = find('Container').getComponent(Container_Manager); this.onButtonEvent(layout.Pause_Btn, async (button: any) => { //打开设置界面 gui.show(UI_Settings); }, this); this.onButtonEvent(layout.Rules_Btn, async (button: any) => { //打开游戏说明 gui.show(UI_GameRules); }, this); //显示关卡数 layout.Level.string = '第' + (Hall.getInstance().player.get_max_floor() + 1) + '关'; //显示剩余方块 layout.Remain_Cube_Des.string = '剩余:' + gui.get(UI_Idioms).idioms.length * 2; //开始倒计时 this.new_level(); let level = Hall.getInstance().player.get_max_floor(); layout.schedule(() => { if (this.running) { if (layout.time != 0) { layout.time -= 1; let minute = Math.floor(layout.time / 60); let second = layout.time % 60; layout.Count_Down_Des.string = (minute >= 10 ? minute : '0' + minute) + ':' + (second >= 10 ? second : '0' + second); } else { if (layout.Container.idioms.length > 0) { gui.show(UI_Fail); this.running = false; } } if (layout.Container.idioms.length <= 0) { Hall.getInstance().player.set_max_floor(Hall.getInstance().player.get_max_floor() + 1); Hall.getInstance().player.setDirty(); Hall.getInstance().player.save_rank_floor(); Hall.getInstance().player.save(); gui.show(UI_Win); this.running = false; } } }, 1.0); this.evt.on(this.evt.key.next_level, this.new_level, this); this.evt.on(this.evt.key.update_remain, this.remain, this); this.evt.on(this.evt.key.update_ui_idioms, this.ui_idioms, this); } new_level() { let level = Hall.getInstance().player.get_max_floor(); const layout = this.getLayout(); layout.time=layout.Container.level_config[level].time; let minute = Math.floor(layout.Container.level_config[level].time / 60); let second = layout.Container.level_config[level].time % 60; layout.Count_Down_Des.string = (minute >= 10 ? minute : '0' + minute) + ':' + (second >= 10 ? second : '0' + second); layout.Remain_Cube_Des.string = '剩余:' + gui.get(UI_Idioms).idioms.length * 2; layout.Level.string = '第' + (Hall.getInstance().player.get_max_floor() + 1) + '关'; this.running = true; } remain() { const layout = this.getLayout(); layout.Remain_Cube_Des.string = '剩余:' + gui.get(UI_Idioms).idioms.length * 2; } ui_idioms() { gui.get(UI_Idioms).init(); } protected onDispose(): void { const layout = this.getLayout(); layout.unscheduleAllCallbacks(); } } export function ani_ui(node: Node, end: number = 1.0): void { gui.scale_elasticOut_anim(node, 1.2, 0.5, end); }