HallUI.ts 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import { _decorator, tween, v3, EditBox, Node, Vec3, Tween, Quat } from 'cc';
  2. import BasePanel from '../core/component/BasePanel';
  3. import { audioMgr } from '../core/manager/AudioManager';
  4. import Data from '../core/manager/Data';
  5. import WindowManager from '../core/manager/WindowManager';
  6. import MsgHints from '../core/utils/MsgHints';
  7. import Utils from '../core/utils/Utils';
  8. import { BoxLayer } from '../gameui/BoxLayer';
  9. import { GameConst, BOX_TYPE, ITEM_TYPE } from '../core/common/GameConst';
  10. import i18n from '../core/i18n/runtime-scripts/LanguageData';
  11. import { autoBind } from '../core/extend/AutoBind';
  12. const { ccclass, property } = _decorator;
  13. @ccclass('HallUI')
  14. export class HallUI extends BasePanel {
  15. @autoBind(EditBox)
  16. public editBox: EditBox = null!;
  17. @autoBind
  18. public chestLevel0: Node = null!;
  19. @autoBind
  20. public chestLevel1: Node = null!;
  21. onLoad(): void {
  22. super.onLoad();
  23. this.shake(this.chestLevel0);
  24. this.shake(this.chestLevel1);
  25. }
  26. /**
  27. * 小幅度旋转晃动节点(轻微摇摆效果)
  28. * @param n 要晃动的节点
  29. * @param intensity 晃动强度(默认1,范围0.1-3)
  30. */
  31. public shake(n: Node, intensity: number = 1) {
  32. Tween.stopAllByTarget(n); // 停止所有之前的动画
  33. const originalAngle = n.angle; // 保存初始角度
  34. const shakeAngle = 3 * Math.min(Math.max(intensity, 0.1), 3);
  35. tween(n)
  36. .delay(1.2)
  37. .repeat(20,
  38. tween()
  39. .to(0.15, { angle: originalAngle + shakeAngle }, { easing: 'sineInOut' }) // 向右微倾
  40. .to(0.15, { angle: originalAngle - shakeAngle }, { easing: 'sineInOut' }) // 向左微倾
  41. .to(0.15, { angle: originalAngle }, { easing: 'sineInOut' }) // 回正
  42. )
  43. .call(() => {
  44. n.angle = originalAngle; // 确保最终回到初始角度
  45. })
  46. .start();
  47. }
  48. onBtnClicked(event: any, customEventData: any) {
  49. audioMgr.playOneShot(GameConst.audios.btnclick);
  50. var btnName = event.target.name;
  51. switch (btnName) {
  52. case "btn_setting":
  53. // WindowManager.ins.open("NewPackOpenedLayer");
  54. WindowManager.ins.open("SettingLayer")
  55. break;
  56. case "btn_play":
  57. //获取输入的内容
  58. if(GameConst.isDebug){
  59. let str: string = this.editBox.string;
  60. if(!Utils.isNull(str)){
  61. const level: number = parseInt(str);
  62. Data.user.lv = level;
  63. }
  64. }
  65. WindowManager.ins.open("LevelLayer");
  66. /*platformSystem.platform.showRewardVideo((b) => {
  67. WindowManager.ins.open("LevelLayer");
  68. })*/
  69. break;
  70. case "btn_buy_life":
  71. if (Data.user.life >= GameConst.MAX_LIFE) {
  72. MsgHints.show(i18n("main.体力已满"))
  73. return;
  74. }
  75. WindowManager.ins.open("BuyLifeLayer")
  76. break;
  77. case "btn_buy_coin":
  78. WindowManager.ins.open("BuyCoinLayer");
  79. break;
  80. case "reward0":
  81. case "full0":
  82. let info0 = Data.user.hasLvBox();
  83. if(!info0){
  84. MsgHints.show(i18n(`main.条件不足`));
  85. return;
  86. }
  87. WindowManager.ins.open("BoxLayer").then((com: BoxLayer) => {
  88. com?.setInfo(BOX_TYPE.LEVEL, GameConst.getLvBoxReward(Math.floor(Data.user.lv / GameConst.LvBox_Reward)))
  89. });
  90. break;
  91. case "reward1":
  92. case "full1":
  93. let info1 = Data.user.hasStarBox();
  94. if(!info1){
  95. MsgHints.show(i18n(`main.条件不足`));
  96. return;
  97. }
  98. WindowManager.ins.open("BoxLayer").then((com: BoxLayer) => {
  99. com?.setInfo(BOX_TYPE.STAR, GameConst.getStarBoxReward(Math.floor(Data.user.lv / GameConst.Start_Progress)))
  100. });
  101. break;
  102. }
  103. }
  104. start() {
  105. if(!GameConst.isDebug){
  106. this.editBox.node.active = false;
  107. }
  108. this.SetText("level_lable", i18n("main.LV:%{value}", { value: Data.user.lv}));
  109. this.SetProgressBar("probar_lv", 0.1);
  110. let btn_play = this.GetNode("btn_play")
  111. tween(btn_play).sequence(tween(btn_play).to(1, { scale: v3(1.05, 1.05, 1.05) }), tween(btn_play).to(1, { scale: v3(1, 1, 1) })).repeatForever().start()
  112. }
  113. update() {
  114. if (Data.user.life >= GameConst.MAX_LIFE) {
  115. this.SetText("lbl_life_time", i18n("main.已满"))
  116. }else {
  117. if (Data.user.life_cost_time == 0) {
  118. Data.user.life_cost_time = Date.now();
  119. }
  120. let nLeft = (Date.now() - Data.user.life_cost_time) / 1000;
  121. let addLife = Math.floor(nLeft / 60 / GameConst.MAX_LIFE_RECOVERY_TIME);
  122. if (addLife > 0)
  123. Data.user.life += addLife;
  124. nLeft -= addLife * GameConst.MAX_LIFE_RECOVERY_TIME * 60;
  125. this.SetText("lbl_life_time", Utils.getTimeStrByS(GameConst.MAX_LIFE_RECOVERY_TIME * 60 - nLeft))
  126. }
  127. this.SetText("lbl_life", Data.user.life + "")
  128. this.SetText("lbl_coin", Data.user.coin + "")
  129. this.SetText("lbl_lv", Data.user.lv + "")
  130. this.SetText("lbl_lv_center", Data.user.lv + "")
  131. let info = Data.user.hasLvBox();
  132. this.GetGameObject("full0").active = info
  133. let lvmin = Data.user.lv % 10;
  134. this.SetText("lbl_pro_lv", lvmin + "/10");
  135. this.SetProgressBar("lbl_pro_star", lvmin / 10);
  136. this.SetProgressBar("probar_lv_center", lvmin / 10);
  137. this.SetProgressBar("probar_lv", lvmin / 10);
  138. info = Data.user.hasStarBox();
  139. if (info) {
  140. this.SetText("probar_star", "满");
  141. this.SetProgressBar("probar_star", 1);
  142. this.GetGameObject("full1").active = true;
  143. }else {
  144. let starmin = Data.user.star % GameConst.Start_Progress;
  145. this.GetGameObject("full1").active = false;
  146. this.SetText("lbl_pro_star", starmin + `/${GameConst.Start_Progress}`);
  147. this.SetProgressBar("probar_star", starmin / GameConst.Start_Progress);
  148. }
  149. }
  150. }