GameUI.ts 6.4 KB

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