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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
//     这里是描述这个窗体的作用的
// <br/>Create: 2019-03-22 11:57:11
// --------------------------------------------------------------------
var PathTool = require("pathtool");
var BattleConst = require("battle_const");
var PlayerHead = require("playerhead");
var RoleController = require("role_controller");
var BattleController = require("battle_controller");
var BattleEvent = require("battle_event");
var CommonScrollView = require("common_scrollview");
var BattleDramaHookRewardListPanel = require("battle_drama_hook_reward_list_panel");
 
var Battle_mvpWindow = cc.Class({
    extends: BaseView,
    ctor: function () {
        this.prefabPath = PathTool.getPrefabPath("battle", "battle_mvp_view");
        this.viewTag = SCENE_TAG.dialogue;                //该窗体所属ui层级,全屏ui需要在ui层,非全屏ui在dialogue层,这个要注意
        this.win_type = WinType.Mini;               //是否是全屏窗体  WinType.Full, WinType.Big, WinType.Mini, WinType.Tips
        this.data = arguments[0];
 
        var data = this.data;
        this.result = data.result
        this.reward_list = data.item_rewards || {}
        this.fight_type = data.combat_type || BattleConst.Fight_Type.Darma
        this.partner_bid = data.partner_bid || 0
        this.partner_hurt = data.partner_hurt || 0
        this.partner_total_hurt = data.partner_total_hurt || 0
        this.role_exp = data.exp || 0
        this.role_lv = data.lev || 1
        this.role_nowlv = data.new_lev || 1
        this.role_nowexp = data.new_exp || 0;
        this.use_skin = data.use_skin || 0;
    },
 
    // 初始化一些配置数据,可以用于声明一些变量之类的
    initConfig: function () {
        this.ani_isover = false
        this.item_list = {}
 
        this.role_vo = RoleController.getInstance().getRoleVo();
        this.ctrl = BattleController.getInstance();
        this.model = this.ctrl.getModel();
    },
 
    // 预制体加载完成之后的回调,可以在这里捕获相关节点或者组件
    openCallBack: function () {
        this.main_container = this.seekChild("container");
        this.main_container.zIndex = 1;
        this.containerSize = this.main_container.getContentSize();
 
        this.background = this.root_wnd.getChildByName("background");
        this.background.scale = FIT_SCALE;
 
        this.auto_combat_num_lb = this.seekChild(this.main_container, "auto_combat_num", cc.Label);
        this.auto_combat_num_lb.node.active = false;
 
        this.seekChild("pic_mvp").zIndex = 1;
 
        this.time_label_rt = this.seekChild(this.main_container, "time_label", cc.RichText);
        this.time_label_rt.string = Utils.TI18N("5秒后关闭");
        this.time_label_rt.node.active = false;
        this.comfirm_btn = this.seekChild(this.main_container, "comfirm_btn");
        this.harm_btn = this.seekChild(this.main_container, "harm_btn");
 
        if (this.data && Utils.next(this.data) != null) {
            this.harm_btn.active = true;
        } else {
            this.harm_btn.active = false;
        }
 
        this.special_sk = this.seekChild(this.main_container, "play_effect", sp.Skeleton);
 
 
        //进度条
        this.progress_bg_nd = this.seekChild(this.main_container, "sprite_3");
        this.sprite_4_nd = this.seekChild(this.main_container, "sprite_4");
        this.progress_pb = this.seekChild(this.main_container, "sprite_3", cc.ProgressBar);
        this.progress_pb.progress = 0;
        this.proTxt_lb = this.seekChild(this.main_container, "proTxt", cc.Label);
        this.progress_bg_nd.active = false;
 
        //延迟0.3秒显示进度条动画
        Utils.delayRun(this.root_wnd, 0.3, function () {
            this.showProgressEffect();
        }.bind(this))
 
        //头像
        var sp_2 = this.seekChild(this.main_container, "sprite_2");
        this.head_icon = new PlayerHead();
        this.head_icon.setParent(sp_2);
        this.head_icon.show();
        this.head_icon.setScale(0.8);
        this.head_icon.setPosition(0, 0);
        this.head_icon.setHeadRes(this.role_vo.face_id);
 
        //等级
        this.roleLvTxt_lb = this.seekChild(this.main_container, "roleLvTxt", cc.Label);
        this.roleLvTxt_lb.string = cc.js.formatStr("Lv.%d", this.role_nowlv);
 
        var partner_config = Config.partner_data.data_partner_base[this.partner_bid];
        let skin_config = Config.partner_skin_data.data_skin_info[this.use_skin];
 
        this.mvp_con_nd = this.seekChild("mvp_con");
 
        //名称和立绘
        var pic_bg = this.seekChild(this.mvp_con_nd, "pic_bg");
        this.bust_icon_sp = this.seekChild("bustIcon", cc.Sprite);
        pic_bg.zIndex = 1;
        this.roleNameTxt_lb = this.seekChild(pic_bg, "roleNameTxt", cc.Label);
        if (partner_config) {
            this.roleNameTxt_lb.string = partner_config.name;
            var bustid = null;
            if(skin_config){
                bustid = skin_config.bustid;
            }else{
                bustid = partner_config.bustid;
            }
 
            var bust_res = PathTool.getPartnerBustRes(bustid);
            this.loadRes(bust_res, function (bg_sf) {
                this.bust_icon_sp.spriteFrame = bg_sf;
            }.bind(this));
        }
 
        //伤害输出
        var hurtTxt_lb = this.seekChild(pic_bg, "hurtTxt", cc.Label);
        var hurtPercent = cc.js.formatStr("%s", Math.floor(this.partner_hurt / this.partner_total_hurt * 100)) + "%";
        hurtTxt_lb.string = cc.js.formatStr("%d(%s)", Math.ceil(Number(this.partner_hurt)), hurtPercent);
 
        //显示特效
        this.handleEffect(true);
 
        this.scroll_con_nd = this.seekChild(this.main_container, "scroll_con");
        var tab_size = this.scroll_con_nd.getContentSize();
        var setting = {
            item_class: BattleDramaHookRewardListPanel,      // 单元类
            start_x: 94,                    // 第一个单元的X起点
            space_x: 20,                    // x方向的间隔
            start_y: 0,                    // 第一个单元的Y起点
            space_y: 0,                   // y方向的间隔
            item_width: 120,               // 单元的尺寸width
            item_height: 180,              // 单元的尺寸height
            row: 1,                        // 行数,作用于水平滚动类型
            col: 4,                        // 列数,作用于垂直滚动类型
            need_dynamic: true
        }
        this.scroll_view = new CommonScrollView();
        this.scroll_view.createScroll(this.scroll_con_nd, cc.v2(0, 0), ScrollViewDir.vertical, ScrollViewStartPos.top, tab_size, setting, cc.v2(0.5, 0.5))
        this.rewardViewUI();
    },
 
    // 注册事件监听的接口,不需要手动调用,如果是使用gcore.GlobalEvent监听,可以直接调用addGlobalEvent
    registerEvent: function () {
        Utils.onTouchEnd(this.comfirm_btn, function () {
            if (this.ani_isover) {
                this.ctrl.openFinishView(false, this.fight_type)
            }
        }.bind(this), 1)
        Utils.onTouchEnd(this.harm_btn, function () {
            if (this.data && Utils.next(this.data) != null) {
                this.ctrl.openBattleHarmInfoView(true, this.data);
            }
        }.bind(this), 1)
    },
 
    showProgressEffect: function () {
        var baseCurMaxExp = Config.role_data.data_role_attr[this.role_lv].exp_max;
        var basePercent = this.role_exp / baseCurMaxExp;
        var maxPercent = this.role_nowexp / baseCurMaxExp;
        if (this.role_lv != this.role_nowlv) {//有升级
            maxPercent = 1;
        }
        if (this.data.auto_num && this.data.auto_num > 0) {
            this.auto_combat_num_lb.node.active = true;
            this.auto_combat_num_lb.string = cc.js.formatStr(Utils.TI18N("已连续通过关卡数:%s"), this.data.auto_num);
        }
 
        this.progress_pb.progress = basePercent;
        this.proTxt_lb.string = cc.js.formatStr("%d/%d", Number(this.role_exp), Number(baseCurMaxExp));
        this.progress_bg_nd.active = true;
 
        var call_back = function () {
            basePercent = basePercent + 0.01;
            if (basePercent > maxPercent) {
                if (this.role_lv == this.role_nowlv) {
                    baseCurMaxExp = Config.role_data.data_role_attr[this.role_nowlv].exp_max;
                    basePercent = this.role_nowexp / baseCurMaxExp;
                    this.progress_pb.progress = basePercent;
                    this.proTxt_lb.string = cc.js.formatStr("%d/%d", this.role_nowexp, Number(baseCurMaxExp))
                    gcore.Timer.del("mvp_progress_timer");
                } else {
                    //播放升级特效
                    if (this.progressEffect == null) {
                        this.progressEffect = this.seekChild(this.sprite_4_nd, "effect", sp.Skeleton);
                        var res = cc.js.formatStr("spine/%s/action.atlas", PathTool.getEffectRes(275));
                        this.loadRes(res, function (res_object) {
                            this.progressEffect.skeletonData = res_object;
                            this.progressEffect.setAnimation(0, PlayerAction.action, false)
                        }.bind(this))
                    } else {
                        this.progressEffect.setAnimation(0, PlayerAction.action, false)
                    }
                    this.role_lv = this.role_lv + 1;
                    basePercent = 0;
                    maxPercent = 1;
                    baseCurMaxExp = Config.role_data.data_role_attr[this.role_lv].exp_max;
                    if (this.role_lv == this.role_nowlv) {
                        maxPercent = this.role_nowexp / Config.role_data.data_role_attr[this.role_nowlv].exp_max;
                    }
                }
            } else {
                this.progress_pb.progress = basePercent;
                this.proTxt_lb.string = cc.js.formatStr("%d/%d", Math.ceil(baseCurMaxExp * basePercent), Number(baseCurMaxExp))
            }
        }.bind(this)
        gcore.Timer.set(call_back, 10, -1, "mvp_progress_timer");
    },
 
    handleEffect: function (status) {
        if (status == false) {
            if (this.special_sk) {
                this.special_sk.setToSetupPose();
                this.special_sk.clearTracks();
                this.special_sk.node.active = false;
            }
            if (this.progressEffect) {
                this.progressEffect.setToSetupPose();
                this.progressEffect.clearTracks();
                this.progressEffect.node.active = false;
            }
        } else {
            if (this.special_sk) {
                this.special_sk.node.active = true;
                var res = cc.js.formatStr("spine/%s/action.atlas", PathTool.getEffectRes(274))
                this.loadRes(res, function (res_object) {
                    this.special_sk.skeletonData = res_object;
                    this.special_sk.setAnimation(1, PlayerAction.action_1, false)
                }.bind(this))
            }
        }
    },
 
    //奖励界面
    rewardViewUI: function () {
        if (!this.reward_list) return
        this.scroll_view.setData(this.reward_list, null, { is_show_name: true });
 
        Utils.delayRun(this.main_container, 0.5, function () {
            this.ani_isover = true;
            this.updateTimer();
        }.bind(this))
    },
 
    updateTimer: function () {
        this.time_label_rt.node.active = true;
        this.comfirm_btn.active = true;
        var time = 5;
        var call_back = function () {
            time = time - 1
            var new_time = Math.ceil(time);
            var str = new_time + Utils.TI18N("秒后关闭");
            if (this.time_label_rt) {
                this.time_label_rt.string = str;
            }
            if (new_time <= 0) {
                gcore.Timer.del("mvp_close_timer");
                this.ctrl.openFinishView(false, this.fight_type);
            }
        }.bind(this)
        gcore.Timer.set(call_back, 1000, -1, "mvp_close_timer");
    },
 
    // 预制体加载完成之后,添加到对应主节点之后的回调,也就是一个窗体的正式入口,可以设置一些数据了
    openRootWnd: function () {
 
    },
 
    // 关闭窗体回调,需要在这里调用该窗体所属controller的close方法没用于置空该窗体实例对象
    closeCallBack: function () {
        this.root_wnd.stopAllActions();
        this.main_container.stopAllActions();
 
        gcore.Timer.del("mvp_close_timer");
        gcore.Timer.del("mvp_progress_timer");
        require("hero_controller").getInstance().openEquipTips(false)
        require("tips_controller").getInstance().closeAllTips();
        
 
        if (this.fight_type == BattleConst.Fight_Type.Darma) {
            gcore.GlobalEvent.fire(BattleEvent.MOVE_DRAMA_EVENT, this.fight_type);
        }
        this.handleEffect(false)
        if (this.model.getBattleScene() && this.ctrl.getIsSameBattleType(this.fight_type)) {
            this.model.result(this.data, null)
        }
        if (this.scroll_view) {
            this.scroll_view.deleteMe();
            this.scroll_view = null;
        }
        this.ctrl.openFinishView(false, this.fight_type)
        gcore.Timer.set(function() {
            gcore.GlobalEvent.fire(BattleEvent.CLOSE_RESULT_VIEW, this.fight_type);
        }.bind(this), 200, 1)
       
    },
})