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
"use strict";
cc._RF.push(module, '88377cpDnpKV5ON+lkTC+0z', 'redbag_item');
// Scripts/mod/redbag/view/redbag_item.js
 
"use strict";
 
// --------------------------------------------------------------------
// @author: @syg.com(必填, 创建模块的人员)
// @description:
//      红包子项
// <br/>Create: new Date().toISOString()
// --------------------------------------------------------------------
var PathTool = require("pathtool");
 
var RedBagItem = cc.Class({
  "extends": BasePanel,
  ctor: function ctor() {
    this.prefabPath = PathTool.getPrefabPath("redbag", "redbag_item");
    this.data = null;
    this.item_list = {};
    this.is_show_point = false;
    this.open_type = 0;
    this.star_list = {};
    this.is_can_get = true;
    this.zindex = null;
    this.action = null;
    this.func = null;
    this.black_bool = null;
    this.scale = null;
  },
  initPanel: function initPanel() {
    this.main_panel = this.seekChild("main_panel");
    this.label_panel = this.seekChild("label_panel");
    this.title = this.seekChild(this.main_panel, "title", cc.Label);
    this.title.string = Utils.TI18N("我是红包标题"); //中间资产图标
 
    this.coin_icon = this.seekChild(this.main_panel, "coin_icon", cc.Sprite);
    var res = PathTool.getUIIconPath("redbag", "redbag_4");
    this.loadRes(res, function (sf_obj) {
      this.coin_icon.spriteFrame = sf_obj;
    }.bind(this)); //领完变灰
 
    this.black_bg = this.seekChild(this.main_panel, "black_bg");
    this.black_bg.active = true; //已领取标志
 
    this.finish_icon = this.seekChild(this.main_panel, "finish_icon");
    this.finish_icon.active = false; //红包状态
 
    this.status_icon = this.seekChild(this.main_panel, "status_icon", cc.Sprite);
    this.status_icon.node.active = false; //点击领取
 
    this.get_status = this.seekChild(this.main_panel, "get_status");
    this.get_status.active = false; //红包描述
 
    this.desc_label = this.seekChild(this.label_panel, "desc_label", cc.RichText); //发红包的人
 
    this.role_name = this.seekChild(this.label_panel, "role_name", cc.RichText);
    this.other_label = this.seekChild(this.label_panel, "other_label", cc.RichText);
    this.other_label.node.active = false;
    this.other_label.string = Utils.TI18N("向公会发送大量金币");
 
    if (this.zindex != null) {
      this.setLocalZOrder(this.zindex);
    }
 
    if (this.action != null) {
      this.runActionFunc(this.action, this.func);
    }
 
    if (this.black_bool != null) {
      this.showBlackBg(this.black_bool);
    }
 
    if (this.scale != null) {
      this.setScale(this.scale);
    }
  },
  registerEvent: function registerEvent() {
    this.root_wnd.on(cc.Node.EventType.TOUCH_END, function () {
      if (this.call_fun) {
        this.call_fun(this, this.data);
      }
    }.bind(this));
  },
  setData: function setData(vo) {
    var data = vo;
    if (vo.open_type != null && vo.open_type == 1) data = vo.data;
    this.open_type = vo.open_type || 0;
    this.data = data;
    if (this.root_wnd) this.onShow();
  },
  onShow: function onShow() {
    if (this.data == null) return;
    var data = this.data;
    var res = PathTool.getUIIconPath("redbag", "redbag_4");
 
    if (this.open_type == 1) {
      var str = data.name || "";
      this.title.string = str;
      this.role_name.string = "";
      this.desc_label.string = "";
      this.get_status.active = false;
      this.other_label.node.active = true;
      var desc = data.desc || "";
      this.other_label.string = desc;
      res = PathTool.getUIIconPath("redbag", data.res_name);
    } else {
      var name = data.name || "";
      var post_num = data.post || 3;
      var post_config = gdata("guild_data", "data_position", [post_num]);
 
      if (post_config) {
        var post = post_config.name || "";
        var str = cc.js.formatStr(Utils.TI18N("来自<color=#ffea96>%s</c>(%s)"), name, post);
        this.role_name.string = str;
      }
 
      var config = gdata("guild_data", "data_guild_red_bag", [data.type]);
 
      if (config) {
        var name = config.name || "";
        this.title.string = name;
        res = PathTool.getUIIconPath("redbag", config.res_name);
        this.desc_label.string = config.desc;
      }
 
      this.updateStatus(data);
    }
 
    this.loadRes(res, function (sf_obj) {
      this.coin_icon.spriteFrame = sf_obj;
    }.bind(this));
  },
  updateStatus: function updateStatus(data) {
    if (!data) return;
    this.is_can_get = true; //是否已经领完
 
    var get_num = data.num;
    var max_num = data.max_num;
    this.is_finish = false;
    if (get_num >= max_num) this.is_finish = true; //是否过期
 
    var less_time = data.time - gcore.SmartSocket.getTime();
    this.is_out_time = false;
    if (less_time <= 0) this.is_out_time = true; //是否自己领完了
 
    this.my_status = data.flag;
 
    if (this.my_status == 1) {
      this.finish_icon.active = true;
      this.is_can_get = false;
    } else {
      this.finish_icon.active = false;
    }
 
    var res;
 
    if (this.is_finish == true) {
      res = PathTool.getUIIconPath("redbag", "txt_cn_redbag_3");
      this.is_can_get = false;
    } else if (this.is_out_time == true) {
      res = PathTool.getUIIconPath("redbag", "txt_cn_redbag_1");
      this.is_can_get = false;
    }
 
    if (res) {
      this.loadRes(res, function (sf_obj) {
        this.status_icon.spriteFrame = sf_obj;
      }.bind(this));
    }
 
    var bool = this.is_finish || this.is_out_time;
    this.status_icon.node.active = bool;
    var bool = this.is_finish || this.is_out_time || this.my_status == 1;
    this.black_bg.active = bool;
    CommonAction.breatheShineAction3(this.get_status, 0.8, 0.8);
    this.get_status.active = this.is_can_get;
  },
  getIsCanGet: function getIsCanGet() {
    return this.is_can_get;
  },
  clickHandler: function clickHandler() {
    if (this.call_fun) this.call_fun(this.data);
  },
  addCallBack: function addCallBack(call_fun) {
    this.call_fun = call_fun;
  },
  showBlackBg: function showBlackBg(bool) {
    this.black_bool = bool;
    if (this.root_wnd == null) return;
    bool = bool || false;
    this.black_bg.active = bool;
  },
  setVisibleStatus: function setVisibleStatus(bool) {
    this.setVisible(bool);
  },
  getData: function getData() {
    return this.data;
  },
  setLocalZOrder: function setLocalZOrder(value) {
    this.zindex = value;
    if (this.root_wnd == null) return;
    this.root_wnd.zIndex = value;
  },
  setScale: function setScale(value) {
    this.scale = value;
    if (this.root_wnd == null) return;
    this.root_wnd.scale = value;
  },
  runActionFunc: function runActionFunc(action, func) {
    this.action = action;
    this.func = func;
    if (this.root_wnd == null) return;
    this.root_wnd.runAction(action, func);
  },
  onDelete: function onDelete() {}
});
module.exports = RedBagItem;
 
cc._RF.pop();