WelfareOne.ts 4.4 KB

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