GameUI.ts 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import { _decorator, v3, Node, tween } from 'cc';
  2. import { Main } from './Main';
  3. import BasePanel from '../core/component/BasePanel';
  4. import { audioMgr } from '../core/manager/AudioManager';
  5. import Data from '../core/manager/Data';
  6. import WindowManager from '../core/manager/WindowManager';
  7. import MsgHints from '../core/utils/MsgHints';
  8. import Utils from '../core/utils/Utils';
  9. import { BuyItemLayer } from '../gameui/BuyItemLayer';
  10. import { GameConst, ITEM_FROZEN_LV, ITEM_HINT_LV, ITEM_TYPE } from '../core/common/GameConst';
  11. import { levelsData } from '../user/LevelsData';
  12. import i18n from '../core/i18n/runtime-scripts/LanguageData';
  13. const { ccclass, property } = _decorator;
  14. @ccclass('GameUI')
  15. export class GameUI extends BasePanel {
  16. private hint_time = 0;
  17. public starNode: Node = null;
  18. onBtnClicked(event: any, customEventData: any) {
  19. var btnName = event.target.name;
  20. switch (btnName) {
  21. case "btn_pause":
  22. audioMgr.playOneShot(GameConst.audios.btnclick);
  23. this.pasue = true;
  24. WindowManager.ins.open("PauseLayer")
  25. break;
  26. case "item_left":
  27. audioMgr.playOneShot(GameConst.audios.btnclick);
  28. if (Date.now() - this.hint_time < 2000) return;
  29. if (Data.user.lv < ITEM_HINT_LV) {
  30. MsgHints.show(i18n("main.关卡%{value}解锁", { value: ITEM_HINT_LV}));
  31. return;
  32. }
  33. if (Data.user.hint > 0) {
  34. this.dispatch(GameConst.USE_ITEM_HINT);
  35. this.hint_time = Date.now();
  36. }
  37. else {
  38. WindowManager.ins.open("BuyItemLayer").then((com: BuyItemLayer) => {
  39. com.setItemType(ITEM_TYPE.Hint);
  40. })
  41. }
  42. break;
  43. case "btn_sp_01"://移除
  44. audioMgr.playOneShot(GameConst.audios.btnclick);
  45. Main.I._GameNode.remove();
  46. break;
  47. case "btn_sp_02"://凑齐
  48. audioMgr.playOneShot(GameConst.audios.btnclick);
  49. Main.I._GameNode.prompt();
  50. break;
  51. case "btn_sp_03"://乱序
  52. audioMgr.playOneShot(GameConst.audios.btnclick);
  53. Main.I._GameNode.mess();
  54. break;
  55. case "item_right":
  56. if (this.freezetime) {
  57. MsgHints.show(i18n("main.冰冻中..."));
  58. return;
  59. }
  60. if (Data.user.lv < ITEM_FROZEN_LV) {
  61. MsgHints.show(i18n("main.关卡%{value}解锁", { value: ITEM_FROZEN_LV}));
  62. return;
  63. }
  64. if (Data.user.frozen > 0) {
  65. Data.user.frozen--;
  66. this.freezetime = true;
  67. setTimeout(() => {
  68. this.freezetime = false;
  69. }, 5000);
  70. audioMgr.playOneShot(GameConst.audios.freeze);
  71. }
  72. else {
  73. WindowManager.ins.open("BuyItemLayer").then((com: BuyItemLayer) => {
  74. com.setItemType(ITEM_TYPE.Frozen);
  75. })
  76. }
  77. break;
  78. }
  79. }
  80. start() {
  81. this.register(GameConst.USE_ITEM_TIME, this.doUseTime.bind(this))
  82. this.register("PAUSE_LAYER_CLOSE", () => {
  83. this.pasue = false;
  84. })
  85. this.starNode = this.GetGameObject("star-with-outline");
  86. }
  87. restart() {
  88. this.SetText("lbl_lv", i18n("main.LV:%{value}", { value: Data.user.lv}));
  89. let obj = levelsData.getCurLevelInfo();
  90. console.log("关卡数据:", obj);
  91. this.levelTime = obj.time;
  92. this.GetGameObject("match-timer-freeze-background").active = false;
  93. this.GetGameObject("match-extra-time-power-up-small").active = false;
  94. this.SetText("lbl_left_item_lv", i18n("main.关卡%{value}", { value: ITEM_HINT_LV}));
  95. this.SetText("lbl_right_item_lv", i18n("main.关卡%{value}", { value: ITEM_FROZEN_LV}));
  96. this.freezetime = false;
  97. this.pasue = false;
  98. this.passedTime = 0;
  99. }
  100. doUseTime() {
  101. Data.user.time--;
  102. let node = this.GetGameObject("match-extra-time-power-up-small");
  103. node.active = true;
  104. node.setPosition(v3(0, 0, 0));
  105. tween(node).to(0.5, { worldPosition: this.GetGameObject("lbl_time").worldPosition }).call(() => {
  106. this.levelTime += 60;
  107. node.active = false;
  108. }).start();
  109. }
  110. levelTime = 0;
  111. passedTime = 0;
  112. pasue: boolean = false;
  113. freezetime: boolean = false;
  114. public star = 0;
  115. update(dt) {
  116. if(WindowManager.ins.isShow("OutOfBoxLayer")||WindowManager.ins.isShow("DrawStarLayer")||WindowManager.ins.isShow("LevelClearLayer")||WindowManager.ins.isShow("FailLayer"))return
  117. this.GetGameObject("match-timer-freeze-background").active = this.freezetime;
  118. if (!this.pasue && !this.freezetime)
  119. this.passedTime += dt;
  120. this.SetText("lbl_star", this.star + "");
  121. let nLeft = this.levelTime - this.passedTime;
  122. if (nLeft > 0) {
  123. this.SetText("lbl_time", Utils.getTimeStrByS(nLeft));
  124. }else {//游戏结束
  125. WindowManager.ins.open("FailLayer")
  126. }
  127. if (Data.user.lv < ITEM_HINT_LV) {
  128. this.GetGameObject("item_left_Locked").active = true;
  129. this.GetGameObject("item_left_icon").active = false;
  130. }else {
  131. this.GetGameObject("item_left_Locked").active = false;
  132. this.GetGameObject("item_left_icon").active = true;
  133. this.SetText("lbl_item_left_count", Data.user.hint == 0 ? "+" : Data.user.hint + "");
  134. }
  135. if (Data.user.lv < ITEM_FROZEN_LV) {
  136. this.GetGameObject("item_right_Locked").active = true;
  137. this.GetGameObject("item_right_icon").active = false;
  138. }else {
  139. this.GetGameObject("item_right_Locked").active = false;
  140. this.GetGameObject("item_right_icon").active = true;
  141. this.SetText("lbl_item_rihgt_count", Data.user.frozen == 0 ? "+" : Data.user.frozen + "");
  142. }
  143. }
  144. }