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