import { _decorator, Component, Node, Label, find } from 'cc'; import { Http, HttpResponseCode } from '../../core/net/Http'; import { Window } from '../../core/ui/window/Window'; import { g } from '../../Data/g'; import { UIEffect } from '../UIEffect'; const { ccclass, property } = _decorator; @ccclass('PiggyBank') export class PiggyBank extends Component { @property({ type: Label, tooltip: "数值文本" }) numLabel: Label; @property({ type: Node, tooltip: "领取按钮节点" }) getBtnNode: Node; @property({ type: Node, tooltip: "背景" }) bg: Node; @property({ type: Window, tooltip: "当前窗口" }) myWin: Window; async start() { let result = await this.getComponent(Http).send("/api/dailyBonus/getDailyBonus"); if (result && result.code == HttpResponseCode.Success) { let bonus = result.data.bonus || 0; this.numLabel.string = bonus; this.getBtnNode.active = result.data.canGet; } else { this.myWin.close(); } } /**领取奖金 */ private async getBouns() { if (!this.getBtnNode.active) { this.myWin.close(); return; } let result = await this.getComponent(Http).send("/api/dailyBonus/receiveDailyBonus"); if (result && result.code == HttpResponseCode.Success) { if (result.bonus) { this.numLabel.string = '0'; g.userData.bonus += result.bonus; find("Canvas/UI").getComponent(UIEffect).showBezierRedBagEffect(0, null, 1); //WindowSystem.open("prefabs/ui/turntable/prizeFly", WindowOpenMode.NotCloseAndCover, [{ type: 3, num: result.bonus }]); } this.myWin.close(); } } private onClose() { this.bg.active = false; } }