UI_Sign.ts 2.7 KB

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