import { _decorator, Button, Component, Label, Node, ProgressBar, Sprite, SpriteFrame } from 'cc'; import { Hall } from '../../hall/Hall'; import { gui } from '../../../core/ui/ui'; import { UI_Task } from './UI_Task'; import { Toast } from '../../../core/util_class/Toast'; 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[] = []; config:any; @property index: number; state: boolean; start() { this.Get.node.on(Button.EventType.CLICK, this.add_Item, this); } update(deltaTime: number) { } //更新进度 show(flag: boolean, config) { this.config=config; this.state = flag; switch (config.type) { //消除 case 1: this.progressBar.progress = Hall.getInstance().player.get_use_item_num() / config.goal; this.Des.string = `${Hall.getInstance().player.get_use_item_num()}/${config.goal}`; break; //洗牌 合成 case 2: this.progressBar.progress = Hall.getInstance().player.get_combine_num() / config.goal; this.Des.string = `${Hall.getInstance().player.get_combine_num()}/${config.goal}`; break; //清空 登陆 case 3: this.progressBar.progress = Hall.getInstance().player.get_login_num() / config.goal; this.Des.string = `${Hall.getInstance().player.get_login_num()}/${config.goal}`; break; //铜币 过关 case 4: this.progressBar.progress = Hall.getInstance().player.get_pass_level() / config.goal; this.Des.string = `${Hall.getInstance().player.get_pass_level()}/${config.goal}`; break; //时间 广告 case 5: this.progressBar.progress = Hall.getInstance().player.get_watch_ad_num() / config.goal; this.Des.string = `${Hall.getInstance().player.get_watch_ad_num()}/${config.goal}`; break; } if (this.progressBar.progress == 1) { if (this.state) { this.Des.string = '已领取'; this.Get.interactable = false; this.Get_Bg.spriteFrame = this.Get_Bgs[0] } else { this.Des.string = '可领取'; this.Get.interactable = true; this.Get_Bg.spriteFrame = this.Get_Bgs[1]; } } else { this.Get.interactable = false; this.Get_Bg.spriteFrame = this.Get_Bgs[0]; } } //添加东西 add_Item() { if (this.progressBar.progress == 1 && this.state == false) { if (this.config.type != 4) { Hall.getInstance().player.add_item(this.config.type, 1); Toast.makeText(gui.getLayerNode(5),'获得道具:'+this.config.name).show(); } else if (this.config.type == 4) { Hall.getInstance().player.set_coin(Hall.getInstance().player.get_coin() + 100); Toast.makeText(gui.getLayerNode(5),'获得铜币:X'+this.config.num).show(); } this.state = true; this.Des.string = '已领取'; this.Get_Bg.spriteFrame = this.Get_Bgs[0]; this.Get.interactable = false; gui.get(UI_Task).update_task_state(true, this.index); } } }