DoubleRewardsView.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /*
  2. * @Author: mojunshou 1637302775@qq.com
  3. * @Date: 2025-03-21 11:57:43
  4. * @LastEditors: mojunshou 1637302775@qq.com
  5. * @LastEditTime: 2025-04-28 16:38:08
  6. * @Description: 惊喜翻倍弹窗
  7. */
  8. import { _decorator, instantiate, Label, Node, Prefab, UITransform } from 'cc';
  9. import { oops } from 'db://oops-framework/core/Oops';
  10. import VMParent from 'db://oops-framework/libs/model-view/VMParent';
  11. import { AD_TYPE } from '../common/config/GameDefine';
  12. import { UIID } from '../common/config/GameUIConfig';
  13. import { ADHandler } from '../common/manager/ADHandler';
  14. import { smc } from '../common/SingletonModuleComp';
  15. import { BricsItem } from './BricsItem';
  16. import { DCHandler } from '../common/manager/DCHandler';
  17. import { ServerHandler } from '../common/manager/ServerHandler';
  18. import { GameEvent } from '../common/config/GameEvent';
  19. const { ccclass, property } = _decorator;
  20. interface LevelInfo {
  21. level: number;
  22. eventType: string;
  23. withdraw: boolean;
  24. position?: number; //位置
  25. isFirstNotWithdraw?: boolean; //是否第一个没提现
  26. isAllWithdrawBeforeSecondLast?: boolean; //是否所有提现点都提现
  27. }
  28. /** 显示对象控制 */
  29. @ccclass('DoubleRewardsView')
  30. export class DoubleRewardsView extends VMParent {
  31. @property([Label])
  32. lab_list: Label[] = [];
  33. @property(Node)
  34. private redBagNode: Node = null!; //红包Node
  35. @property(Node)
  36. private iconNode: Node = null!; //角标Node
  37. //进度条Node
  38. @property(Node)
  39. private progressNode: Node = null!; //进度条Node
  40. //提示文字Node
  41. @property(Node)
  42. private tipsLabelNode: Node = null!; //提示文字Node
  43. @property(Node)
  44. private levelListNode: Node = null!; //等级Node
  45. @property(Prefab)
  46. private levelItemPrefab: Prefab = null!; //等级Item预制体
  47. data: any = {
  48. cd: 0,
  49. cdMax: 0,
  50. //总金额
  51. totalGoldNum: 0,
  52. //手续费
  53. handlingCharge: 0,
  54. //已经有的金额
  55. curGoldNum: 0,
  56. //差多少
  57. gapGoldNum: 0,
  58. //自动领取时间
  59. time: 0,
  60. goldNum: 0, //金砖数量
  61. }
  62. private callback: Function = null!;
  63. private isAuto: boolean = true;
  64. protected start() {
  65. DCHandler.inst.reportData(2000400);
  66. this.setButton();
  67. this.setData();
  68. this.setAutoReceive();
  69. oops.message.dispatchEvent(GameEvent.updateGameState, "paused");
  70. }
  71. btn_alittle() {
  72. oops.gui.remove(UIID.DoubleRewards);
  73. ServerHandler.inst.getLittleRewards();
  74. ADHandler.inst.showAd(AD_TYPE.Double_Close);
  75. DCHandler.inst.reportData(2000401);
  76. DCHandler.inst.reportData(2000403);
  77. oops.message.dispatchEvent(GameEvent.updateGameState, "playing");
  78. smc.game.GameModel.smallAdCount++;
  79. }
  80. btn_all() {
  81. this.isAuto = false;
  82. smc.game.GameModel.viewType = "double_reward";
  83. ADHandler.inst.showAd(AD_TYPE.Double_Receive);
  84. oops.gui.remove(UIID.DoubleRewards);
  85. oops.message.dispatchEvent(GameEvent.updateGameState, "playing");
  86. smc.game.GameModel.allAdCount++;
  87. smc.game.GameModel.smallAdCount = 0;
  88. }
  89. //设置3秒自动领取
  90. private setAutoReceive() {
  91. this.callback = () => {
  92. this.data.time--;
  93. if (this.data.time <= 0) {
  94. //
  95. if (this.isAuto) {
  96. this.isAuto = false;
  97. oops.gui.remove(UIID.DoubleRewards);
  98. ServerHandler.inst.getLittleRewards();
  99. ADHandler.inst.showAd(AD_TYPE.Double_Close);
  100. DCHandler.inst.reportData(2000402);
  101. DCHandler.inst.reportData(2000403);
  102. oops.message.dispatchEvent(GameEvent.updateGameState, "playing");
  103. smc.game.GameModel.smallAdCount++;
  104. }
  105. if (this.callback) {
  106. this.unschedule(this.callback);
  107. }
  108. }
  109. }
  110. this.schedule(this.callback, 1, this.data.time - 1);
  111. }
  112. //算出底部进度条位置
  113. //设置数据
  114. private setData() {
  115. this.data.time = 3;
  116. this.isAuto = true;
  117. const info = smc.game.GameModel.doubleRewardInfo;
  118. if (info) {
  119. if (info.handingChargeProgress) {
  120. this.data.totalGoldNum = info.handingChargeProgress.totalMoney;
  121. this.data.handlingCharge = info.handingChargeProgress.handingCharge;
  122. this.data.curGoldNum = info.handingChargeProgress.hasNum;
  123. this.data.gapGoldNum = info.handingChargeProgress.gapNum;
  124. const showNode = this.node.getChildByPath("bottonNode/tips_node1");
  125. if (showNode) {
  126. showNode.active = true;
  127. }
  128. //计算红包的位置,计算角标位置
  129. //获取进度条长度
  130. const transform = this.progressNode.getComponent(UITransform);
  131. if (transform) {
  132. const progressWidth = transform.width;
  133. //通过长度,然后加上原始位置加长度*进度,就等于红包和icon需要放置的X轴位置
  134. const progressX = this.progressNode.position.x;
  135. //计算红包的位置
  136. const redBagX = progressX + (this.data.curGoldNum / this.data.handlingCharge) * progressWidth;
  137. this.redBagNode.setPosition(redBagX, this.redBagNode.position.y);
  138. //计算角标的位置
  139. this.iconNode.setPosition(redBagX, this.iconNode.position.y);
  140. //可以通过除,如果大于0.5就右边一点小于就左边一点,中间就在中间
  141. //x轴位置,-60, 0,60;
  142. if (this.data.curGoldNum / this.data.handlingCharge > 0.5) {
  143. this.tipsLabelNode.setPosition(60, this.tipsLabelNode.position.y);
  144. } else if (this.data.curGoldNum / this.data.handlingCharge < 0.5) {
  145. this.tipsLabelNode.setPosition(-60, this.tipsLabelNode.position.y);
  146. } else {
  147. this.tipsLabelNode.setPosition(0, this.tipsLabelNode.position.y);
  148. }
  149. }
  150. } else {
  151. //隐藏节点
  152. const showNode = this.node.getChildByPath("bottonNode/tips_node1");
  153. if (showNode) {
  154. showNode.active = false;
  155. }
  156. }
  157. if (info.levelProgress) {
  158. //设置进度条
  159. //克隆,然后添加
  160. const showNode = this.node.getChildByPath("bottonNode/tips_node2");
  161. if (showNode) {
  162. showNode.active = true;
  163. }
  164. this.data.goldNum = info.levelProgress.nextProgress;
  165. const levelInfoList = this.processLevelInfo(info.levelProgress.levelInfoList);
  166. this.levelListNode.destroyAllChildren();
  167. levelInfoList.forEach((item, index) => {
  168. const levelItem = instantiate(this.levelItemPrefab);
  169. this.levelListNode.addChild(levelItem);
  170. if (item.position) {
  171. levelItem.setPosition(item.position, 0);
  172. //设置数据
  173. const script = levelItem.getComponent(BricsItem);
  174. if (script) {
  175. script.updateData(item);
  176. }
  177. }
  178. });
  179. //计算进度//如果当前关提现了
  180. //const 最大关
  181. const maxLevel = levelInfoList[levelInfoList.length - 1].level;
  182. //const 当前关
  183. const currentLevel = smc.account.AccountModel.curLevel;
  184. this.data.curGoldNum = currentLevel;
  185. this.data.handlingCharge = maxLevel;
  186. } else {
  187. //隐藏节点
  188. const showNode = this.node.getChildByPath("bottonNode/tips_node2");
  189. if (showNode) {
  190. showNode.active = false;
  191. }
  192. }
  193. if (info.showReward) {
  194. info.showReward.forEach((item, index) => {
  195. if (this.lab_list[index]) {
  196. this.lab_list[index].string = item.propNum + "";
  197. }
  198. })
  199. }
  200. }
  201. }
  202. //计算位置
  203. calculatePositions(levelInfoList: LevelInfo[], totalLength: number = 516): LevelInfo[] {
  204. if (levelInfoList.length === 0) return [];
  205. const firstLevel = levelInfoList[0].level;
  206. const lastLevel = levelInfoList[levelInfoList.length - 1].level;
  207. const levelRange = lastLevel - firstLevel || 1; // 避免除0
  208. return levelInfoList.map((item, index) => {
  209. if (index === 0) {
  210. item.position = this.progressNode.position.x;
  211. } else if (index === levelInfoList.length - 1) {
  212. item.position = this.progressNode.position.x + totalLength;
  213. } else {
  214. //这里还有是进度条的初始位置+进度条的长度*当前的进度
  215. item.position = this.progressNode.position.x + ((item.level - firstLevel) / levelRange) * totalLength;
  216. }
  217. return item;
  218. });
  219. }
  220. processLevelInfo(levelInfoList: LevelInfo[], totalLength: number = 516): LevelInfo[] {
  221. if (levelInfoList.length === 0) return [];
  222. const firstLevel = levelInfoList[0].level;
  223. const lastLevel = levelInfoList[levelInfoList.length - 1].level;
  224. const levelRange = lastLevel - firstLevel || 1;
  225. let foundFirstNotWithdraw = false;
  226. const secondLastIndex = levelInfoList.length - 2;
  227. const allBeforeSecondLastWithdrawed = levelInfoList
  228. .slice(0, secondLastIndex)
  229. .every(item => item.withdraw);
  230. return levelInfoList.map((item, index) => {
  231. // 设置 position
  232. if (index === 0) {
  233. item.position = this.progressNode.position.x;
  234. } else if (index === levelInfoList.length - 1) {
  235. item.position = this.progressNode.position.x + totalLength;
  236. } else {
  237. item.position = this.progressNode.position.x + (((item.level - firstLevel) / levelRange) * totalLength);
  238. }
  239. // 标记第一个未提现
  240. if (!foundFirstNotWithdraw && !item.withdraw) {
  241. item.isFirstNotWithdraw = true;
  242. foundFirstNotWithdraw = true;
  243. } else {
  244. item.isFirstNotWithdraw = false;
  245. }
  246. // 标记是否倒数第二个之前的都提现
  247. item.isAllWithdrawBeforeSecondLast = allBeforeSecondLastWithdrawed;
  248. return item;
  249. });
  250. }
  251. }