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-23 17:33:31
  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. }
  76. btn_all() {
  77. this.isAuto = false;
  78. smc.game.GameModel.viewType = "double_reward";
  79. ADHandler.inst.showAd(AD_TYPE.Double_Receive);
  80. oops.gui.remove(UIID.DoubleRewards);
  81. }
  82. //设置3秒自动领取
  83. private setAutoReceive() {
  84. this.callback = () => {
  85. this.data.time--;
  86. if (this.data.time <= 0) {
  87. //
  88. if (this.isAuto) {
  89. this.isAuto = false;
  90. oops.gui.remove(UIID.DoubleRewards);
  91. //插屏广告
  92. ADHandler.inst.showAd(AD_TYPE.Double_Close);
  93. DCHandler.inst.reportData(2000402);
  94. DCHandler.inst.reportData(2000403);
  95. }
  96. this.unschedule(this.callback);
  97. }
  98. }
  99. this.schedule(this.callback, 1, this.data.time - 1);
  100. }
  101. //算出底部进度条位置
  102. //设置数据
  103. private setData() {
  104. this.data.time = 3;
  105. this.isAuto = true;
  106. const info = smc.game.GameModel.doubleRewardInfo;
  107. if (info) {
  108. if (info.handingChargeProgress) {
  109. this.data.totalGoldNum = info.handingChargeProgress.totalMoney;
  110. this.data.handlingCharge = info.handingChargeProgress.handingCharge;
  111. this.data.curGoldNum = info.handingChargeProgress.hasNum;
  112. this.data.gapGoldNum = info.handingChargeProgress.gapNum;
  113. const showNode = this.node.getChildByPath("bottonNode/tips_node1");
  114. if (showNode) {
  115. showNode.active = true;
  116. }
  117. //计算红包的位置,计算角标位置
  118. //获取进度条长度
  119. const transform = this.progressNode.getComponent(UITransform);
  120. if (transform) {
  121. const progressWidth = transform.width;
  122. //通过长度,然后加上原始位置加长度*进度,就等于红包和icon需要放置的X轴位置
  123. const progressX = this.progressNode.position.x;
  124. //计算红包的位置
  125. const redBagX = progressX + (this.data.curGoldNum / this.data.handlingCharge) * progressWidth;
  126. this.redBagNode.setPosition(redBagX, this.redBagNode.position.y);
  127. //计算角标的位置
  128. this.iconNode.setPosition(redBagX, this.iconNode.position.y);
  129. //可以通过除,如果大于0.5就右边一点小于就左边一点,中间就在中间
  130. //x轴位置,-60, 0,60;
  131. if (this.data.curGoldNum / this.data.handlingCharge > 0.5) {
  132. this.tipsLabelNode.setPosition(60, this.tipsLabelNode.position.y);
  133. } else if (this.data.curGoldNum / this.data.handlingCharge < 0.5) {
  134. this.tipsLabelNode.setPosition(-60, this.tipsLabelNode.position.y);
  135. } else {
  136. this.tipsLabelNode.setPosition(0, this.tipsLabelNode.position.y);
  137. }
  138. }
  139. } else {
  140. //隐藏节点
  141. const showNode = this.node.getChildByPath("bottonNode/tips_node1");
  142. if (showNode) {
  143. showNode.active = false;
  144. }
  145. }
  146. if (info.levelProgress) {
  147. //设置进度条
  148. //克隆,然后添加
  149. const showNode = this.node.getChildByPath("bottonNode/tips_node2");
  150. if (showNode) {
  151. showNode.active = true;
  152. }
  153. this.data.goldNum = info.levelProgress.nextProgress;
  154. const levelInfoList = this.processLevelInfo(info.levelProgress.levelInfoList);
  155. this.levelListNode.destroyAllChildren();
  156. levelInfoList.forEach((item, index) => {
  157. const levelItem = instantiate(this.levelItemPrefab);
  158. this.levelListNode.addChild(levelItem);
  159. if (item.position) {
  160. levelItem.setPosition(item.position, 0);
  161. //设置数据
  162. const script = levelItem.getComponent(BricsItem);
  163. if (script) {
  164. script.updateData(item);
  165. }
  166. }
  167. });
  168. //计算进度//如果当前关提现了
  169. //const 最大关
  170. const maxLevel = levelInfoList[levelInfoList.length - 1].level;
  171. //const 当前关
  172. const currentLevel = smc.account.AccountModel.curLevel;
  173. this.data.curGoldNum = currentLevel;
  174. this.data.handlingCharge = maxLevel;
  175. } else {
  176. //隐藏节点
  177. const showNode = this.node.getChildByPath("bottonNode/tips_node2");
  178. if (showNode) {
  179. showNode.active = false;
  180. }
  181. }
  182. if (info.showReward) {
  183. info.showReward.forEach((item, index) => {
  184. if (this.lab_list[index]) {
  185. this.lab_list[index].string = item.propNum + "";
  186. }
  187. })
  188. }
  189. }
  190. }
  191. //计算位置
  192. calculatePositions(levelInfoList: LevelInfo[], totalLength: number = 516): LevelInfo[] {
  193. if (levelInfoList.length === 0) return [];
  194. const firstLevel = levelInfoList[0].level;
  195. const lastLevel = levelInfoList[levelInfoList.length - 1].level;
  196. const levelRange = lastLevel - firstLevel || 1; // 避免除0
  197. return levelInfoList.map((item, index) => {
  198. if (index === 0) {
  199. item.position = this.progressNode.position.x;
  200. } else if (index === levelInfoList.length - 1) {
  201. item.position = this.progressNode.position.x + totalLength;
  202. } else {
  203. //这里还有是进度条的初始位置+进度条的长度*当前的进度
  204. item.position = this.progressNode.position.x + ((item.level - firstLevel) / levelRange) * totalLength;
  205. }
  206. return item;
  207. });
  208. }
  209. processLevelInfo(levelInfoList: LevelInfo[], totalLength: number = 516): LevelInfo[] {
  210. if (levelInfoList.length === 0) return [];
  211. const firstLevel = levelInfoList[0].level;
  212. const lastLevel = levelInfoList[levelInfoList.length - 1].level;
  213. const levelRange = lastLevel - firstLevel || 1;
  214. let foundFirstNotWithdraw = false;
  215. const secondLastIndex = levelInfoList.length - 2;
  216. const allBeforeSecondLastWithdrawed = levelInfoList
  217. .slice(0, secondLastIndex)
  218. .every(item => item.withdraw);
  219. return levelInfoList.map((item, index) => {
  220. // 设置 position
  221. if (index === 0) {
  222. item.position = this.progressNode.position.x;
  223. } else if (index === levelInfoList.length - 1) {
  224. item.position = this.progressNode.position.x + totalLength;
  225. } else {
  226. item.position = this.progressNode.position.x + (((item.level - firstLevel) / levelRange) * totalLength);
  227. }
  228. // 标记第一个未提现
  229. if (!foundFirstNotWithdraw && !item.withdraw) {
  230. item.isFirstNotWithdraw = true;
  231. foundFirstNotWithdraw = true;
  232. } else {
  233. item.isFirstNotWithdraw = false;
  234. }
  235. // 标记是否倒数第二个之前的都提现
  236. item.isAllWithdrawBeforeSecondLast = allBeforeSecondLastWithdrawed;
  237. return item;
  238. });
  239. }
  240. }