WelfareTwo.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. import { GameEvent } from '../../common/config/GameEvent';
  13. const { ccclass, property } = _decorator;
  14. interface LevelInfo {
  15. level: number;
  16. eventType: string;
  17. withdraw: boolean;
  18. position?: number; //位置
  19. isFirstNotWithdraw?: boolean; //是否第一个没提现
  20. }
  21. @ccclass('WelfareTwo')
  22. export class WelfareTwo extends VMParent {
  23. data: any = {
  24. itemList: [],
  25. cur_num: 1,
  26. total_num: 12,
  27. wealCount: 0
  28. }
  29. @property(Node)
  30. private progressNode: Node = null!;
  31. @property(Node)
  32. private showNode1: Node = null!; //福利一
  33. @property(Node)
  34. private showNode2: Node = null!; //自动提现进度
  35. @property(Prefab)
  36. itemPrefab: Prefab = null!;
  37. @property(Node)
  38. itemList: Node = null!;
  39. start() {
  40. //三秒后进自动提现进度条
  41. this.showNode1.active = false;
  42. this.showNode2.active = false;
  43. this.showWelfareTwo();
  44. this.updateData();
  45. oops.message.dispatchEvent(GameEvent.updateGameState, "paused");
  46. }
  47. showWelfareTwo() {
  48. this.showNode1.active = true;
  49. //
  50. this.scheduleOnce(() => {
  51. this.showNode1.active = false;
  52. this.showLoadBar();
  53. }, 3)
  54. }
  55. //展示进度条界面
  56. showLoadBar() {
  57. this.showNode2.active = true;
  58. const animation = this.showNode2.getComponent(Animation);
  59. if (animation) {
  60. animation.play();
  61. }
  62. //3秒后关闭
  63. this.scheduleOnce(() => {
  64. // oops.gui.open(UIID.UnlockFunction);
  65. this.updateState();
  66. oops.gui.remove(UIID.WelfareTwo);
  67. //解锁新功能
  68. }, 3)
  69. }
  70. //更新数据
  71. updateData() {
  72. if (DeviceUtil.isAndroid && DeviceUtil.isNative) {
  73. if (smc.game.GameModel.loadbarInfo.levelProgress) {
  74. this.data.itemList = smc.game.GameModel.loadbarInfo.levelProgress.levelInfoList
  75. //进度
  76. this.data.cur_num = smc.account.AccountModel.curLevel;
  77. this.data.total_num = this.data.itemList[this.data.itemList.length - 1].level;
  78. const itemInfoList = this.processLevelInfo(this.data.itemList);
  79. this.itemList.destroyAllChildren();
  80. itemInfoList.forEach((item, index) => {
  81. const loadLevelItem = instantiate(this.itemPrefab)
  82. this.itemList.addChild(loadLevelItem);
  83. if (item.position) {
  84. loadLevelItem.setPosition(item.position, 0);
  85. //设置数据
  86. const script = loadLevelItem.getComponent(LoadBricsItem);
  87. if (script) {
  88. script.updateData(item);
  89. }
  90. }
  91. })
  92. }
  93. }
  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. updateState() {
  121. ServerHandler.inst.updatePopupState({
  122. level: smc.account.AccountModel.curLevel,
  123. type: smc.game.GameModel.popupType
  124. })
  125. }
  126. }