FactoryWindowItem.ts 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { _decorator, Sprite, SpriteFrame, UITransform, Size, Node } from 'cc';
  2. import InfiniteCell from '../../core/InfiniteList/InfiniteCell';
  3. import { ResourcesUtils } from '../../core/resourceManager/ResourcesUtils';
  4. import { FactoryWindow } from './FactoryWindow';
  5. import { BitmapFont } from '../../core/ui/BitmapFont';
  6. import { ConfigData } from '../../Data/ConfigData';
  7. import { g } from '../../Data/g';
  8. import { Sound } from '../../core/sound/Sound';
  9. import { platform } from '../../Data/platform';
  10. import { Utils } from '../../core/utils/Utils';
  11. const { ccclass, property } = _decorator;
  12. @ccclass('FactoryWindowItem')
  13. export class FactoryWindowItem extends InfiniteCell {
  14. @property({ type: Sprite, tooltip: "产品图标" }) icon: Sprite;
  15. @property({ type: Sprite, tooltip: "产品名称" }) nameLabel: Sprite;
  16. @property({ type: BitmapFont, tooltip: "次数文本" }) countLabel: BitmapFont;
  17. @property({ type: BitmapFont, tooltip: "时间文本" }) timeLabel: BitmapFont;
  18. @property({ type: Node, tooltip: "无次数遮罩" }) maskNode: Node
  19. private productID: number = 0;
  20. private window: FactoryWindow;
  21. private count = 0;
  22. public async UpdateContent(data: any) {
  23. this.productID = data.id;
  24. this.window = data.obj;
  25. this.icon.spriteFrame = await ResourcesUtils.load<SpriteFrame>("factory_icons/factory_" + this.productID + "/spriteFrame", SpriteFrame, this.node);
  26. this.icon.getComponent(UITransform).contentSize = new Size(154, 169);
  27. this.nameLabel.spriteFrame = await ResourcesUtils.load<SpriteFrame>("factory_icons/factoryNams/factory_name_icon_" + this.productID + "/spriteFrame", SpriteFrame, this.node);
  28. let config = ConfigData.configMap.get("product")[this.productID];
  29. this.timeLabel.string = config["time"] / 60 + "";
  30. this.count = this.window.countMap.get(this.productID);
  31. this.countLabel.string = this.count + "";
  32. this.maskNode.active = this.count == 0;
  33. }
  34. update() {
  35. if (this.count != this.window.countMap.get(this.productID)) {
  36. this.count = this.window.countMap.get(this.productID);
  37. this.countLabel.string = this.window.countMap.get(this.productID) + "";
  38. }
  39. }
  40. private onclick(): void {
  41. if (this.window.countMap.get(this.productID) > 0 && g.gameData.getProductingList(this.window.buildID).length < g.gameData.getUnlock(this.window.buildID)) {
  42. platform.reportThinking("produce", JSON.stringify({ factory_name: this.getThankingKey(), product_name: this.productID, id: g.userData.id, level: g.userData.getLevel(), role_name: g.userData.nickName, feed_time: Utils.formatDate(new Date()), queue: g.gameData.getProductingList(this.window.buildID).length, produce_time: ConfigData.configMap.get("product")[this.productID]["time"] }));
  43. this.window.make(this.productID);
  44. this.getComponent(Sound).play();
  45. }
  46. }
  47. private getThankingKey(): string {
  48. let key = "";
  49. switch (this.window.buildID) {
  50. case 30001: key = "chick"; break;
  51. case 30002: key = "cow"; break;
  52. case 30003: key = "pig"; break;
  53. case 30004: key = "corn"; break;
  54. case 30005: key = "milk"; break;
  55. case 30006: key = "sugar"; break;
  56. case 30007: key = "cake"; break;
  57. case 30008: key = "fastfood"; break;
  58. case 30009: key = "noodle"; break;
  59. }
  60. return key;
  61. }
  62. }