Sign.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import JsbSystem from "../../../mk/system/JsbSystem";
  2. import TableView from "../../component/TableView";
  3. import { AdFun } from "../../data/AdData";
  4. import { DataEventId, RewardType, VideoAdType } from "../../data/GameData";
  5. /**
  6. * 签到界面
  7. * - 每天第一次上线默认弹出一次【除首日】。待处理
  8. * - 全部签完后,不可再签到。此处需要判断上次签到天数。
  9. * - 滑动列表需要滚动到对应签到条目的高度,待处理。
  10. * @author 薛鸿潇
  11. */
  12. const { ccclass, property } = cc._decorator;
  13. @ccclass
  14. export default class Sign extends cc.Component {
  15. @property({ type: cc.ScrollView, displayName: '滚动视图' })
  16. private scroll_view: cc.ScrollView = null!;
  17. @property({ type: cc.Animation, displayName: '按钮_动画' })
  18. private anim_btn: cc.Animation = null!;
  19. private tableview: TableView = null;
  20. onLoad() {
  21. }
  22. start() {
  23. mk.ad.showNative(4);
  24. // gData.sign.sign_can = gData.gameData.getProp(GameProp.sign_can);
  25. gData.sign.initListData();
  26. gData.sign.init_data = true;
  27. this.initScollView();
  28. }
  29. /**
  30. * 初始化滚动视图
  31. */
  32. private initScollView() {
  33. let list_data = gData.sign.list_data;
  34. this.scroll_view.node.emit('srollview-init', list_data)
  35. this.tableview = this.scroll_view.node.getComponent('TableView')
  36. let index = gData.sign.getItemIndexByCanSign();
  37. if (index > 0)
  38. index -= 1;
  39. //index = 4;
  40. this.tableview.contentMoveByIndex(index, 0.01);
  41. cc.tween(this.node).delay(0.2).call(()=>{
  42. let allItem = this.tableview.getItemByIndexAndCount(index, 3);
  43. allItem && allItem.sort((a, b)=>{
  44. return a.index - b.index;
  45. })
  46. for(let i = 0; i != allItem.length; ++i)
  47. {
  48. allItem[i].active = true;
  49. allItem[i].setPosition(allItem[i].position.x, allItem[i].position.y - 600);
  50. cc.tween(allItem[i]).delay(i*0.1).by(0.3, {y: 600}, cc.easeSineOut()).start();
  51. }
  52. console.log("---");
  53. }).start();
  54. }
  55. update(dt) {
  56. if (gData.sign.init_data) {
  57. this.initBtnStyle();
  58. return;
  59. }
  60. if (gData.sign.adData) {
  61. // 展示奖励
  62. this.getReward();
  63. }
  64. }
  65. lateUpdate() {
  66. gData.sign.adData = null;
  67. }
  68. /**
  69. * 点击领取按钮
  70. */
  71. private clickReceiveReward() {
  72. mk.audio.playEffect("button");
  73. if (gData.gameData.gameData.isSignInToday == 1) return;
  74. if (!gData.sign.haveSignDay()) return;
  75. //const index_old = gData.sign.getItemIndexByCanSign();
  76. const index_old = gData.gameData.gameData.signInDay;
  77. if(cc.sys.isNative)
  78. {
  79. if (gData.sign.c_sign[index_old].rewardType === RewardType.rmb) {
  80. if (!gData.loginData.isAuth) {
  81. JsbSystem.WxAuth();
  82. return;
  83. }
  84. }
  85. }
  86. mk.ad.videoAdType = VideoAdType.Sign;
  87. // 看广告
  88. mk.ad.watchAd((success: boolean) => {
  89. mk.console.log("watchAD:" + success);
  90. if (success) {
  91. gData.adData.watchVideo(AdFun.sign);
  92. //FC:埋点
  93. if (gData.sign.c_sign[index_old].rewardType === RewardType.rmb) {
  94. mk.data.sendDataEvent(DataEventId.signWithDrawal, "签到提现成功");
  95. }
  96. mk.ad.destroyNativeAd();
  97. }
  98. });
  99. }
  100. /**
  101. * 拿奖励
  102. */
  103. private getReward() {
  104. const index_old = gData.sign.getItemIndexByCanSign();
  105. // 完成展示
  106. gData.sign.signComplete();
  107. // 指定条目数据刷新
  108. this.tableview.resetItemData(index_old, gData.sign.list_data[index_old]);
  109. // 打开奖励界面
  110. // to do
  111. }
  112. /**
  113. * 初始化按钮样式
  114. */
  115. private initBtnStyle() {
  116. if (gData.gameData.gameData.isSignInToday == 0 && gData.sign.haveSignDay()) {
  117. this.anim_btn.play();
  118. // this.anim_btn.getComponent(SetGray).setGray(false);
  119. this.anim_btn.getComponent(mk.component.setGray).setGray(false)
  120. } else {
  121. this.anim_btn.stop();
  122. this.anim_btn.node.scale = 1;
  123. // this.anim_btn.getComponent('SetGray').setGray(true);
  124. this.anim_btn.getComponent(mk.component.setGray).setGray(true)
  125. }
  126. gData.sign.init_data = false;
  127. }
  128. onClickClose() {
  129. mk.audio.playEffect("closeButton");
  130. mk.ad.destroyNativeAd();
  131. mk.ad.checkShowInterByChance();
  132. }
  133. }