CheckpointSettingViewComp.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * @Author: dgflash
  3. * @Date: 2022-06-02 09:38:48
  4. * @LastEditors: dgflash
  5. * @LastEditTime: 2022-09-20 17:18:29
  6. */
  7. import { EventTouch, Node, Toggle, Tween, UIOpacity, Vec3, _decorator, easing, tween } from "cc";
  8. import { oops } from "../../../../../extensions/oops-plugin-framework/assets/core/Oops";
  9. import { ecs } from "../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
  10. import { CCComp } from "../../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
  11. import { UIID } from "../../common/config/GameUIConfig";
  12. import { SingletonModuleComp } from "../../common/SingletonModuleComp";
  13. import { InitCheckpointComp } from "../bll/InitCheckpoint";
  14. const { ccclass, property } = _decorator;
  15. /** 角色信息界面 */
  16. @ccclass('CheckpointSettingViewComp')
  17. @ecs.register('CheckpointSettingView', false)
  18. export class CheckpointSettingViewComp extends CCComp {
  19. private btnClose
  20. private btnRestart
  21. private btnEffect
  22. private btnVibrate
  23. private btnSound
  24. onAdded(args: any) {
  25. console.log(args);
  26. }
  27. onLoad() {
  28. this.btnClose = this.node.getChildByPath("BG/btn_close")
  29. this.btnRestart = this.node.getChildByPath("BG/btn_restart")
  30. this.btnEffect = this.node.getChildByPath("BG/btn_effect")
  31. this.btnVibrate = this.node.getChildByPath("BG/btn_vibrate")
  32. this.btnSound = this.node.getChildByPath("BG/btn_sound")
  33. this.btnClose.on(Node.EventType.TOUCH_END, this.onTouchEnd, this);
  34. this.btnRestart.on(Node.EventType.TOUCH_END, this.onTouchEnd, this);
  35. this.btnEffect.on(Node.EventType.TOUCH_END, this.onTouchEnd, this);
  36. this.btnVibrate.on(Node.EventType.TOUCH_END, this.onTouchEnd, this);
  37. this.btnSound.on(Node.EventType.TOUCH_END, this.onTouchEnd, this);
  38. const setting = ecs.getSingleton(SingletonModuleComp).account.AccountModelSetting
  39. this.btnEffect.getComponent(Toggle)!.isChecked = setting.effectOn
  40. this.btnVibrate.getComponent(Toggle)!.isChecked = setting.vibrationOn
  41. this.btnSound.getComponent(Toggle)!.isChecked = setting.musicOn
  42. const window = this.node.getChildByName("BG")
  43. window.setScale(new Vec3(0, 0, 1));
  44. // 使用Tween来实现动画效果
  45. Tween.stopAllByTarget(window); // 停止该节点上的所有其他Tween
  46. tween(window)
  47. // .delay(0.1)
  48. .to(0.3, { scale: new Vec3(0.5, 0.5, 1) }, { easing: easing.backOut }) // 缩放动画
  49. .start(); // 开始动画
  50. }
  51. private onTouchEnd(event: EventTouch) {
  52. switch (event.target.name) {
  53. case "btn_restart":
  54. const checkpoint = ecs.getSingleton(SingletonModuleComp).account.checkpoint;
  55. checkpoint.add(InitCheckpointComp)
  56. break;
  57. case "btn_close":
  58. oops.gui.remove(UIID.Setting);
  59. break;
  60. case "btn_effect":
  61. ecs.getSingleton(SingletonModuleComp).account.AccountModelSetting.effectOn = !ecs.getSingleton(SingletonModuleComp).account.AccountModelSetting.effectOn
  62. break;
  63. case "btn_vibrate":
  64. ecs.getSingleton(SingletonModuleComp).account.AccountModelSetting.vibrationOn = !ecs.getSingleton(SingletonModuleComp).account.AccountModelSetting.vibrationOn
  65. break;
  66. case "btn_sound":
  67. ecs.getSingleton(SingletonModuleComp).account.AccountModelSetting.musicOn = !ecs.getSingleton(SingletonModuleComp).account.AccountModelSetting.musicOn
  68. }
  69. event.propagationStopped = true;
  70. }
  71. reset() {
  72. this.node.destroy();
  73. }
  74. }