| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- import { _decorator, Sprite, SpriteFrame, UITransform, Size, Node } from 'cc';
- import InfiniteCell from '../../core/InfiniteList/InfiniteCell';
- import { ResourcesUtils } from '../../core/resourceManager/ResourcesUtils';
- import { FactoryWindow } from './FactoryWindow';
- import { BitmapFont } from '../../core/ui/BitmapFont';
- import { ConfigData } from '../../Data/ConfigData';
- import { g } from '../../Data/g';
- import { Sound } from '../../core/sound/Sound';
- import { platform } from '../../Data/platform';
- import { Utils } from '../../core/utils/Utils';
- const { ccclass, property } = _decorator;
- @ccclass('FactoryWindowItem')
- export class FactoryWindowItem extends InfiniteCell {
- @property({ type: Sprite, tooltip: "产品图标" }) icon: Sprite;
- @property({ type: Sprite, tooltip: "产品名称" }) nameLabel: Sprite;
- @property({ type: BitmapFont, tooltip: "次数文本" }) countLabel: BitmapFont;
- @property({ type: BitmapFont, tooltip: "时间文本" }) timeLabel: BitmapFont;
- @property({ type: Node, tooltip: "无次数遮罩" }) maskNode: Node
- private productID: number = 0;
- private window: FactoryWindow;
- private count = 0;
- public async UpdateContent(data: any) {
- this.productID = data.id;
- this.window = data.obj;
- this.icon.spriteFrame = await ResourcesUtils.load<SpriteFrame>("factory_icons/factory_" + this.productID + "/spriteFrame", SpriteFrame, this.node);
- this.icon.getComponent(UITransform).contentSize = new Size(154, 169);
- this.nameLabel.spriteFrame = await ResourcesUtils.load<SpriteFrame>("factory_icons/factoryNams/factory_name_icon_" + this.productID + "/spriteFrame", SpriteFrame, this.node);
- let config = ConfigData.configMap.get("product")[this.productID];
- this.timeLabel.string = config["time"] / 60 + "";
- this.count = this.window.countMap.get(this.productID);
- this.countLabel.string = this.count + "";
- this.maskNode.active = this.count == 0;
- }
- update() {
- if (this.count != this.window.countMap.get(this.productID)) {
- this.count = this.window.countMap.get(this.productID);
- this.countLabel.string = this.window.countMap.get(this.productID) + "";
- }
- }
- private onclick(): void {
- if (this.window.countMap.get(this.productID) > 0 && g.gameData.getProductingList(this.window.buildID).length < g.gameData.getUnlock(this.window.buildID)) {
- 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"] }));
- this.window.make(this.productID);
- this.getComponent(Sound).play();
- }
- }
- private getThankingKey(): string {
- let key = "";
- switch (this.window.buildID) {
- case 30001: key = "chick"; break;
- case 30002: key = "cow"; break;
- case 30003: key = "pig"; break;
- case 30004: key = "corn"; break;
- case 30005: key = "milk"; break;
- case 30006: key = "sugar"; break;
- case 30007: key = "cake"; break;
- case 30008: key = "fastfood"; break;
- case 30009: key = "noodle"; break;
- }
- return key;
- }
- }
|