123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- import { _decorator, Button, Component, instantiate, Label, Node, Sprite, SpriteFrame, tween, v3 } from 'cc';
- import { ch } from '../../../ch/ch';
- import { gui } from '../../../core/ui/ui';
- import { UI_Main } from '../UI_Main/UI_Main';
- import { Layout_Main } from '../UI_Main/Layout_Main';
- import { Hall } from '../../hall/Hall';
- import { Toast } from '../../../core/util_class/Toast';
- const { ccclass, property } = _decorator;
- @ccclass('UI_Item')
- export class UI_Item extends Component {
- @property
- type: number = 0;
- @property(Sprite)
- Ad: Sprite;
- @property(Label)
- count: Label;
- private _c: number = 0;
- protected start(): void {
- if (this.type == 0) return;
- this.show(this.type, Hall.getInstance().player.get_item(this.type));
- if (this.node.getComponent(Button)) {
- this.node.on(Node.EventType.TOUCH_END, this.onClick, this);
- }
- Hall.getInstance().player.event.on(Hall.getInstance().player.event.key.item_count, this.show, this);
- }
- protected onDestroy(): void {
- Hall.getInstance().player.event.off(Hall.getInstance().player.event.key.item_count, this.show, this);
- }
- show(type: number, count: number): void {
- if (type != this.type) return;
- if (this._c != count) {
- tween(this.node).to(0.05, { scale: v3(1.2, 1.2, 1) }).to(0.1, { scale: v3(1, 1, 1) }).start();
- if (count < this._c) {
- // if (type == 1) {
- // ch.audio.playOneShot('sounds/sfx_item1');
- // } else if (type == 2) {
- // ch.audio.playOneShot('sounds/sfx_item2');
- // } else {
- // ch.audio.playOneShot('sounds/sfx_item3');
- // }
- }
- }
- this._c = count;
- if (count != 0) {
- this.Ad.node.active = false;
- this.count.node.parent.active = true;
- this.count.string = count.toString();
- } else {
- this.Ad.node.active = true;
- this.count.node.parent.active = false;
- }
- if (type == 1) {
- // if (GameLink.getInst().lv.dir == LvDir.none) {
- // this.node.active = false;
- // } else {
- // this.node.active = true;
- // }
- }
- //this.ad.active = count <= 0;
- }
- //
- private async onClick(evt: any) {
- if (this._c <= 0) {
- if (this.type == 3) {
- let flag = false;
- for (let element of gui.get(UI_Main).getLayout<Layout_Main>().Container.node_isIdiom) {
- console.log(element);
- if (element == true) {
- flag = true;
- break;
- }
- }
- if (!flag) {
- Toast.makeText(gui.getLayerNode(5), "槽中无可清除的方块").show();
- return;
- }
- }
- const ret = await chsdk.playRewardAd('获得道具' + this.type);
- if (ret) {
- // ch.audio.playOneShot('sounds/sfx_add_item');
- Hall.getInstance().player.add_item(this.type, 1);
- Hall.getInstance().player.set_watch_ad_num(1);
- ch.audio.resume();
- }
- // gui.show(UI_ad_get, this.type);
- } else {
- if (this.type == 3) {
- let flag = false;
- for (let element of gui.get(UI_Main).getLayout<Layout_Main>().Container.node_isIdiom) {
- console.log(element);
- if (element == true) {
- Hall.getInstance().player.use_item(this.type);
- flag = true;
- break;
- }
- }
- if (!flag)
- Toast.makeText(gui.getLayerNode(5), "槽中无可清除的方块").show();
- //UINotify.show('槽中无可清除的方块');
- }
- else {
- Hall.getInstance().player.use_item(this.type);
- }
- }
- }
- }
|