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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
"use strict";
cc._RF.push(module, 'bf47cbOcMtMtpRlgD62WU36', 'variety_store_window');
// Scripts/mod/mall/view/variety_store_window.js
 
"use strict";
 
// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
//     杂货店
// <br/>Create: 2019-03-07 21:30:19
// --------------------------------------------------------------------
var PathTool = require("pathtool");
 
var CommonScrollView = require("common_scrollview");
 
var MallConst = require("mall_const");
 
var MallEvent = require("mall_event");
 
var VarietyStoreItem = require("variety_store_item_panel");
 
var TimeTool = require("timetool");
 
var Variety_storeWindow = cc.Class({
  "extends": BaseView,
  ctor: function ctor() {
    this.prefabPath = PathTool.getPrefabPath("mall", "varietystore_window");
    this.viewTag = SCENE_TAG.ui; //该窗体所属ui层级,全屏ui需要在ui层,非全屏ui在dialogue层,这个要注意
 
    this.win_type = WinType.Full; //是否是全屏窗体  WinType.Full, WinType.Big, WinType.Mini, WinType.Tips
 
    this.ctrl = arguments[0];
    this.model = this.ctrl.getModel();
  },
  // 初始化一些配置数据,可以用于声明一些变量之类的
  initConfig: function initConfig() {},
  // 预制体加载完成之后的回调,可以在这里捕获相关节点或者组件
  openCallBack: function openCallBack() {
    this.background = this.root_wnd.getChildByName("background");
    this.background.scale = FIT_SCALE;
    this.bg = this.background.getComponent(cc.Sprite);
    this.loadRes(PathTool.getBigBg("bigbg_72"), function (resObject) {
      this.bg.spriteFrame = resObject;
    }.bind(this));
    var main_container = this.root_wnd.getChildByName("main_container");
    this.main_container = main_container;
    this.image_1 = this.main_container.getChildByName("image_1").getComponent(cc.Sprite);
    this.loadRes(PathTool.getBigBg("bigbg_74"), function (resObject) {
      this.image_1.spriteFrame = resObject;
    }.bind(this));
    this.image_2_node = this.main_container.getChildByName("image_2");
    this.image_2 = this.image_2_node.getComponent(cc.Sprite);
    this.loadRes(PathTool.getBigBg("bigbg_73"), function (resObject) {
      this.image_2.spriteFrame = resObject;
    }.bind(this));
    this.image_3 = this.main_container.getChildByName("image_3").getComponent(cc.Sprite);
    this.loadRes(PathTool.getBigBg("bigbg_75"), function (resObject) {
      this.image_3.spriteFrame = resObject;
    }.bind(this));
    this.image_4 = this.main_container.getChildByName("image_4").getComponent(cc.Sprite);
    this.loadRes(PathTool.getBigBg("bigbg_76"), function (resObject) {
      this.image_4.spriteFrame = resObject;
    }.bind(this));
    this.refresh_label = main_container.getChildByName("refresh_label").getComponent(cc.Label);
    this.time_label = main_container.getChildByName("time_label").getComponent(cc.Label);
    this.time_label.string = "0:00:00";
    this.refresh_btn = main_container.getChildByName("refresh_btn");
    this.refresh_btn_label = Utils.createRichLabel(26, new cc.Color(0xff, 0xff, 0xff, 0xff), cc.v2(0.5, 0.5), cc.v2(0, 0), 30);
    this.refresh_btn.addChild(this.refresh_btn_label.node);
    this.close_btn = main_container.getChildByName("close_btn");
    var item_list = main_container.getChildByName("item_list");
    var bg_size = item_list.getContentSize();
    var scroll_view_size = cc.size(bg_size.width, bg_size.height + 50);
    var setting = {
      item_class: VarietyStoreItem,
      // 单元类
      start_x: 20,
      // 第一个单元的X起点
      space_x: 38,
      // x方向的间隔
      start_y: 30,
      // 第一个单元的Y起点
      space_y: 85,
      // y方向的间隔
      item_width: 158,
      // 单元的尺寸width
      item_height: 214,
      // 单元的尺寸height
      row: 0,
      // 行数,作用于水平滚动类型
      col: 3 // 列数,作用于垂直滚动类型
 
    };
    this.item_scrollview = new CommonScrollView();
    this.item_scrollview.createScroll(item_list, cc.v2(0, -40), ScrollViewDir.vertical, ScrollViewStartPos.top, scroll_view_size, setting); // this.item_scrollview.setSwallowTouches(false)
 
    this.item_scrollview.setBounceEnabled(false);
  },
  // 注册事件监听的接口,不需要手动调用,如果是使用gcore.GlobalEvent监听,可以直接调用addGlobalEvent
  registerEvent: function registerEvent() {
    Utils.onTouchEnd(this.close_btn, function () {
      this._onClickCloseBtn();
    }.bind(this), 2);
    Utils.onTouchEnd(this.refresh_btn, function () {
      this._onClickRefreshBtn();
    }.bind(this), 2); // 商店数据
 
    this.addGlobalEvent(MallEvent.Get_Buy_list, function (data) {
      if (data.type == MallConst.MallType.VarietyShop) {
        this.setData(data);
      }
    }.bind(this)); // 刷新数据
 
    this.addGlobalEvent(MallEvent.Free_Refresh_Data, function (data) {
      if (data.type == MallConst.MallType.VarietyShop && data && this.data) {
        for (var i in data) {
          this.data[i] = data[i];
        }
 
        this.updateRefreshInfo();
      }
    }.bind(this));
  },
  setData: function setData(data) {
    this.data = data || [];
    this.updateRefreshInfo(); //  添加位置标识,引导需要
 
    if (data.item_list) {
      for (var i in data.item_list) {
        data.item_list[i].index = i;
      }
    }
 
    this.item_scrollview.setData(data.item_list || []);
  },
  updateRefreshInfo: function updateRefreshInfo() {
    if (this.data) {
      // 总刷新次数
      var max_num_cfg = Config.exchange_data.data_shop_exchage_cost["maximum_number"];
      this.refresh_label.string = cc.js.formatStr(Utils.TI18N("刷新次数:%d/%d"), this.data.count, max_num_cfg.val); // 按钮上刷新文字
 
      var btn_str = "";
      var res = "";
 
      if (this.data.free_count > 0) {
        var free_num_cfg = Config.exchange_data.data_shop_exchage_cost["max_free_times"];
        btn_str = cc.js.formatStr(Utils.TI18N("<color=#ffffff><outline=2,color=#2B610D>刷新(%d/%d)</outline></color>"), this.data.free_count, free_num_cfg.val);
      } else {
        var refresh_cost_cfg = Config.exchange_data.data_shop_list[MallConst.MallType.VarietyShop];
 
        if (refresh_cost_cfg && refresh_cost_cfg.cost_list) {
          var bid = refresh_cost_cfg.cost_list[0][0];
          var num = refresh_cost_cfg.cost_list[0][1];
          var item_config = Utils.getItemConfig(bid);
 
          if (item_config) {
            res = PathTool.getItemRes(item_config.icon);
            btn_str = cc.js.formatStr(Utils.TI18N("<img src='%s'/><color=#ffffff><outline=2,color=#2B610D> %d 刷新</outline></color>"), item_config.icon, num);
          }
        }
      }
 
      this.refresh_btn_label.string = btn_str;
 
      if (res) {
        this.loadRes(res, function (resObject) {
          this.refresh_btn_label.addSpriteFrame(resObject);
        }.bind(this));
      }
 
      if (this.data.refresh_time > 0) {
        var left_time = this.data.refresh_time - gcore.SmartSocket.getTime();
 
        if (left_time < 0) {
          left_time = 0;
          this.openRefreshTimer(false);
        } else {
          this.openRefreshTimer(true);
        }
 
        this.time_label.string = TimeTool.getTimeFormat(left_time);
      } else {
        this.openRefreshTimer(false);
        this.time_label.string = "0:00:00";
      }
    }
  },
  openRefreshTimer: function openRefreshTimer(status) {
    if (status == true) {
      if (this.refresh_timer == null) {
        this.refresh_timer = gcore.Timer.set(function () {
          if (this.data && this.data.refresh_time > 0) {
            var left_time = this.data.refresh_time - gcore.SmartSocket.getTime();
 
            if (left_time < 0) {
              gcore.Timer.del(this.refresh_timer);
              this.refresh_timer = null;
            }
 
            this.time_label.string = TimeTool.getTimeFormat(left_time);
          } else {
            this.time_label.string = "0:00:00";
            gcore.Timer.del(this.refresh_timer);
            this.refresh_timer = null;
          }
        }.bind(this), 1, -1);
      }
    } else {
      if (this.refresh_timer != null) {
        gcore.Timer.del(this.refresh_timer);
        this.refresh_timer = null;
      }
    }
  },
  _onClickCloseBtn: function _onClickCloseBtn() {
    this.ctrl.openVarietyStoreWindows(false);
  },
  _onClickRefreshBtn: function _onClickRefreshBtn() {
    if (this.data) {
      this.ctrl.sender13405(MallConst.MallType.VarietyShop);
    }
  },
  // 预制体加载完成之后,添加到对应主节点之后的回调,也就是一个窗体的正式入口,可以设置一些数据了
  openRootWnd: function openRootWnd(params) {
    this.ctrl.sender13403(MallConst.MallType.VarietyShop);
  },
  // 关闭窗体回调,需要在这里调用该窗体所属controller的close方法没用于置空该窗体实例对象
  closeCallBack: function closeCallBack() {
    if (this.item_scrollview) {
      this.item_scrollview.deleteMe();
      this.item_scrollview = null;
    }
 
    this.openRefreshTimer(false);
    this.ctrl.openVarietyStoreWindows(false);
  }
});
 
cc._RF.pop();