UI_Sign.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { _decorator, Sprite } from "cc";
  2. import ch_sign from "../../../ch/sign/sign";
  3. import { GameUILayers, gui } from "../../../core/ui/ui";
  4. import ui_base from "../../../core/ui/ui_base";
  5. import { ModuleDef } from "../../../Scripts/ModuleDef";
  6. import { ani_ui } from "../UI_Main/UI_Main";
  7. import { Layout_Sign } from "./Layout_Sign";
  8. import { Hall } from "../../hall/Hall";
  9. const { ccclass, property } = _decorator;
  10. @ccclass('UI_Sign')
  11. export class UI_Sign extends ui_base {
  12. constructor() {
  13. super(ModuleDef.GAME, 'ui/UI_Sign/Sign', GameUILayers.HUD, Layout_Sign);
  14. }
  15. protected async onCreated() {
  16. const layout = this.getLayout<Layout_Sign>();
  17. ani_ui(layout.Return.node.parent.parent);
  18. this.onButtonEvent(layout.Return, () => {
  19. gui.close(UI_Sign);
  20. });
  21. this.onButtonEvent(layout.Free_Get, async () => {
  22. if (layout.Toggle.isChecked) {
  23. this.Sign(true);
  24. } else {
  25. //不看广告
  26. this.Sign(false);
  27. }
  28. });
  29. this.init_Sign();
  30. }
  31. private async init_Sign() {
  32. const layout = this.getLayout<Layout_Sign>();
  33. for (let i = 0; i < 7; i++) {
  34. layout.Sign_Reward[i].show(i + 1);
  35. }
  36. if (!ch_sign.getInstance().checkSigin()) {
  37. layout.Free_Get.node.getComponent(Sprite).grayscale = true;
  38. layout.Free_Get.interactable = false;
  39. }
  40. }
  41. private async Sign(flag: boolean) {
  42. const layout = this.getLayout<Layout_Sign>();
  43. let day = await ch_sign.getInstance().signIn();
  44. if (day == 0) {
  45. } else {
  46. //签到成功获取奖励
  47. if (flag) {
  48. //看广告领双倍
  49. let ret = await chsdk.playRewardAd('领取双倍签到奖励');
  50. if (ret) {
  51. Hall.getInstance().player.set_watch_ad_num(1);
  52. layout.Sign_Reward[day - 1].show(day);
  53. layout.Sign_Reward[day - 1].add_Item(flag);
  54. layout.Free_Get.node.getComponent(Sprite).grayscale = true;
  55. layout.Free_Get.interactable = false;
  56. }
  57. } else {
  58. layout.Sign_Reward[day - 1].show(day);
  59. layout.Sign_Reward[day - 1].add_Item(flag);
  60. layout.Free_Get.node.getComponent(Sprite).grayscale = true;
  61. layout.Free_Get.interactable = false;
  62. }
  63. // Hall.getInstance().player.save();
  64. }
  65. }
  66. }