GameUI.ts 7.2 KB

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