import { _decorator, Sprite } from "cc"; import ch_sign from "../../../ch/sign/sign"; import { GameUILayers, gui } from "../../../core/ui/ui"; import ui_base from "../../../core/ui/ui_base"; import { ModuleDef } from "../../../Scripts/ModuleDef"; import { ani_ui } from "../UI_Main/UI_Main"; import { Layout_Sign } from "./Layout_Sign"; import { Hall } from "../../hall/Hall"; const { ccclass, property } = _decorator; @ccclass('UI_Sign') export class UI_Sign extends ui_base { constructor() { super(ModuleDef.GAME, 'ui/UI_Sign/Sign', GameUILayers.HUD, Layout_Sign); } protected async onCreated() { const layout = this.getLayout(); ani_ui(layout.Return.node.parent.parent); this.onButtonEvent(layout.Return, () => { gui.close(UI_Sign); }); this.onButtonEvent(layout.Free_Get, async () => { if (layout.Toggle.isChecked) { this.Sign(true); } else { //不看广告 this.Sign(false); } }); this.init_Sign(); } private async init_Sign() { const layout = this.getLayout(); for (let i = 0; i < 7; i++) { layout.Sign_Reward[i].show(i + 1); } if (!ch_sign.getInstance().checkSigin()) { layout.Free_Get.node.getComponent(Sprite).grayscale = true; layout.Free_Get.interactable = false; } } private async Sign(flag: boolean) { const layout = this.getLayout(); let day = await ch_sign.getInstance().signIn(); if (day == 0) { } else { //签到成功获取奖励 if (flag) { //看广告领双倍 let ret = await chsdk.playRewardAd('领取双倍签到奖励'); if (ret) { Hall.getInstance().player.set_watch_ad_num(1); layout.Sign_Reward[day - 1].show(day); layout.Sign_Reward[day - 1].add_Item(flag); layout.Free_Get.node.getComponent(Sprite).grayscale = true; layout.Free_Get.interactable = false; } } else { layout.Sign_Reward[day - 1].show(day); layout.Sign_Reward[day - 1].add_Item(flag); layout.Free_Get.node.getComponent(Sprite).grayscale = true; layout.Free_Get.interactable = false; } // Hall.getInstance().player.save(); } } }