WelfareTwo.ts 4.3 KB

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