AchievementItem.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { _decorator, Component, Label, Sprite } from 'cc';
  2. import { Http } from '../core/net/Http';
  3. import { BitmapFont } from '../core/ui/BitmapFont';
  4. import { OpenWindow } from '../core/ui/window/OpenWindow';
  5. import { WindowManager } from '../core/ui/window/WindowManager';
  6. import { WindowOpenMode } from '../core/ui/window/WindowOpenMode';
  7. import { Utils } from '../core/utils/Utils';
  8. import { g } from '../Data/g';
  9. import { HttpErrorCode } from '../Data/HttpErrorCode';
  10. import { platform } from '../Data/platform';
  11. import { GetType } from '../UI/GetWindow/GetType';
  12. const { ccclass, property } = _decorator;
  13. @ccclass('AchievementItem')
  14. export class AchievementItem extends Component {
  15. @property({ type: BitmapFont })
  16. public gradeRight: BitmapFont = null;
  17. @property({ type: BitmapFont })
  18. public title: BitmapFont = null;
  19. @property({ type: Label })
  20. public redNum: Label = null;
  21. @property({ type: Sprite })
  22. public unGet: Sprite = null;
  23. @property({ type: Sprite })
  24. public canGet: Sprite = null;
  25. @property({ type: Sprite })
  26. public geted: Sprite = null;
  27. private http: Http;
  28. start() {
  29. this.http = this.node.getComponent(Http);
  30. }
  31. /**
  32. * Item ID
  33. */
  34. public id: number;
  35. onUngetClick() {
  36. WindowManager.showTips("未到达指定等级");
  37. }
  38. async onCangetClick() {
  39. let result = await this.http.send("/api/ad/watchVideoAD");
  40. if (result.code == 0) {
  41. platform.reportThinking("ad_init", JSON.stringify({ ad_id: "farm_reward", ad_time: Utils.formatDate(new Date()), id: g.userData.id, role_name: g.userData.nickName, level: g.userData.getLevel() }));
  42. //播放视频
  43. let adData = await g.showRewardVideo();
  44. if (adData) {
  45. this.onVideoOver();
  46. } else {
  47. //视频观看失败
  48. WindowManager.showTips("视频观看时间不足");
  49. }
  50. } else if (result.code == 106) {
  51. WindowManager.showTips("今日视频次数已用完,请明日再继续");
  52. } else if (result.code == HttpErrorCode.VideoADCD) {
  53. WindowManager.showTips("请求频繁,请稍后再试");
  54. }
  55. else {
  56. WindowManager.showTips("视频准备中,请稍后再试");
  57. }
  58. }
  59. /**
  60. * 视频结束
  61. */
  62. private async onVideoOver() {
  63. let data = await this.http.send("/api/levelReward/getLevelReward", { configID: this.id, adData: g.adData })
  64. if (data.code == 0) {
  65. platform.reportThinking("ad_end", JSON.stringify({ ad_id: "farm_reward", ad_time: Utils.formatDate(new Date()), id: g.userData.id, role_name: g.userData.nickName, level: g.userData.getLevel(), award: this.redNum.string }))
  66. platform.umUp("lvReward");//成就埋点
  67. platform.reportThinking("envelope_increase", JSON.stringify({ previous_number: g.userData.bonus, increase_number: parseInt(this.redNum.string), current_number: g.userData.bonus + parseInt(this.redNum.string), reasons: "LevelReward" }));
  68. WindowManager.open("Prefabs/GetWindow", WindowOpenMode.CloseAndAdd, [{ count: (Number)(this.redNum.string), type: GetType.RedBag, needBezierEffect: true }]);
  69. this.canGet.node.active = false;
  70. this.unGet.node.active = !this.canGet.node.active;
  71. }
  72. }
  73. }