UISignPage.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. import UIPage from "../Framework/UIPage";
  2. import Constant, { PageName, PanelName } from "../Framework/Constant";
  3. import { cocosz } from "../Framework/CocosZ";
  4. import Msg from "../Framework/Msg";
  5. import FlyCoin from "../Framework/FlyCoin";
  6. import { utils } from "../../common-plugin/Scripts/Utils";
  7. import TweenEffect from "../Framework/TweenEffect";
  8. // @ts-ignore
  9. const i18n = require('LanguageData');
  10. import AESUtil from "../AESUtil"
  11. import ATSDK from "../AnyThinkAds/ATJSSDK";
  12. import ATRewardedVideoSDK from "../AnyThinkAds/ATRewardedVideoJSSDK";
  13. import AAJS2 from "../ATAndroidJS2";
  14. import GlobalManager from '../GlobalManager';
  15. const { ccclass, property } = cc._decorator;
  16. const REWARD_SIGN: number[] = [500, 1000, 1500, 50, 2000, 2500, 100];
  17. class DayItem {
  18. private _index: number = -1;
  19. private _node: cc.Node = null;
  20. private _normal: cc.Node = null;
  21. private _current: cc.Node = null;
  22. private _got: cc.Node = null;
  23. private _label: cc.Label = null;
  24. constructor(index: number, node: cc.Node) {
  25. this._index = index;
  26. this._node = node;
  27. this._normal = this._node.getChildByName("st1");
  28. this._current = this._node.getChildByName("st2");
  29. this._got = this._node.getChildByName("st3");
  30. if (this._node.getChildByName("rewardLabel")) {
  31. this._label = this._node.getChildByName("rewardLabel").getComponent(cc.Label);
  32. this._label.node.scale = 0.7;
  33. this._label.node.setPosition(this._node.x, this._node.y - 60);
  34. this._label.node.setParent(this._node.parent);
  35. this._label.string = "+" + REWARD_SIGN[this._index];
  36. }
  37. }
  38. public setStatus(status: number) {
  39. if (status == 0) {
  40. this._normal.active = true;
  41. this._current.active = false;
  42. this._got.active = false;
  43. this._label.node.active = true;
  44. }
  45. else if (status == 1) {
  46. this._normal.active = false;
  47. this._current.active = true;
  48. this._got.active = false;
  49. this._label.node.active = true;
  50. }
  51. else if (status == 2) {
  52. this._normal.active = true;
  53. this._current.active = false;
  54. this._got.active = true;
  55. this._label.node.active = false;
  56. }
  57. }
  58. public update() {
  59. // 上一次领取的是第几天,从0开始
  60. let lastDayIndex: number = cocosz.dataMgr.LastDailyBonusIndex;
  61. // 超过一天, 重置一下天数
  62. if (lastDayIndex == 6) {
  63. lastDayIndex = -1;
  64. }
  65. // 上次领取的时间
  66. const lastDayTime: string = cocosz.dataMgr.LastDailyBonusTime;
  67. let canGet: boolean = false;
  68. if (new Date().toDateString() != lastDayTime && this._index == lastDayIndex + 1) {
  69. canGet = true;
  70. }
  71. // cc.log(`lastDayIndex: ${lastDayIndex} --- lastDayTime: ${lastDayTime}`);
  72. // this._got.active = false;
  73. // this._normal.active = false;
  74. // this._current.active = false;
  75. if (this._index <= lastDayIndex) {
  76. // 已经领取过了
  77. // this._got.active = true;
  78. this.setStatus(2)
  79. } else {
  80. if (canGet) {
  81. this.setStatus(1)
  82. // this._current.active = true;
  83. } else {
  84. this.setStatus(0)
  85. // this._normal.active = true;
  86. }
  87. }
  88. }
  89. }
  90. @ccclass
  91. export default class UISignPanel extends UIPage {
  92. private _mask: cc.Node = null;
  93. private _panel: cc.Node = null;
  94. private _btnGet: cc.Node = null;
  95. private _btnDouble: cc.Node = null;
  96. private _btnClose: cc.Node = null;
  97. private _day: DayItem[] = [];
  98. private adKey: string = "zh_ad_type";
  99. constructor() {
  100. super(PanelName.UISignPanel);
  101. this.isValid() && this.onLoad();
  102. }
  103. protected onLoad() {
  104. this._panel = this._page.getChildByName("Panel");
  105. this._mask = this._page.getChildByName("mask");
  106. let btnNames: string[] = ["BtnClose", "BtnDouble", "BtnGet"];
  107. for (let i = 0; i < btnNames.length; i++) {
  108. let btn: cc.Node = cc.find(btnNames[i], this._panel);
  109. if (!btn) continue
  110. btn.on(cc.Node.EventType.TOUCH_END, this._onBtnClickedHandler, this);
  111. if (btn.name == "BtnGet") {
  112. this._btnGet = btn;
  113. } else if (btn.name == "BtnDouble") {
  114. this._btnDouble = btn;
  115. this._btnDouble.active = cocosz.isADON;
  116. }
  117. else {
  118. this._btnClose = btn;
  119. }
  120. }
  121. for (let i = 0; i < 6; i++) {
  122. let dayItem: DayItem = new DayItem(i, this._panel.getChildByName("Day_" + (i + 1)));
  123. this._day.push(dayItem);
  124. }
  125. this.initAdForPage();
  126. }
  127. initAdForPage() {
  128. if (cc.sys.os === cc.sys.OS_ANDROID) {
  129. let deviceId = AAJS2.getDeviceUserId();
  130. console.log("zh:checkstatus:", ATRewardedVideoSDK.checkAdStatus(AAJS2.getPlacementId()));
  131. var setting = {};
  132. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  133. ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting);
  134. }
  135. }
  136. protected onOpen() {
  137. // 上报 首页签到
  138. utils.umaEvent("gamegamesign");
  139. utils.SendEvent("1页面-签到");
  140. this._initPanel();
  141. }
  142. private _initPanel() {
  143. TweenEffect.panel_open_scale(this._panel);
  144. // 缩放
  145. this._updateDayItem();
  146. }
  147. private _updateDayItem() {
  148. for (let i = 0; i < 6; i++) {
  149. this._day[i].update();
  150. }
  151. }
  152. private async _onBtnClickedHandler(event: cc.Event, data: any) {
  153. cocosz.audioMgr.playBtnEffect();
  154. switch (event.target.name) {
  155. case "BtnGet": {
  156. if (!this._canGetBonus()) {
  157. Msg.Show(i18n.t("msg.jryqd"));//今日已领取奖励
  158. return;
  159. }
  160. this._getReward(false);
  161. break;
  162. }
  163. case "BtnDouble": {
  164. if (!this._canGetBonus()) {
  165. Msg.Show(i18n.t("msg.jryqd"));//今日已领取奖励
  166. return;
  167. }
  168. // 注册方法 , this.ClickClose.bind(this));
  169. GlobalManager.getInstance().registerMethod('_getReward_eventForAd', this._getReward_eventForAd.bind(this));
  170. cc.sys.localStorage.setItem(this.adKey, 'qianDao_dblq');//
  171. if (ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementId())) {
  172. console.log('zh:AD ready for idx2')
  173. ATRewardedVideoSDK.showAd(AAJS2.getPlacementId());
  174. } else {
  175. this.initAdForPage();
  176. console.log('zh:AD not ready for idx2')
  177. this._getReward_eventForAd(true);
  178. }
  179. if (2 > 1) {
  180. return;//下面是原始的代码
  181. }
  182. utils.SendEvent("视频-双倍签到-播放")
  183. cocosz.watchAD(() => {
  184. utils.SendEvent("视频-双倍签到-成功")
  185. this._getReward(true);
  186. }, () => {
  187. utils.SendEvent("视频-双倍签到-失败")
  188. });
  189. break;
  190. }
  191. case "BtnClose": {
  192. cocosz.uiMgr.closePanel(PanelName.UISignPanel);
  193. break;
  194. }
  195. }
  196. }
  197. private _getReward(double: boolean) {
  198. if (double == false) {
  199. // 上报 普通签到
  200. utils.umaEvent("gamesignordinary");
  201. utils.SendEvent("签到-普通");
  202. } else {
  203. // 上报 双倍签到
  204. utils.umaEvent("gamedoublesign");
  205. utils.SendEvent("签到-双倍");
  206. }
  207. // 签到索引
  208. let lastDayIndex: number = cocosz.dataMgr.LastDailyBonusIndex;
  209. if (lastDayIndex == 6) {
  210. lastDayIndex = -1;
  211. }
  212. let curDayIndex = lastDayIndex + 1;
  213. // 奖励数量
  214. let count: number = REWARD_SIGN[curDayIndex];
  215. if (double) { count *= 2; }
  216. if (curDayIndex == 3 || curDayIndex == 6) {
  217. // 钻石
  218. Msg.Show(i18n.t("msg.gxhdzs") + count);
  219. cocosz.dataMgr.DiamondCount += count;
  220. // 飞金币事件
  221. setTimeout(() => {
  222. cc.game.emit(Constant.E_GAME_LOGIC, { type: Constant.E_Fly_Coin, iconName: 'diamond', frameNodeName: 'CoinLabel2' })
  223. }, 500);
  224. } else {
  225. // 金币
  226. Msg.Show(i18n.t("msg.gxhdjb") + count);
  227. cocosz.dataMgr.CoinCount += count;
  228. // 飞金币事件
  229. setTimeout(() => {
  230. cc.game.emit(Constant.E_GAME_LOGIC, { type: Constant.E_Fly_Coin, iconName: 'coin', frameNodeName: 'CoinLabel' })
  231. }, 500);
  232. }
  233. // 本地信息
  234. cocosz.dataMgr.LastDailyBonusIndex = curDayIndex;
  235. cocosz.dataMgr.LastDailyBonusTime = new Date().toDateString();
  236. // 刷新UI
  237. // this._updateDayItem();
  238. // 关闭弹窗
  239. cocosz.uiMgr.closePanel(PanelName.UISignPanel);
  240. }
  241. //AD
  242. private _getReward_eventForAd(double: boolean) {
  243. console.log('zh:AD eventForAd 被触发:', double);
  244. if (double == false) {
  245. // 上报 普通签到
  246. utils.umaEvent("gamesignordinary");
  247. utils.SendEvent("签到-普通");
  248. } else {
  249. // 上报 双倍签到
  250. utils.umaEvent("gamedoublesign");
  251. utils.SendEvent("签到-双倍");
  252. }
  253. // 签到索引
  254. let lastDayIndex: number = cocosz.dataMgr.LastDailyBonusIndex;
  255. if (lastDayIndex == 6) {
  256. lastDayIndex = -1;
  257. }
  258. let curDayIndex = lastDayIndex + 1;
  259. // 奖励数量
  260. let count: number = REWARD_SIGN[curDayIndex];
  261. if (double) { count *= 2; }
  262. if (curDayIndex == 3 || curDayIndex == 6) {
  263. // 钻石
  264. Msg.Show(i18n.t("msg.gxhdzs") + count);
  265. cocosz.dataMgr.DiamondCount += count;
  266. // 飞金币事件
  267. setTimeout(() => {
  268. cc.game.emit(Constant.E_GAME_LOGIC, { type: Constant.E_Fly_Coin, iconName: 'diamond', frameNodeName: 'CoinLabel2' })
  269. }, 500);
  270. } else {
  271. // 金币
  272. Msg.Show(i18n.t("msg.gxhdjb") + count);
  273. cocosz.dataMgr.CoinCount += count;
  274. // 飞金币事件
  275. setTimeout(() => {
  276. cc.game.emit(Constant.E_GAME_LOGIC, { type: Constant.E_Fly_Coin, iconName: 'coin', frameNodeName: 'CoinLabel' })
  277. }, 500);
  278. }
  279. // 本地信息
  280. cocosz.dataMgr.LastDailyBonusIndex = curDayIndex;
  281. cocosz.dataMgr.LastDailyBonusTime = new Date().toDateString();
  282. // 刷新UI
  283. // this._updateDayItem();
  284. // 关闭弹窗
  285. cocosz.uiMgr.closePanel(PanelName.UISignPanel);
  286. }
  287. private _canGetBonus() {
  288. // cocosz.dataMgr.LastDailyBonusTime = 'Fri Dec 18 2024';
  289. return (new Date().toDateString() != cocosz.dataMgr.LastDailyBonusTime);
  290. }
  291. }