DoubleRewardsView.ts 9.8 KB

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