SetViewComp.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * @Author: mojunshou 1637302775@qq.com
  3. * @Date: 2025-03-12 11:17:12
  4. * @LastEditors: mojunshou 1637302775@qq.com
  5. * @LastEditTime: 2025-03-12 14:39:32
  6. * @Description:
  7. */
  8. import { EventTouch } from "cc";
  9. import { _decorator } from "cc";
  10. import { oops } from "db://oops-framework/core/Oops";
  11. import { ecs } from "db://oops-framework/libs/ecs/ECS";
  12. import { CCVMParentComp } from "db://oops-framework/module/common/CCVMParentComp";
  13. import { UIID } from "../config/GameUIConfig";
  14. import { Slider } from "cc";
  15. const { ccclass, property } = _decorator;
  16. /** 视图层对象 - 支持 MVVM 框架的数据绑定 */
  17. @ccclass('SetViewComp')
  18. @ecs.register('SetView', false)
  19. export class SetViewComp extends CCVMParentComp {
  20. /** 脚本控制的界面 MVVM 框架绑定数据 */
  21. /** VM 组件绑定数据 */
  22. data: any = {
  23. /** 音乐音量进度 */
  24. finished: 0,
  25. /** 音乐音量 */
  26. total: 0,
  27. /** 加载资源进度比例值 */
  28. progress: "0",
  29. };
  30. private progress: number = 0;
  31. /** 视图层逻辑代码分离演示 */
  32. protected start() {
  33. this.data.progress = 0;
  34. this.setButton();
  35. //监听
  36. }
  37. private btn_close(event: EventTouch) {
  38. console.log("关闭页面");
  39. oops.gui.remove(UIID.Setting)
  40. }
  41. //VMEvent的改变回调
  42. private onTest(newNum: any, oldNum: any) {
  43. console.log(newNum, "==========", oldNum);
  44. }
  45. //滑动的回调
  46. private onSliderCallback(event: Slider) {
  47. console.log("slider回调===========", event);
  48. let progress = event.progress;
  49. //保留两位小数
  50. let num = Math.round(progress * 100) / 100;
  51. this.data.progress = num;
  52. }
  53. /** 加载进度事件 */
  54. // private onProgressCallback(finished: number, total: number, item: any) {
  55. // oops.log.logView(finished, ">>>>>>>>>>>>>>>")
  56. // this.data.finished = finished;
  57. // this.data.total = total;
  58. // var progress = finished / total;
  59. // if (progress > this.progress) {
  60. // this.progress = progress;
  61. // this.data.progress = (progress * 100).toFixed(2);
  62. // }
  63. // }
  64. /** 视图对象通过 ecs.Entity.remove(SetViewComp) 删除组件是触发组件处理自定义释放逻辑 */
  65. reset() {
  66. this.node.destroy();
  67. }
  68. }