12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- 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 ch_audio from "../../../ch/audio/audio";
- import { Hall } from "../../hall/Hall";
- import { ch } from "../../../ch/ch";
- 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<Layout_Sign>();
- ani_ui(layout.Return.node.parent.parent);
- this.onButtonEvent(layout.Return, () => {
- ch_audio.getInstance().playOneShot('sound/click_Btn');
- gui.close(UI_Sign);
- });
- this.onButtonEvent(layout.Free_Get, async () => {
- ch_audio.getInstance().playOneShot('sound/click_Btn');
- if (layout.Toggle.isChecked) {
- this.Sign(true);
- } else {
- //不看广告
- this.Sign(false);
- }
- });
- this.init_Sign();
- }
- private init_Sign() {
- const layout = this.getLayout<Layout_Sign>();
- 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<Layout_Sign>();
- //签到成功获取奖励
- if (flag) {
- //看广告领双倍
- let ret = await chsdk.playRewardAd('领取双倍签到奖励');
- if (ret) {
- let day = await ch_sign.getInstance().signIn();
- 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;
- ch.audio.resume();
- }
- } else {
- let day = await ch_sign.getInstance().signIn();
- if (day != 0) {
- 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;
- }
- }
- }
- }
|