WelfareOne.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * @Author: mojunshou 1637302775@qq.com
  3. * @Date: 2025-04-18 19:11:51
  4. * @LastEditors: mojunshou 1637302775@qq.com
  5. * @LastEditTime: 2025-04-27 18:52:48
  6. * @Description: 福利一
  7. */
  8. import { _decorator, Animation, instantiate, Node, Prefab } from 'cc';
  9. import { oops } from 'db://oops-framework/core/Oops';
  10. import { DeviceUtil } from 'db://oops-framework/core/utils/DeviceUtil';
  11. import VMParent from 'db://oops-framework/libs/model-view/VMParent';
  12. import { UIID } from '../../common/config/GameUIConfig';
  13. import { smc } from '../../common/SingletonModuleComp';
  14. import { LoadBricsItem } from '../LoadBricsItem';
  15. import { ServerHandler } from '../../common/manager/ServerHandler';
  16. const { ccclass, property } = _decorator;
  17. interface LevelInfo {
  18. level: number;
  19. eventType: string;
  20. withdraw: boolean;
  21. position?: number; //位置
  22. isFirstNotWithdraw?: boolean; //是否第一个没提现
  23. }
  24. @ccclass('WelfareOne')
  25. export class WelfareOne extends VMParent {
  26. data: any = {
  27. itemList: [],
  28. frequency: 5,
  29. cur_num: 1,
  30. total_num: 12,
  31. wealCount: 0
  32. }
  33. @property(Node)
  34. private progressNode: Node = null!;
  35. @property(Node)
  36. private showNode1: Node = null!; //福利一
  37. @property(Node)
  38. private showNode2: Node = null!; //自动提现进度
  39. @property(Prefab)
  40. itemPrefab: Prefab = null!;
  41. @property(Node)
  42. itemList: Node = null!;
  43. start() {
  44. //三秒后进自动提现进度条
  45. this.showNode1.active = false;
  46. this.showNode2.active = false;
  47. this.showWelfareOne();
  48. this.updateData();
  49. }
  50. //展示福利一界面
  51. showWelfareOne() {
  52. this.showNode1.active = true;
  53. //
  54. this.scheduleOnce(() => {
  55. this.showNode1.active = false;
  56. this.showLoadBar();
  57. }, 3)
  58. }
  59. //更新数据
  60. updateData() {
  61. if (DeviceUtil.isAndroid && DeviceUtil.isNative) {
  62. if (smc.game.GameModel.loadbarInfo.levelProgress) {
  63. this.data.itemList = smc.game.GameModel.loadbarInfo.levelProgress.levelInfoList
  64. //进度
  65. this.data.cur_num = smc.account.AccountModel.curLevel;
  66. this.data.total_num = this.data.itemList[this.data.itemList.length - 1].level;
  67. const itemInfoList = this.processLevelInfo(this.data.itemList);
  68. this.itemList.destroyAllChildren();
  69. itemInfoList.forEach((item, index) => {
  70. const loadLevelItem = instantiate(this.itemPrefab)
  71. this.itemList.addChild(loadLevelItem);
  72. if (item.position) {
  73. loadLevelItem.setPosition(item.position, 0);
  74. //设置数据
  75. const script = loadLevelItem.getComponent(LoadBricsItem);
  76. if (script) {
  77. script.updateData(item);
  78. }
  79. }
  80. })
  81. }
  82. }
  83. }
  84. //展示进度条界面
  85. showLoadBar() {
  86. this.showNode2.active = true;
  87. const animation = this.showNode2.getComponent(Animation);
  88. if (animation) {
  89. animation.play();
  90. }
  91. //3秒后关闭
  92. this.scheduleOnce(() => {
  93. // this.updateState();
  94. //展示解锁
  95. oops.gui.open(UIID.UnlockFunction);
  96. oops.gui.remove(UIID.WelfareOne);
  97. }, 3)
  98. }
  99. processLevelInfo(levelInfoList: LevelInfo[], totalLength: number = 602): LevelInfo[] {
  100. if (levelInfoList.length === 0) return [];
  101. const firstLevel = levelInfoList[0].level;
  102. const lastLevel = levelInfoList[levelInfoList.length - 1].level;
  103. //单段距离 总长度/最后一个level-1
  104. const singleLength = totalLength / (lastLevel - 1);
  105. return levelInfoList.map((item, index) => {
  106. let foundFirstNotWithdraw = false;
  107. if (index === 0) {
  108. item.position = this.progressNode.position.x;
  109. } else if (index === levelInfoList.length - 1) {
  110. item.position = this.progressNode.position.x + totalLength;
  111. } else {
  112. item.position = this.progressNode.position.x + ((item.level - firstLevel) * singleLength);
  113. }
  114. // 标记第一个未提现
  115. if (!foundFirstNotWithdraw && item.withdraw) {
  116. item.isFirstNotWithdraw = true;
  117. foundFirstNotWithdraw = true;
  118. } else {
  119. item.isFirstNotWithdraw = false;
  120. }
  121. return item;
  122. });
  123. }
  124. }