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
// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
//     这里是描述这个窗体的作用的
// <br/>Create: 2019-05-09 10:03:33
// --------------------------------------------------------------------
var PathTool = require("pathtool");
var AdventureActivityConst= require("adventureactivity_const");
var MainuiController = require("mainui_controller");
var AdventureActivityController = require("adventureactivity_controller");
var AdventureController = require("adventure_controller");
 
var Adventureactivity_itemPanel = cc.Class({
    extends: BasePanel,
    ctor: function () {
        this.prefabPath = PathTool.getPrefabPath("adventureactivity", "adventureactivity_item");
        this.ctrl = AdventureActivityController.getInstance();
    },
 
    // 可以初始化声明一些变量的
    initConfig:function(){
 
    },
 
    // 初始化一些配置数据,可以用于声明一些变量之类的
    initPanel:function(){
        this.main_container = this.root_wnd.getChildByName("main_container");
        this.item_bg_node = this.main_container.getChildByName("item_bg");
        this.item_bg = this.item_bg_node.getComponent(cc.Sprite);
        this.open_desc = this.main_container.getChildByName("open_desc").getComponent(cc.Label);
        this.open_desc.node.active = false;
        this.open_desc2 = this.main_container.getChildByName("open_desc_2").getComponent(cc.Label);
        this.open_desc2.node.active = false;
 
        this.join_bg = this.main_container.getChildByName("join_bg");
        this.join_desc = this.main_container.getChildByName("join_desc").getComponent(cc.Label);
        this.join_desc.string = "";
        this.lock_layer = this.main_container.getChildByName("lock_layer");
        this.award_list = this.main_container.getChildByName("award_list");
        this.award_list.active = false;
        var scroll_view_size = this.award_list.getContentSize();
        var setting = {
            item_class: "backpack_item",      // 单元类
            start_x: 0,                  // 第一个单元的X起点
            space_x: 10,                    // x方向的间隔
            start_y: 0,                    // 第一个单元的Y起点
            space_y: 0,                   // y方向的间隔
            item_width: 120*0.7,               // 单元的尺寸width
            item_height: 120*0.7,              // 单元的尺寸height
            row: 1,                        // 行数,作用于水平滚动类型
            col: 0,                         // 列数,作用于垂直滚动类型
            need_dynamic: true,
            scale: 0.7
        }
        var CommonScrollView = require("common_scrollview");
        this.award_scrollview = new CommonScrollView();
        this.award_scrollview .createScroll(this.award_list, cc.v2(0,0) , ScrollViewDir.horizontal, ScrollViewStartPos.top, scroll_view_size, setting);
        // this.award_scrollview:setSwallowTouches(false)
 
        if(this.data){
            this.updateInfo();
        }
    },
 
    // 注册事件监听的接口,不需要手动调用,如果是使用gcore.GlobalEvent监听,可以直接调用addGlobalEvent
    registerEvent:function(){
        //当用户点击的时候记录鼠标点击状态
        this.main_container.on(cc.Node.EventType.TOUCH_START, function(event){
            var touches = event.getTouches();
            this.touch_began = touches[0].getDelta();
        },this);
 
        //当鼠标抬起的时候恢复状态
        this.main_container.on(cc.Node.EventType.TOUCH_END, function(event){
            var touches = event.getTouches();
            this.touch_end = touches[0].getDelta();
            var is_click = true;
            if(this.touch_began!=null){
                is_click = Math.abs(this.touch_end.x - this.touch_began.x) <= 20 && Math.abs(this.touch_end.y - this.touch_began.y) <= 20;
            }
            if(is_click){
                if(this.data){
                    var is_open = MainuiController.getInstance().checkIsOpenByActivate(this.data.activate);
                    if(is_open == true){
                        this.ctrl.onClickGotoAdvenTureAcivity(this.data.retrue_id);
                    }else{
                        if(this.data.id == AdventureActivityConst.Ground_Type.heaven){
                            var str = cc.js.formatStr(Utils.TI18N("%s,角色%s可进入"),this.data.desc2,this.data.desc);
                            message(str);
                        }else{
                            message(this.data.desc)
                        }
                    }
                }
            }
        },this);
    },
 
    setData:function(data){
        if(!data)return;
        this.data = data;
        if(this.root_wnd){
            this.updateInfo();
        }
    },
    
    updateInfo:function(){
        // 背景
        var res = PathTool.getBigBg(cc.js.formatStr("txt_cn_adventrueactivity_%d", this.data.res_id),null,"adventrueactivity");
        this.loadRes(res, (function(resObject){
            this.item_bg.spriteFrame = resObject;
        }).bind(this));
        this.join_desc.string = this.data.item_desc;
 
        var size = this.join_desc.node.getContentSize();
        if(size.width < 250){
            size.width = 250;
        }
        this.join_bg.setContentSize(cc.size(size.width+60, size.height));
        // 奖励数据
        var item_list = [];
        for(var i in this.data.award){
            var v = this.data.award[i];
            var vo = {};
            if(vo){
                vo.bid = v[0];
                vo.num = v[1];
                item_list.push(vo);
            }
        }
        this.award_scrollview.setData(item_list);
        this.award_scrollview.addEndCallBack(function(){
            var list = this.award_scrollview.getItemList();
            // var book_id_cfg = Config.dungeon_heaven_data.data_const["heaven_handbook"];
            for(var k in list){
                var iData = list[k].getData();
                var is_special;
                // if(this.data.id == AdventureActivityConst.Ground_Type.heaven && book_id_cfg && iData){
                //     for(var n in book_id_cfg.val){
                //         if(book_id_cfg.val[n] == iData.id){
                //             is_special = 2;
                //             break;
                //         }
                //     }
                // }
                list[k].setDefaultTip(true, null, null, is_special);
            }
        }.bind(this));
 
        var is_open = MainuiController.getInstance().checkIsOpenByActivate(this.data.activate);
        if(is_open == true){
            this.lock_layer.active = false;
            this.open_desc.node.active = false;
            this.award_list.active = true;
        }else{
            this.lock_layer.active = true;
            this.open_desc.string = this.data.desc;
            this.open_desc.node.active = true;
            if(this.data.desc != ""){
                this.open_desc2.string = this.data.desc2;
                this.open_desc2.node.active = true;
            }
            this.award_list.active = false;
        }
        this.updateRedStatus();
    },
 
    //  红点刷新
    updateRedStatus:function(){
        if(this.data){
            var red_status = false;
            if(this.data.id == AdventureActivityConst.Ground_Type.adventure){ //冒险
                red_status = AdventureController.getInstance().getModel().getAdventureRedPoint();
            }else if(this.data.id == AdventureActivityConst.Ground_Type.element){ //元素
                // red_status = ElementController:getInstance():getModel():checkElementRedStatus();
            }else if(this.data.id == AdventureActivityConst.Ground_Type.heaven){ //天界副本
                // red_status = HeavenController:getInstance():getModel():getHeavenRedStatus();
            }
            var is_open = MainuiController.getInstance().checkIsOpenByActivate(this.data.activate);
            if(is_open == false){
                red_status = false;
            }
            Utils.addRedPointToNodeByStatus(this.main_container, red_status, this.main_container.width/2, this.main_container.height/2, 99, 2)
        }
    },
    // 预制体加载完成之后,添加到对应主节点之后的回调可以设置一些数据了
    onShow:function(params){
 
    },
 
    // 面板设置不可见的回调,这里做一些不可见的屏蔽处理
    onHide:function(){
 
    },
 
    // 当面板从主节点释放掉的调用接口,需要手动调用,而且也一定要调用
    onDelete:function(){
        if(this.award_scrollview){
            this.award_scrollview.deleteMe();
            this.award_scrollview = null;
        }
    },
})