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