Files
fc/dev/project/library/imports/f8/f884fca1-b3ad-4ca3-9784-9f7117c54b15.js
T
2026-05-24 10:21:26 +08:00

164 lines
4.6 KiB
JavaScript

"use strict";
cc._RF.push(module, 'f884fyhs61Mo5eEn3EXxUsV', 'cmp.guildmarket.buy');
// Scripts/mod/guild/marketplace/cmp/cmp.guildmarket.buy.js
"use strict";
var GuildMarketMod = require("guildmarketplace_controller");
var BridgeWindow = require("bridge.window");
var MarketEvent = require("guildmarketplace_event");
var MarketConst = require("guildmarketplace_const");
var BackPackConst = require("backpack_const");
var BackPackController = require("backpack_controller");
cc.Class({
"extends": BridgeWindow,
properties: {
fabItem: {
"default": null,
type: cc.Prefab
},
tag: {
"default": null,
type: cc.Node
},
tips: {
"default": null,
type: cc.Node
},
sld: {
"default": null,
type: cc.Slider
},
bar: {
"default": null,
type: cc.ProgressBar
},
totalPrice: {
"default": null,
type: cc.Node
},
iname: {
"default": null,
type: cc.Node
},
buyTxt: {
"default": null,
type: cc.Node
},
buyBtn: {
"default": null,
type: cc.Node
},
sellBtn: {
"default": null,
type: cc.Node
}
},
// LIFE-CYCLE CALLBACKS:
onLoad: function onLoad() {
this.mod = GuildMarketMod.getInstance();
this.buy_num = 0;
this.sld.node.on("slide", this.onSliding.bind(this));
// this.bindGEvent(MarketEvent.GUILD_MARKET_PLACE_ITEM_EVENT,this.updateMarketItems.bind(this));
},
onSliding: function onSliding() {
var num = Math.ceil(this.sld.progress * this.totalNum);
if (num >= this.totalNum) {
num = this.totalNum;
}
this.buy_num = num;
this.updateNum();
},
onOpenConfigs: function onOpenConfigs(params) {
if (!params || !params.data) {
return this.delayClose();
}
this.data = params.data;
this.totalNum = this.data.num || this.data.quantity;
this.is_sell = params.is_sell;
this.iCfg = this.mod.getModel().getMarketCfg(this.data.base_id);
if (this.iCfg) {
if (params.is_sell) {
nx.gui.setString(this.tips, "", "");
this.buyBtn.active = false;
this.sellBtn.active = true;
} else {
nx.gui.setString(this.totalPrice, "", cc.js.formatStr("<img src='%s' />%s", this.iCfg.price[0], 0));
var sec = nx.bridge.time.toNeedSeconds(this.data.end_time[0].end_unixtime - client.socket.getTime());
nx.gui.setString(this.tips, "", cc.js.formatStr(nx.text.getKey("GuildMktOver"), this.data.end_time[0].end_num, sec));
this.buyBtn.active = true;
this.sellBtn.active = false;
}
this.updateNum();
nx.gui.setString(this.iname, "", this.iCfg.name);
var item = cc.instantiate(this.fabItem);
item.parent = this.tag;
var cmp = nx.gui.getComponent(item, "", "cmp.item.base");
if (cmp) {
cmp.rebind(0, {
bid: this.iCfg.id,
num: 0
}, "");
}
}
},
onPreClosed: function onPreClosed() {},
updateNum: function updateNum() {
nx.gui.setString(this.buyTxt, "", this.buy_num);
this.bar.progress = this.buy_num / this.totalNum;
this.sld.progress = this.buy_num / this.totalNum;
if (this.is_sell) {
var ico = 0;
var pri = 0;
if (this.iCfg.sell.length > 0) {
ico = this.iCfg.sell[0][0];
pri = this.iCfg.sell[0][1];
}
nx.gui.setString(this.totalPrice, "", cc.js.formatStr("<img src='%s' />%s", ico, pri * this.buy_num));
} else {
nx.gui.setString(this.totalPrice, "", cc.js.formatStr("<img src='%s' />%s", this.iCfg.price[0][0], this.iCfg.price[0][1] * this.buy_num));
}
},
touchMax: function touchMax() {
this.buy_num = this.totalNum;
this.updateNum();
},
touchAdd: function touchAdd() {
this.buy_num++;
if (this.buy_num >= this.totalNum) this.buy_num = this.totalNum;
this.updateNum();
},
touchSub: function touchSub() {
this.buy_num--;
if (this.buy_num <= 0) this.buy_num = 0;
this.updateNum();
},
touchBuy: function touchBuy() {
var _this = this;
if (this.buy_num > 0 && this.data.id) {
this.mod.sender26902(this.data.id, this.buy_num, function (_data) {
if (_data) {
_this.close();
}
});
} else {
if (this.buy_num <= 0) {
nx.tbox("arean_loop_str2");
this.close();
} else if (!this.data.id) {
this.close();
}
}
},
touchSell: function touchSell() {
var _this2 = this;
var stor_type = this.mod.getModel().getStorageType(this.data.config.sub_type);
this.mod.sender26901(this.data.id, this.buy_num, stor_type, function (_data) {
if (_data) {
_this2.close();
}
});
}
});
cc._RF.pop();