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
"use strict";
cc._RF.push(module, '5eb4e8Vy5dIzZW42xAX+Xy4', 'action_time_gift_item');
// Scripts/mod/action/view/action_time_gift_item.js
 
"use strict";
 
var PathTool = require("pathtool");
 
var TimeTool = require("timetool");
 
var actionTimeGiftPanel = cc.Class({
  "extends": BasePanel,
  ctor: function ctor() {
    this.prefabPath = PathTool.getPrefabPath("action", "action_time_gift_big_panel");
  },
  // 可以初始化声明一些变量的
  initConfig: function initConfig() {
    this.itemArr = [];
  },
  // 初始化一些配置数据,可以用于声明一些变量之类的
  initPanel: function initPanel() {
    var sp = this.seekChild("bg", cc.Sprite);
    this.loadRes(PathTool.getBigBg("action/action_time_gift_bg"), function (res) {
      sp.spriteFrame = res;
    }.bind(this));
    var text_sp = this.seekChild("text", cc.Sprite);
    this.loadRes(PathTool.getUIIconPath("timegiftbig", "time_gift_big_text_1"), function (res) {
      text_sp.spriteFrame = res;
    }.bind(this));
    var jia_sp = this.seekChild("jia", cc.Sprite);
    this.loadRes(PathTool.getUIIconPath("timegiftbig", "time_gift_big_text_jia"), function (res) {
      jia_sp.spriteFrame = res;
    }.bind(this));
    var percent_sp = this.seekChild("timegiftbig_percent", cc.Sprite);
    this.loadRes(PathTool.getUIIconPath("timegiftbig", "timegiftbig_percent"), function (res) {
      percent_sp.spriteFrame = res;
    }.bind(this));
    this.num_lb = this.seekChild("num", cc.Label);
    this.rmb_lb = this.seekChild("Label", cc.Label);
    this.buyCount_lb = this.seekChild("text", cc.Label);
    this.buy_btn = this.seekChild("buy_btn", cc.Button);
    this.goods_list = this.seekChild("goods_list", cc.Layout);
    this.time_lb = this.seekChild("time", cc.Label);
 
    if (this.data) {
      this.setData(this.data);
    }
  },
  // 注册事件监听的接口,不需要手动调用,如果是使用gcore.GlobalEvent监听,可以直接调用addGlobalEvent
  registerEvent: function registerEvent() {
    this.buy_btn.node.on('click', function () {
      var config = Config.tri_gift_data.data_limit_gift[this.data.id];
      var charge_config = Config.charge_data.data_charge_data[config.package_id || 0];
 
      if (charge_config) {
        SDK.pay(charge_config.val, null, charge_config.id, charge_config.name, charge_config.name);
      }
    }.bind(this));
  },
  onShow: function onShow(data) {},
  setData: function setData(data) {
    this.data = data;
    if (!this.root_wnd) return;
    var config = Config.tri_gift_data.data_limit_gift[data.id];
    if (!config) return;
    this.buyCount_lb.string = Utils.TI18N(cc.js.formatStr("限购:%d/%d", data.num, config.limit_num));
 
    if (this.itemArr.length == 0) {
      //只首次进入
      this.loadRes(PathTool.getUIIconPath("timegiftbig", "time_gift_big_num", "labelatlas"), function (res) {
        this.num_lb.font = res;
        this.num_lb.string = config.desc;
      }.bind(this));
      var chargeConfig = Config.charge_data.data_charge_data[config.package_id];
 
      if (chargeConfig) {
        this.rmb_lb.string = Utils.TI18N(chargeConfig.val + "元");
      }
 
      var reward = config.reward;
      var scale;
 
      if (reward.length > 4) {
        scale = 0.8;
        this.goods_list.type = cc.Layout.Type.GRID;
        this.goods_list.spacingX = 20;
        this.goods_list.spacingY = 15;
        this.goods_list.node.width = 450;
      } else {
        scale = 0.9;
        this.goods_list.type = cc.Layout.Type.HORIZONTAL;
        this.goods_list.node.width = 0;
        this.goods_list.spacingX = 8;
      }
 
      this.setLessTime();
      this.time_ticket = gcore.Timer.set(function () {
        this.setLessTime();
      }.bind(this), 1000, -1);
      this.updateItem = this.startUpdate(reward.length, function (index) {
        var node = new cc.Node();
        node.setContentSize(120 * scale, 120 * scale);
        this.goods_list.node.addChild(node);
        var item = ItemsPool.getInstance().getItem("backpack_item");
        item.initConfig(false, scale, false, true);
        item.setParent(node);
        item.show();
        item.setData({
          bid: reward[index][0],
          num: reward[index][1]
        });
        this.itemArr.push(item);
      }.bind(this));
 
      if (this.item_callback) {
        this.item_callback(this);
      }
    }
 
    if (data.num >= config.limit_num) {
      this.buy_btn.interactable = false;
      this.buy_btn.enableAutoGrayEffect = true;
      this.rmb_lb.node.getComponent(cc.LabelOutline).enabled = false;
    }
  },
  // 面板设置不可见的回调,这里做一些不可见的屏蔽处理
  onHide: function onHide() {},
  setLessTime: function setLessTime() {
    var time = this.data.end_time - gcore.SmartSocket.getTime();
 
    if (time <= 0) {
      time = 0;
 
      if (this.time_ticket) {
        gcore.Timer.del(this.time_ticket);
        this.time_ticket = null;
        this.buy_btn.interactable = false;
        this.buy_btn.enableAutoGrayEffect = true;
        this.rmb_lb.node.getComponent(cc.LabelOutline).enabled = false;
      }
    }
 
    var time_desc = TimeTool.getTimeForFunction(time);
    this.time_lb.string = Utils.TI18N(time_desc + "后礼包消失");
  },
  addCallFunc: function addCallFunc(callFunc) {
    this.item_callback = callFunc;
  },
  // 当面板从主节点释放掉的调用接口,需要手动调用,而且也一定要调用
  onDelete: function onDelete() {
    if (this.time_ticket) {
      gcore.Timer.del(this.time_ticket);
      this.time_ticket = null;
    }
 
    if (this.updateItem) {
      gcore.Timer.del(this.updateItem);
      this.updateItem = null;
    }
 
    if (this.itemArr) {
      for (var i = 0; i < this.itemArr.length; ++i) {
        if (this.itemArr[i]) {
          this.itemArr[i].deleteMe();
          this.itemArr[i] = null;
        }
      }
 
      this.itemArr = null;
    }
  }
});
 
cc._RF.pop();