difenduandada
2024-12-31 34abe6963b344c882358274957f4b992456fee40
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
"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();