UI_Sign.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { _decorator } 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 { UINotify } from "../../../module_basic/ui_notify/UINotify";
  6. import { Hall } from "../../../Scripts/Hall";
  7. import { ModuleDef } from "../../../Scripts/ModuleDef";
  8. import { ani_ui } from "../UI_Main/UI_Main";
  9. import { Layout_Sign } from "./Layout_Sign";
  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. gui.close(UI_Sign);
  21. });
  22. this.onButtonEvent(layout.Free_Get,async () => {
  23. if(layout.Toggle.isChecked)
  24. {
  25. //看广告领双倍
  26. let ret = await chsdk.playRewardAd('领取双倍签到奖励');
  27. if(ret){
  28. this.Sign(true);
  29. }
  30. }else{
  31. //不看广告
  32. this.Sign(false);
  33. }
  34. });
  35. this.init_Sign();
  36. }
  37. private async init_Sign() {
  38. const layout = this.getLayout<Layout_Sign>();
  39. for (let i = 0; i < Hall.getInstance().player.get_sign(); i++) {
  40. layout.Sign_Reward[i].show(i + 1);
  41. }
  42. }
  43. private async Sign(flag: boolean) {
  44. const layout = this.getLayout<Layout_Sign>();
  45. let day = await ch_sign.getInstance().signIn();
  46. if (day == 0) {
  47. UINotify.show("签到失败");
  48. } else {
  49. //签到成功获取奖励
  50. layout.Sign_Reward[day - 1].show(day);
  51. layout.Sign_Reward[day - 1].add_Item(flag);
  52. Hall.getInstance().player.set_sign(day);
  53. Hall.getInstance().player.setDirty();
  54. Hall.getInstance().player.save();
  55. }
  56. }
  57. private async DoubleSign() {
  58. if (ch_sign.getInstance().checkReSigin() == 0) {
  59. return;
  60. }
  61. }
  62. }