import { _decorator, Button, Component, Label, Node, ProgressBar, Sprite, SpriteFrame } from 'cc'; import { Hall } from '../../hall/Hall'; import { UINotify } from '../../../module_basic/ui_notify/UINotify'; import { gui } from '../../../core/ui/ui'; import { UI_Task } from './UI_Task'; const { ccclass, property } = _decorator; @ccclass('UI_Task_Item') export class UI_Task_Item extends Component { @property(ProgressBar) progressBar: ProgressBar; @property(Label) Des: Label; @property(Button) Get: Button; @property(Sprite) Get_Bg: Sprite; @property([SpriteFrame]) Get_Bgs: SpriteFrame[] = []; @property type: number = 0; @property index: number = 0; state: boolean; start() { this.Get.node.on(Button.EventType.CLICK, this.add_Item, this); } update(deltaTime: number) { } //更新进度 show(flag: boolean, target: number) { this.state = flag; switch (this.type) { //消除 case 1: this.progressBar.progress = Hall.getInstance().player.get_use_item_num() / target; this.Des.string = `${Hall.getInstance().player.get_use_item_num()}/${target}`; break; //洗牌 合成 case 2: this.progressBar.progress = Hall.getInstance().player.get_combine_num() / target; this.Des.string = `${Hall.getInstance().player.get_combine_num()}/${target}`; break; //清空 登陆 case 3: this.progressBar.progress = Hall.getInstance().player.get_login_num() / target; this.Des.string = `${Hall.getInstance().player.get_login_num()}/${target}`; break; //金币 过关 case 4: this.progressBar.progress = Hall.getInstance().player.get_pass_level() / target; this.Des.string = `${Hall.getInstance().player.get_pass_level()}/${target}`; break; //时间 广告 case 5: this.progressBar.progress = Hall.getInstance().player.get_watch_ad_num() / target; this.Des.string = `${Hall.getInstance().player.get_watch_ad_num()}/${target}`; break; } if (this.progressBar.progress == 1) { if (this.state) { this.Des.string = '已领取'; this.Get_Bg.spriteFrame = this.Get_Bgs[0] } else { this.Des.string = '可领取'; this.Get_Bg.spriteFrame = this.Get_Bgs[1]; } } else { this.Get_Bg.spriteFrame = this.Get_Bgs[0]; } } //添加东西 add_Item() { if (this.progressBar.progress == 1 && this.state == false) { if (this.type != 4) { Hall.getInstance().player.add_item(this.type, 1); } else if (this.type == 4) { Hall.getInstance().player.set_coin(Hall.getInstance().player.get_coin() + 100); } this.state = true; this.Des.string = '已领取'; this.state ? this.Get_Bg.spriteFrame = this.Get_Bgs[0] : this.Get_Bg.spriteFrame = this.Get_Bgs[1]; gui.get(UI_Task).update_task_state(true, this.index); } } }