UI_Main.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import { _decorator, find,Node } from "cc";
  2. import { ch } from "../../../ch/ch";
  3. import { GameUILayers, gui } from "../../../core/ui/ui";
  4. import ui_base from "../../../core/ui/ui_base";
  5. import { Container_Manager } from "../../../Scripts/Container_Manager";
  6. import { Hall } from "../../../Scripts/Hall";
  7. import { ModuleDef } from "../../../Scripts/ModuleDef";
  8. import { UI_Fail } from "../UI_Fail/UI_Fail";
  9. import { UI_GameRules } from "../UI_GameRules/UI_GameRules";
  10. import { UI_Idioms } from "../UI_Idioms/UI_Idioms";
  11. import { UI_Settings } from "../UI_Settings/UI_Settings";
  12. import { UI_Win } from "../UI_Win/UI_Win";
  13. import { Layout_Main } from "./Layout_Main";
  14. const { ccclass, property } = _decorator;
  15. interface event_protocol {
  16. update_remain(): void;
  17. update_ui_idioms(): void;
  18. next_level(): void;
  19. }
  20. @ccclass('UI_Main')
  21. export class UI_Main extends ui_base {
  22. public evt = ch.get_new_event<event_protocol>();
  23. running = true;
  24. constructor() {
  25. super(ModuleDef.GAME, 'ui/UI_Main/Main', GameUILayers.GAME, Layout_Main);
  26. }
  27. protected async onCreated() {
  28. const layout = this.getLayout<Layout_Main>();
  29. layout.Container = find('Container').getComponent(Container_Manager);
  30. this.onButtonEvent(layout.Pause_Btn, async (button: any) => {
  31. //打开设置界面
  32. gui.show(UI_Settings);
  33. }, this);
  34. this.onButtonEvent(layout.Rules_Btn, async (button: any) => {
  35. //打开游戏说明
  36. gui.show(UI_GameRules);
  37. }, this);
  38. //显示关卡数
  39. layout.Level.string = '第' + (Hall.getInstance().player.get_max_floor() + 1) + '关';
  40. //显示剩余方块
  41. layout.Remain_Cube_Des.string = '剩余:' + gui.get(UI_Idioms).idioms.length * 2;
  42. //开始倒计时
  43. this.new_level();
  44. let level = Hall.getInstance().player.get_max_floor();
  45. layout.schedule(() => {
  46. if (this.running) {
  47. if (layout.time != 0) {
  48. layout.time -= 1;
  49. let minute = Math.floor(layout.time / 60);
  50. let second = layout.time % 60;
  51. layout.Count_Down_Des.string = (minute >= 10 ? minute : '0' + minute) + ':' + (second >= 10 ? second : '0' + second);
  52. }
  53. else {
  54. if (layout.Container.idioms.length > 0) {
  55. gui.show(UI_Fail);
  56. this.running = false;
  57. }
  58. }
  59. if (layout.Container.idioms.length <= 0) {
  60. Hall.getInstance().player.set_max_floor(Hall.getInstance().player.get_max_floor() + 1);
  61. Hall.getInstance().player.setDirty();
  62. Hall.getInstance().player.save_rank_floor();
  63. Hall.getInstance().player.save();
  64. gui.show(UI_Win);
  65. this.running = false;
  66. }
  67. }
  68. }, 1.0);
  69. this.evt.on(this.evt.key.next_level, this.new_level, this);
  70. this.evt.on(this.evt.key.update_remain, this.remain, this);
  71. this.evt.on(this.evt.key.update_ui_idioms, this.ui_idioms, this);
  72. }
  73. new_level() {
  74. let level = Hall.getInstance().player.get_max_floor();
  75. const layout = this.getLayout<Layout_Main>();
  76. layout.time=layout.Container.level_config[level].time;
  77. let minute = Math.floor(layout.Container.level_config[level].time / 60);
  78. let second = layout.Container.level_config[level].time % 60;
  79. layout.Count_Down_Des.string = (minute >= 10 ? minute : '0' + minute) + ':' + (second >= 10 ? second : '0' + second);
  80. layout.Remain_Cube_Des.string = '剩余:' + gui.get(UI_Idioms).idioms.length * 2;
  81. layout.Level.string = '第' + (Hall.getInstance().player.get_max_floor() + 1) + '关';
  82. this.running = true;
  83. }
  84. remain() {
  85. const layout = this.getLayout<Layout_Main>();
  86. layout.Remain_Cube_Des.string = '剩余:' + gui.get(UI_Idioms).idioms.length * 2;
  87. }
  88. ui_idioms() {
  89. gui.get(UI_Idioms).init();
  90. }
  91. protected onDispose(): void {
  92. const layout = this.getLayout<Layout_Main>();
  93. layout.unscheduleAllCallbacks();
  94. }
  95. }
  96. export function ani_ui(node: Node, end: number = 1.0): void {
  97. gui.scale_elasticOut_anim(node, 1.2, 0.5, end);
  98. }