PlantWindowItem.ts 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { _decorator, Label, JsonAsset, Sprite, SpriteFrame, Node } from 'cc';
  2. import InfiniteCell from '../../core/InfiniteList/InfiniteCell';
  3. import { ResourcesUtils } from '../../core/resourceManager/ResourcesUtils';
  4. import { BitmapFont } from '../../core/ui/BitmapFont';
  5. import { Utils } from '../../core/utils/Utils';
  6. import { ConfigData } from '../../Data/ConfigData';
  7. import { g } from '../../Data/g';
  8. import { platform } from '../../Data/platform';
  9. import { FarmState } from '../../Main/FarmIcon';
  10. import { FarmManager } from '../../Main/FarmManager';
  11. import { PlantWindow } from './PlantWindow';
  12. const { ccclass, property } = _decorator;
  13. @ccclass('PlantWindowItem')
  14. export class PlantWindowItem extends InfiniteCell {
  15. @property({ type: Sprite, tooltip: "作物图标" }) plantIcon: Sprite;
  16. @property({ type: Sprite, tooltip: "名字图标" }) nameIcon: Sprite;
  17. @property({ type: BitmapFont, tooltip: "获得数量文本" }) awardLabel: BitmapFont;
  18. @property({ type: BitmapFont, tooltip: "成熟时间文本" }) timeLabel: BitmapFont;
  19. @property({ type: BitmapFont, tooltip: "可种植次数文本" }) countLabel: BitmapFont;
  20. @property({ type: Node, tooltip: "可种植次数文本" }) maskNode: Node;
  21. private data: any;
  22. private count = -1;
  23. public UpdateContent(data: any): void {
  24. this.data = data;
  25. this.setData(data);
  26. }
  27. private async setData(data: any) {
  28. let config = ConfigData.configMap.get("product");
  29. let result = config[data];
  30. this.plantIcon.spriteFrame = await ResourcesUtils.load<SpriteFrame>("plant_icons/" + "plantIcon_" + result["id"] + "/spriteFrame", SpriteFrame, this.node);
  31. this.nameIcon.spriteFrame = await ResourcesUtils.load<SpriteFrame>("plant_icons/nameIcon/plant_name_" + result["id"] + "/spriteFrame", SpriteFrame, this.node);
  32. this.awardLabel.string = result["award"] + "";
  33. this.timeLabel.string = result["time"];
  34. this.count = FarmManager.plantCountMap.get(data);
  35. this.countLabel.string = this.count + "";
  36. if (!this.maskNode.active && this.count == 0) {
  37. this.maskNode.active = true;
  38. }
  39. if (this.count != 0) {
  40. this.maskNode.active = false;
  41. }
  42. }
  43. update() {
  44. if (this.count != FarmManager.plantCountMap.get(this.data)) {
  45. this.count = FarmManager.plantCountMap.get(this.data);
  46. this.countLabel.string = this.count + "";
  47. }
  48. }
  49. public onClick(): void {
  50. if (FarmManager.plantCountMap.get(this.data) > 0 && FarmManager.getCurrFarm().state == FarmState.Empty && !FarmManager.plantIsRequesting) {
  51. platform.umUp("growVegetables");//作物埋点
  52. 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())}));
  53. FarmManager.onPlant(this.data);
  54. }
  55. }
  56. }