Log.js
9.39 KB
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
var Network = require('Network');
var Common = require('Common');
cc.Class({
extends: cc.Component,
properties: {
// foo: {
// default: null, // The default value will be used only when the component attaching
// to a node for the first time
// url: cc.Texture2D, // optional, default is typeof default
// serializable: true, // optional, default is true
// visible: true, // optional, default is true
// displayName: 'Foo', // optional
// readonly: false, // optional, default is false
// },
// ...
_iLogCount:0,
_oScene:null,
},
init: function (oScene) {
try {
this._oScene=oScene;
} catch (error) {
if (cc.sys.isNative){
jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V","init Error in Log==>"+error);
}
}
},
// use this for initialization
onLoad: function () {
try {
//设置本身节点的宽高透明
this.node.x=0;
this.node.y=0;
//this.node.width=Common.SCREEN_WIDTH-20;
//this.node.height=Common.SCREEN_HEIGHT;
this.node.width=Common.SCREEN_HEIGHT;
this.node.height=Common.SCREEN_WIDTH;
let nodeLogMask=new cc.Node('LogMask');
nodeLogMask.x=0;
nodeLogMask.y=0;
this.node.addChild(nodeLogMask,10);
//设置为全屏遮罩
let strLoadImagePath = 'Texture/splash_black';
Common.renderSpriteByLocalImage(strLoadImagePath,nodeLogMask.addComponent(cc.Sprite));
//因为纹理2*2所以这里写死了
//nodeLogMask.setScale(Common.SCREEN_WIDTH/2,Common.SCREEN_HEIGHT/2);
nodeLogMask.setScale(Common.SCREEN_HEIGHT/2,Common.SCREEN_WIDTH/2);
//nodeLogMask.opacity=100;
nodeLogMask.opacity = 100;
nodeLogMask.zIndex = 400;
let nodeLogList=new cc.Node('LogList');
let layoutLog = nodeLogList.addComponent(cc.Layout);
layoutLog.type = cc.Layout.Type.VERTICAL;
layoutLog.resizeMode = cc.Layout.ResizeMode.CONTAINER;
layoutLog.spacingY = 0;
//nodeLogList.x = 20 - Common.SCREEN_WIDTH/2;
//nodeLogList.y = Common.SCREEN_HEIGHT/2 - 20;
nodeLogList.x = -Common.SCREEN_WIDTH/2+290;
nodeLogList.y = Common.SCREEN_HEIGHT/2+270;
nodeLogList.setAnchorPoint(0,1);
this.node.addChild(nodeLogList,10);
nodeLogList.zIndex = 402;
//this.node.color=new cc.Color(0, 0, 0); //黑色
//this.node.cascadeOpacity=false;
//this.node.parent=this._oScene.node;
//this.node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(Texture2D.);
//parentNode.cascadeOpacity=false;
} catch (error) {
if (cc.sys.isNative){
jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V","onLoad Error in Log==>"+error);
}
}
},
//statics: {
serverD:function(strInfo){
},
screenD:function(strInfo){
try {
this.flushLogToScreen(strInfo,'Debug');
} catch (error) {
if (cc.sys.isNative){
jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V","screenD Error in Log==>"+error);
}
}
},
serverI:function(strInfo){
},
screenI:function(strInfo){
try {
if(strInfo){
this.flushLogToScreen(strInfo,'Info');
cc.log("Info:"+strInfo);
if (cc.sys.isNative){
jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V",strInfo);
}
}
} catch (error) {
if (cc.sys.isNative){
jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V","screenI Error in Log==>"+error);
}
}
},
serverW:function(strInfo){
},
screenW:function(strInfo){
try {
if(strInfo){
this.flushLogToScreen(strInfo,'Warning');
cc.log("Warning:"+strInfo);
if (cc.sys.isNative){
jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneW", "(Ljava/lang/String;)V",strInfo);
}
}
} catch (error) {
if (cc.sys.isNative){
jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V","screenW Error in Log==>"+error);
}
}
},
serverE:function(strInfo){
},
screenE:function(strInfo){
try {
if(strInfo){
this.flushLogToScreen(strInfo,'Error');
cc.log("strInfo:"+strInfo);
if (cc.sys.isNative){
jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneE", "(Ljava/lang/String;)V",strInfo);
}
}
} catch (error) {
if (cc.sys.isNative){
jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V","screenE Error in Log==>"+error);
}
}
},
flushLogToScreen:function(strInfo, strLevel){
try {
if(!Common.DEBUG_MODE){//todo:是否还有把日志显示在屏幕上的必要,目前是觉得没有的
return;
}
this._iLogCount++;
let nodeLogList = this.node.getChildByName("LogList");
//this._iLogCount = this._iLogCount%100;
let nodeInfo=new cc.Node('log_info_'+this._iLogCount);
let lblInfo=nodeInfo.addComponent(cc.Label);
lblInfo.string="("+this._iLogCount+"):"+strLevel+':'+strInfo;//+(nodeInfo.width/2-Common.SCREEN_WIDTH/2);
lblInfo.fontSize=10;
lblInfo.lineHeight=10;
//nodeInfo.parent=this.node;
nodeInfo.parent=nodeLogList;
switch(strLevel){
case 'Debug':
nodeInfo.color=new cc.color(51,255,255,255);
break;
case 'Info':
nodeInfo.color=new cc.color(51,255,51,255);
break;
case 'Warning':
nodeInfo.color=new cc.color(255,255,51,255);
break;
case 'Error':
nodeInfo.color=new cc.color(255,51,51,255);
break;
default:
nodeInfo.color=new cc.color(255,255,255,255);
}
//nodeInfo.color=new cc.color(255,255,255,255);
//nodeInfo.height=20;
//nodeInfo.y = -(this._iLogCount-1)*20;
nodeInfo.y = -(this._iLogCount-1)*10;
nodeInfo.height=10;
nodeInfo.setAnchorPoint(0,1);
nodeInfo.zIndex = 401;
//if(nodeLogList.height > Common.SCREEN_HEIGHT -20){
if(nodeLogList.height > Common.SCREEN_WIDTH){
nodeLogList.children[0].destroy();
}
} catch (error) {
if (cc.sys.isNative){
jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V","flushLogToScreen Error in Log==>"+error);
}
}
},
clearLogOnScreen : function () {
try {
let nodeLogList = this.node.getChildByName("LogList");
nodeLogList.destroy();
this._iLogCount = 0;
nodeLogList=new cc.Node('LogList');
nodeLogList.x = 20 - Common.SCREEN_WIDTH/2;
nodeLogList.y = Common.SCREEN_HEIGHT/2 - 20;
nodeLogList.setAnchorPoint(0,1);
this.node.addChild(nodeLogList,10);
nodeLogList.zIndex = 402;
} catch (error) {
if (cc.sys.isNative){
jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "logInSceneI", "(Ljava/lang/String;)V","clearLogOnScreen Error in Log==>"+error);
}
}
},
flushLogToServer:function(){
}
//TODO:需要加一个清除(所有条目全删除)和删除日志(一条一条删除)的函数
//}
// called every frame, uncomment this function to activate update callback
// update: function (dt) {
// },
});