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