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
// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
//     联盟战 据点
// <br/>Create: 2019-05-08 10:14:55
// --------------------------------------------------------------------
var PathTool = require("pathtool");
var GuildwarConst = require("guildwar_const");
var RoleController = require("role_controller")
var GuildwarEvent = require("guildwar_event");
 
var Guildwar_position_itemPanel = cc.Class({
    extends: BasePanel,
    ctor: function () {
        this.prefabPath = PathTool.getPrefabPath("guildwar", "guildwar_position");
    },
 
    // 可以初始化声明一些变量的
    initConfig: function () {
        this.star_list = {};
        this.ctrl = require("guildwar_controller").getInstance();
        this.model = this.ctrl.getModel();
        this.color_1 = new cc.Color(123, 194, 244);
        this.color_2 = new cc.Color(244, 140, 123);
    },
 
    // 初始化一些配置数据,可以用于声明一些变量之类的
    initPanel: function () {
        this.container = this.seekChild("container");
 
        this.build_sp = this.seekChild("build", cc.Sprite);
        this.name_label_lb = this.seekChild("name_label", cc.Label);
        this.attk_label_lb = this.seekChild("attk_label", cc.Label);
        this.pos_bg_nd = this.seekChild("pos_bg");
        this.pos_label_lb = this.seekChild(this.pos_bg_nd, "pos_label", cc.Label);
        this.image_success_nd = this.seekChild("image_success");
        this.image_success_nd.zIndex = 10;
        this.image_buff = this.seekChild(this.image_success_nd,"image_buff", cc.Sprite);
        this.loadRes(PathTool.getIconPath("bufficon", "2"), function (sp) {
                this.image_buff.spriteFrame = sp;
            }.bind(this))
        var temp_index = {
            [1]: 3,
            [2]: 2,
            [3]: 1
        }
        for (var i = 1; i <= 3; i++) {
            var star = this.seekChild("star_" + i);
            if (star) {
                star.active = false;
                var index = temp_index[i];
                this.star_list[index] = star;
            }
        }
 
 
        if (this.parent_nd) {
            this.setParentIndex(this.parent_nd, this.z_index);
        }
    },
 
    // 注册事件监听的接口,不需要手动调用,如果是使用gcore.GlobalEvent监听,可以直接调用addGlobalEvent
    registerEvent: function () {
        Utils.onTouchEnd(this.container, function () {
            if (this.cur_position_type == GuildwarConst.positions.others && this.data && this.data.pos) {
                var guildwar_status = this.model.getGuildWarStatus();
                if (guildwar_status == GuildwarConst.status.settlement) {
                    message(Utils.TI18N("本次公会战已结束啦,不能再挑战了哦"));
                } else {
                    this.ctrl.openAttkPositionWindow(true, this.data.pos);
                }
            } else if (this.cur_position_type == GuildwarConst.positions.myself && this.data && this.data.pos) {
                var role_vo = RoleController.getInstance().getRoleVo();
                if (role_vo.gid != 0) {
                    this.ctrl.openDefendLookWindow(true, role_vo.gid, role_vo.gsrv_id, this.data.pos) // 我方据点直接打开据点防守记录
                }
            }
        }.bind(this), 1)
    },
 
    setData: function (data, position_type) {
        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.UpdateGuildWarPositionDataEvent, function () {
                    this.onShow();
                }, this)
            }
        }
        this.cur_position_type = position_type;
        if (this.root_wnd)
            this.onShow();
    },
 
    // 预制体加载完成之后,添加到对应主节点之后的回调可以设置一些数据了
    onShow: function (params) {
        if (this.data == null) return
        if (this.data.hp == 0) {
            this.loadRes(PathTool.getUIIconPath("guildwar", "guildwar_1020"), function (sp) {
                this.build_sp.spriteFrame = sp;
            }.bind(this))
            if (!this.special_sk) {
                this.special_sk = this.seekChild("special_sk", sp.Skeleton);
                var res = cc.js.formatStr("spine/%s/action.atlas", PathTool.getEffectRes(326))
                this.loadRes(res, function (res_object) {
                    this.special_sk.skeletonData = res_object;
                    this.special_sk.setAnimation(1, PlayerAction.action, true)
                }.bind(this))
            }
            this.special_sk.node.active = true;
        } else {
            this.loadRes(PathTool.getUIIconPath("guildwar", "guildwar_1017"), function (sp) {
                this.build_sp.spriteFrame = sp;
            }.bind(this))
            if (this.special_sk) {
                this.special_sk.node.active = false;
            }
        }
        for (var i = 1; i < 4; i++) {
            var star = this.star_list[i];
            if (this.data.hp < i) {
                star.active = true;
            } else {
                star.active = false;
            }
        }
 
        this.pos_label_lb.string = this.data.pos;
 
        var guild_srvid = "";
        if (this.cur_position_type == GuildwarConst.positions.others) {
            var enemy_baseinfo = this.model.getEnemyGuildWarBaseInfo();
            guild_srvid = enemy_baseinfo.g_sid || "";
        } else {
            var role_vo = RoleController.getInstance().getRoleVo();
            guild_srvid = role_vo.gsrv_id || "";
        }
 
        var index = guild_srvid.search("_");
        var srv_index = 1;
        if (index != null) {
            srv_index = guild_srvid.substring(index + 1);
        }
        var name_str = cc.js.formatStr("[S%s]%s", srv_index, this.data.name);
        this.name_label_lb.string = name_str;
        this.attk_label_lb.string = Utils.TI18N(cc.js.formatStr("战力:%d", this.data.power));
 
        this.image_success_nd.active = false;
        if (this.cur_position_type == GuildwarConst.positions.myself) {
            this.name_label_lb.node.color = this.color_1;
        } else {
            this.name_label_lb.node.color = this.color_2;
            this.image_success_nd.active = this.data.hp <= 0;
        }
        var name_size = this.name_label_lb.node.getContentSize();
        var name_pos_x = this.name_label_lb.node.x;
        this.pos_bg_nd.x = name_pos_x - name_size.width / 2;
    },
 
    //获取pos
    getPositionPos: function () {
        return this.data.pos
    },
 
    suspendAllActions: function () {
        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;
        }
    },
 
    getPosition: function () {
        if (this.root_wnd) {
            return cc.v2(this.root_wnd.x, this.root_wnd.y)
        } else {
            return cc.v2(0, 0);
        }
    },
 
    setParentIndex: function (parent, index) {
        if (this.root_wnd) {
            parent.addChild(this.root_wnd, index);
        } else {
            this.parent_nd = parent;
            this.z_index = index;
        }
    },
 
    // 面板设置不可见的回调,这里做一些不可见的屏蔽处理
    onHide: function () {
 
    },
 
    // 当面板从主节点释放掉的调用接口,需要手动调用,而且也一定要调用
    onDelete: function () {
        if (this.special_sk) {
            this.special_sk.setToSetupPose();
            this.special_sk.clearTracks();
        }
        this.suspendAllActions();
    },
})