Sign.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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.1).call(()=>{
  42. this.scroll_view.vertical = false;
  43. }).call(()=>{
  44. let allItem = this.tableview.getItemByIndexAndCount(index, 3);
  45. allItem && allItem.sort((a, b)=>{
  46. return a.index - b.index;
  47. })
  48. let len = allItem.length;
  49. for(let i = 0; i != len; ++i)
  50. {
  51. //allItem[i].active = true;
  52. let posY = allItem[i].position.y
  53. allItem[i].y = posY - 600;
  54. cc.tween(allItem[i]).delay(i*0.1).to(0.3, {y: posY}, cc.easeSineOut()).start();
  55. }
  56. }).delay(0.7).call(()=>{
  57. this.scroll_view.vertical = true;
  58. }).start();
  59. }
  60. update(dt) {
  61. if (gData.sign.init_data) {
  62. this.initBtnStyle();
  63. return;
  64. }
  65. if (gData.sign.adData) {
  66. // 展示奖励
  67. this.getReward();
  68. }
  69. }
  70. lateUpdate() {
  71. gData.sign.adData = null;
  72. }
  73. /**
  74. * 点击领取按钮
  75. */
  76. private clickReceiveReward() {
  77. mk.audio.playEffect("button");
  78. if (gData.gameData.playerProp.isSignInToday == 1) return;
  79. if (!gData.sign.haveSignDay()) return;
  80. //const index_old = gData.sign.getItemIndexByCanSign();
  81. const index_old = gData.gameData.playerProp.signInDay;
  82. if(cc.sys.isNative)
  83. {
  84. if (gData.sign.c_sign[index_old].rewardType === RewardType.rmb) {
  85. if (!gData.loginData.isAuth) {
  86. // JsbSystem.WxAuth();
  87. gData.gameData.authUIType = 0;
  88. mk.ui.openPanel('module/authUI/authUI');
  89. return;
  90. }
  91. }
  92. }
  93. mk.ad.videoAdType = VideoAdType.video_init_4;
  94. // 看广告
  95. mk.ad.watchAd((success: boolean) => {
  96. mk.console.log("watchAD:" + success);
  97. if (success) {
  98. gData.adData.watchVideo(AdFun.sign);
  99. //FC:埋点
  100. if (gData.sign.c_sign[index_old].rewardType === RewardType.rmb) {
  101. mk.data.sendDataEvent(DataEventId.Sundry, "签到提现成功");
  102. }
  103. mk.ad.destroyNativeAd();
  104. }
  105. });
  106. }
  107. /**
  108. * 拿奖励
  109. */
  110. private getReward() {
  111. const index_old = gData.sign.getItemIndexByCanSign();
  112. // 完成展示
  113. gData.sign.signComplete();
  114. // 指定条目数据刷新
  115. this.tableview.resetItemData(index_old, gData.sign.list_data[index_old]);
  116. // 打开奖励界面
  117. // to do
  118. }
  119. /**
  120. * 初始化按钮样式
  121. */
  122. private initBtnStyle() {
  123. if (gData.gameData.playerProp.isSignInToday == 0 && gData.sign.haveSignDay()) {
  124. this.anim_btn.play();
  125. // this.anim_btn.getComponent(SetGray).setGray(false);
  126. this.anim_btn.getComponent(mk.component.setGray).setGray(false)
  127. } else {
  128. this.anim_btn.stop();
  129. this.anim_btn.node.scale = 1;
  130. // this.anim_btn.getComponent('SetGray').setGray(true);
  131. this.anim_btn.getComponent(mk.component.setGray).setGray(true)
  132. }
  133. gData.sign.init_data = false;
  134. }
  135. onClickClose() {
  136. mk.audio.playEffect("button");
  137. //mk.ad.destroyNativeAd();
  138. }
  139. }