"use strict";
|
cc._RF.push(module, '7fb6c1VdDVC6ok8cQp3cFLO', 'exchange_window');
|
// Scripts/mod/exchange/view/exchange_window.js
|
|
"use strict";
|
|
// --------------------------------------------------------------------
|
// @author: shiraho@syg.com(必填, 创建模块的人员)
|
// @description:
|
// 用户输入框
|
// <br/>Create: new Date().toISOString()
|
// --------------------------------------------------------------------
|
var PathTool = require("pathtool");
|
|
var LoaderManager = require("loadermanager");
|
|
var RoleController = require("role_controller");
|
|
var ExchangeController = require("exchange_controller");
|
|
var ExchangeEvent = require("exchange_event");
|
|
var TimeTool = require("timetool");
|
|
var ExchangeWindow = cc.Class({
|
"extends": BaseView,
|
ctor: function ctor() {
|
this.prefabPath = PathTool.getPrefabPath("exchange", "exchange_main_win");
|
this.viewTag = SCENE_TAG.dialogue;
|
},
|
openCallBack: function openCallBack() {
|
var _this = this;
|
|
this.main_container = this.root_wnd.getChildByName("main_container");
|
this.background = this.root_wnd.getChildByName("background");
|
this.bg = this.root_wnd.getChildByName("bg").getComponent(cc.Sprite);
|
LoaderManager.getInstance().loadRes(PathTool.getBigBg("bigbg_65", "png"), function (spriteFrame) {
|
this.bg.spriteFrame = spriteFrame;
|
}.bind(this));
|
this.objects = {};
|
|
var _loop = function _loop(i) {
|
item = {};
|
item.remain = _this.main_container.getChildByName("remain_text_" + i).getComponent(cc.Label);
|
item.btn = _this.main_container.getChildByName("btn_" + i);
|
item.get = _this.main_container.getChildByName("get_" + i);
|
item.gold = item.btn.getChildByName("label").getComponent(cc.Label);
|
item.coin = _this.main_container.getChildByName("coin_" + i).getChildByName("label").getComponent(cc.Label);
|
_this.objects[i] = item;
|
LoaderManager.getInstance().loadRes(PathTool.getItemRes("1"), function (res) {
|
this.main_container.getChildByName("coin_" + i).getChildByName("icon").getComponent(cc.Sprite).spriteFrame = res;
|
}.bind(_this));
|
|
if (_this.main_container.getChildByName("btn_" + i).getChildByName("icon")) {
|
LoaderManager.getInstance().loadRes(PathTool.getItemRes("3"), function (res) {
|
this.main_container.getChildByName("btn_" + i).getChildByName("icon").getComponent(cc.Sprite).spriteFrame = res;
|
}.bind(_this));
|
}
|
};
|
|
for (var i = 1; i <= 3; i++) {
|
var item;
|
|
_loop(i);
|
}
|
|
this.textTime = this.main_container.getChildByName("textTime").getComponent(cc.Label);
|
},
|
registerEvent: function registerEvent() {
|
var _this2 = this;
|
|
this.background.on(cc.Node.EventType.TOUCH_END, function (event) {
|
Utils.playButtonSound(2);
|
ExchangeController.getInstance().openExchangeMainView(false);
|
}, this);
|
|
var _loop2 = function _loop2(i) {
|
_this2.objects[i].btn.on(cc.Node.EventType.TOUCH_END, function (event) {
|
Utils.playButtonSound(1);
|
|
if (this.objects[i].v) {
|
ExchangeController.getInstance().send23607(this.objects[i].v.id);
|
}
|
}, _this2);
|
};
|
|
for (var i in this.objects) {
|
_loop2(i);
|
}
|
|
this.addGlobalEvent(ExchangeEvent.Extra_Reward, function (data) {
|
this.updateData(data);
|
}, this);
|
},
|
openRootWnd: function openRootWnd() {
|
ExchangeController.getInstance().send23606();
|
},
|
updateData: function updateData(data) {
|
this.data = data;
|
this.setLessTime();
|
|
for (var i in data.list) {
|
var v = data.list[i];
|
var item = this.objects[v.id];
|
item.v = v;
|
item.remain.string = Utils.TI18N("剩余:" + Math.max(0, v.max - v.num));
|
item.coin.string = v.gain;
|
|
if (v.num >= v.max) {
|
item.btn.active = false;
|
item.get.active = true;
|
} else {
|
item.btn.active = true;
|
item.get.active = false;
|
|
if (v.price == 0) {
|
item.gold.string = Utils.TI18N("免费获取");
|
} else {
|
item.gold.string = v.price + Utils.TI18N("获取");
|
}
|
}
|
}
|
},
|
setLessTime: function setLessTime() {
|
if (!cc.isValid(this.textTime) || !this.data) {
|
return;
|
}
|
|
var lesstime = this.data.ref_time - gcore.SmartSocket.getTime(); // Log.info("====>>>", lesstime, this.data, gcore.SmartSocket.getTime());
|
|
if (lesstime > 0) {
|
this.textTime.string = TimeTool.getTimeFormat(lesstime);
|
this.timer = gcore.Timer.set(function () {
|
this.setLessTime();
|
this.timer = null;
|
}.bind(this), 1000, 1);
|
} else {
|
this.textTime.string = "00:00:00";
|
}
|
},
|
closeCallBack: function closeCallBack() {
|
ExchangeController.getInstance().openExchangeMainView(false);
|
|
if (this.timer) {
|
gcore.Timer.del(this.timer);
|
}
|
|
LoaderManager.getInstance().deleteRes(PathTool.getBigBg("bigbg_65", "png"));
|
}
|
});
|
module.exports = ExchangeWindow;
|
|
cc._RF.pop();
|