DoubleRewardsView.ts 10 KB

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