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
"use strict";
cc._RF.push(module, '2bc87aFHBJOYol0HFhV/Kcp', 'guildwar_award_box_item');
// Scripts/mod/guildwar/view/guildwar_award_box_item.js
 
"use strict";
 
// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
//     这里是描述这个窗体的作用的
// <br/>Create: 2019-05-08 17:15:18
// --------------------------------------------------------------------
var PathTool = require("pathtool");
 
var GuildwarEvent = require("guildwar_event");
 
var GuildwarConst = require("guildwar_const");
 
var Guildwar_award_boxPanel = cc.Class({
  "extends": BasePanel,
  ctor: function ctor() {
    this.prefabPath = PathTool.getPrefabPath("guildwar", "guildwar_award_box_item");
  },
  // 可以初始化声明一些变量的
  initConfig: function initConfig() {
    this.ctrl = require("guildwar_controller").getInstance();
    this.model = this.ctrl.getModel();
    this.size = cc.size(206, 218);
  },
  // 初始化一些配置数据,可以用于声明一些变量之类的
  initPanel: function initPanel() {
    this.container = this.seekChild("container");
    this.iamge_box_sp = this.seekChild("image_box", cc.Sprite);
    this.name_txt_lb = this.seekChild("name_txt", cc.Label);
    this.name_txt_lb.node.active = false;
  },
  // 注册事件监听的接口,不需要手动调用,如果是使用gcore.GlobalEvent监听,可以直接调用addGlobalEvent
  registerEvent: function registerEvent() {
    // this.addGlobalEvent(GuildwarEvent.UpdateSingleBoxDataEvent, function () {
    //     this.onShow();
    // }, this)
    this.container.on(cc.Node.EventType.TOUCH_END, function () {
      if (this.data == null) return;
      this.ctrl.requestGetBoxAward(this.data.order);
    }, this);
  },
  setData: function setData(data) {
    if (this.data != null) {
      if (this.update_self_event != null) {
        this.data.unbind(this.update_self_event);
        this.update_self_event = null;
      }
    }
 
    if (data != null) {
      this.data = data;
 
      if (this.update_self_event == null) {
        this.update_self_event = this.data.bind(GuildwarEvent.UpdateSingleBoxDataEvent, function () {
          this.onShow();
        }, this);
      }
    }
 
    if (this.root_wnd) this.onShow(); // this.data = data;
    // if (this.root_wnd)
    //     this.onShow();
  },
  // 预制体加载完成之后,添加到对应主节点之后的回调可以设置一些数据了
  onShow: function onShow() {
    if (this.data == null) return; //是否已经被开启
 
    if (this.data.rid == 0) {
      this.iamge_box_sp.node.active = true;
      this.name_txt_lb.node.active = false;
 
      if (this.item_node) {
        this.item_node.setVisible(false);
      } //加载金或者铜宝箱,避免重复加载
 
 
      if (!this.load_image_flag) {
        this.load_image_flag = true;
 
        if (this.data.status == GuildwarConst.box_type.gold) {
          this.loadRes(PathTool.getUIIconPath("bigbg/guildwar", "guildwar_3"), function (sp) {
            this.iamge_box_sp.spriteFrame = sp;
          }.bind(this));
        } else if (this.data.status == GuildwarConst.box_type.copper) {
          this.loadRes(PathTool.getUIIconPath("bigbg/guildwar", "guildwar_4"), function (sp) {
            this.iamge_box_sp.spriteFrame = sp;
          }.bind(this));
        }
      }
    } else {
      this.iamge_box_sp.node.active = false;
      this.name_txt_lb.node.active = true;
 
      if (this.item_node == null) {
        this.item_node = ItemsPool.getInstance().getItem("backpack_item");
        this.item_node.initConfig(false, 1, false, true);
        this.item_node.setPosition(0, 20);
        this.item_node.show();
        this.item_node.setParent(this.container);
      }
 
      this.item_node.setVisible(true);
      this.item_node.setData({
        bid: this.data.item_id,
        num: this.data.item_num
      });
      this.name_txt_lb.string = this.data.name;
 
      var role_vo = require("role_controller").getInstance().getRoleVo();
 
      if (this.data.rid == role_vo.rid && this.data.sid == role_vo.srv_id) {
        this.name_txt_lb.node.color = new cc.Color(36, 144, 3);
      }
    }
  },
  // 面板设置不可见的回调,这里做一些不可见的屏蔽处理
  onHide: function onHide() {},
  suspendAllActions: function suspendAllActions() {
    if (this.data != null) {
      if (this.update_self_event != null) {
        this.data.unbind(this.update_self_event);
        this.update_self_event = null;
      }
 
      this.data = null;
    }
  },
  // 当面板从主节点释放掉的调用接口,需要手动调用,而且也一定要调用
  onDelete: function onDelete() {
    if (this.item_node) {
      this.item_node.deleteMe();
      this.item_node = null;
    }
 
    this.suspendAllActions();
  }
});
 
cc._RF.pop();