123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- import { _decorator, find, Node } from "cc";
- import { ch } from "../../../ch/ch";
- import { GameUILayers, gui } from "../../../core/ui/ui";
- import ui_base from "../../../core/ui/ui_base";
- import { ModuleDef } from "../../../Scripts/ModuleDef";
- import { UI_Fail } from "../UI_Fail/UI_Fail";
- import { UI_GameRules } from "../UI_GameRules/UI_GameRules";
- import { UI_Idioms } from "../UI_Idioms/UI_Idioms";
- import { UI_Settings } from "../UI_Settings/UI_Settings";
- import { UI_Win } from "../UI_Win/UI_Win";
- import { Layout_Main } from "./Layout_Main";
- import { Container_Manager } from "../../game/Container_Manager";
- import { Hall } from "../../hall/Hall";
- import { UI_LatticeFull } from "../UI_LatticeFull/UI_LatticeFull";
- import { UI_TimesOver } from "../UI_TimesOver/UI_TimesOver";
- const { ccclass, property } = _decorator;
- interface event_protocol {
- pause(): void;
- resume(): void;
- 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<event_protocol>();
- running = true;
- constructor() {
- super(ModuleDef.GAME, 'ui/UI_Main/Main', GameUILayers.GAME, Layout_Main);
- }
- protected async onCreated() {
- const layout = this.getLayout<Layout_Main>();
- layout.Container = find('Container').getComponent(Container_Manager);
- this.onButtonEvent(layout.Pause_Btn, async (button: any) => {
- //打开设置界面
- gui.show(UI_Settings);
- this.pause();
- }, 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_TimesOver);
- this.running = false;
- }
- }
- if (layout.Container.idioms.length <= 0) {
- console.log('恭喜你,通关成功');
- Hall.getInstance().player.set_pass_level(1);
- 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.pause, this.pause, this);
- this.evt.on(this.evt.key.resume, this.resume, this);
- 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_Main>();
- 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) + '关';
- // if(level==0){
- // layout.Hand.active=true;
- // }else{
- // layout.Hand.active=false;
- // }
- this.running = true;
- }
- remain() {
- const layout = this.getLayout<Layout_Main>();
- layout.Remain_Cube_Des.string = '剩余:' + gui.get(UI_Idioms).idioms.length * 2;
- }
- ui_idioms() {
- gui.get(UI_Idioms).init();
- }
- pause() {
- this.running = false;
- }
- resume() {
- this.running = true;
- }
- protected onDispose(): void {
- const layout = this.getLayout<Layout_Main>();
- layout.unscheduleAllCallbacks();
- }
- }
- export function ani_ui(node: Node, end: number = 1.0): void {
- gui.scale_elasticOut_anim(node, 1.2, 0.5, end);
- }
|