WelfareTwo.ts 4.6 KB

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