GameUI.ts 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import { _decorator, v3, Node, tween, Material, Sprite } 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. }else{
  39. WindowManager.ins.open("BuyItemLayer").then((com: BuyItemLayer) => {
  40. com?.setItemType(ITEM_TYPE.Hint);
  41. })
  42. }
  43. break;
  44. case "item_right":
  45. if (this.freezetime) {
  46. MsgHints.show(i18n("main.冰冻中"));
  47. return;
  48. }
  49. if (Data.user.lv < ITEM_FROZEN_LV) {
  50. MsgHints.show(i18n("main.关卡%{value}解锁", { value: ITEM_FROZEN_LV}));
  51. return;
  52. }
  53. if (Data.user.frozen > 0) {
  54. Data.user.frozen--;
  55. this.freezetime = true;
  56. setTimeout(() => {
  57. this.freezetime = false;
  58. }, 5000);
  59. audioMgr.playOneShot(GameConst.audios.freeze);
  60. }else {
  61. WindowManager.ins.open("BuyItemLayer").then((com: BuyItemLayer) => {
  62. com?.setItemType(ITEM_TYPE.Frozen);
  63. })
  64. }
  65. break;
  66. case "btn_sp_01"://移除
  67. audioMgr.playOneShot(GameConst.audios.btnclick);
  68. Main.I._GameNode.remove();
  69. break;
  70. case "btn_sp_02"://凑齐
  71. audioMgr.playOneShot(GameConst.audios.btnclick);
  72. Main.I._GameNode.prompt();
  73. break;
  74. case "btn_sp_03"://乱序
  75. audioMgr.playOneShot(GameConst.audios.btnclick);
  76. Main.I._GameNode.mess();
  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. this.GetGameObject("match-power-up-bg-001").getComponent(Sprite).customMaterial = this.garyMaterial;
  131. }else {
  132. this.GetGameObject("item_left_Locked").active = false;
  133. this.GetGameObject("item_left_icon").active = true;
  134. this.SetText("lbl_item_left_count", Data.user.hint == 0 ? "+" : Data.user.hint + "");
  135. this.GetGameObject("match-power-up-bg-001").getComponent(Sprite).customMaterial = null;
  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. this.GetGameObject("match-power-up-bg-002").getComponent(Sprite).customMaterial = this.garyMaterial;
  141. }else {
  142. this.GetGameObject("item_right_Locked").active = false;
  143. this.GetGameObject("item_right_icon").active = true;
  144. this.SetText("lbl_item_rihgt_count", Data.user.frozen == 0 ? "+" : Data.user.frozen + "");
  145. this.GetGameObject("match-power-up-bg-002").getComponent(Sprite).customMaterial = null;
  146. }
  147. }
  148. }