HallUI.ts 6.6 KB

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