| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- import { _decorator, Label, JsonAsset, Sprite, SpriteFrame, Node } from 'cc';
- import InfiniteCell from '../../core/InfiniteList/InfiniteCell';
- import { ResourcesUtils } from '../../core/resourceManager/ResourcesUtils';
- import { BitmapFont } from '../../core/ui/BitmapFont';
- import { Utils } from '../../core/utils/Utils';
- import { ConfigData } from '../../Data/ConfigData';
- import { g } from '../../Data/g';
- import { platform } from '../../Data/platform';
- import { FarmState } from '../../Main/FarmIcon';
- import { FarmManager } from '../../Main/FarmManager';
- import { PlantWindow } from './PlantWindow';
- const { ccclass, property } = _decorator;
- @ccclass('PlantWindowItem')
- export class PlantWindowItem extends InfiniteCell {
- @property({ type: Sprite, tooltip: "作物图标" }) plantIcon: Sprite;
- @property({ type: Sprite, tooltip: "名字图标" }) nameIcon: Sprite;
- @property({ type: BitmapFont, tooltip: "获得数量文本" }) awardLabel: BitmapFont;
- @property({ type: BitmapFont, tooltip: "成熟时间文本" }) timeLabel: BitmapFont;
- @property({ type: BitmapFont, tooltip: "可种植次数文本" }) countLabel: BitmapFont;
- @property({ type: Node, tooltip: "可种植次数文本" }) maskNode: Node;
- private data: any;
- private count = -1;
- public UpdateContent(data: any): void {
- this.data = data;
- this.setData(data);
- }
- private async setData(data: any) {
- let config = ConfigData.configMap.get("product");
- let result = config[data];
- this.plantIcon.spriteFrame = await ResourcesUtils.load<SpriteFrame>("plant_icons/" + "plantIcon_" + result["id"] + "/spriteFrame", SpriteFrame, this.node);
- this.nameIcon.spriteFrame = await ResourcesUtils.load<SpriteFrame>("plant_icons/nameIcon/plant_name_" + result["id"] + "/spriteFrame", SpriteFrame, this.node);
- this.awardLabel.string = result["award"] + "";
- this.timeLabel.string = result["time"];
- this.count = FarmManager.plantCountMap.get(data);
- this.countLabel.string = this.count + "";
- if (!this.maskNode.active && this.count == 0) {
- this.maskNode.active = true;
- }
- if (this.count != 0) {
- this.maskNode.active = false;
- }
- }
- update() {
- if (this.count != FarmManager.plantCountMap.get(this.data)) {
- this.count = FarmManager.plantCountMap.get(this.data);
- this.countLabel.string = this.count + "";
- }
- }
- public onClick(): void {
- if (FarmManager.plantCountMap.get(this.data) > 0 && FarmManager.getCurrFarm().state == FarmState.Empty && !FarmManager.plantIsRequesting) {
- platform.umUp("growVegetables");//作物埋点
- platform.reportThinking("field", JSON.stringify({ field_name: FarmManager.getCurrFarm().configID, plant_name: this.data, id: g.userData.id ,level:g.userData.getLevel(),role_name:g.userData.nickName,plant_time:Utils.formatDate(new Date())}));
- FarmManager.onPlant(this.data);
- }
- }
- }
|